Use a simple deallocator for backtrace info
Clang doesn't like using the array form of unique_ptr with backtrace calls for some reason. Less important to figure this out.
This commit is contained in:
parent
6ff8405c6a
commit
f5fa3219b4
@ -1,6 +1,7 @@
|
|||||||
#include "backtrace.hpp"
|
#include "backtrace.hpp"
|
||||||
|
|
||||||
#include "debug.hpp"
|
#include "debug.hpp"
|
||||||
|
#include "types/casts.hpp"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
@ -14,7 +15,7 @@ debug::backtrace::backtrace (void):
|
|||||||
m_frames (DEFAULT_DEPTH) {
|
m_frames (DEFAULT_DEPTH) {
|
||||||
|
|
||||||
int final;
|
int final;
|
||||||
while ((final = ::backtrace (&m_frames[0], m_frames.size ())) == m_frames.size ())
|
while ((final = ::backtrace (&m_frames[0], m_frames.size ())) == sign_cast<ssize_t> (m_frames.size ()))
|
||||||
m_frames.resize (m_frames.size () * 2);
|
m_frames.resize (m_frames.size () * 2);
|
||||||
|
|
||||||
CHECK_HARD (final > 0);
|
CHECK_HARD (final > 0);
|
||||||
@ -26,11 +27,12 @@ ostream&
|
|||||||
debug::operator <<(ostream &os, const debug::backtrace &rhs) {
|
debug::operator <<(ostream &os, const debug::backtrace &rhs) {
|
||||||
const auto frames = rhs.frames ();
|
const auto frames = rhs.frames ();
|
||||||
|
|
||||||
typedef unique_ptr<char *[], decltype(&std::free)> unique_str;
|
// We don't use the array form of unique_ptr as clang fails on ambigious constructors
|
||||||
unique_str names (backtrace_symbols (&frames[0], frames.size ()), std::free);
|
typedef unique_ptr<char *, decltype(&std::free)> unique_str;
|
||||||
|
unique_str names (backtrace_symbols (frames.data (), frames.size ()), ::free);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < frames.size (); ++i)
|
for (unsigned int i = 0; i < frames.size (); ++i)
|
||||||
os << frames[i] << "\t" << names[i] << "\n";
|
os << frames[i] << "\t" << names.get()[i] << "\n";
|
||||||
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user