forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print a C backtrace on fatal errors to make it easier to debug issues like nodejs#6727.
- Loading branch information
1 parent
ae17883
commit cd737bb
Showing
5 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "node.h" | ||
|
||
#include <cxxabi.h> | ||
#include <dlfcn.h> | ||
#include <execinfo.h> | ||
#include <stdio.h> | ||
|
||
namespace node { | ||
|
||
void DumpBacktrace(FILE* fp) { | ||
void* frames[256]; | ||
const int size = backtrace(frames, arraysize(frames)); | ||
if (size <= 0) { | ||
return; | ||
} | ||
for (int i = 1; i < size; i += 1) { | ||
const void* frame = frames[i]; | ||
fprintf(fp, "%2d: ", i); | ||
Dl_info info; | ||
const bool have_info = dladdr(frame, &info); | ||
if (!have_info || info.dli_sname == nullptr) { | ||
fprintf(fp, "%p", frame); | ||
} else if (char* demangled = abi::__cxa_demangle(info.dli_sname, 0, 0, 0)) { | ||
fprintf(fp, "%s", demangled); | ||
free(demangled); | ||
} else { | ||
fprintf(fp, "%s", info.dli_sname); | ||
} | ||
if (have_info && info.dli_fname != nullptr) { | ||
fprintf(fp, " [%s]", info.dli_fname); | ||
} | ||
fprintf(fp, "\n"); | ||
} | ||
} | ||
|
||
} // namespace node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "node.h" | ||
|
||
namespace node { | ||
|
||
void DumpBacktrace(FILE* fp) { | ||
} | ||
|
||
} // namespace node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters