-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: implement backtrace-on-abort for windows
PR-URL: #16951 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
Showing
3 changed files
with
39 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,40 @@ | ||
#include "node.h" | ||
#include "node_internals.h" | ||
#include <windows.h> | ||
#include <dbghelp.h> | ||
|
||
namespace node { | ||
|
||
void DumpBacktrace(FILE* fp) { | ||
void* frames[256]; | ||
int size = CaptureStackBackTrace(0, arraysize(frames), frames, nullptr); | ||
HANDLE process = GetCurrentProcess(); | ||
(void)SymInitialize(process, nullptr, true); | ||
|
||
// Ref: https://msdn.microsoft.com/en-en/library/windows/desktop/ms680578(v=vs.85).aspx | ||
char info_buf[sizeof(SYMBOL_INFO) + MAX_SYM_NAME]; | ||
SYMBOL_INFO* info = reinterpret_cast<SYMBOL_INFO*>(info_buf); | ||
char demangled[MAX_SYM_NAME]; | ||
|
||
for (int i = 1; i < size; i += 1) { | ||
void* frame = frames[i]; | ||
fprintf(fp, "%2d: ", i); | ||
info->MaxNameLen = MAX_SYM_NAME; | ||
info->SizeOfStruct = sizeof(SYMBOL_INFO); | ||
const bool have_info = | ||
SymFromAddr(process, reinterpret_cast<DWORD64>(frame), nullptr, info); | ||
if (!have_info || strlen(info->Name) == 0) { | ||
fprintf(fp, "%p", frame); | ||
} else if (UnDecorateSymbolName(info->Name, | ||
demangled, | ||
sizeof(demangled), | ||
UNDNAME_COMPLETE)) { | ||
fprintf(fp, "%s", demangled); | ||
} else { | ||
fprintf(fp, "%s", info->Name); | ||
} | ||
fprintf(fp, "\n"); | ||
} | ||
(void)SymCleanup(process); | ||
} | ||
|
||
} // 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