Visual Studio 会调用调试引擎的 (DE) IDebugStackFrame2:: GetDebugProperty,然后调用 IDebugExpressionEvaluator:: GetMethodProperty 获取有关当前方法的信息在堆栈帧。
IDebugExpressionEvaluator::GetMethodProperty 的此实现执行以下任务:
调用 IDebugSymbolProvider:: GetContainerField,通过在 IDebugAddress 对象。 符号提供 (SP)程序返回表示包含指定的地址的方法的 IDebugContainerField 。
获取从 IDebugContainerField的 IDebugMethodField 。
实例化类 (称为在此示例中的 CFieldProperty ) 实现 IDebugProperty2 接口并包含从 SP 返回的 IDebugMethodField 对象。
返回从 CFieldProperty 对象的 IDebugProperty2 接口。
托管代码
此示例在托管代码公开 IDebugExpressionEvaluator::GetMethodProperty 的实现。
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;
}
}
}
非托管代码
此示例在非托管代码演示 IDebugExpressionEvaluator::GetMethodProperty 的实现。
[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;
}