ICorDebugILFrame3::GetReturnValueForILOffset Method
Gets an "ICorDebugValue" object that encapsulates the return value of a function.
Syntax
HRESULT GetReturnValueForILOffset(
ULONG32 ILoffset,
[out] ICorDebugValue **ppReturnValue
);
Parameters
ILOffset
The IL offset. See the Remarks section.
ppReturnValue
A pointer to the address of an "ICorDebugValue" interface object that provides information about the return value of a function call.
Remarks
This method is used along with the ICorDebugCode3::GetReturnValueLiveOffset method to get the return value of a method. It is particularly useful in the case of methods whose return values are ignored, as in the following two code examples. The first example calls the Int32.TryParse method, but ignores the method's return value.
private static int ConvertNumericString(string s)
{
int number;
if (s.Trim().Length == 8)
Int32.TryParse(s, System.Globalization.NumberStyles.HexNumber,
null, out number);
else
Int32.TryParse(s, out number);
return number;
}
Private Function ConvertNumericString(s As String) As Integer
Dim number As Integer
If s.Trim().Length = 8 Then
Int32.TryParse(s, System.Globalization.NumberStyles.HexNumber,
Nothing, number)
Else
Int32.TryParse(s, number)
End If
Return number
End Function
The second example illustrates a much more common problem in debugging. Because a method is used as an argument in a method call, its return value is accessible only when the debugger steps through the called method. In many cases, particularly when the called method is defined in an external library, that is not possible.
using System;
public class Example
{
private static Random rnd;
public static void Main()
{
rnd = new Random();
Example ex = new Example();
double value = MathLib.GetComputedValue(ex.GetInt(), ex.GetDouble());
Console.WriteLine(value);
}
private int GetInt()
{
return rnd.Next(11, 100);
}
private double GetDouble()
{
return rnd.NextDouble();
}
}
Public Module Example
Dim rnd As Random
Public Sub Main()
rnd = New Random()
Dim value As Double = MathLib.GetComputedValue(GetInt(), GetDouble())
Console.WriteLine(value)
End Sub
Private Function GetInt() As Integer
Return rnd.Next(11, 100)
End Function
Private Function GetDouble() As Double
Return rnd.NextDouble()
End Function
End Module
If you pass the ICorDebugCode3::GetReturnValueLiveOffset method an IL offset to a function call site, it returns one or more native offsets. The debugger can then set breakpoints on these native offsets in the function. When the debugger hits one of the breakpoints, you can then pass the same IL offset that you passed to this method to get the return value. The debugger should then clear all the breakpoints that it set.
Warning
The ICorDebugCode3::GetReturnValueLiveOffset Method and ICorDebugILFrame3::GetReturnValueForILOffset
methods allow you to get return value information for reference types only. Retrieving return value information from value types (that is, all types that derive from ValueType) is not supported.
The IL offset specified by the ILOffset
parameter should be at a function call site, and the debuggee should be stopped at a breakpoint set at the native offset returned by the ICorDebugCode3::GetReturnValueLiveOffset method for the same IL offset. If the debuggee is not stopped at the correct location for the specified IL offset, the API will fail.
If the function call doesn't return a value, the API will fail.
The ICorDebugILFrame3::GetReturnValueForILOffset
method is available only on x86-based and AMD64 systems.
Requirements
Platforms: See System Requirements.
Header: CorDebug.idl, CorDebug.h
Library: CorGuids.lib
.NET Framework Versions: Available since 4.5.1
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for