6 #include "common/version.h"
9 #define STRINGIFY(x) _STR(x)
13 void BackTrace::print(std::ostream& out) const
15 out << " " << pretty_version_to_str() << std::endl;
16 for (size_t i = skip; i < size; i++) {
17 // out << " " << (i-skip+1) << ": " << strings[i] << std::endl;
19 size_t sz = 1024; // just a guess, template names will go much wider
20 char *function = (char *)malloc(sz);
23 char *begin = 0, *end = 0;
25 // find the parentheses and address offset surrounding the mangled name
27 static constexpr char OPEN = '<';
29 static constexpr char OPEN = '(';
31 for (char *j = strings[i]; *j; ++j) {
38 int len = end - begin;
39 char *foo = (char *)malloc(len+1);
44 memcpy(foo, begin, len);
49 // only demangle a C++ mangled name
50 if (foo[0] == '_' && foo[1] == 'Z')
51 ret = abi::__cxa_demangle(foo, function, &sz, &status);
53 // return value may be a realloc() of the input
57 // demangling failed, just pretend it's a C function with no args
58 strncpy(function, foo, sz);
59 strncat(function, "()", sz);
62 out << " " << (i-skip+1) << ": " << OPEN << function << end << std::endl;
63 //fprintf(out, " %s:%s\n", stack.strings[i], function);
66 // didn't find the mangled name, just print the whole line
67 out << " " << (i-skip+1) << ": " << strings[i] << std::endl;