26 stackStrings = backtrace_symbols(stackTrace, stackDepth);
32 exeSize = readlink(
"/proc/self/exe", exe, PATH_MAX);
34 dprintf(fd,
"Unable to detect exectuable name\n");
37 dprintf(fd,
"Executable is %.*s\n", exeSize, exe);
43 for (
size_t i = 1;
i < stackDepth;
i++) {
46 char* function =
static_cast<char*
>(malloc(sz));
47 char *begin =
nullptr, *
end =
nullptr;
50 for (
char*
j = stackStrings[
i]; *
j; ++
j) {
51 if (*
j ==
' ' && *(
j + 1) !=
'+') {
53 }
else if (*
j ==
' ' && *(
j + 1) ==
'+') {
58 bool tryAddr2Line =
false;
60 for (
char*
j = stackStrings[
i];
j && *
j; ++
j) {
63 }
else if (*
j ==
'+') {
68 bool tryAddr2Line =
true;
77 char* ret = abi::__cxa_demangle(begin, function, &sz, &status);
81 dprintf(fd,
" %s: %s\n", stackStrings[
i], function);
89 dprintf(fd,
" %s: ", stackStrings[
i]);
90 if (stackTrace[
i] && hasExe) {
91 char syscom[4096 + PATH_MAX];
95 static char const* cxxfilt = getenv(
"CXXFILT");
96 if (cxxfilt ==
nullptr) {
100 static char const* addr2line = getenv(
"ADDR2LINE");
101 if (addr2line ==
nullptr) {
102 addr2line =
"addr2line";
104 snprintf(syscom, 4096,
"%s %p -p -s -f -e %.*s 2>/dev/null | %s ", addr2line, stackTrace[
i], exeSize, exe, cxxfilt);
109 fp = popen(syscom,
"r");
113 dprintf(fd,
"%s\n", begin);
118 while (fgets(
path,
sizeof(
path) - 1, fp) !=
nullptr) {
119 dprintf(fd,
" %s",
path);
124 dprintf(fd,
"%s\n", begin);