void MicrosoftInstrumentationEngine::CMethodInfo::LogMethodInfo()

in src/InstrumentationEngine/MethodInfo.cpp [1487:1667]


void MicrosoftInstrumentationEngine::CMethodInfo::LogMethodInfo()
{
    if (!CLogging::AllowLogEntry(LoggingFlags_InstrumentationResults))
    {
        return;
    }

    CComBSTR bstrMethodName;
    this->GetName(&bstrMethodName);

    CComBSTR bstrMethodFullName;
    this->GetFullName(&bstrMethodFullName);

    ClassID classId = 0;
    FunctionID functionId = 0;

    if (!IsRejit())
    {
        this->GetClassId(&classId);
        this->GetFunctionId(&functionId);
    }

    mdToken methodToken = mdTokenNil;
    this->GetMethodToken(&methodToken);

    DWORD genericParamCount = 0;
    this->GetGenericParameterCount(&genericParamCount);

    BOOL isStatic = false;
    this->GetIsStatic(&isStatic);

    BOOL isPublic = false;
    this->GetIsPublic(&isPublic);

    BOOL isPrivate = false;
    this->GetIsPrivate(&isPrivate);

    BOOL isPropGetter = false;
    this->GetIsPropertyGetter(&isPropGetter);

    BOOL isPropSetter = false;
    this->GetIsPropertySetter(&isPropSetter);

    BOOL isFinalizer = false;
    this->GetIsFinalizer(&isFinalizer);

    BOOL isConstructor = false;
    this->GetIsConstructor(&isConstructor);

    BOOL isStaticConstructor = false;
    this->GetIsStaticConstructor(&isStaticConstructor);

    CComPtr<IType> pDeclaringType;
    this->GetDeclaringType(&pDeclaringType);
    CComPtr<ITokenType> pDeclaringTokenType;
    pDeclaringType->QueryInterface(__uuidof(ITokenType), (LPVOID*)&pDeclaringTokenType);
    mdToken declaringTypeToken = mdTokenNil;
    pDeclaringTokenType->GetToken(&declaringTypeToken);

    CComPtr<IType> pReturnType;
    this->GetReturnType(&pReturnType);

    mdToken retTypeToken = mdTokenNil;
    CComPtr<ITokenType> pReturnTokenType;
    pReturnType->QueryInterface(__uuidof(ITokenType), (LPVOID*)&pReturnTokenType);

    if (pReturnTokenType != nullptr)
    {
        pReturnTokenType->GetToken(&retTypeToken);
    }

    DWORD cbCorSig = 0;
    DWORD cbCorSigActual = 0;
    this->GetCorSignature(cbCorSig, NULL, &cbCorSigActual);

    CAutoVectorPtr<BYTE> pCorSig;
    pCorSig.Allocate(cbCorSigActual);
    cbCorSig = cbCorSigActual;
    this->GetCorSignature(cbCorSig, pCorSig, &cbCorSigActual);

    CorMethodAttr corMethodAttr = CorMethodAttr::mdPrivateScope;
    this->GetAttributes((DWORD*)(&corMethodAttr));

    DWORD rva = 0;
    this->GetCodeRva(&rva);

    CorMethodImpl methodImpl = CorMethodImpl::miIL;
    this->MethodImplFlags((UINT*)(&methodImpl));

    CComPtr<CInstructionGraph> pInstructionGraph;
    CComPtr<CExceptionSection> pExceptionSection;
    CAutoVectorPtr<COR_IL_MAP> pCorILMap;
    DWORD dwCorILMapmLen;

    CComPtr<ILocalVariableCollection> pLocals;
    CComPtr<ISignatureBuilder> pSignatureBuilder;
    const BYTE* pLocalSig = nullptr;
    DWORD dwLocalSigCount = 0;
    if (SUCCEEDED(this->GetLocalVariables(&pLocals)))
    {
        if (SUCCEEDED(pLocals->GetCorSignature(&pSignatureBuilder)))
        {
            pSignatureBuilder->GetCorSignaturePtr(&pLocalSig);
            pSignatureBuilder->GetSize(&dwLocalSigCount);
        }
    }

    DWORD maxStack = 0;
    this->GetMaxStack(&maxStack);

    CLogging::LogDumpMessage(_T("<?xml version=\"1.0\"?>"));
    CLogging::LogDumpMessage(_T("[TestIgnore]<Pid>%5d</Pid>"), GetCurrentProcessId());
    CLogging::LogDumpMessage(_T("<InstrumentedMethod>"));
    CLogging::LogDumpMessage(_T("    <Name>%s</Name>"), bstrMethodName.m_str);
    CLogging::LogDumpMessage(_T("    <FullName>%s</FullName>"), bstrMethodFullName.m_str);
    CLogging::LogDumpMessage(_T("    <ClassID Volatile=\"True\">0x%08" PRIxPTR "</ClassID>"), classId);
    CLogging::LogDumpMessage(_T("    <FunctionID Volatile=\"True\">0x%08" PRIxPTR "</FunctionID>"), functionId);
    CLogging::LogDumpMessage(_T("    <MethodToken>0x%08x</MethodToken>"), methodToken);
    CLogging::LogDumpMessage(_T("    <GenericParameterCount>0x%08x</GenericParameterCount>"), genericParamCount);
    CLogging::LogDumpMessage(_T("    <IsStatic>%1d</IsStatic>"), isStatic);
    CLogging::LogDumpMessage(_T("    <IsPublic>%1d</IsPublic>"), isPublic);
    CLogging::LogDumpMessage(_T("    <IsPrivate>%1d</IsPrivate>"), isPrivate);
    CLogging::LogDumpMessage(_T("    <IsPropGetter>%1d</IsPropGetter>"), isPropGetter);
    CLogging::LogDumpMessage(_T("    <IsPropSetter>%1d</IsPropSetter>"), isPropSetter);
    CLogging::LogDumpMessage(_T("    <IsFinalizer>%1d</IsFinalizer>"), isFinalizer);
    CLogging::LogDumpMessage(_T("    <IsConstructor>%1d</IsConstructor>"), isConstructor);
    CLogging::LogDumpMessage(_T("    <IsStaticConstructor>%1d</IsStaticConstructor>"), isConstructor & isStatic);
    CLogging::LogDumpMessage(_T("    <DeclaringTypeToken>0x%08x</DeclaringTypeToken>"), declaringTypeToken);

    tstring strRetValType = GetCorElementTypeString(pReturnType);
    CLogging::LogDumpMessage(_T("    <RetValueCorElementType>%s</RetValueCorElementType>"), strRetValType.c_str());
    CLogging::LogDumpMessage(_T("    <RetTypeToken>0x%08x</RetTypeToken>"), retTypeToken);

    const size_t HexByteBufferSize = 6;
    WCHAR wszHexByteBuffer[HexByteBufferSize];

    tstring strCorSigElement(_T("    <CorSignature>"));
    for (DWORD i = 0; i < cbCorSigActual; i++)
    {
        ZeroMemory(wszHexByteBuffer, HexByteBufferSize);
        _snwprintf_s(
            wszHexByteBuffer,
            HexByteBufferSize,
            _TRUNCATE,
            _T("0x%02x "),
            pCorSig[i]);
        strCorSigElement.append(wszHexByteBuffer);
    }
    strCorSigElement.append(_T("</CorSignature>"));
    CLogging::LogDumpMessage(_T("%s"), strCorSigElement.c_str());

    CLogging::LogDumpMessage(_T("    <CorMethodAttr>0x%08x</CorMethodAttr>"), corMethodAttr);
    CLogging::LogDumpMessage(_T("    <CodeRVA>0x%08x</CodeRVA>"), rva);
    CLogging::LogDumpMessage(_T("    <MethodImpl>0x%08x</MethodImpl>"), methodImpl);

    tstring strLocalSigElement(_T("    <LocalSignature>"));
    for (DWORD i = 0; i < dwLocalSigCount; i++)
    {
        ZeroMemory(wszHexByteBuffer, HexByteBufferSize);
        _snwprintf_s(
            wszHexByteBuffer,
            HexByteBufferSize,
            _TRUNCATE,
            _T("0x%02x "),
            pLocalSig[i]);
        strLocalSigElement.append(wszHexByteBuffer);
    }
    strLocalSigElement.append(_T("</LocalSignature>"));
    CLogging::LogDumpMessage(_T("%s"), strLocalSigElement.c_str());

    CLogging::LogDumpMessage(_T("    <MaxStack>0x%08x</MaxStack>"), maxStack);

    if (SUCCEEDED(this->GetInstrumentationResults(&pInstructionGraph, &pExceptionSection, (COR_IL_MAP**)&pCorILMap, &dwCorILMapmLen)))
    {
        LogInstructionGraph(pInstructionGraph);
        LogExceptionSection(pExceptionSection);
        LogCorIlMap(pCorILMap, dwCorILMapmLen);
    }

    CLogging::LogDumpMessage(_T("</InstrumentedMethod>"));
}