Skip to content

[cDAC] Implement GetArgumentByIndex and GetLocalVariableByIndex on ClrDataFrame#125463

Merged
max-charlamb merged 3 commits intodotnet:mainfrom
max-charlamb:cdac-dataframe-value-apis
Mar 25, 2026
Merged

[cDAC] Implement GetArgumentByIndex and GetLocalVariableByIndex on ClrDataFrame#125463
max-charlamb merged 3 commits intodotnet:mainfrom
max-charlamb:cdac-dataframe-value-apis

Conversation

@max-charlamb
Copy link
Copy Markdown
Member

@max-charlamb max-charlamb commented Mar 11, 2026

[cDAC] Implement GetArgumentByIndex and GetLocalVariableByIndex on ClrDataFrame

Builds on #125064 (GetContext/GetAppDomain) to add variable inspection support to the managed cDAC.

What this PR does

DebugInfo contract (variable location resolution):

  • GetMethodVarInfo on IDebugInfo for resolving native variable locations from JIT debug info
  • NativeVarInfo types (internal) with DoVars nibble decoder
  • DebugVarInfo/DebugVarLocKind (public stable API in Abstractions)
  • Register mapping for x64/x86/ARM64/ARM including REGNUM_AMBIENT_SP
  • Documented in DebugInfo.md (Version 2 section with VarLocType constants and encoding format)

SignatureDecoder contract (type resolution):

  • DecodeMethodSignature -- decodes full method signature resolving all parameter/return types including generic instantiations (VAR, MVAR, GENERICINST)
  • DecodeLocalSignature -- reads IL method body header, finds local signature token, decodes all local variable types
  • SignatureTypeProvider updated to resolve class-level generic params (VAR) via MethodDescHandle context
  • Documented in SignatureDecoder.md

RuntimeTypeSystem contract:

  • IsEnum(TypeHandle) -- detects enum types via GetSignatureCorElementType(ValueType) + InternalCorElementType != ValueType
  • GetPrimitiveType(CorElementType) -- returns TypeHandle for a primitive/well-known CorElementType
  • Documented in RuntimeTypeSystem.md (API section + Version 1 pseudocode)

ClrDataFrame.GetArgumentByIndex / GetLocalVariableByIndex:

  • Parameter name resolution from metadata, this handling for instance methods
  • Type resolution via ISignatureDecoder contracts (DecodeMethodSignature/DecodeLocalSignature)
  • Variable location resolution via GetMethodVarInfo + local register/stack resolution
  • MapCorElementTypeToFlags matches native DAC's GetTypeFieldValueFlags: IS_PRIMITIVE, IS_VALUE_TYPE, IS_REFERENCE, IS_STRING, IS_ARRAY, IS_ENUM, IS_POINTER
  • ByRef unwrapping for underlying type flag resolution
  • Function pointer types mapped to IntPtr matching native DAC behavior (ELEMENT_TYPE_FNPTR under #ifndef DACCESS_COMPILE -> IntPtr)
  • Primitive size adjustment (NativeVarLocations always reports pointer-sized; shrink for actual primitive sizes)
  • Legacy verification with AllowCdacSuccess validation mode

ClrDataValue (new, implements IXCLRDataValue):

  • GetFlags, GetSize, GetBytes, GetAddress, GetNumLocations, GetLocationByIndex
  • Legacy verification on all implemented methods
  • ClrDataValueFlag and ClrDataVLocFlag made public for test access

Native DAC fix:

  • REGNUM_AMBIENT_SP handling in GetRegOffsInCONTEXT on AMD64 (util.cpp)

Known Gaps (tracked as issues)

Dump test scenarios

LocalVariables debuggee with 13 frames exercising type coverage from simple to complex:

Frame Arguments Locals Types Tested Expected Flags
PrimitiveVars int, double, bool, char, byte, short, long, float int, double I4, R8, BOOLEAN, CHAR, U1, I2, I8, R4 IS_PRIMITIVE
NativeIntVars nint, nuint nint, nuint I, U IS_PRIMITIVE (pointer-sized)
StructVars TinyStruct(1B), SmallStruct(8B), LargeStruct(32B) SmallStruct VALUETYPE IS_VALUE_TYPE
ReferenceTypeVars string, class, enum, object, int[] -- STRING, CLASS, VALUETYPE(enum), OBJECT, SZARRAY IS_REFERENCE, IS_ENUM
GenericInstAndByRefVars List<int>, KeyValuePair<int,string>, ref int List<int> GENERICINST+CLASS, GENERICINST+VALUETYPE, BYREF IS_REFERENCE, IS_VALUE_TYPE, IS_PRIMITIVE (unwrapped)
InstanceMethodOnStruct SmallStruct -- VALUETYPE (static helper) IS_VALUE_TYPE
InstanceMethodVars this (SimpleClass), int int CLASS (this), I4 IS_REFERENCE, IS_PRIMITIVE
ClassGenericVars T (class-level VAR) T VAR -> instantiated type IS_REFERENCE
MethodGenericVars T1, T2 (method-level MVAR) T1 MVAR -> instantiated type IS_PRIMITIVE, IS_REFERENCE
SingleDimArrayVars int[] int[] SZARRAY IS_REFERENCE
MultiDimArrayVars int[,] int[,] ARRAY IS_REFERENCE
PointerVars int*, delegate*<int,int> -- PTR, FNPTR IS_POINTER (gap: #125792), IS_PRIMITIVE
Crash -- -- (triggers dump) --

IXCLRDataValueDumpTests -- validates GetSize, GetFlags, GetBytes, GetNumLocations, GetLocationByIndex across all frames above.

IXCLRDataFrameDumpTests -- validates GetArgumentByIndex, GetLocalVariableByIndex, GetNumArguments, GetNumLocalVariables, GetContext, GetAppDomain, GetMethodInstance.

Validation

Copilot AI review requested due to automatic review settings March 11, 2026 22:27
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

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

Implements cDAC-backed IXCLRDataFrame.GetArgumentByIndex / GetLocalVariableByIndex and introduces supporting DebugInfo/StackWalk contract APIs plus a new managed IXCLRDataValue implementation, with dump-based integration tests to validate behavior against the legacy DAC.

Changes:

  • Extend DebugInfo contract v2 to decode/resolve native variable locations (vars section) and StackWalk contract to expose frame instruction pointers.
  • Implement ClrDataFrame.GetArgumentByIndex / GetLocalVariableByIndex using cDAC debug info, and add a new managed ClrDataValue (IXCLRDataValue) for returned argument/local values.
  • Add new dump debuggee (LocalVariables) and dump-based integration tests for IXCLRDataFrame, IXCLRDataValue, and IXCLRDataAppDomain.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
src/native/managed/cdac/tests/DumpTests/IXCLRDataValueDumpTests.cs New dump tests validating IXCLRDataValue returned from arg/local APIs
src/native/managed/cdac/tests/DumpTests/IXCLRDataFrameDumpTests.cs New dump tests covering IXCLRDataFrame APIs including arg/local retrieval
src/native/managed/cdac/tests/DumpTests/IXCLRDataAppDomainDumpTests.cs New dump tests for IXCLRDataAppDomain behavior via frame GetAppDomain
src/native/managed/cdac/tests/DumpTests/DumpTestBase.cs Adds overload to initialize dump tests with per-test debuggee + dump type
src/native/managed/cdac/tests/DumpTests/Debuggees/StackWalk/Program.cs Adjusts debuggee to ensure locals/args exist for stack inspection
src/native/managed/cdac/tests/DumpTests/Debuggees/LocalVariables/Program.cs New debuggee producing known args/locals for value inspection
src/native/managed/cdac/tests/DumpTests/Debuggees/LocalVariables/LocalVariables.csproj New debuggee project enabling full dumps
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/IXCLRData.cs Updates COM signatures to use DacComNullableByRef for AppDomain methods
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataValue.cs New managed IXCLRDataValue implementation with legacy cross-validation
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataTask.cs Updates ClrDataAppDomain construction to include Target
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataFrame.cs Implements cDAC versions of GetAppDomain, arg/local-by-index, and helper parsing
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataAppDomain.cs Implements cDAC AppDomain methods (GetName, GetUniqueID, GetFlags)
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/StackWalk_1.cs Adds GetInstructionPointer for frame IP retrieval
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Loader_1.cs Returns "DefaultDomain" when FriendlyName is null
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/DebugInfo/NativeVarInfo.cs Adds internal var-loc types/struct mirroring runtime encoding
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/DebugInfo/DebugInfo_2.cs Implements GetMethodVarInfo + GetVariableLocations for v2
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/DebugInfo/DebugInfoHelpers.cs Adds vars nibble-decoder and var-loc resolution across architectures
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IStackWalk.cs Extends abstraction with GetInstructionPointer
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IDebugInfo.cs Adds public stable DebugVarInfo/NativeVarLocation APIs
docs/design/datacontracts/Loader.md Documents "DefaultDomain" fallback behavior
docs/design/datacontracts/DebugInfo.md Documents DebugInfo v2 vars decoding + new APIs

@max-charlamb max-charlamb added the NO-REVIEW Experimental/testing PR, do NOT review it label Mar 11, 2026
@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from 50b6258 to 487d34e Compare March 12, 2026 18:11
Copilot AI review requested due to automatic review settings March 12, 2026 21:55
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 13 out of 13 changed files in this pull request and generated 5 comments.

@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from 5ec7202 to 47b23bf Compare March 13, 2026 18:47
Copilot AI review requested due to automatic review settings March 13, 2026 20:47
@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from 47b23bf to 790f597 Compare March 13, 2026 20:47
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 13 out of 13 changed files in this pull request and generated 5 comments.

@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from 790f597 to 9b0a451 Compare March 13, 2026 21:52
Copilot AI review requested due to automatic review settings March 16, 2026 14:19
@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from 9b0a451 to dafa127 Compare March 16, 2026 14:19
@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from dafa127 to f00fc33 Compare March 16, 2026 14:22
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 14 out of 14 changed files in this pull request and generated 4 comments.

@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from f00fc33 to 0d65124 Compare March 16, 2026 16:05
Copilot AI review requested due to automatic review settings March 16, 2026 16:08
@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch 2 times, most recently from 8a5ac15 to 14e2764 Compare March 16, 2026 16:08
@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from 14e2764 to 6da2d24 Compare March 16, 2026 16:12
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 15 out of 15 changed files in this pull request and generated 7 comments.

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 26 out of 26 changed files in this pull request and generated 1 comment.

@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from baa8a3c to ae8782c Compare March 20, 2026 15:39
Copilot AI review requested due to automatic review settings March 20, 2026 16:24
@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from ae8782c to 4e9d328 Compare March 20, 2026 16:24
@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from 4e9d328 to 00fd3c6 Compare March 20, 2026 16:30
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 5 comments.

@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from 00fd3c6 to 8325e2d Compare March 20, 2026 16:35
@max-charlamb max-charlamb requested a review from noahfalk March 20, 2026 18:38
@max-charlamb max-charlamb removed the NO-REVIEW Experimental/testing PR, do NOT review it label Mar 20, 2026
@max-charlamb max-charlamb marked this pull request as ready for review March 20, 2026 18:38
Copilot AI review requested due to automatic review settings March 20, 2026 18:38
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 3 comments.

…nd IXCLRDataValue in managed cDAC

Adds managed cDAC implementations for variable inspection APIs:
- ClrDataFrame: GetArgumentByIndex, GetLocalVariableByIndex with signature
  decoding, debug info lookup, and register/stack variable resolution
- ClrDataValue: GetFlags, GetAddress, GetSize, GetBytes, GetNumLocations,
  GetLocationByIndex with full type flag computation from metadata signatures
- DebugInfo contract: GetMethodVarInfo with code offset computation
- Integration tests covering all new APIs against real process dumps

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@max-charlamb max-charlamb force-pushed the cdac-dataframe-value-apis branch from 8325e2d to fb9d865 Compare March 20, 2026 18:58
@noahfalk
Copy link
Copy Markdown
Member

max-charlamb force-pushed the cdac-dataframe-value-apis branch from 8325e2d to fb9d865

The force push re-writing commit history makes it harder to compare what changed from the last time I reviewed. I'd prefer if we keep the history intact while reviews are happening and then squash at the end.

…n, comment

- Fix GetMethodSignatureInfo to skip generic arity before reading
  paramCount for generic method signatures (ECMA-335 compliance)
- Fix GetArgumentByIndex to write empty string when GetParameterName
  returns null instead of leaving name buffer untouched
- Replace unused 'out uint token' with 'out _' in GetLocalVariableByIndex
- Fix outdated comment about GenericInstAndByRefVars parameter count

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 24, 2026 17:54
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 1 comment.

NativeVarLocation is an implementation detail of the IXCLRData interface,
not part of the contract API surface. Move it to ClrDataValue.cs in the
Legacy project where it is consumed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@max-charlamb
Copy link
Copy Markdown
Member Author

/ba-g test failures unrelated to cDAC change

@max-charlamb max-charlamb merged commit c8917ea into dotnet:main Mar 25, 2026
97 of 110 checks passed
@max-charlamb max-charlamb deleted the cdac-dataframe-value-apis branch March 25, 2026 14:59
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