8 #include <boost/algorithm/string.hpp>
19 char **strs = backtrace_symbols(callstack, frames);
23 for (
int i = 0; i < frames; ++i) {
25 std::vector<std::string> SplitVec;
27 if (i == frames - 1)
continue;
28 boost::split(SplitVec, strs[i], boost::is_any_of(
"()"),
29 boost::token_compress_on);
30 boost::split(SplitVec, SplitVec[1], boost::is_any_of(
"+"),
31 boost::token_compress_on);
33 abi::__cxa_demangle(SplitVec[0].c_str(), NULL, NULL, &status);
37 if (!strstr(demangledName,
"boost::") &&
38 !strstr(demangledName,
"tbb::") &&
39 !strstr(demangledName,
"BackTrace::") &&
40 !strstr(demangledName,
"BgpDebug::") &&
41 !strstr(demangledName,
"testing::")) {
42 len = snprintf(str, buf_len - (str - buf),
43 "\t%s+%s\n", demangledName,
44 SplitVec[line_pos].c_str());
45 if (len > buf_len - (str - buf)) {
49 str += buf_len - (str - buf);
50 assert((
size_t) (str - buf) == buf_len);
64 callstack = (
void *
const *) calloc(1024,
sizeof(
void *));
65 return backtrace((
void **) callstack, 1024);
69 const std::string &msg) {
72 ToString(callstack, frames, buf,
sizeof(buf));
73 std::string s(buf, strlen(buf));
74 LOG(DEBUG, msg <<
":BackTrace\n" << s);
75 free((
void *) callstack);
79 void *
const*callstack;
81 int frames =
Get(callstack);
82 Log(callstack, frames, msg);
static int Get(void *const *&callstack)
static ssize_t ToString(void *const *callstack, int frames, char *buf, size_t buf_len)
static void Log(const std::string &msg)
#define LOG(_Level, _Msg)