다음을 통해 공유


GetMethodProperty 구현

Important

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