Enable printing generic types for method
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Fri, 7 Jul 2017 18:42:20 +0000 (21:42 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Mon, 13 Nov 2017 19:22:40 +0000 (22:22 +0300)
src/debug/debugger/main.cpp
src/debug/debugger/typeprinter.cpp
src/debug/debugger/typeprinter.h

index 98463f7..f772c54 100644 (file)
@@ -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 << "]";
index fc6fe43..8c43692 100644 (file)
@@ -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<ICorDebugILFrame2> pILFrame2;
+    IfFailRet(pFrame->QueryInterface(IID_ICorDebugILFrame2, (LPVOID*) &pILFrame2));
+
+    ToRelease<ICorDebugFunction> pFunction;
+    IfFailRet(pFrame->GetFunction(&pFunction));
+
     ToRelease<ICorDebugClass> pClass;
     ToRelease<ICorDebugModule> 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<IMDInternalImport> 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<IMetaDataImport2> 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<ICorDebugTypeEnum> pTypeEnum;
+
+    if (SUCCEEDED(pILFrame2->EnumerateTypeParameters(&pTypeEnum)))
+    {
+        ULONG numTypes = 0;
+        ToRelease<ICorDebugType> 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;
 }
index fff7103..5b78912 100644 (file)
@@ -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);
 };