-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: implement backtrace-on-abort for windows #16951
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,41 @@ | ||
#include "node.h" | ||
#define _WIN32_WINNT 0x0600 | ||
#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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nodejs/platform-windows What’s the right way to do this? That’s basically the only question I have left here…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually an interesting question. We have multiple version targeting macros:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(shirt-return is not the right key-chord. it's not new line, it's Submit)
node/deps/v8/src/base/win32-headers.h
Lines 32 to 34 in 73ae2d1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(grrrr, shift-return again)
node/deps/uv/include/uv-win.h
Lines 22 to 24 in 766cd1f
node/src/node.h
Lines 42 to 47 in a36aa04
tl;dr this should be injected by the build system, so you should
ifndef
around it. Also semantically it's used for targeting a minimum platform requirements, and0x0600
is anyway our platform minimum.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not at my laptop rn but if it's really just ifdef'ing it feel free to push that to this branch