Repository navigation
Description
Description
ICorDebugILFrame3::GetReturnValueForILOffset can expose a 9–16 byte value type returned in two integer registers on a 64-bit target. If that ICorDebugValue is subsequently supplied as an argument to ICorDebugEval::CallFunction, the Right Side serializes its RegRegValueHome as RAK_REGREG.
The Left Side cannot currently consume that argument on a 64-bit target. GetRegisterValueAndReturnAddress handles RAK_REGREG only under !HOST_64BIT, so it returns nullptr. That becomes E_POINTER, which is surfaced as an ArgumentNullException from the func-eval rather than invoking the requested method.
This creates an inconsistency between two debugger APIs:
- The managed-return-value APIs produce a valid two-register
ICorDebugValue. - Func-eval accepts that value as an argument during setup but cannot materialize it for invocation.
Reproduction Steps
Run the following program as ARM64. A 16-byte non-HFA struct is returned in x0/x1.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public readonly struct Pair
{
public readonly long Low;
public readonly long High;
public Pair(long low, long high)
{
Low = low;
High = high;
}
}
public static class Program
{
[MethodImpl(MethodImplOptions.NoInlining)]
private static Pair MakePair()
{
return new Pair(
0x1111_1111_2222_2222,
0x3333_3333_4444_4444);
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static long Consume(Pair value)
{
// The current func-eval implementation fails before entering this method.
return value.Low ^ value.High;
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
private static void Scenario()
{
// Set an ICorDebug return-value breakpoint for the call to MakePair.
//
// The debugger must stop at the native offset immediately after
// `MakePair` returns but before x0/x1 are stored into `value`.
// At that point the Pair return value is exposed as VLT_REG_REG.
Pair value = MakePair();
Console.WriteLine($"{value.Low:X16} {value.High:X16}");
}
public static void Main()
{
Scenario();
}
}The debugger should perform the following operations:
// Locate the IL offset of the call to Program.MakePair.
ULONG32 callILOffset = /* call instruction IL offset */;
// Get the native location where the call's return value is live.
ICorDebugCode3* code3 = /* QI from the native code */;
ULONG32 returnValueOffset = 0;
ULONG32 fetched = 0;
HRESULT hr = code3->GetReturnValueLiveOffset(
callILOffset,
1,
&fetched,
&returnValueOffset);
// Set an ICorDebugCode breakpoint at returnValueOffset and continue.
//
// The resulting stop is immediately after the ARM64 `bl MakePair`.
// x0 contains Pair.Low and x1 contains Pair.High.
// Obtain the register-backed return value.
ICorDebugILFrame3* frame3 = /* QI from the current IL frame */;
ICorDebugValue* pairValue = nullptr;
hr = frame3->GetReturnValueForILOffset(
callILOffset,
&pairValue);
// Resolve Program.Consume(Pair).
ICorDebugFunction* consumeFunction = /* metadata/function lookup */;
// Create a func-eval on the stopped thread.
ICorDebugEval* eval = nullptr;
hr = thread->CreateEval(&eval);
// Pass the register-backed return value directly into func-eval.
ICorDebugValue* arguments[] = { pairValue };
hr = eval->CallFunction(consumeFunction, 1, arguments);
// Continue to run the func-eval.
hr = process->Continue(FALSE);The return value is initially described as:
VLT_REG_REG
vlrrReg1 = x0 // low 8 bytes
vlrrReg2 = x1 // high 8 bytes
CordbNativeFrame::GetLocalDoubleRegisterValue converts this to a RegRegValueHome. CordbEval::GatherArgInfo then serializes the argument as:
argElementType = ELEMENT_TYPE_VALUETYPE
argAddr = 0
fullArgType = serialized Pair type
argHome.kind = RAK_REGREG
argHome.reg1 = x1 // high half
argHome.u.reg2 = x0 // low half
Expected behavior
The func-eval should reconstruct the two register pieces into correctly typed contiguous storage and invoke:
Consume(new Pair(
0x1111_1111_2222_2222,
0x3333_3333_4444_4444))The debugger should receive EvalComplete, and GetResult should return:
0x2222_2222_6666_6666
Actual behavior
The func-eval setup succeeds, but execution follows this path:
ProtectFuncEvalArgumentStorage
→ ReadFuncEvalRegisterValue
→ GetRegisterValueAndReturnAddress
The RAK_REGREG case is excluded on a 64-bit host:
#if !defined(HOST_64BIT)
case RAK_REGREG:
...
#endifIt therefore reaches:
default:
pAddr = nullptr;
break;The resulting failure is:
GetRegisterValueAndReturnAddress → nullptr
ReadFuncEvalRegisterValue → FALSE
ProtectFuncEvalArgumentStorage → E_POINTER
InvokeManagedFuncEval → ArgumentNullException
The debugger receives EvalException, and Program.Consume is never entered.
Regression?
Not established. This appears to be a composition gap between two-register managed-return-value support and the func-eval argument materialization path.
Known Workarounds
Continue or step until the returned struct has been stored into contiguous target memory, then obtain that local value and use it as the func-eval argument.
Alternatively, invoke the producing method through func-eval. Value-type func-eval results are boxed into a strong handle, so a subsequent func-eval receives a handle-backed object rather than RAK_REGREG.
Configuration
The minimal reproduction should use:
- ARM64, where a 16-byte non-HFA struct is returned in
x0/x1. - A runtime build containing two-register managed-return-value debugger support.
- An
ICorDebugdebugger that uses the return-value breakpoint andGetReturnValueForILOffsetAPIs.
SysV AMD64 should provide another reproduction when the struct is classified into two integer return registers. Windows x64 is not suitable for this specific example because it returns this struct through a hidden return buffer.
Other information
Relevant code paths include:
src/coreclr/jit/codegencommon.cpp- Emits
VLT_REG_REGmanaged-return-value information.
- Emits
src/coreclr/jit/scopeinfo.cpp- Publishes the one-instruction
CALL_RETURN_ILNUMlive range.
- Publishes the one-instruction
src/coreclr/debug/di/rsthread.cpp- Creates
RegRegValueHomefor an integer-registerVLT_REG_REGvalue. CordbEval::GatherArgInfoserializes it asRAK_REGREG.
- Creates
src/coreclr/debug/di/valuehome.cppRegRegValueHome::CopyToIPCEType.
src/coreclr/debug/ee/funceval.cppGetRegisterValueAndReturnAddressonly handlesRAK_REGREGunder!HOST_64BIT.ProtectFuncEvalArgumentStorageconverts the failed read intoE_POINTER.
src/coreclr/System.Private.CoreLib/src/System/Diagnostics/Debugger.FunctionEvaluation.cs- Register-backed value-type copying currently supports at most eight bytes.
A fix needs to materialize two pointer-sized register pieces into contiguous, correctly ordered, typed storage. It should not assume the underlying CONTEXT register fields are adjacent: for example, AMD64 stores RAX, RCX, and then RDX, and FP/mixed return-register pairs occupy separate or padded context regions.
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.
Fix debugger func-eval support for 64-bit RAK_REGREG value types (dot…