Repository navigation
Description
Description
CoreCLR debugger func-eval can use a stale serialized register value when an argument is a register-resident value type from a non-leaf managed frame and the value type contains an object reference or managed byref.
Source analysis was performed against current main commit f5f66b5f3ceadcd7daca3098b48ba5c8930f01f7 (2026-10-05). The relevant lifetime is:
-
DBI snapshots a non-leaf register rather than retaining an updatable location.
CordbNativeFrame::GetLeftSideAddressOfRegisterreturnskNonLeafFrameRegAddrfor every non-leaf frame (rsthread.cpp#L6414-L6424).RegValueHomesimultaneously captures the register bits inm_regValue(rspriv.h#L7788-L7794), andCopyToIPCETypeserializes the marker plusreg1Value(valuehome.cpp#L29-L35).CordbEval::GatherArgInfodoes this for enregisteredELEMENT_TYPE_VALUETYPEarguments (rsthread.cpp#L9280-L9314), thenSendFuncEvalcopies those bytes into the Left Side'sDebuggerEval::m_argDatabuffer (rsthread.cpp#L9397-L9433). There is no later write that refreshes the serializedreg1Value/reg2Value; the EE only reads them. -
The native bootstrap establishes normal interrupted-frame reporting, but not a root for the serialized copy.
FuncEvalHijackWorkerpushes aFuncEvalFramebefore starting the eval (funceval.cpp#L3816-L3897).FuncEvalFrame::UpdateRegDisplayexposes the saved interrupted leaf context inDebuggerEval::m_contextas mutable register locations for stack walking and GC (debugger.cpp#L15933-L15987). A GC can therefore walk the interrupted managed stack and update the actual root location reconstructed for a non-leaf frame, whether that location is a saved context slot or a stack spill. -
The initial argument-protection pass omits an enregistered value type.
GCProtectArgsAndDoNormalFuncEvalallocates protected object/interior arrays and pushes aProtectValueClassFrame, then callsGCProtectAllPassedArgsin a no-GC region before any type resolution (funceval.cpp#L3485-L3574). ForELEMENT_TYPE_VALUETYPE, however, that pass only records a location whenargAddr != 0; an enregistered value type hasargAddr == 0, so its register bits are neither copied nor protected (funceval.cpp#L1509-L1519). TheProtectValueClassFramelist is still empty for this argument. -
GC-capable work occurs before the register value is materialized.
DoNormalFuncEvalimmediately enters a preemptive region and callsResolveFuncEvalGenericArgInfo(funceval.cpp#L3199-L3233). That function isGC_TRIGGERSand performs type-handle resolution,LoadMethodDef, method/type activation, class initialization, and potentially instantiation loading (funceval.cpp#L1659-L1723);TypeDataWalk::ReadTypeHandleis itselfGC_TRIGGERSand may load array, pointer/byref, and instantiated value types (debugger.cpp#L11789-L11838). Method/class activation and cctors can also allocate or run managed code. Further GC-capable boxing and return-object allocation occur before packing (funceval.cpp#L3285-L3372). -
The non-leaf snapshot is consumed only after that GC window.
CopyArgsToBufferexplicitly does nothing for value types (funceval.cpp#L2271-L2408). Only whilePackArgumentArrayis already inGCX_FORBIDdoesGetFuncEvalArgValuematerialize an enregistered value type (funceval.cpp#L2634-L2653, funceval.cpp#L816-L932).GetRegisterValuedistinguishes the two cases: a non-leaf marker returns the serializedregValue, while a leaf marker readsDebuggerEval::m_context(funceval.cpp#L261-L275).
This creates the stale-reference mechanism: a compacting GC after the early protection pass updates the original interrupted-frame root through normal stack walking, but it cannot update the separate scalar copy in m_argData[].argHome.reg1Value. Late packing then copies the pre-GC object reference or interior byref into the invoked method's argument.
Leaf CPU-context slots are different and appear safe for this specific problem: kLeafFrameRegAddr causes the late read to use pDE->m_context, which is the storage exposed by FuncEvalFrame::UpdateRegDisplay and is GC-updated. The unsafe path is the effectively immutable serialized value selected by kNonLeafFrameRegAddr.
No invariant prevents the input shape. JIT VLT_REG locations are handed to GetLocalRegisterValue without a value-type GC-layout exclusion (rsthread.cpp#L8325-L8352); CordbValue::CreateValueByType supports ELEMENT_TYPE_VALUETYPE with a register home (divalue.cpp#L230-L263). The DBI comment only assumes an enregistered value class has a single field (valuehome.cpp#L824-L830); a pointer-sized struct with one object-reference field or one managed-byref field satisfies that assumption. GatherArgInfo has no ContainsGCPointers or byref-like rejection for value-type arguments.
Reproduction Steps
No deterministic public repro was run for this report. The conclusion above is from the current-main source lifetime, not from the in-progress managed func-eval branch or from a clean runtime A/B experiment.
A deterministic debugger-harness regression test should:
- Stop at a GC-safe point in a deeper managed method while a non-leaf frame has a live pointer-sized value-type local in a register. Test both a struct with one object-reference field and a byref-like struct with one managed-byref field.
- Obtain that non-leaf local through
ICorDebugILFrameand pass itsICorDebugValueas an argument toICorDebugEval::CallFunction. - Inject a compacting GC after the func-eval native bootstrap and
GCProtectAllPassedArgs, but beforePackArgumentArrayperforms the late register read. Arrange for the referenced object to move. - Have the evaluated method verify the received object identity or byref target/address.
- Include leaf-register and memory-home controls. The leaf case should use the GC-updated
DebuggerEval::m_context; the memory-home case should reread updated storage.
The test needs a JIT/debugger hook or controlled code shape to guarantee the non-leaf VLT_REG home and the GC timing.
Expected behavior
All object references and managed byrefs contained in a func-eval argument remain live and are updated to their post-GC locations before the argument is passed to the evaluated method, regardless of whether the debugger obtained the value from a leaf or non-leaf frame.
Actual behavior
For a non-leaf register-resident value type, a compacting GC in the resolution/activation/boxing window can update the original interrupted-frame home but leave the serialized regValue unchanged. The evaluated method can receive a stale object reference or stale interior pointer. This can produce a wrong object/value, an invalid byref, or a debuggee crash/corruption. No crash or corruption is claimed as observed for this report.
Regression?
Not established. This appears to be an existing lifetime gap in current main; no regressing commit was identified or bisected.
Known Workarounds
No general runtime workaround is known. A debugger can avoid passing non-leaf enregistered value-type values containing object references or managed byrefs, or first materialize an equivalent value in GC-tracked/memory-backed storage when possible.
Configuration
- Source: current
dotnet/runtimemain, commitf5f66b5f3ceadcd7daca3098b48ba5c8930f01f7(2026-10-05). - Component: CoreCLR native debugger /
ICorDebugEval. - x64 is a concrete architecture for a pointer-sized single-register case. The marker, serialization, early-protection, and late-read logic is shared, but other architectures were not independently executed.
- No end-to-end runtime repro was run.
Other information
Suggested fix direction:
- Capture and GC-protect register-resident value types before the first GC-capable work, using their exact layout, or register the serialized storage itself in place once an exact no-load layout is available.
- Ensure the initial protection step cannot itself require type loading or allocation before the values are rooted.
- Preserve the distinction between leaf context-backed register slots and non-leaf serialized values.
- Avoid reporting the same storage slot twice if protection is integrated with existing interrupted-frame reporting.
- Keep late argument packing in a no-GC region, but do not rely on that region to repair an earlier stale snapshot.
Focused open-and-closed issue searches for debugger func eval non-leaf register GC stale value type, serialized regValue GC root, and nonleaf frame func-eval struct found no duplicate. Related but distinct issues are:
- Debugger func-eval byref result can become stale before deferred completion #135247: stale raw byref result during deferred completion.
- Debugger func-eval: a by-value
ref structwith overlappingreffields is reported to the GC twice, so a compacting GC relocates the byref twice #135245: double-reporting overlapping byref fields in an already protected by-valueref structcopy. - Debugger func-eval cannot consume a 64-bit RAK_REGREG value-type argument #135231: inability to materialize a 64-bit
RAK_REGREGvalue-type argument. - Func eval of functions that take 16-byte input structs corrupts the input #6628: an older 16-byte input-struct corruption fixed by Fix funceval for enregistered value types arguments. coreclr#7149.
Note
This issue was drafted with GitHub Copilot.
Activity
dotnet-policy-service commentedon Oct 5, 2026
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.
Invoke debugger function evaluations through managed UCO (#133659)