Skip to content

Commit

Permalink
src: print backtrace on abort/unreachable code
Browse files Browse the repository at this point in the history
Print a C backtrace on fatal errors to make it easier to debug issues.
  • Loading branch information
bnoordhuis committed May 13, 2016
1 parent cd737bb commit 9c63535
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2383,7 +2383,6 @@ static void OnFatalError(const char* location, const char* message) {
} else {
PrintErrorString("FATAL ERROR: %s\n", message);
}
DumpBacktrace(stderr);
fflush(stderr);
ABORT();
}
Expand Down
17 changes: 15 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <assert.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

namespace node {
Expand All @@ -21,9 +22,21 @@ namespace node {

// Windows 8+ does not like abort() in Release mode
#ifdef _WIN32
#define ABORT() raise(SIGABRT)
#define ABORT_NO_BACKTRACE() raise(SIGABRT)
#else
#define ABORT() abort()
#define ABORT_NO_BACKTRACE() abort()
#endif

// This macro is also used indirectly by some of the addons in test/addons.
#ifdef NODE_WANT_INTERNALS
# define ABORT() \
do { \
node::DumpBacktrace(stderr); \
fflush(stderr); \
ABORT_NO_BACKTRACE(); \
} while (0)
#else
# define ABORT() ABORT_NO_BACKTRACE()
#endif

#if defined(NDEBUG)
Expand Down

0 comments on commit 9c63535

Please sign in to comment.