diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 46ebb2dd7e85c7..a1dd220373ebb0 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -5088,7 +5088,7 @@ ClrDataAccess::FollowStubStep( methodDesc = PTR_MethodDesc(CORDB_ADDRESS_TO_TADDR(inBuffer->u.addr)); if (methodDesc->HasNativeCode()) { - *outAddr = methodDesc->GetNativeCode(); + *outAddr = methodDesc->GetCodeForInterpreterOrJitted(); *outFlags = CLRDATA_FOLLOW_STUB_EXIT; return S_OK; } @@ -5737,7 +5737,7 @@ ClrDataAccess::RawGetMethodName( MethodDesc* methodDesc = NULL; { - EECodeInfo codeInfo(TO_TADDR(address)); + EECodeInfo codeInfo(GetInterpreterCodeFromInterpreterPrecodeIfPresent(TO_TADDR(address))); if (codeInfo.IsValid()) { if (displacement) @@ -5886,7 +5886,7 @@ ClrDataAccess::GetMethodExtents(MethodDesc* methodDesc, // for all types of managed code. // - PCODE methodStart = methodDesc->GetNativeCode(); + PCODE methodStart = methodDesc->GetCodeForInterpreterOrJitted(); if (!methodStart) { return E_NOINTERFACE; @@ -5940,11 +5940,11 @@ ClrDataAccess::GetMethodVarInfo(MethodDesc* methodDesc, { return E_INVALIDARG; } - nativeCodeStartAddr = PCODEToPINSTR(requestedNativeCodeVersion.GetNativeCode()); + nativeCodeStartAddr = PCODEToPINSTR(GetInterpreterCodeFromInterpreterPrecodeIfPresent(requestedNativeCodeVersion.GetNativeCode())); } else { - nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode()); + nativeCodeStartAddr = PCODEToPINSTR(GetInterpreterCodeFromInterpreterPrecodeIfPresent(methodDesc->GetNativeCode())); } DebugInfoRequest request; @@ -5999,11 +5999,11 @@ ClrDataAccess::GetMethodNativeMap(MethodDesc* methodDesc, { return E_INVALIDARG; } - nativeCodeStartAddr = PCODEToPINSTR(requestedNativeCodeVersion.GetNativeCode()); + nativeCodeStartAddr = PCODEToPINSTR(GetInterpreterCodeFromInterpreterPrecodeIfPresent(requestedNativeCodeVersion.GetNativeCode())); } else { - nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode()); + nativeCodeStartAddr = PCODEToPINSTR(GetInterpreterCodeFromInterpreterPrecodeIfPresent(methodDesc->GetNativeCode())); } DebugInfoRequest request; diff --git a/src/coreclr/debug/daccess/dacdbiimpl.cpp b/src/coreclr/debug/daccess/dacdbiimpl.cpp index b0461e50e7daa4..c698c3e77cb480 100644 --- a/src/coreclr/debug/daccess/dacdbiimpl.cpp +++ b/src/coreclr/debug/daccess/dacdbiimpl.cpp @@ -1137,7 +1137,7 @@ void DacDbiInterfaceImpl::GetMethodRegionInfo(MethodDesc * pMethodDe CONTRACTL_END; IJitManager::MethodRegionInfo methodRegionInfo = {(TADDR)NULL, 0, (TADDR)NULL, 0}; - PCODE functionAddress = pMethodDesc->GetNativeCode(); + PCODE functionAddress = pMethodDesc->GetCodeForInterpreterOrJitted(); // get the start address of the hot region and initialize the jit manager pCodeInfo->m_rgCodeRegions[kHot].pAddress = CORDB_ADDRESS(PCODEToPINSTR(functionAddress)); @@ -1229,6 +1229,12 @@ void DacDbiInterfaceImpl::GetNativeCodeInfoForAddr(VMPTR_MethodDesc vmMe IJitManager::MethodRegionInfo methodRegionInfo = {(TADDR)NULL, 0, (TADDR)NULL, 0}; TADDR codeAddr = CORDB_ADDRESS_TO_TADDR(hotCodeStartAddr); + EX_TRY_ALLOW_DATATARGET_MISSING_MEMORY + { + codeAddr = GetInterpreterCodeFromInterpreterPrecodeIfPresent(codeAddr); + } + EX_END_CATCH_ALLOW_DATATARGET_MISSING_MEMORY; + #ifdef TARGET_ARM // TADDR should not have the thumb code bit set. _ASSERTE((codeAddr & THUMB_CODE) == 0); diff --git a/src/coreclr/debug/daccess/enummem.cpp b/src/coreclr/debug/daccess/enummem.cpp index 338e885f67f3a6..b24049603e65ea 100644 --- a/src/coreclr/debug/daccess/enummem.cpp +++ b/src/coreclr/debug/daccess/enummem.cpp @@ -593,7 +593,7 @@ HRESULT ClrDataAccess::DumpManagedExcepObject(CLRDataEnumMemoryFlags flags, OBJE // Pulls in data to translate from token to MethodDesc FindLoadedMethodRefOrDef(pMD->GetMethodTable()->GetModule(), pMD->GetMemberDef()); - PCODE addr = pMD->GetNativeCode(); + PCODE addr = pMD->GetCodeForInterpreterOrJitted(); if (addr != (PCODE)NULL) { EECodeInfo codeInfo(addr); diff --git a/src/coreclr/debug/daccess/request.cpp b/src/coreclr/debug/daccess/request.cpp index e3650b48cd6a41..c1a59f690d307c 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -227,7 +227,7 @@ BOOL DacValidateMD(PTR_MethodDesc pMD) if (retval && pMD->HasNativeCode() && !pMD->IsFCall()) { - PCODE jitCodeAddr = pMD->GetNativeCode(); + PCODE jitCodeAddr = pMD->GetCodeForInterpreterOrJitted(); MethodDesc *pMDCheck = ExecutionManager::GetCodeMethodDesc(jitCodeAddr); if (pMDCheck) @@ -901,7 +901,7 @@ HRESULT ClrDataAccess::GetThreadData(CLRDATA_ADDRESS threadAddr, struct DacpThre void CopyNativeCodeVersionToReJitData(NativeCodeVersion nativeCodeVersion, NativeCodeVersion activeCodeVersion, DacpReJitData * pReJitData) { pReJitData->rejitID = nativeCodeVersion.GetILCodeVersion().GetVersionId(); - pReJitData->NativeCodeAddr = nativeCodeVersion.GetNativeCode(); + pReJitData->NativeCodeAddr = GetInterpreterCodeFromInterpreterPrecodeIfPresent(nativeCodeVersion.GetNativeCode()); if (nativeCodeVersion != activeCodeVersion) { @@ -1011,7 +1011,7 @@ HRESULT ClrDataAccess::GetMethodDescData( if (!requestedNativeCodeVersion.IsNull() && requestedNativeCodeVersion.GetNativeCode() != (PCODE)NULL) { methodDescData->bHasNativeCode = TRUE; - methodDescData->NativeCodeAddr = TO_CDADDR(PCODEToPINSTR(requestedNativeCodeVersion.GetNativeCode())); + methodDescData->NativeCodeAddr = TO_CDADDR(PCODEToPINSTR(GetInterpreterCodeFromInterpreterPrecodeIfPresent(requestedNativeCodeVersion.GetNativeCode()))); } else { @@ -1235,7 +1235,7 @@ HRESULT ClrDataAccess::GetTieredVersions( int count = 0; for (NativeCodeVersionIterator iter = nativeCodeVersions.Begin(); iter != nativeCodeVersions.End(); iter++) { - TADDR pNativeCode = PCODEToPINSTR((*iter).GetNativeCode()); + TADDR pNativeCode = PCODEToPINSTR(GetInterpreterCodeFromInterpreterPrecodeIfPresent((*iter).GetNativeCode())); nativeCodeAddrs[count].NativeCodeAddr = pNativeCode; PTR_NativeCodeVersionNode pNode = (*iter).AsNode(); nativeCodeAddrs[count].NativeCodeVersionNodePtr = PTR_CDADDR(pNode); diff --git a/src/coreclr/vm/method.hpp b/src/coreclr/vm/method.hpp index c63f9e344d87d0..f870080f2921b5 100644 --- a/src/coreclr/vm/method.hpp +++ b/src/coreclr/vm/method.hpp @@ -1613,6 +1613,13 @@ class MethodDesc // Returns the address of the native code. PCODE GetNativeCode(); + // Returns either the jitted code or the interpreter code (will not return the InterpreterStub which GetNativeCode might return) + PCODE GetCodeForInterpreterOrJitted() + { + WRAPPER_NO_CONTRACT; + return GetInterpreterCodeFromInterpreterPrecodeIfPresent(GetNativeCode()); + } + // Returns GetNativeCode() if it exists, but also checks to see if there // is a non-default code version that is populated with a code body and returns that. // Perf warning: takes the CodeVersionManagerLock on every call diff --git a/src/coreclr/vm/precode.cpp b/src/coreclr/vm/precode.cpp index 031c0a06f57cfb..5b1422aa1c8273 100644 --- a/src/coreclr/vm/precode.cpp +++ b/src/coreclr/vm/precode.cpp @@ -958,3 +958,33 @@ BOOL StubPrecode::IsStubPrecodeByASM(PCODE addr) } #endif // !FEATURE_PORTABLE_ENTRYPOINTS + +TADDR GetInterpreterCodeFromInterpreterPrecodeIfPresent(TADDR codePointerMaybeInterpreterStub) +{ + CONTRACTL { + NOTHROW; + GC_NOTRIGGER; + SUPPORTS_DAC; + } CONTRACTL_END; + +#if defined(FEATURE_INTERPRETER) && !defined(FEATURE_PORTABLE_ENTRYPOINTS) + if (codePointerMaybeInterpreterStub == (TADDR)NULL) + { + return (TADDR)NULL; + } + + RangeSection * pRS = ExecutionManager::FindCodeRange(codePointerMaybeInterpreterStub, ExecutionManager::GetScanFlags()); + if (pRS != NULL && pRS->_flags & RangeSection::RANGE_SECTION_RANGELIST) + { + if (pRS->_pRangeList->GetCodeBlockKind() == STUB_CODE_BLOCK_STUBPRECODE) + { + if (dac_cast(PCODEToPINSTR(codePointerMaybeInterpreterStub))->GetType() == PRECODE_INTERPRETER) + { + codePointerMaybeInterpreterStub = (dac_cast(PCODEToPINSTR(codePointerMaybeInterpreterStub)))->GetData()->ByteCodeAddr; + } + } + } +#endif + + return codePointerMaybeInterpreterStub; +} diff --git a/src/coreclr/vm/precode.h b/src/coreclr/vm/precode.h index 9e386bfa394142..3f8958ecea9b83 100644 --- a/src/coreclr/vm/precode.h +++ b/src/coreclr/vm/precode.h @@ -864,4 +864,6 @@ extern InterleavedLoaderHeapConfig s_fixupStubPrecodeHeapConfig; #endif // FEATURE_PORTABLE_ENTRYPOINTS +TADDR GetInterpreterCodeFromInterpreterPrecodeIfPresent(TADDR codePointerMaybeInterpreterStub); + #endif // __PRECODE_H__ diff --git a/src/coreclr/vm/stubmgr.cpp b/src/coreclr/vm/stubmgr.cpp index b503c24cc0ef65..cbae7c8a2f2045 100644 --- a/src/coreclr/vm/stubmgr.cpp +++ b/src/coreclr/vm/stubmgr.cpp @@ -1011,6 +1011,15 @@ BOOL PrecodeStubManager::CheckIsStub_Internal(PCODE stubStartAddress) else if (stubKind == STUB_CODE_BLOCK_STUBPRECODE) { Precode* pPrecode = Precode::GetPrecodeFromEntryPoint(stubStartAddress); +#ifdef DACCESS_COMPILE + // The DAC always treats GetPrecodeFromEntryPoint as if the speculative flag is TRUE. + // so it may return NULL + if (pPrecode == NULL) + { + return FALSE; + } +#endif + switch (pPrecode->GetType()) { case PRECODE_STUB: