-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fixes #25306; Dangling pointers in stack traces with -d:nimStackTraceOverride
#25313
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
Changes from 5 commits
132a827
6272cd1
7d64465
7db358d
c7cdccb
3090d8f
f6ffcb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,9 @@ when defined(nimStackTraceOverride): | |
| proc (programCounters: seq[cuintptr_t], maxLength: cint): seq[StackTraceEntry] {. | ||
| nimcall, gcsafe, raises: [], tags: [], noinline.} | ||
|
|
||
|
|
||
| const NimStackTraceMsgs = compileOption("stacktraceMsgs") | ||
ringabout marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Default procedures (not normally used, because people opting in on this | ||
| # override are supposed to register their own versions). | ||
| var | ||
|
|
@@ -65,6 +68,23 @@ when defined(nimStackTraceOverride): | |
| for i in 0..<programCounters.len: | ||
| s.add(StackTraceEntry(programCounter: cast[uint](programCounters[i]))) | ||
|
|
||
| proc copyStackTraceEntry(x: ptr StackTraceEntry): StackTraceEntry = | ||
| result = StackTraceEntry(line: x.line, programCounter: x.programCounter, | ||
| procnameStr: x.procnameStr, filenameStr: x.filenameStr | ||
| ) | ||
| when NimStackTraceMsgs: | ||
| result.frameMsg = x.frameMsg | ||
|
|
||
| # points `procname`, `filename` to its own corresponding fields | ||
| # to avoid dangling pointers # bug #25306 18039 | ||
| result.procname = result.procnameStr.cstring | ||
| result.filename = result.filenameStr.cstring | ||
|
|
||
| proc copyStackTraceEntrySeq(result: var seq[StackTraceEntry]; s: seq[StackTraceEntry]) = | ||
| for i in 0..<s.len: | ||
| let entry = addr s[i] | ||
| result.add(copyStackTraceEntry entry) | ||
|
|
||
|
Member
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. You don't have to copy anything here, all you need to do it to patch every entry after an
Contributor
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. strictly speaking, in this particular case, one would want to move the existing entries...
Member
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.
Member
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. patch entries after an |
||
| # We may have more stack trace lines in the output, due to inlined procedures. | ||
| proc addDebuggingInfo*(s: seq[StackTraceEntry]): seq[StackTraceEntry] = | ||
| var programCounters: seq[cuintptr_t] | ||
|
|
@@ -75,10 +95,10 @@ when defined(nimStackTraceOverride): | |
| if entry.procname.isNil and entry.programCounter != 0: | ||
| programCounters.add(cast[cuintptr_t](entry.programCounter)) | ||
| elif entry.procname.isNil and (entry.line == reraisedFromBegin or entry.line == reraisedFromEnd): | ||
| result.add(stackTraceOverrideGetDebuggingInfo(programCounters, maxStackTraceLines)) | ||
| result.copyStackTraceEntrySeq(stackTraceOverrideGetDebuggingInfo(programCounters, maxStackTraceLines)) | ||
| programCounters = @[] | ||
| result.add(entry[]) | ||
| result.add(copyStackTraceEntry entry) | ||
| else: | ||
| result.add(entry[]) | ||
| result.add(copyStackTraceEntry entry) | ||
| if programCounters.len > 0: | ||
| result.add(stackTraceOverrideGetDebuggingInfo(programCounters, maxStackTraceLines)) | ||
| result.copyStackTraceEntrySeq(stackTraceOverrideGetDebuggingInfo(programCounters, maxStackTraceLines)) | ||
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.
Unused code?