Skip to content

[cDAC] Adding IsLeafFrame and GetContext DacDbi APIs#127195

Open
rcj1 wants to merge 5 commits intodotnet:mainfrom
rcj1:context
Open

[cDAC] Adding IsLeafFrame and GetContext DacDbi APIs#127195
rcj1 wants to merge 5 commits intodotnet:mainfrom
rcj1:context

Conversation

@rcj1
Copy link
Copy Markdown
Contributor

@rcj1 rcj1 commented Apr 21, 2026

Assuming we don't care about datatargets that don't implement GetThreadContext.

Copilot AI review requested due to automatic review settings April 21, 2026 00:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for new stack-walk related APIs across the cDAC contracts layer and the legacy DacDbi surface, focusing on retrieving thread contexts and determining leaf frames, and updates dump-based tests accordingly. It also removes the native DAC fallback behavior when the data target doesn’t implement GetThreadContext, aligning with the PR’s stated assumption.

Changes:

  • Add IThread.GetContext(...) and IStackWalk.AreContextsEqual(...) contract APIs and use them from stack walking and DacDbi implementations.
  • Implement DacDbiImpl.GetContext / DacDbiImpl.IsLeafFrame in managed cDAC and add dump tests for these APIs.
  • Update native DAC GetContext / IsLeafFrame to always rely on GetThreadContext (no E_NOTIMPL fallback).

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/native/managed/cdac/tests/DumpTests/StackWalkDumpTests.cs Adds dump tests for Thread.GetContext and StackWalk.AreContextsEqual.
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiStackWalkDumpTests.cs New dump tests validating DacDbiImpl GetContext and IsLeafFrame.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/IDacDbiInterface.cs Updates interop signatures to use byte* context buffers.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs Implements IsLeafFrame and GetContext via contracts (with DEBUG cross-validation).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Thread_1.cs Implements IThread.GetContext using filter contexts or TryGetThreadContext.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/StackWalk_1.cs Adds AreContextsEqual and routes stackwalk thread-context acquisition through Thread.GetContext.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/*.cs Splits context flags into FullContextFlags vs AllContextFlags across supported architectures.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/IPlatformContext.cs Renames/expands context-flag properties to FullContextFlags and AllContextFlags.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/IPlatformAgnosticContext.cs Same flag-property updates at platform-agnostic level.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/ContextHolder.cs Plumbs new context-flag properties through the holder type.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IThread.cs Adds ThreadContextSource and the GetContext contract API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IStackWalk.cs Adds AreContextsEqual to the StackWalk contract surface.
src/coreclr/debug/daccess/dacdbiimplstackwalk.cpp Updates native IsLeafFrame to always use GetThreadContext directly.
src/coreclr/debug/daccess/dacdbiimpl.cpp Removes E_NOTIMPL fallback path from native GetContext.
docs/design/datacontracts/StackWalk.md Documents new AreContextsEqual API behavior.

Comment thread docs/design/datacontracts/StackWalk.md Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 01:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

Comment thread src/native/managed/cdac/tests/DumpTests/StackWalkDumpTests.cs Outdated
Comment thread docs/design/datacontracts/StackWalk.md Outdated
Comment thread docs/design/datacontracts/StackWalk.md Outdated

// Compares two raw thread contexts for equality of the architecture's control registers.
// Typically this means stack pointer, frame pointer, and instruction pointer; however, on ARM32
// the native DAC compares only SP and IP/PC and does not require frame pointer equality.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frame pointer is optional. Method does not have to have one.

Is the frame pointer equality actually needed for what it does (on all architectures)? I would expect SP + IP to be enough to detect the leaf frame.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this should work.

byte[] givenContext = new byte[leafContext.Length];
new Span<byte>(pContext, givenContext.Length).CopyTo(givenContext);

*pResult = sw.AreContextsEqual(givenContext, leafContext) ? Interop.BOOL.TRUE : Interop.BOOL.FALSE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to just compare IP and SP here instead of behind IStackWalk contract?

rcj1 and others added 2 commits April 21, 2026 09:26
…er.Contracts/Contracts/StackWalk/StackWalk_1.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 16:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.


*pResult = givenCtx.StackPointer == leafCtx.StackPointer
&& givenCtx.InstructionPointer == leafCtx.InstructionPointer
? Interop.BOOL.TRUE : Interop.BOOL.FALSE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the unmanaged implementation of the IsLeafFrame to match?

@rcj1 rcj1 marked this pull request as ready for review April 21, 2026 18:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.

Comment on lines +127 to +131
Assert.NotNull(nonLeafContext);

Interop.BOOL result;
fixed (byte* pContext = nonLeafContext)
{
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nonLeafContext is declared as byte[]?, and after Assert.NotNull(nonLeafContext) the compiler may still treat it as nullable for subsequent uses (e.g., the fixed statement), depending on nullable annotations on xUnit. To avoid nullable warnings/errors (and make the non-null assumption explicit), assign the non-null value back (e.g., nonLeafContext = Assert.NotNull(nonLeafContext);) or otherwise cast/throw so the type is byte[] before the fixed block.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants