diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 848e1a53314c8..abcae89dcf326 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -2265,8 +2265,20 @@ class ICorStaticInfo int bufferSize /* IN */ ) = 0; - // Calls ToString() for given pinned/frozen object handle - virtual int objectToString ( + + //------------------------------------------------------------------------------ + // appendFrozenObjectTextualRepresentation: Append a (possibly truncated) textual UTF8 representation of the given frozen/pinned + // object to a preallocated buffer. It's intended to use only for debug/diagnostic purposes such as JitDisasm + // + // Arguments: + // handle - Direct handle for a pinned/frozen object + // buffer - Pointer to buffer + // bufferSize - Pointer to buffer length. Must not be nullptr + // + // Return Value: + // bytes written to the buffer, the data is not null-terminated so caller is responsible for that. + // + virtual int appendFrozenObjectTextualRepresentation ( void* handle, /* IN */ char* buffer, /* OUT */ int bufferSize /* IN */ diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 4e0e1094eb250..bd3a17bdd7472 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -175,7 +175,7 @@ int getStringLiteral( char16_t* buffer, int bufferSize) override; -int objectToString( +int appendFrozenObjectTextualRepresentation( void* handle, char* buffer, int bufferSize) override; diff --git a/src/coreclr/jit/ICorJitInfo_API_names.h b/src/coreclr/jit/ICorJitInfo_API_names.h index 9ebd42f381af6..57ae8211b6922 100644 --- a/src/coreclr/jit/ICorJitInfo_API_names.h +++ b/src/coreclr/jit/ICorJitInfo_API_names.h @@ -41,7 +41,7 @@ DEF_CLR_API(getTokenTypeAsHandle) DEF_CLR_API(isValidToken) DEF_CLR_API(isValidStringRef) DEF_CLR_API(getStringLiteral) -DEF_CLR_API(objectToString) +DEF_CLR_API(appendFrozenObjectTextualRepresentation) DEF_CLR_API(asCorInfoType) DEF_CLR_API(getClassName) DEF_CLR_API(getClassNameFromMetadata) diff --git a/src/coreclr/jit/ICorJitInfo_API_wrapper.hpp b/src/coreclr/jit/ICorJitInfo_API_wrapper.hpp index 4bedcebcf3b0c..f7b30d6659e38 100644 --- a/src/coreclr/jit/ICorJitInfo_API_wrapper.hpp +++ b/src/coreclr/jit/ICorJitInfo_API_wrapper.hpp @@ -374,14 +374,14 @@ int WrapICorJitInfo::getStringLiteral( return temp; } -int WrapICorJitInfo::objectToString( +int WrapICorJitInfo::appendFrozenObjectTextualRepresentation( void* handle, char* buffer, int bufferSize) { - API_ENTER(objectToString); - int temp = wrapHnd->objectToString(handle, buffer, bufferSize); - API_LEAVE(objectToString); + API_ENTER(appendFrozenObjectTextualRepresentation); + int temp = wrapHnd->appendFrozenObjectTextualRepresentation(handle, buffer, bufferSize); + API_LEAVE(appendFrozenObjectTextualRepresentation); return temp; } diff --git a/src/coreclr/jit/ee_il_dll.cpp b/src/coreclr/jit/ee_il_dll.cpp index 71a0dd52630a5..08eabe9d8328a 100644 --- a/src/coreclr/jit/ee_il_dll.cpp +++ b/src/coreclr/jit/ee_il_dll.cpp @@ -1619,13 +1619,13 @@ void Compiler::eePrintFrozenObjectDescription(const char* prefix, size_t handle) { const int maxStrSize = 64; char str[maxStrSize]; - int realLength = this->info.compCompHnd->objectToString((void*)handle, str, maxStrSize); - if (realLength == -1) + int bytesWritten = this->info.compCompHnd->appendFrozenObjectTextualRepresentation((void*)handle, str, maxStrSize); + if (bytesWritten == -1) { printf("%s 'unknown frozen object'", prefix); return; } - else if (realLength >= maxStrSize) + else if (bytesWritten >= maxStrSize) { // string is too long, trim it and null-terminate str[maxStrSize - 4] = '.'; @@ -1635,11 +1635,11 @@ void Compiler::eePrintFrozenObjectDescription(const char* prefix, size_t handle) } else { - // objectToString doesn't null-terminate buffer - str[realLength] = 0; + // appendFrozenObjectTextualRepresentation doesn't null-terminate buffer + str[bytesWritten] = 0; } - for (int i = 0; i < min(maxStrSize, realLength); i++) + for (int i = 0; i < min(maxStrSize, bytesWritten); i++) { // Replace \n and \r symbols with whitespaces if (str[i] == '\n' || str[i] == '\r') diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoBase.cs b/src/coreclr/tools/Common/JitInterface/CorInfoBase.cs index 8d8c426a7130d..98d0954f853b3 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoBase.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoBase.cs @@ -554,12 +554,12 @@ private static int _getStringLiteral(IntPtr thisHandle, IntPtr* ppException, COR } [UnmanagedCallersOnly] - private static int _objectToString(IntPtr thisHandle, IntPtr* ppException, void* handle, byte* buffer, int bufferSize) + private static int _appendFrozenObjectTextualRepresentation(IntPtr thisHandle, IntPtr* ppException, void* handle, byte* buffer, int bufferSize) { var _this = GetThis(thisHandle); try { - return _this.objectToString(handle, buffer, bufferSize); + return _this.appendFrozenObjectTextualRepresentation(handle, buffer, bufferSize); } catch (Exception ex) { @@ -2664,7 +2664,7 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[34] = (delegate* unmanaged)&_isValidToken; callbacks[35] = (delegate* unmanaged)&_isValidStringRef; callbacks[36] = (delegate* unmanaged)&_getStringLiteral; - callbacks[37] = (delegate* unmanaged)&_objectToString; + callbacks[37] = (delegate* unmanaged)&_appendFrozenObjectTextualRepresentation; callbacks[38] = (delegate* unmanaged)&_asCorInfoType; callbacks[39] = (delegate* unmanaged)&_getClassName; callbacks[40] = (delegate* unmanaged)&_getClassNameFromMetadata; diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index fb9d6251b8907..46c84d9590e43 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1831,16 +1831,14 @@ private int getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, char* return str.Length; } -#pragma warning disable CA1822 // Mark members as static - private int objectToString(void* handle, byte* buffer, int bufferSize) -#pragma warning restore CA1822 // Mark members as static + private int appendFrozenObjectTextualRepresentation(void* handle, byte* buffer, int bufferSize) { Debug.Assert(bufferSize > 0 && handle != null && buffer != null); // NOTE: this function is used for pinned/frozen handles // it doesn't need to null-terminate the string - ReadOnlySpan objStr = HandleToObject(handle).ToString(); + ReadOnlySpan objStr = HandleToObject((IntPtr)handle).ToString(); var bufferSpan = new Span(buffer, bufferSize); Utf8.FromUtf16(objStr, bufferSpan, out _, out int written); return written; diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 0294eced60258..52a2ceee827e9 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -192,7 +192,7 @@ FUNCTIONS bool isValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK) bool isValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK) int getStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, char16_t* buffer, int bufferSize) - int objectToString(void* handle, char* buffer, int bufferSize) + int appendFrozenObjectTextualRepresentation(void* handle, char* buffer, int bufferSize) CorInfoType asCorInfoType(CORINFO_CLASS_HANDLE cls) const char* getClassName(CORINFO_CLASS_HANDLE cls) const char* getClassNameFromMetadata(CORINFO_CLASS_HANDLE cls, const char **namespaceName) diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface.h b/src/coreclr/tools/aot/jitinterface/jitinterface.h index f12f60b98cb9c..66c1000ae3ee4 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface.h @@ -48,7 +48,7 @@ struct JitInterfaceCallbacks bool (* isValidToken)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_MODULE_HANDLE module, unsigned metaTOK); bool (* isValidStringRef)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_MODULE_HANDLE module, unsigned metaTOK); int (* getStringLiteral)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_MODULE_HANDLE module, unsigned metaTOK, char16_t* buffer, int bufferSize); - int (* objectToString)(void * thisHandle, CorInfoExceptionClass** ppException, void* handle, char* buffer, int bufferSize); + int (* appendFrozenObjectTextualRepresentation)(void * thisHandle, CorInfoExceptionClass** ppException, void* handle, char* buffer, int bufferSize); CorInfoType (* asCorInfoType)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls); const char* (* getClassName)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls); const char* (* getClassNameFromMetadata)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls, const char** namespaceName); @@ -565,13 +565,13 @@ class JitInterfaceWrapper : public ICorJitInfo return temp; } - virtual int objectToString( + virtual int appendFrozenObjectTextualRepresentation( void* handle, char* buffer, int bufferSize) { CorInfoExceptionClass* pException = nullptr; - int temp = _callbacks->objectToString(_thisHandle, &pException, handle, buffer, bufferSize); + int temp = _callbacks->appendFrozenObjectTextualRepresentation(_thisHandle, &pException, handle, buffer, bufferSize); if (pException != nullptr) throw pException; return temp; } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h index a40f741eea317..ce185f26fa4bf 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h @@ -149,7 +149,7 @@ LWM(IsIntrinsicType, DWORDLONG, DWORD) LWM(IsSDArray, DWORDLONG, DWORD) LWM(IsValidStringRef, DLD, DWORD) LWM(GetStringLiteral, DLDD, DD) -LWM(ObjectToString, DLD, DD) +LWM(AppendFrozenObjectTextualRepresentation, DLD, DD) LWM(IsValidToken, DLD, DWORD) LWM(IsValueClass, DWORDLONG, DWORD) LWM(MergeClasses, DLDL, DWORDLONG) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index d93d337bf0638..5e9536d58880f 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -4898,10 +4898,10 @@ int MethodContext::repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned me } } -void MethodContext::recObjectToString(void* handle, char* buffer, int bufferSize, int length) +void MethodContext::recAppendFrozenObjectTextualRepresentation(void* handle, char* buffer, int bufferSize, int length) { - if (ObjectToString == nullptr) - ObjectToString = new LightWeightMap(); + if (AppendFrozenObjectTextualRepresentation == nullptr) + AppendFrozenObjectTextualRepresentation = new LightWeightMap(); DLD key; ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding @@ -4912,24 +4912,24 @@ void MethodContext::recObjectToString(void* handle, char* buffer, int bufferSize if (buffer != nullptr && length != -1) { int bufferRealSize = min(length, bufferSize); - strBuf = (DWORD)ObjectToString->AddBuffer((unsigned char*)buffer, (unsigned int)bufferRealSize); + strBuf = (DWORD)AppendFrozenObjectTextualRepresentation->AddBuffer((unsigned char*)buffer, (unsigned int)bufferRealSize); } DD value; value.A = (DWORD)length; value.B = (DWORD)strBuf; - ObjectToString->Add(key, value); - DEBUG_REC(dmpObjectToString(key, value)); + AppendFrozenObjectTextualRepresentation->Add(key, value); + DEBUG_REC(dmpAppendFrozenObjectTextualRepresentation(key, value)); } -void MethodContext::dmpObjectToString(DLD key, DD value) +void MethodContext::dmpAppendFrozenObjectTextualRepresentation(DLD key, DD value) { - printf("ObjectToString key hnd-%016llX bufSize-%u, len-%u", key.A, key.B, value.A); - ObjectToString->Unlock(); + printf("AppendFrozenObjectTextualRepresentation key hnd-%016llX bufSize-%u, len-%u", key.A, key.B, value.A); + AppendFrozenObjectTextualRepresentation->Unlock(); } -int MethodContext::repObjectToString(void* handle, char* buffer, int bufferSize) +int MethodContext::repAppendFrozenObjectTextualRepresentation(void* handle, char* buffer, int bufferSize) { - if (ObjectToString == nullptr) + if (AppendFrozenObjectTextualRepresentation == nullptr) { return -1; } @@ -4939,19 +4939,19 @@ int MethodContext::repObjectToString(void* handle, char* buffer, int bufferSize) key.A = CastHandle(handle); key.B = (DWORD)bufferSize; - int itemIndex = ObjectToString->GetIndex(key); + int itemIndex = AppendFrozenObjectTextualRepresentation->GetIndex(key); if (itemIndex < 0) { return -1; } else { - DD value = ObjectToString->Get(key); - DEBUG_REP(dmpObjectToString(key, value)); + DD value = AppendFrozenObjectTextualRepresentation->Get(key); + DEBUG_REP(dmpAppendFrozenObjectTextualRepresentation(key, value)); int srcBufferLength = (int)value.A; if (buffer != nullptr && srcBufferLength > 0) { - char* srcBuffer = (char*)ObjectToString->GetBuffer(value.B); + char* srcBuffer = (char*)AppendFrozenObjectTextualRepresentation->GetBuffer(value.B); Assert(srcBuffer != nullptr); memcpy(buffer, srcBuffer, min(srcBufferLength, bufferSize)); } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index 4505d40667e79..1730caca609da 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -622,9 +622,9 @@ class MethodContext void dmpGetStringLiteral(DLDD key, DD value); int repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, char16_t* buffer, int bufferSize); - void recObjectToString(void* handle, char* buffer, int bufferSize, int length); - void dmpObjectToString(DLD key, DD value); - int repObjectToString(void* handle, char* buffer, int bufferSize); + void recAppendFrozenObjectTextualRepresentation(void* handle, char* buffer, int bufferSize, int length); + void dmpAppendFrozenObjectTextualRepresentation(DLD key, DD value); + int repAppendFrozenObjectTextualRepresentation(void* handle, char* buffer, int bufferSize); void recGetHelperName(CorInfoHelpFunc funcNum, const char* result); void dmpGetHelperName(DWORD key, DWORD value); @@ -1139,7 +1139,7 @@ enum mcPackets Packet_GetLoongArch64PassStructInRegisterFlags = 194, Packet_GetExactClasses = 195, Packet_GetRuntimeTypePointer = 196, - Packet_ObjectToString = 197, + Packet_AppendFrozenObjectTextualRepresentation = 197, }; void SetDebugDumpVariables(); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index b19faebf60967..ec47eac43238d 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -453,14 +453,14 @@ int interceptor_ICJI::getStringLiteral(CORINFO_MODULE_HANDLE module, /* IN * return temp; } -int interceptor_ICJI::objectToString(void* handle, /* IN */ +int interceptor_ICJI::appendFrozenObjectTextualRepresentation(void* handle, /* IN */ char* buffer, /* OUT */ int bufferSize /* IN */ ) { - mc->cr->AddCall("objectToString"); - int temp = original_ICorJitInfo->objectToString(handle, buffer, bufferSize); - mc->recObjectToString(handle, buffer, bufferSize, temp); + mc->cr->AddCall("appendFrozenObjectTextualRepresentation"); + int temp = original_ICorJitInfo->appendFrozenObjectTextualRepresentation(handle, buffer, bufferSize); + mc->recAppendFrozenObjectTextualRepresentation(handle, buffer, bufferSize, temp); return temp; } diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo.cpp index 2a12825c89907..1b8fd9808d447 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo.cpp @@ -314,13 +314,13 @@ int interceptor_ICJI::getStringLiteral( return original_ICorJitInfo->getStringLiteral(module, metaTOK, buffer, bufferSize); } -int interceptor_ICJI::objectToString( +int interceptor_ICJI::appendFrozenObjectTextualRepresentation( void* handle, char* buffer, int bufferSize) { - mcs->AddCall("objectToString"); - return original_ICorJitInfo->objectToString(handle, buffer, bufferSize); + mcs->AddCall("appendFrozenObjectTextualRepresentation"); + return original_ICorJitInfo->appendFrozenObjectTextualRepresentation(handle, buffer, bufferSize); } CorInfoType interceptor_ICJI::asCorInfoType( diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo.cpp index 808ccc3ab473d..9659addf93e7d 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo.cpp @@ -277,12 +277,12 @@ int interceptor_ICJI::getStringLiteral( return original_ICorJitInfo->getStringLiteral(module, metaTOK, buffer, bufferSize); } -int interceptor_ICJI::objectToString( +int interceptor_ICJI::appendFrozenObjectTextualRepresentation( void* handle, char* buffer, int bufferSize) { - return original_ICorJitInfo->objectToString(handle, buffer, bufferSize); + return original_ICorJitInfo->appendFrozenObjectTextualRepresentation(handle, buffer, bufferSize); } CorInfoType interceptor_ICJI::asCorInfoType( diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index efdfafffb8d3b..e34de83e4bf9a 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -388,13 +388,13 @@ int MyICJI::getStringLiteral(CORINFO_MODULE_HANDLE module, /* IN */ return jitInstance->mc->repGetStringLiteral(module, metaTOK, buffer, bufferSize); } -int MyICJI::objectToString(void* handle, /* IN */ +int MyICJI::appendFrozenObjectTextualRepresentation(void* handle, /* IN */ char* buffer, /* OUT */ int bufferSize /* IN */ ) { - jitInstance->mc->cr->AddCall("objectToString"); - return jitInstance->mc->repObjectToString(handle, buffer, bufferSize); + jitInstance->mc->cr->AddCall("appendFrozenObjectTextualRepresentation"); + return jitInstance->mc->repAppendFrozenObjectTextualRepresentation(handle, buffer, bufferSize); } /**********************************************************************************/ diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index faed5332a0c1c..9ee4b920206bf 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -715,7 +715,7 @@ int CEEInfo::getStringLiteral ( return result; } -int CEEInfo::objectToString ( +int CEEInfo::appendFrozenObjectTextualRepresentation ( void* handle, char* buffer, int bufferSize)