-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[cDAC] Add interpreter support for stack walking and diagnostics #126520
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
Open
max-charlamb
wants to merge
9
commits into
dotnet:main
Choose a base branch
from
max-charlamb:dev/max-charlamb/cdac-interpreter-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bc301ae
Add cDAC interpreter support for stack walking and diagnostics
max-charlamb f56b741
Add interpreter dump test infrastructure
max-charlamb aae8ed7
Address review feedback: add GetCodeForInterpreterOrJitted API and co…
max-charlamb c1cd2af
Fix CI pipeline: restore buildConfig to release for dump test stages
max-charlamb e5a5c8c
Fix comment and doc typos from review feedback
max-charlamb 63f4e8e
Remove GetCodeForInterpreterOrJitted API and inline ResolveInterprete…
max-charlamb 1473606
Address janvorli feedback: resolve TopInterpMethodContextFrame hint a…
max-charlamb a8246a4
Add InterpreterStackDoubleWalk dump test and fix unwind infinite loop
max-charlamb 5410ee8
Address review feedback: revert IRuntimeTypeSystem and refactor Resol…
max-charlamb 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
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
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 |
|---|---|---|
|
|
@@ -73,6 +73,11 @@ This contract depends on the following descriptors: | |
| | `HijackArgs` (amd64) | `CalleeSavedRegisters` | CalleeSavedRegisters data structure | | ||
| | `HijackArgs` (amd64 Windows) | `Rsp` | Saved stack pointer | | ||
| | `HijackArgs` (arm/arm64/x86) | For each register `r` saved in HijackArgs, `r` | Register names associated with stored register values | | ||
| | `InterpreterFrame` | `TopInterpMethodContextFrame` | Pointer to the InterpreterFrame's top `InterpMethodContextFrame` | | ||
| | `InterpMethodContextFrame` | `StartIp` | Pointer to the `InterpByteCodeStart` for resolving the MethodDesc | | ||
| | `InterpMethodContextFrame` | `ParentPtr` | Pointer to the parent `InterpMethodContextFrame` in the call chain (null for outermost frame) | | ||
|
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.
|
||
| | `InterpMethodContextFrame` | `Ip` | The actual instruction pointer within the method (null if frame is inactive/reusable) | | ||
| | `InterpMethodContextFrame` | `NextPtr` | Pointer to the next `InterpMethodContextFrame` toward the top of the stack | | ||
| | `ArgumentRegisters` (arm) | For each register `r` saved in ArgumentRegisters, `r` | Register names associated with stored register values | | ||
| | `CalleeSavedRegisters` | For each callee saved register `r`, `r` | Register names associated with stored register values | | ||
| | `TailCallFrame` (x86 Windows) | `CalleeSavedRegisters` | CalleeSavedRegisters data structure | | ||
|
|
@@ -119,6 +124,33 @@ In reality, the actual algorithm is a little more complex fow two reasons. It re | |
| If the address of the `frame` is less than the caller's stack pointer, **return the current context**, pop the top Frame from `frameStack`, and **go to step 3**. | ||
| 3. Unwind `currContext` using the Windows style unwinder. **Return the current context**. | ||
|
|
||
| #### Interpreter Frame Expansion | ||
|
|
||
| When the stack walker encounters an `InterpreterFrame`, it expands it into multiple logical frames by walking the `InterpMethodContextFrame` chain. The runtime maintains a linked list of `InterpMethodContextFrame` nodes representing each interpreted method currently on the call stack within a single `InterpreterFrame`. | ||
|
|
||
| The `TopInterpMethodContextFrame` field is an approximate hint that may point to a stale frame during dump or native debugging. The actual top frame must be resolved using the `Ip` and `NextPtr`/`ParentPtr` fields, replicating `InterpreterFrame::GetTopInterpMethodContextFrame()`: | ||
|
|
||
| - If the hinted frame's `Ip` is non-null (active): seek upward via `NextPtr` while the next frame's `Ip` is also non-null. | ||
| - If the hinted frame's `Ip` is null (inactive/reusable): seek downward via `ParentPtr` until finding a frame with non-null `Ip`. | ||
|
|
||
| Only frames with non-null `Ip` (active frames) are yielded during the walk. Each node's `ParentPtr` points to its caller. | ||
|
|
||
| For each active `InterpMethodContextFrame` in the chain, the stack walker yields a separate frame. The `MethodDesc` for each frame is resolved by following: | ||
| `InterpMethodContextFrame.StartIp` -> `InterpByteCodeStart.Method` -> `InterpMethod.MethodDesc` | ||
|
|
||
| ``` | ||
| InterpreterFrame | ||
| └-> TopInterpMethodContextFrame (hint, may be stale) | ||
| └-> ResolveTop() -> InterpMethodContextFrame (method C, Ip != null) | ||
| └-> ParentPtr -> InterpMethodContextFrame (method B, Ip != null) | ||
| └-> ParentPtr -> InterpMethodContextFrame (method A, Ip != null) | ||
| └-> ParentPtr -> null | ||
| ``` | ||
|
|
||
| This produces three frames in order: C, B, A (innermost to outermost). | ||
|
|
||
| When the stack walk starts with an explicit context in interpreted code (e.g., from a debugger breakpoint), the interpreted frames are already yielded from the initial context as frameless frames. When the walker subsequently encounters the corresponding `InterpreterFrame`, it skips expanding it to prevent the same frames from being walked twice. | ||
|
|
||
|
|
||
| #### Simple Example | ||
|
|
||
|
|
||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
@janvorli @kotlarmilos - Please take a look at these contracts (the markdown files) and see what you think. Every type/field/algorithm included here becomes part of the interpreter's contract with diagnostic tools. Changing the data structures is possible, but its a breaking change that requires developers to update their tools so we'd only expect to do it rarely. Make sure the things documented here are things you'd expect to be reasonably stable over time or please suggest alternatives.
Thanks!
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.
Want to bump @janvorli @kotlarmilos @jkotas, planning to merge this soon.
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 sorry, I've missed the comment from @noahfalk last week. I'll look at it today.