22 #include <drizzled/util/backtrace.h>
30 # ifdef HAVE_BACKTRACE
31 # include <execinfo.h>
33 # endif // HAVE_BACKTRACE
41 void custom_backtrace(
const char *file,
int line,
const char *func,
size_t depth)
43 (void)file; (void)line; (void)func; (void)depth;
47 size_t size= backtrace(array, 50);
48 char **strings= backtrace_symbols(array, size);
55 std::cerr << std::endl <<
"call_backtrace(" << size <<
") began at " << file <<
":" << line <<
" for " << func <<
"()" << std::endl;
63 depth= std::min(depth, size);
66 char *named_function= (
char *)::realloc(NULL, 1024);
68 if (named_function == NULL)
74 for (
size_t x= 1; x < depth; x++)
79 char *named_function_ptr= (
char *)::realloc(named_function, sz);
80 if (named_function_ptr == NULL)
84 named_function= named_function_ptr;
87 char *begin_offset= 0;
90 for (
char *j= strings[x]; *j; ++j)
100 else if (*j ==
')' and begin_offset)
107 if (begin_name and begin_offset and end_offset and begin_name < begin_offset)
110 *begin_offset++=
'\0';
114 char *ret= abi::__cxa_demangle(begin_name, named_function, &sz, &status);
118 std::cerr <<
" " << strings[x] <<
" : " << begin_name <<
"() + " << begin_offset << std::endl;
122 std::cerr <<
" " << strings[x] <<
" : " << begin_name <<
"() + " << begin_offset << std::endl;
127 std::cerr <<
" " << strings[x] << std::endl;
132 std::cerr <<
" unmangled:" << strings[x] << std::endl;
136 ::free(named_function);
138 #endif // HAVE_BACKTRACE