-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[cDAC] implement GetRuntimeNameByAddress #127134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
610be95
1b691c2
f01a100
7122161
d999faf
06b4f83
fa28222
634d396
e7c904b
4afaf7f
a80676b
d5ac0d6
544289e
65b6f78
589d3c0
514a3cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5309,86 +5309,6 @@ ClrDataAccess::GetJitHelperName(IN TADDR address) | |
| return NULL; | ||
| } | ||
|
|
||
| // This function expects more memory than maybe needed. | ||
| static int FormatCLRStubName( | ||
| _In_opt_z_ LPCWSTR stubNameMaybe, | ||
| _In_ TADDR stubAddr, | ||
| _In_ ULONG32 bufLen, | ||
| _Out_ ULONG32 *symbolLen, | ||
| _Out_writes_bytes_opt_(bufLen) WCHAR* symbolBuf) | ||
| { | ||
| // Parts needed to construct a name: | ||
| // With stub manager name: "CLRStub[%s]@%p" | ||
| // No stub manager name: "CLRStub@%p" | ||
| const WCHAR formatName_Prefix[] = W("CLRStub"); | ||
| const WCHAR formatName_OpenBracket[] = W("["); | ||
| const WCHAR formatName_CloseBracket[] = W("]"); | ||
| const WCHAR formatName_PrefixEnd[] = W("@"); | ||
|
|
||
| // Compute the address as a string safely. | ||
| WCHAR addrString[Max64BitHexString + 1]; | ||
| FormatInteger(addrString, ARRAY_SIZE(addrString), "%p", stubAddr); | ||
| size_t addStringLen = u16_strlen(addrString); | ||
|
|
||
| // Compute maximum length, include the null terminator. | ||
| size_t formatName_MaxLen = ARRAY_SIZE(formatName_Prefix) // Include trailing null | ||
| + ARRAY_SIZE(formatName_PrefixEnd) - 1 | ||
| + addStringLen; | ||
|
|
||
| // Consider stub manager name | ||
| size_t stubManagedNameLen = 0; | ||
| if (stubNameMaybe != NULL) | ||
| { | ||
| stubManagedNameLen = u16_strlen(stubNameMaybe); | ||
| formatName_MaxLen += ARRAY_SIZE(formatName_OpenBracket) - 1; | ||
| formatName_MaxLen += ARRAY_SIZE(formatName_CloseBracket) - 1; | ||
| } | ||
|
|
||
| HRESULT hr = S_FALSE; | ||
|
|
||
| // Compute the exact length needed. | ||
| const size_t lenNeeded = formatName_MaxLen + stubManagedNameLen; | ||
| if (lenNeeded <= bufLen) | ||
| { | ||
| size_t written = 0; | ||
|
|
||
| // Set the prefix | ||
| wcscpy_s(symbolBuf, bufLen - written, formatName_Prefix); | ||
| written += ARRAY_SIZE(formatName_Prefix) - 1; | ||
|
|
||
| // Add the name | ||
| if (stubManagedNameLen > 0) | ||
| { | ||
| wcscat_s(symbolBuf, bufLen - written, formatName_OpenBracket); | ||
| written += ARRAY_SIZE(formatName_OpenBracket) - 1; | ||
| wcscat_s(symbolBuf, bufLen - written, stubNameMaybe); | ||
| written += stubManagedNameLen; | ||
| wcscat_s(symbolBuf, bufLen - written, formatName_CloseBracket); | ||
| written += ARRAY_SIZE(formatName_CloseBracket) - 1; | ||
| } | ||
|
|
||
| // Append the prefix end | ||
| wcscat_s(symbolBuf, bufLen - written, formatName_PrefixEnd); | ||
| written += ARRAY_SIZE(formatName_PrefixEnd) - 1; | ||
|
|
||
| // Append the address | ||
| wcscat_s(symbolBuf, bufLen - written, addrString); | ||
| written += addStringLen; | ||
|
|
||
| hr = S_OK; | ||
| } | ||
|
|
||
| if (symbolLen) | ||
| { | ||
| if (!FitsIn<ULONG32>(lenNeeded)) | ||
| return COR_E_OVERFLOW; | ||
|
|
||
| *symbolLen = (ULONG32)lenNeeded; | ||
| } | ||
|
|
||
| return hr; | ||
| } | ||
|
|
||
| HRESULT | ||
| ClrDataAccess::RawGetMethodName( | ||
| /* [in] */ CLRDATA_ADDRESS address, | ||
|
|
@@ -5424,51 +5344,42 @@ ClrDataAccess::RawGetMethodName( | |
| PTR_StubManager pStubManager; | ||
| MethodDesc* methodDesc = NULL; | ||
|
|
||
| { | ||
| EECodeInfo codeInfo(GetInterpreterCodeFromEntryPointIfPresent(TO_TADDR(address))); | ||
|
jkotas marked this conversation as resolved.
|
||
| if (codeInfo.IsValid()) | ||
| { | ||
| if (displacement) | ||
| { | ||
| *displacement = codeInfo.GetRelOffset(); | ||
| } | ||
|
|
||
| methodDesc = codeInfo.GetMethodDesc(); | ||
| goto NameFromMethodDesc; | ||
| } | ||
| } | ||
|
|
||
| pStubManager = StubManager::FindStubManager(TO_TADDR(address)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to update fragile DAC to match cDAC implementation and behavior? Or are we intentionally going to leave them out of sync?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only remaining case of dynamically allocated remaining that are covered by If we want to handle this case in cDAC, we should switch the tracking of these stubs to the RangeSection plan so that are covered by RangeSection.FInd as well. (It can be done in a follow up PR.)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think so. If we update the DAC to our liking, the SOS tests will hit it repeatedly through !u and other commands and catch any regressions in the cDAC implementation. |
||
| if (pStubManager != NULL) | ||
| { | ||
| if (displacement) | ||
| { | ||
| *displacement = 0; | ||
| } | ||
|
|
||
| // | ||
| // Special-cased stub managers | ||
| // | ||
| if (pStubManager == PrecodeStubManager::g_pManager) | ||
| { | ||
| PCODE alignedAddress = AlignDown(TO_TADDR(address), PRECODE_ALIGNMENT); | ||
| StubCodeBlockKind stubKind = RangeSectionStubManager::GetStubKind(TO_TADDR(address)); | ||
| SIZE_T stubSize = 0; | ||
|
|
||
| #ifdef TARGET_ARM | ||
| alignedAddress += THUMB_CODE; | ||
| switch (stubKind) | ||
| { | ||
| case STUB_CODE_BLOCK_STUBPRECODE: | ||
| stubSize = StubPrecode::CodeSize; | ||
| break; | ||
| #ifdef HAS_FIXUP_PRECODE | ||
| case STUB_CODE_BLOCK_FIXUPPRECODE: | ||
| stubSize = FixupPrecode::CodeSize; | ||
| break; | ||
| #endif | ||
| default: | ||
| break; | ||
| } | ||
|
|
||
| SIZE_T maxPrecodeSize = sizeof(StubPrecode); | ||
| if (stubSize != 0) | ||
| { | ||
| const SIZE_T pageMask = GetStubCodePageSize() - 1; | ||
| const TADDR pageBase = TO_TADDR(address) & ~static_cast<TADDR>(pageMask); | ||
| const SIZE_T offset = static_cast<SIZE_T>(TO_TADDR(address) - pageBase); | ||
| PCODE precodeAddress = pageBase + (offset / stubSize) * stubSize; | ||
|
|
||
| #ifdef HAS_THISPTR_RETBUF_PRECODE | ||
| maxPrecodeSize = max((size_t)maxPrecodeSize, sizeof(ThisPtrRetBufPrecode)); | ||
| #ifdef TARGET_ARM | ||
| precodeAddress += THUMB_CODE; | ||
| #endif | ||
|
|
||
| for (SIZE_T i = 0; i < maxPrecodeSize / PRECODE_ALIGNMENT; i++) | ||
| { | ||
| EX_TRY | ||
| { | ||
| // Try to find matching precode entrypoint | ||
| Precode* pPrecode = Precode::GetPrecodeFromEntryPoint(alignedAddress, TRUE); | ||
| Precode* pPrecode = Precode::GetPrecodeFromEntryPoint(precodeAddress, TRUE); | ||
| if (pPrecode != NULL && pPrecode->GetType() != PRECODE_UMENTRY_THUNK) | ||
| { | ||
| methodDesc = pPrecode->GetMethodDesc(); | ||
|
|
@@ -5478,64 +5389,64 @@ ClrDataAccess::RawGetMethodName( | |
| { | ||
| if (displacement) | ||
| { | ||
| *displacement = TO_TADDR(address) - PCODEToPINSTR(alignedAddress); | ||
| *displacement = TO_TADDR(address) - PCODEToPINSTR(precodeAddress); | ||
| } | ||
| goto NameFromMethodDesc; | ||
| return GetFullMethodName(methodDesc, bufLen, symbolLen, symbolBuf); | ||
| } | ||
| } | ||
| } | ||
| alignedAddress -= PRECODE_ALIGNMENT; | ||
| } | ||
| EX_CATCH | ||
| { | ||
| } | ||
| EX_END_CATCH | ||
| } | ||
| } | ||
|
|
||
| LPCWSTR wszStubManagerName = pStubManager->GetStubManagerName(TO_TADDR(address)); | ||
| _ASSERTE(wszStubManagerName != NULL); | ||
|
|
||
| return FormatCLRStubName( | ||
| wszStubManagerName, | ||
| TO_TADDR(address), | ||
| bufLen, | ||
| symbolLen, | ||
| symbolBuf); | ||
| if (u16_strcmp(wszStubManagerName, W("ThePreStub")) != 0 && u16_strcmp(wszStubManagerName, W("InteropDispatchStub")) != 0 && u16_strcmp(wszStubManagerName, W("TailCallStub")) != 0) | ||
| { | ||
| // Skip the stubs that are just assembly helpers. | ||
|
rcj1 marked this conversation as resolved.
|
||
| size_t nameLen = u16_strlen(wszStubManagerName) + 1; // include null terminator | ||
| if (symbolLen) | ||
| { | ||
| if (!FitsIn<ULONG32>(nameLen)) | ||
| return COR_E_OVERFLOW; | ||
| *symbolLen = (ULONG32)nameLen; | ||
| } | ||
| if (symbolBuf && bufLen >= nameLen) | ||
| { | ||
| wcscpy_s(symbolBuf, bufLen, wszStubManagerName); | ||
| } | ||
| else if (symbolBuf) | ||
| { | ||
| return S_FALSE; | ||
| } | ||
| if (displacement) | ||
| { | ||
| *displacement = 0; | ||
| } | ||
| return S_OK; | ||
| } | ||
|
rcj1 marked this conversation as resolved.
rcj1 marked this conversation as resolved.
rcj1 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // Do not waste time looking up name for static helper. Debugger can get the actual name from .pdb. | ||
| PCSTR pHelperName; | ||
| pHelperName = GetJitHelperName(TO_TADDR(address)); | ||
| if (pHelperName != NULL) | ||
| { | ||
| if (displacement) | ||
| { | ||
| *displacement = 0; | ||
| } | ||
|
|
||
| HRESULT hr = ConvertUtf8(pHelperName, bufLen, symbolLen, symbolBuf); | ||
| if (FAILED(hr)) | ||
| return S_FALSE; | ||
|
|
||
| if (displacement) | ||
| { | ||
| *displacement = 0; | ||
| } | ||
| return S_OK; | ||
| } | ||
|
|
||
| return E_NOINTERFACE; | ||
|
|
||
| NameFromMethodDesc: | ||
| if (methodDesc->GetClassification() == mcDynamic | ||
| && methodDesc->GetSigParser().IsNull()) | ||
| { | ||
| return FormatCLRStubName( | ||
| NULL, | ||
| TO_TADDR(address), | ||
| bufLen, | ||
| symbolLen, | ||
| symbolBuf); | ||
| } | ||
|
|
||
| return GetFullMethodName(methodDesc, bufLen, symbolLen, symbolBuf); | ||
| } | ||
|
|
||
| HRESULT | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.