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