From 658dc5ca85c68e9b69aa588f47cd60f9ad72f95d Mon Sep 17 00:00:00 2001 From: Igor Kulaychuk Date: Fri, 7 Jul 2017 21:42:20 +0300 Subject: [PATCH] Enable printing generic types for method --- src/debug/debugger/main.cpp | 6 ++-- src/debug/debugger/typeprinter.cpp | 72 ++++++++++++++++++++++++++++---------- src/debug/debugger/typeprinter.h | 2 +- 3 files changed, 57 insertions(+), 23 deletions(-) diff --git a/src/debug/debugger/main.cpp b/src/debug/debugger/main.cpp index 98463f7..f772c54 100644 --- a/src/debug/debugger/main.cpp +++ b/src/debug/debugger/main.cpp @@ -396,10 +396,10 @@ HRESULT PrintFrames(ICorDebugThread *pThread, std::string &output) if (!frameLocation.empty()) ss << frameLocation << ","; - std::string funcType; - TypePrinter::GetMethodType(pFunction, funcType); + std::string methodName; + TypePrinter::GetMethodName(pFrame, methodName); - ss << "func=\"" << funcType << "\"}"; + ss << "func=\"" << methodName << "\"}"; } ss << "]"; diff --git a/src/debug/debugger/typeprinter.cpp b/src/debug/debugger/typeprinter.cpp index fc6fe43..8c43692 100644 --- a/src/debug/debugger/typeprinter.cpp +++ b/src/debug/debugger/typeprinter.cpp @@ -366,10 +366,16 @@ HRESULT TypePrinter::GetTypeOfValue(ICorDebugType *pType, std::string &output) return S_OK; } -HRESULT TypePrinter::GetMethodType(ICorDebugFunction *pFunction, std::string &output) +HRESULT TypePrinter::GetMethodName(ICorDebugFrame *pFrame, std::string &output) { HRESULT Status; + ToRelease pILFrame2; + IfFailRet(pFrame->QueryInterface(IID_ICorDebugILFrame2, (LPVOID*) &pILFrame2)); + + ToRelease pFunction; + IfFailRet(pFrame->GetFunction(&pFunction)); + ToRelease pClass; ToRelease pModule; mdMethodDef methodDef; @@ -408,35 +414,63 @@ HRESULT TypePrinter::GetMethodType(ICorDebugFunction *pFunction, std::string &ou WCHAR m_szName[mdNameLen] = {0}; m_szName[0] = L'\0'; + char nameBuffer[2048] = {0}; + std::stringstream ss; + if (memTypeDef != mdTypeDefNil) { hr = NameForTypeDef_s (memTypeDef, pMD, m_szName, _countof(m_szName)); if (SUCCEEDED (hr)) { - wcscat_s (m_szName, _countof(m_szName), W(".")); + WideCharToMultiByte(CP_UTF8, 0, m_szName, (int)(_wcslen(m_szName) + 1), nameBuffer, _countof(nameBuffer), NULL, NULL); + ss << nameBuffer << "."; } } - wcscat_s (m_szName, _countof(m_szName), szFunctionName); - ToRelease pIMDI; - IfFailRet(GetMDInternalFromImport(pMD, &pIMDI)); + WideCharToMultiByte(CP_UTF8, 0, szFunctionName, (int)(_wcslen(szFunctionName) + 1), nameBuffer, _countof(nameBuffer), NULL, NULL); + ss << nameBuffer; - LPCSTR szName = NULL; - LPCSTR szNameSpace = NULL; - pIMDI->GetNameOfTypeDef(memTypeDef, &szName, &szNameSpace); + ToRelease pMD2; + IfFailRet(pMDUnknown->QueryInterface(IID_IMetaDataImport2, (LPVOID*) &pMD2)); - // CORDB_ADDRESS modAddress; - // IfFailRet(pModule->GetBaseAddress(&modAddress)); - // WCHAR cBuffer[2048]; - // PrettyPrintClassFromToken(modAddress, typeDef, cBuffer, 2048); - // IMDInternalImport *pIMDI; + ULONG methodGenericsCount = 0; + HCORENUM hEnum = NULL; + mdGenericParam gp; + ULONG fetched; + while (SUCCEEDED(pMD2->EnumGenericParams(&hEnum, methodDef, &gp, 1, &fetched)) && fetched == 1) + { + methodGenericsCount++; + } + pMD2->CloseEnum(hEnum); + + if (methodGenericsCount > 0) + { + ss << '`' << methodGenericsCount; + } + + ToRelease pTypeEnum; + + if (SUCCEEDED(pILFrame2->EnumerateTypeParameters(&pTypeEnum))) + { + ULONG numTypes = 0; + ToRelease pCurrentTypeParam; - // TODO: - // LONG lSigBlobRemaining; - // hr = GetFullNameForMD(pbSigBlob, ulSigBlob, &lSigBlobRemaining); + bool isFirst = true; + + while (SUCCEEDED(pTypeEnum->Next(1, &pCurrentTypeParam, &numTypes)) && numTypes == 1) + { + ss << (isFirst ? "<" : ","); + isFirst = false; + + std::string name; + GetTypeOfValue(pCurrentTypeParam, name); + ss << name; + } + if(!isFirst) + ss << ">"; + } - char funcName[2048] = {0}; - WideCharToMultiByte(CP_UTF8, 0, m_szName, (int)(_wcslen(m_szName) + 1), funcName, _countof(funcName), NULL, NULL); + ss << "()"; - output = funcName; + output = ss.str(); return S_OK; } diff --git a/src/debug/debugger/typeprinter.h b/src/debug/debugger/typeprinter.h index fff7103..5b78912 100644 --- a/src/debug/debugger/typeprinter.h +++ b/src/debug/debugger/typeprinter.h @@ -8,5 +8,5 @@ class TypePrinter public: static HRESULT GetTypeOfValue(ICorDebugType *pType, std::string &output); static HRESULT GetTypeOfValue(ICorDebugValue *pValue, std::string &output); - static HRESULT GetMethodType(ICorDebugFunction *pFunction, std::string &output); + static HRESULT GetMethodName(ICorDebugFrame *pFrame, std::string &output); }; -- 2.7.4