-
Notifications
You must be signed in to change notification settings - Fork 30k
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,win: informative stack traces #23822
Conversation
|
src/debug_utils.cc
Outdated
class Win32SymbolDebuggingContext final : public NativeSymbolDebuggingContext { | ||
public: | ||
Win32SymbolDebuggingContext() { | ||
explicit Win32SymbolDebuggingContext(void* out) { | ||
out_ = reinterpret_cast<FILE*>(out); |
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.
Why not just take a FILE*
as input parameter?
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.
Polymorphism with the POSIX class:
https://github.com/nodejs/node/blob/0b565eb7f7404fb8774865826afba10c1919788f/src/debug_utils.cc#L253
I could move the cast to https://github.com/nodejs/node/blob/0b565eb7f7404fb8774865826afba10c1919788f/src/debug_utils.cc#L232-L235
(Now that I see it I could assume it's always stderr
and eliminate the argument).
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.
Since this is only used for printing diagnostic information, I don’t think an extra parameter is necessary at all; we can always just use stderr
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.
Done
src/debug_utils.cc
Outdated
// Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-symbol-information-by-address | ||
// Patches: | ||
// * Use `fprintf(out, ` instead of `printf` | ||
// * `sym ~= line` on success |
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.
What does the ~=
mean?
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.
assign almost all fields... I'll rephrase
(I might have used more fields in an earlier imp)
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.
Rephrased
src/debug_utils.cc
Outdated
char demangled[MAX_SYM_NAME]; | ||
using NameAndDisplacement = std::pair<std::string, DWORD64>; | ||
NameAndDisplacement WrappedSymFromAddr(DWORD64 dwAddress) const { | ||
HANDLE hProcess = current_process_; |
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.
snake_case
for variables.
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 wanted to keep the code as similar as possible to https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-symbol-information-by-address
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.
Done
src/debug_utils.cc
Outdated
// Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-symbol-information-by-address | ||
// Patches: | ||
// * Use `fprintf(out_, ` instead of `printf` | ||
// * `sym.filename = pSymbol->Name` on success |
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 feel this information about what you changed isn’t particularly useful. Both of the patches are fairly trivial. This also apply to the other places.
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'd rather keep the comment, AFAIK more comment never hurt...
Also they might be useful since the examples on MSDN change from time to time (for example they changed since the last time this code was lifted, and I had to reverse engineer the patches).
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.
Also they might be useful since the examples on MSDN change from time to time
Wouldn’t that be a good reason to drop the comment, since the diff can change on both sides, and so the Patches:
list can grow out of date?
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'll sleep on it.
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.
Since MSDN does have a history, I'm thinking the comments might still be useful.
Anyway they are free, and IMHO more info is almost always better then missing info...
I did go over them to make sure they are uniform, and not too obfuscated.
src/debug_utils.cc
Outdated
// * `sym ~= line` on success | ||
|
||
// Patch: made into arg - DWORD64 dwAddress; | ||
DWORD dwDisplacement; |
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.
nit: one space after DWORD.
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.
Ack.
cc @gireeshpunathil There may be opportunities here to reuse some code for Windows backtraces w.r.t. node-report in core and this PR. |
src/debug_utils.h
Outdated
oss << "+" << dis; | ||
} | ||
return oss.str(); | ||
} |
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.
Can we put this back in the .cc
file?
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.
Done.
But may I ask why?
src/debug_utils.cc
Outdated
class Win32SymbolDebuggingContext final : public NativeSymbolDebuggingContext { | ||
public: | ||
Win32SymbolDebuggingContext() { | ||
explicit Win32SymbolDebuggingContext(void* out) { | ||
out_ = reinterpret_cast<FILE*>(out); |
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.
Since this is only used for printing diagnostic information, I don’t think an extra parameter is necessary at all; we can always just use stderr
src/debug_utils.cc
Outdated
} else { | ||
// SymFromAddr failed | ||
const DWORD error = GetLastError(); | ||
#ifdef _DEBUG |
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.
When is #ifdef _DEBUG
defined? Is it the same as our #ifdef DEBUG
?
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.
Line 109 in f1b9546
'defines': [ 'DEBUG', '_DEBUG', 'V8_ENABLE_CHECKS' ], |
I picked it arbitrarily... I'll change
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.
Since I don’t know much about the Windows debugging stuff … how common would these errors be? i.e. do we only print them in debug mode because they would otherwise appear relatively frequently?
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.e. do we only print them in debug mode because they would otherwise appear relatively frequently?
Yes very frequent. If the *.pdb
is not available, or is partial. Also the last (deepest) frame almost always fails to resolve.
Done /s/_DEBUG/DEBUG
src/debug_utils.cc
Outdated
|
||
SymbolInfo LookupSymbol(void* address) override { | ||
auto dwAddress = reinterpret_cast<DWORD64>(address); |
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.
DWORD64 dw_address
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.
Ack.
But the type stated explicitly on the rhs.
And the name is copied from the example, which I'd rather not change...
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.
Ack.
bf00718
to
073a5be
Compare
Debug mode exe:Example output with
Without
|
All comments addressed, PTAL. |
// UnDecorateSymbolName returned success | ||
return szUndName; | ||
} else { | ||
// UnDecorateSymbolName failed |
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 am not a fan of this type of comment: What happens is obvious in both branches, and the branches themselves are short. (And I think we have a convention of ending comments with a period.)
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 code was lifter verbatim from https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-symbol-information-by-address
I would rather keep changes to minimon, for future reverse engineering.
// Patches: | ||
// Use `fprintf(stderr, ` instead of `printf`. | ||
// Assign values to `sym` on success. | ||
// `current_process_` instead of `hProcess. |
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 am still not sure whether this is going to help us at some point, I suspect it won't.
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.
Comment are free.
Personally I have not been in a situation where I said "I wish there was less comments"
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 tend to agree, but someone will either change our code or the original, and updating the comment will mostly be a maintenance burden at that point from my perspective.
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.
LGTM either way, even though I don't see much value in some of the comments.
Refresh `Win32SymbolDebuggingContext::LookupSymbol` to use more APIs PR-URL: nodejs#23822 Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-symbol-information-by-address Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-undecorated-symbol-names Reviewed-By: Tobias Nießen <tniessen@tnie.de>
073a5be
to
247b513
Compare
Refresh `Win32SymbolDebuggingContext::LookupSymbol` to use more APIs PR-URL: #23822 Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-symbol-information-by-address Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-undecorated-symbol-names Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Notable changes: * child_process: * All child processes will again open up a new Window on Windows by default. [#24034](#24034) * deps: * A new and fast experimental HTTP parser (`llhttp`) is now supported. [#24059](#24059) * **Windows** * A crashing process will now show the names of stack frames if the node.pdb file is available. [#23822](#23822) * Added new collaborators: * [oyyd](https://github.com/oyyd) - Ouyang Yadong. [#24300](#24300) * [psmarshall](https://github.com/psmarshall) - Peter Marshall. [#24170](#24170) * [shisama](https://github.com/shisama) - Masashi Hirano. [#24136](#24136)
Notable changes: * deps: * A new experimental HTTP parser (`llhttp`) is now supported. #24059 * timers: * Fixed an issue that could cause setTimeout to stop working as expected. #24322 * Windows * A crashing process will now show the names of stack frames if the node.pdb file is available. #23822 * Continued effort to improve the installer's new stage that installs native build tools. #23987, #24348 * child_process: * On Windows the `windowsHide` option default was restored to `false`. This means `detached` child processes and GUI apps will once again start in a new window. #24034 * Added new collaborators: * [oyyd](https://github.com/oyyd) - Ouyang Yadong. #24300 * [psmarshall](https://github.com/psmarshall) - Peter Marshall. #24170 * [shisama](https://github.com/shisama) - Masashi Hirano. #24136
Notable changes: * deps: * A new experimental HTTP parser (`llhttp`) is now supported. #24059 * timers: * Fixed an issue that could cause setTimeout to stop working as expected. #24322 * Windows * A crashing process will now show the names of stack frames if the node.pdb file is available. #23822 * Continued effort to improve the installer's new stage that installs native build tools. #23987, #24348 * child_process: * On Windows the `windowsHide` option default was restored to `false`. This means `detached` child processes and GUI apps will once again start in a new window. #24034 * Added new collaborators: * [oyyd](https://github.com/oyyd) - Ouyang Yadong. #24300 * [psmarshall](https://github.com/psmarshall) - Peter Marshall. #24170 * [shisama](https://github.com/shisama) - Masashi Hirano. #24136 PR-URL: #24350
Refresh `Win32SymbolDebuggingContext::LookupSymbol` to use more APIs PR-URL: #23822 Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-symbol-information-by-address Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-undecorated-symbol-names Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This does not land cleanly in |
Refresh `Win32SymbolDebuggingContext::LookupSymbol` to use more APIs PR-URL: #23822 Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-symbol-information-by-address Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-undecorated-symbol-names Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Refresh `Win32SymbolDebuggingContext::LookupSymbol` to use more APIs PR-URL: #23822 Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-symbol-information-by-address Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-undecorated-symbol-names Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Notable changes: * deps: * upgrade to c-ares v1.15.0 (Ben Noordhuis) #23854 * Windows: * A crashing process will now show the names of stack frames if the node.pdb file is available. (Refael Ackermann) #23822 * Added new collaborators: * Peter Marshall. #24170 * Masashi Hirano. #24136 PR-URL: #24727
Notable changes: * deps: * upgrade to c-ares v1.15.0 (Ben Noordhuis) #23854 * Windows: * A crashing process will now show the names of stack frames if the node.pdb file is available. (Refael Ackermann) #23822 * Added new collaborators: * Peter Marshall. #24170 * Masashi Hirano. #24136 PR-URL: #24727
Notable changes: * deps: * upgrade to c-ares v1.15.0 (Ben Noordhuis) nodejs#23854 * Windows: * A crashing process will now show the names of stack frames if the node.pdb file is available. (Refael Ackermann) nodejs#23822 * Added new collaborators: * Peter Marshall. nodejs#24170 * Masashi Hirano. nodejs#24136 PR-URL: nodejs#24727
Refresh
Win32SymbolDebuggingContext::LookupSymbol
to use more APIsRefs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-symbol-information-by-address
Refs: https://docs.microsoft.com/en-us/windows/desktop/Debug/retrieving-undecorated-symbol-names
Before:
After (with PDB available):
Fallback with no PDB loaded:
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes