From c21a3d6d137cc148d146d93306dab56085c6371f Mon Sep 17 00:00:00 2001 From: szehetner <32911487+szehetner@users.noreply.github.com> Date: Fri, 16 Nov 2018 03:14:03 +0100 Subject: Fixed signatures of ref readonly methods in JIT ETW events (#20981) * fixed ETW method signature of ref readonly methods * added type token * extract method for printing classes * fixed optional_modifier, use CorSigUncompressToken_EndPtr --- src/utilcode/prettyprintsig.cpp | 123 ++++++++++++++++++++++++++-------------- 1 file changed, 81 insertions(+), 42 deletions(-) (limited to 'src/utilcode') diff --git a/src/utilcode/prettyprintsig.cpp b/src/utilcode/prettyprintsig.cpp index fc0844ce4a..2c516e4fae 100644 --- a/src/utilcode/prettyprintsig.cpp +++ b/src/utilcode/prettyprintsig.cpp @@ -556,6 +556,13 @@ HRESULT PrettyPrintSigWorkerInternal( CQuickBytes * out, // where to put the pretty printed string IMDInternalImport * pIMDI); // Import api to use. +static HRESULT PrettyPrintClass( + PCCOR_SIGNATURE &typePtr, // type to convert + PCCOR_SIGNATURE typeEnd, // end of the signature. + CQuickBytes *out, // where to put the pretty printed string + IMDInternalImport *pIMDI); // ptr to IMDInternal class with ComSig + + #ifdef _PREFAST_ #pragma warning(push) #pragma warning(disable:21000) // Suppress PREFast warning about overly large function @@ -581,8 +588,6 @@ static HRESULT PrettyPrintTypeA( mdToken tk; // A type's token. const CHAR *str; // Temporary string. - LPCUTF8 pNS; // A type's namespace. - LPCUTF8 pN; // A type's name. HRESULT hr; // A result. PCCOR_SIGNATURE typeEnd = typePtr + typeLen; // End of the signature. @@ -685,55 +690,27 @@ static HRESULT PrettyPrintTypeA( case ELEMENT_TYPE_CLASS: str = "class "; goto DO_CLASS; + + DO_CLASS: + IfFailGo(appendStrA(out, str)); + IfFailGo(PrettyPrintClass(typePtr, typeEnd, out, pIMDI)); + break; case ELEMENT_TYPE_CMOD_REQD: str = "required_modifier "; - goto DO_CLASS; + goto CMOD; case ELEMENT_TYPE_CMOD_OPT: str = "optional_modifier "; - goto DO_CLASS; + goto CMOD; - DO_CLASS: - typePtr += CorSigUncompressToken(typePtr, &tk); + CMOD: IfFailGo(appendStrA(out, str)); - str = ""; - - if (TypeFromToken(tk) == mdtTypeSpec) - { - ULONG cSig; - PCCOR_SIGNATURE sig; - IfFailGo(pIMDI->GetSigFromToken(tk, &cSig, &sig)); - IfFailGo(PrettyPrintTypeA(sig, cSig, out, pIMDI)); - } - else - { - if (TypeFromToken(tk) == mdtTypeRef) - { - //@consider: assembly name? - if (FAILED(pIMDI->GetNameOfTypeRef(tk, &pNS, &pN))) - { - pNS = pN = "Invalid TypeRef record"; - } - } - else - { - _ASSERTE(TypeFromToken(tk) == mdtTypeDef); - if (FAILED(pIMDI->GetNameOfTypeDef(tk, &pN, &pNS))) - { - pNS = pN = "Invalid TypeDef record"; - } - } - - if (pNS && *pNS) - { - IfFailGo(appendStrA(out, pNS)); - IfFailGo(appendStrA(out, NAMESPACE_SEPARATOR_STR)); - } - IfFailGo(appendStrA(out, pN)); - } + IfFailGo(PrettyPrintClass(typePtr, typeEnd, out, pIMDI)); + IfFailGo(appendStrA(out, " ")); + IfFailGo(PrettyPrintTypeA(typePtr, (typeEnd - typePtr), out, pIMDI)); break; - + case ELEMENT_TYPE_SZARRAY: IfFailGo(PrettyPrintTypeA(typePtr, (typeEnd - typePtr), out, pIMDI)); IfFailGo(appendStrA(out, "[]")); @@ -866,6 +843,68 @@ static HRESULT PrettyPrintTypeA( #pragma warning(pop) #endif +// pretty prints the class 'type' to the buffer 'out' +static HRESULT PrettyPrintClass( + PCCOR_SIGNATURE &typePtr, // type to convert + PCCOR_SIGNATURE typeEnd, // end of the signature. + CQuickBytes *out, // where to put the pretty printed string + IMDInternalImport *pIMDI) // ptr to IMDInternal class with ComSig +{ + CONTRACTL + { + NOTHROW; + INJECT_FAULT(return E_OUTOFMEMORY;); + } + CONTRACTL_END + + mdToken tk; + const CHAR *str; // type's token. + LPCUTF8 pNS; // type's namespace. + LPCUTF8 pN; // type's name. + HRESULT hr; // result + + IfFailGo(CorSigUncompressToken_EndPtr(typePtr, typeEnd, &tk)); + str = ""; + + if (TypeFromToken(tk) == mdtTypeSpec) + { + ULONG cSig; + PCCOR_SIGNATURE sig; + IfFailGo(pIMDI->GetSigFromToken(tk, &cSig, &sig)); + IfFailGo(PrettyPrintTypeA(sig, cSig, out, pIMDI)); + } + else + { + if (TypeFromToken(tk) == mdtTypeRef) + { + //@consider: assembly name? + if (FAILED(pIMDI->GetNameOfTypeRef(tk, &pNS, &pN))) + { + pNS = pN = "Invalid TypeRef record"; + } + } + else + { + _ASSERTE(TypeFromToken(tk) == mdtTypeDef); + if (FAILED(pIMDI->GetNameOfTypeDef(tk, &pN, &pNS))) + { + pNS = pN = "Invalid TypeDef record"; + } + } + + if (pNS && *pNS) + { + IfFailGo(appendStrA(out, pNS)); + IfFailGo(appendStrA(out, NAMESPACE_SEPARATOR_STR)); + } + IfFailGo(appendStrA(out, pN)); + } + return S_OK; + +ErrExit: + return hr; +} // static HRESULT PrettyPrintClass() + //***************************************************************************** // Converts a com signature to a text signature. // -- cgit v1.2.3