mirror of https://github.com/lukechilds/node.git
Browse Source
Print a C backtrace on fatal errors to make it easier to debug issues like https://github.com/nodejs/node/issues/6727. PR-URL: https://github.com/nodejs/node/pull/6734 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>v7.x
Ben Noordhuis
9 years ago
5 changed files with 64 additions and 0 deletions
@ -0,0 +1,50 @@ |
|||
#include "node.h" |
|||
|
|||
#if defined(__linux__) |
|||
#include <features.h> |
|||
#endif |
|||
|
|||
#if defined(__linux__) && !defined(__GLIBC__) |
|||
#define HAVE_EXECINFO_H 0 |
|||
#else |
|||
#define HAVE_EXECINFO_H 1 |
|||
#endif |
|||
|
|||
#if HAVE_EXECINFO_H |
|||
#include <cxxabi.h> |
|||
#include <dlfcn.h> |
|||
#include <execinfo.h> |
|||
#include <stdio.h> |
|||
#endif |
|||
|
|||
namespace node { |
|||
|
|||
void DumpBacktrace(FILE* fp) { |
|||
#if HAVE_EXECINFO_H |
|||
void* frames[256]; |
|||
const int size = backtrace(frames, arraysize(frames)); |
|||
if (size <= 0) { |
|||
return; |
|||
} |
|||
for (int i = 1; i < size; i += 1) { |
|||
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"); |
|||
} |
|||
#endif // HAVE_EXECINFO_H
|
|||
} |
|||
|
|||
} // namespace node
|
@ -0,0 +1,8 @@ |
|||
#include "node.h" |
|||
|
|||
namespace node { |
|||
|
|||
void DumpBacktrace(FILE* fp) { |
|||
} |
|||
|
|||
} // namespace node
|
Loading…
Reference in new issue