次の方法で共有


GetMethodProperty の実装

重要

Visual Studio 2015 では、この方法での式エバリュエーターの実装は非推奨です。 CLR 式エバリュエーターの実装については、CLR 式エバリュエーターに関する記事とマネージド式エバリュエーターのサンプルに関する記事をご覧ください。

Visual Studio から、デバッグ エンジンの (DE) GetDebugProperty が呼び出されます。これにより GetMethodProperty が呼び出され、スタック フレームの現在のメソッドに関する情報が取得されます。

この IDebugExpressionEvaluator::GetMethodProperty の実装では、次のタスクが実行されます。

  1. GetContainerField が呼び出され、IDebugAddress オブジェクトが渡されます。 シンボル プロバイダー (SP) から、指定されたアドレスを含むメソッドを表す IDebugContainerField が返されます。

  2. IDebugContainerField から IDebugMethodField が取得されます。

  3. IDebugProperty2 インターフェイスを実装し、SP から返された IDebugMethodField オブジェクトを格納するクラス (この例では CFieldProperty と呼ばれます) をインスタンス化します。

  4. 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;
}