Implementing GetMethodProperty
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
Important
In Visual Studio 2015, this way of implementing expression evaluators is deprecated. For information about implementing CLR expression evaluators, please see CLR Expression Evaluators and Managed Expression Evaluator Sample.
Visual Studio calls the debug engine's (DE) GetDebugProperty, which in turn calls GetMethodProperty to obtain information about the current method on the stack frame.
This implementation of IDebugExpressionEvaluator::GetMethodProperty
performs the following tasks:
Calls GetContainerField, passing in the IDebugAddress object. The symbol provider (SP) returns an IDebugContainerField representing the method that contains the specified address.
Obtains the IDebugMethodField from the
IDebugContainerField
.Instantiates a class (called
CFieldProperty
in this example) that implements the IDebugProperty2 interface and contains theIDebugMethodField
object returned from the SP.Returns the
IDebugProperty2
interface from theCFieldProperty
object.
Managed Code
This example shows an implementation of IDebugExpressionEvaluator::GetMethodProperty
in managed code.
namespace EEMC
{
[GuidAttribute("462D4A3D-B257-4AEE-97CD-5918C7531757")]
public class EEMCClass : IDebugExpressionEvaluator
{
public HRESULT GetMethodProperty(
IDebugSymbolProvider symbolProvider,
IDebugAddress address,
IDebugBinder binder,
int includeHiddenLocals,
out IDebugProperty2 property)
{
IDebugContainerField containerField = null;
IDebugMethodField methodField = null;
property = null;
// Get the containing method field.
symbolProvider.GetContainerField(address, out containerField);
methodField = (IDebugMethodField) containerField;
// Return the property of method field.
property = new CFieldProperty(symbolProvider, address, binder, methodField);
return COM.S_OK;
}
}
}
Unmanaged Code
This example shows an implementation of IDebugExpressionEvaluator::GetMethodProperty
in unmanaged code.
[CPP]
STDMETHODIMP CExpressionEvaluator::GetMethodProperty(
in IDebugSymbolProvider *pprovider,
in IDebugAddress *paddress,
in IDebugBinder *pbinder,
in BOOL includeHiddenLocals,
out IDebugProperty2 **ppproperty
)
{
if (pprovider == NULL)
return E_INVALIDARG;
if (ppproperty == NULL)
return E_INVALIDARG;
else
*ppproperty = 0;
HRESULT hr;
IDebugContainerField* pcontainer = NULL;
hr = pprovider->GetContainerField(paddress, &pcontainer);
if (FAILED(hr))
return hr;
IDebugMethodField* pmethod = NULL;
hr = pcontainer->QueryInterface( IID_IDebugMethodField,
reinterpret_cast<void**>(&pmethod));
pcontainer->Release();
if (FAILED(hr))
return hr;
CFieldProperty* pfieldProperty = new CFieldProperty( pprovider,
paddress,
pbinder,
pmethod );
pmethod->Release();
if (!pfieldProperty)
return E_OUTOFMEMORY;
hr = pfieldProperty->Init();
if (FAILED(hr))
{
pfieldProperty->Release();
return hr;
}
hr = pfieldProperty->QueryInterface( IID_IDebugProperty2,
reinterpret_cast<void**>(ppproperty));
pfieldProperty->Release();
return hr;
}