This repository was archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 411
2 fixes for rt.backtrace.dwarf #2151
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 |
|---|---|---|
|
|
@@ -79,31 +79,44 @@ int traceHandlerOpApplyImpl(const void*[] callstack, scope int delegate(ref size | |
| int ret = 0; | ||
| foreach (size_t i; 0 .. callstack.length) | ||
| { | ||
| char[1536] buffer = void; buffer[0] = 0; | ||
| char[256] addressBuffer = void; addressBuffer[0] = 0; | ||
| char[1536] buffer = void; | ||
| size_t bufferLength = 0; | ||
|
|
||
| void appendToBuffer(Args...)(const(char)* format, Args args) | ||
| { | ||
| const count = snprintf(buffer.ptr + bufferLength, buffer.length - bufferLength, format, args); | ||
| assert(count >= 0); | ||
| bufferLength += count; | ||
| if (bufferLength >= buffer.length) | ||
| bufferLength = buffer.length - 1; | ||
| } | ||
|
|
||
| if (locations.length > 0 && locations[i].line != -1) | ||
| snprintf(addressBuffer.ptr, addressBuffer.length, "%.*s:%d ", cast(int) locations[i].file.length, locations[i].file.ptr, locations[i].line); | ||
| { | ||
| appendToBuffer("%.*s:%d ", cast(int) locations[i].file.length, locations[i].file.ptr, locations[i].line); | ||
| } | ||
| else | ||
| addressBuffer[] = "??:? \0"; | ||
| { | ||
| buffer[0 .. 5] = "??:? "; | ||
| bufferLength = 5; | ||
| } | ||
|
|
||
| char[1024] symbolBuffer = void; | ||
| int bufferLength; | ||
| auto symbol = getDemangledSymbol(frameList[i][0 .. strlen(frameList[i])], symbolBuffer); | ||
| if (symbol.length > 0) | ||
| bufferLength = snprintf(buffer.ptr, buffer.length, "%s%.*s ", addressBuffer.ptr, cast(int) symbol.length, symbol.ptr); | ||
| else | ||
| bufferLength = snprintf(buffer.ptr, buffer.length, "%s", addressBuffer.ptr); | ||
| appendToBuffer("%.*s ", cast(int) symbol.length, symbol.ptr); | ||
|
|
||
| assert(bufferLength >= 0); | ||
| const addressLength = 20; | ||
| const maxBufferLength = buffer.length - addressLength; | ||
| if (bufferLength > maxBufferLength) | ||
| { | ||
| buffer[maxBufferLength-4 .. maxBufferLength] = "... "; | ||
| bufferLength = maxBufferLength; | ||
| buffer[$-4-addressLength..$-addressLength] = "... "; | ||
| } | ||
| bufferLength += snprintf(buffer.ptr + bufferLength, buffer.length, "[0x%x]", callstack[i]); | ||
| static if (size_t.sizeof == 8) | ||
| appendToBuffer("[0x%llx]", callstack[i]); | ||
| else | ||
| appendToBuffer("[0x%x]", callstack[i]); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix 2: don't restrict to lower 32 bits of address on 64-bit platforms, e.g., now |
||
|
|
||
| auto output = buffer[0 .. bufferLength]; | ||
| auto pos = i; | ||
|
|
||
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.
Fix 1:
addressBuffer[] = "??:? \0";=>
object.Error@(0): Array lengths don't match for copyhttps://run.dlang.io/is/4RQZWhThere 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.
Any chance we can add a test for this to prevent future regressions?
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.
It's pretty bad with
-release, causing a segfault as long as the destination buffer is sufficiently large: https://run.dlang.io/is/NEqZOB. Without-releasean exception is thrown during stacktrace generation, which is also pretty bad.The latter is how I stumbled on this. LLVM 6.0 led to DWARF v4 debuginfos, rt.backtrace.dwarf doesn't support that version, so no file/line infos => "??:? \0" + exception (debug druntime only; release druntime compiled with
-releasehappily reads beyond the string constant, causing no segfault on x86 apparently). The exception with debug-druntime is swallowed in my test case, it only manifests itself in an incomplete stack trace (single entry).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.
@wilzbach: There's no debug druntime (i.e., compiled with enabled bounds checks) available for CI, right? Then it's untestable.