Skip to content

Commit 149a289

Browse files
Revert "Put HasNativeCodeReJITAware into GetFunctionAddress (#90049)" (#90696)
This reverts commit eacb32e. Need to investigate changes because they caused a test failure.
1 parent 702d02c commit 149a289

File tree

13 files changed

+113
-40
lines changed

13 files changed

+113
-40
lines changed

src/coreclr/debug/daccess/dacimpl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,17 @@ class ClrDataAccess
12531253
/* [out] */ union STUB_BUF* outBuffer,
12541254
/* [out] */ ULONG32* outFlags);
12551255

1256+
DebuggerJitInfo* GetDebuggerJitInfo(MethodDesc* methodDesc,
1257+
TADDR addr)
1258+
{
1259+
if (g_pDebugger)
1260+
{
1261+
return g_pDebugger->GetJitInfo(methodDesc, (PBYTE)addr, NULL);
1262+
}
1263+
1264+
return NULL;
1265+
}
1266+
12561267
HRESULT GetMethodExtents(MethodDesc* methodDesc,
12571268
METH_EXTENTS** extents);
12581269
HRESULT GetMethodVarInfo(MethodDesc* methodDesc,

src/coreclr/debug/daccess/task.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5225,7 +5225,7 @@ EnumMethodInstances::Next(ClrDataAccess* dac,
52255225
}
52265226
}
52275227

5228-
if (!m_methodIter.Current()->HasNativeCodeAnyVersion())
5228+
if (!m_methodIter.Current()->HasNativeCodeReJITAware())
52295229
{
52305230
goto NextMethod;
52315231
}
@@ -5243,7 +5243,7 @@ EnumMethodInstances::CdStart(MethodDesc* methodDesc,
52435243
CLRDATA_ENUM* handle)
52445244
{
52455245
if (!methodDesc->HasClassOrMethodInstantiation() &&
5246-
!(methodDesc->HasNativeCodeAnyVersion()))
5246+
!methodDesc->HasNativeCodeReJITAware())
52475247
{
52485248
*handle = 0;
52495249
return S_FALSE;

src/coreclr/debug/di/breakpoint.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,11 @@ HRESULT CordbFunctionBreakpoint::Activate(BOOL fActivate)
211211
if (codeIsIL)
212212
{
213213
pEvent->BreakpointData.nativeCodeMethodDescToken = pEvent->BreakpointData.nativeCodeMethodDescToken.NullPtr();
214-
pEvent->BreakpointData.codeStartAddress = 0;
215214
}
216215
else
217216
{
218217
pEvent->BreakpointData.nativeCodeMethodDescToken =
219218
(m_code.GetValue()->AsNativeCode())->GetVMNativeCodeMethodDescToken().ToLsPtr();
220-
pEvent->BreakpointData.codeStartAddress = (m_code.GetValue()->AsNativeCode())->GetAddress();
221219
}
222220

223221
// Note: we're sending a two-way event, so it blocks here

src/coreclr/debug/ee/controller.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,8 +1247,26 @@ bool DebuggerController::BindPatch(DebuggerControllerPatch *patch,
12471247
startAddr = (CORDB_ADDRESS_TYPE *) CORDB_ADDRESS_TO_PTR(patch->GetDJI()->m_addrOfCode);
12481248
_ASSERTE(startAddr != NULL);
12491249
}
1250-
//We should never be calling this function with both a NULL startAddr and a DJI that doesn't have code.
1251-
_ASSERTE(startAddr != NULL);
1250+
if (startAddr == NULL)
1251+
{
1252+
// Should not be trying to place patches on MethodDecs's for stubs.
1253+
// These stubs will never get jitted.
1254+
CONSISTENCY_CHECK_MSGF(!pMD->IsWrapperStub(), ("Can't place patch at stub md %p, %s::%s",
1255+
pMD, pMD->m_pszDebugClassName, pMD->m_pszDebugMethodName));
1256+
1257+
startAddr = (CORDB_ADDRESS_TYPE *)g_pEEInterface->GetFunctionAddress(pMD);
1258+
//
1259+
// Code is not available yet to patch. The prestub should
1260+
// notify us when it is executed.
1261+
//
1262+
if (startAddr == NULL)
1263+
{
1264+
LOG((LF_CORDB, LL_INFO10000,
1265+
"DC::BP: Patch at 0x%zx not bindable yet.\n", patch->offset));
1266+
1267+
return false;
1268+
}
1269+
}
12521270
}
12531271

12541272
_ASSERTE(!g_pEEInterface->IsStub((const BYTE *)startAddr));
@@ -8638,7 +8656,7 @@ bool DebuggerFuncEvalComplete::SendEvent(Thread *thread, bool fIpChanged)
86388656
// DebuggerEnCBreakpoint constructor - creates and activates a new EnC breakpoint
86398657
//
86408658
// Arguments:
8641-
// offset - IL offset in the function to place the patch
8659+
// offset - native offset in the function to place the patch
86428660
// jitInfo - identifies the function in which the breakpoint is being placed
86438661
// fTriggerType - breakpoint type: either REMAP_PENDING or REMAP_COMPLETE
86448662
// pAppDomain - the breakpoint applies to the specified AppDomain only

src/coreclr/debug/ee/debugger.cpp

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,8 +2841,6 @@ HRESULT Debugger::GetILToNativeMapping(PCODE pNativeCodeStartAddress, ULONG32 cM
28412841
}
28422842
CONTRACTL_END;
28432843

2844-
_ASSERTE(pNativeCodeStartAddress != NULL);
2845-
28462844
#ifdef PROFILING_SUPPORTED
28472845
// At this point, we're pulling in the debugger.
28482846
if (!HasLazyData())
@@ -3009,7 +3007,6 @@ HRESULT Debugger::GetILToNativeMappingIntoArrays(
30093007
_ASSERTE(pcMap != NULL);
30103008
_ASSERTE(prguiILOffset != NULL);
30113009
_ASSERTE(prguiNativeOffset != NULL);
3012-
_ASSERTE(pNativeCodeStartAddress != NULL);
30133010

30143011
// Any caller of GetILToNativeMappingIntoArrays had better call
30153012
// InitializeLazyDataIfNecessary first!
@@ -5414,6 +5411,28 @@ void Debugger::ReleaseAllRuntimeThreads(AppDomain *pAppDomain)
54145411
g_pEEInterface->ResumeFromDebug(pAppDomain);
54155412
}
54165413

5414+
// Given a method, get's its EnC version number. 1 if the method is not EnCed.
5415+
// Note that MethodDescs are reused between versions so this will give us
5416+
// the most recent EnC number.
5417+
int Debugger::GetMethodEncNumber(MethodDesc * pMethod)
5418+
{
5419+
CONTRACTL
5420+
{
5421+
THROWS;
5422+
GC_NOTRIGGER;
5423+
}
5424+
CONTRACTL_END;
5425+
5426+
DebuggerJitInfo * dji = GetLatestJitInfoFromMethodDesc(pMethod);
5427+
if (dji == NULL)
5428+
{
5429+
// If there's no DJI, couldn't have been EnCed.
5430+
return 1;
5431+
}
5432+
return (int) dji->m_encVersion;
5433+
}
5434+
5435+
54175436
bool Debugger::IsJMCMethod(Module* pModule, mdMethodDef tkMethod)
54185437
{
54195438
CONTRACTL
@@ -6200,6 +6219,25 @@ void Debugger::LockAndSendEnCRemapCompleteEvent(MethodDesc *pMD)
62006219
Thread *thread = g_pEEInterface->GetThread();
62016220
// Note that the debugger lock is reentrant, so we may or may not hold it already.
62026221
SENDIPCEVENT_BEGIN(this, thread);
6222+
6223+
EX_TRY
6224+
{
6225+
// Ensure the DJI for the latest version of this method has been pre-created.
6226+
// It's not clear whether this is necessary or not, but it shouldn't hurt since
6227+
// we're going to need to create it anyway since we'll be debugging inside it.
6228+
DebuggerJitInfo *dji = g_pDebugger->GetLatestJitInfoFromMethodDesc(pMD);
6229+
(void)dji; //prevent "unused variable" error from GCC
6230+
_ASSERTE( dji != NULL );
6231+
}
6232+
EX_CATCH
6233+
{
6234+
// GetLatestJitInfo could throw on OOM, but the debugger isn't resiliant to OOM.
6235+
// I'm not aware of any other legitimate reason why it may throw, so we'll ASSERT
6236+
// if it fails.
6237+
_ASSERTE(!"Unexpected exception from Debugger::GetLatestJitInfoFromMethodDesc on EnC remap complete");
6238+
}
6239+
EX_END_CATCH(RethrowTerminalExceptions);
6240+
62036241
// Send an EnC remap complete event to the Right Side.
62046242
DebuggerIPCEvent* ipce = m_pRCThread->GetIPCEventSendBuffer();
62056243
InitIPCEvent(ipce,
@@ -7827,7 +7865,6 @@ void Debugger::FirstChanceManagedExceptionCatcherFound(Thread *pThread,
78277865
// Implements DebugInterface
78287866
// Call by EE/exception. Must be on managed thread
78297867
_ASSERTE(GetThreadNULLOk() != NULL);
7830-
_ASSERTE(pMethodAddr != NULL);
78317868

78327869
// Quick check.
78337870
if (!CORDebuggerAttached())
@@ -10461,7 +10498,7 @@ bool Debugger::HandleIPCEvent(DebuggerIPCEvent * pEvent)
1046110498
DebuggerJitInfo * pDJI = NULL;
1046210499
if ((pMethodDesc != NULL) && (pDMI != NULL))
1046310500
{
10464-
pDJI = pDMI->FindOrCreateInitAndAddJitInfo(pMethodDesc, PINSTRToPCODE(dac_cast<TADDR>(pEvent->BreakpointData.codeStartAddress)));
10501+
pDJI = pDMI->FindOrCreateInitAndAddJitInfo(pMethodDesc, NULL /* startAddr */);
1046510502
}
1046610503

1046710504
{
@@ -12588,7 +12625,7 @@ DWORD Debugger::GetThreadIdHelper(Thread *pThread)
1258812625
// does not own the memory provided via vars outparameter.
1258912626
//-----------------------------------------------------------------------------
1259012627
void Debugger::GetVarInfo(MethodDesc * fd, // [IN] method of interest
12591-
CORDB_ADDRESS nativeCodeAddress, // [IN] which edit version
12628+
void *DebuggerVersionToken, // [IN] which edit version
1259212629
SIZE_T * cVars, // [OUT] size of 'vars'
1259312630
const ICorDebugInfo::NativeVarInfo **vars // [OUT] map telling where local vars are stored
1259412631
)
@@ -12600,7 +12637,7 @@ void Debugger::GetVarInfo(MethodDesc * fd, // [IN] method of interest
1260012637
}
1260112638
CONTRACTL_END;
1260212639

12603-
DebuggerJitInfo * ji = g_pDebugger->GetJitInfo(fd, (const BYTE *)nativeCodeAddress);
12640+
DebuggerJitInfo * ji = (DebuggerJitInfo *)DebuggerVersionToken;
1260412641

1260512642
// If we didn't supply a DJI, then we're asking for the most recent version.
1260612643
if (ji == NULL)
@@ -12924,11 +12961,6 @@ HRESULT Debugger::UpdateFunction(MethodDesc* pMD, SIZE_T encVersion)
1292412961

1292512962
// For each offset in the IL->Native map, set a new EnC breakpoint on the
1292612963
// ones that we know could be remap points.
12927-
12928-
// Depending on which DJI was picked, the code might compute different IL offsets. The JIT may not guarantee it produces
12929-
// the same set of sequence points for every generic instantiation.
12930-
// Inside ENCSequencePointHelper there is logic that skips IL offsets that map to the same native offset.
12931-
// Its possible that one version of the code maps two IL offsets to the same native offset but another version of the code maps them to different offsets.
1293212964
PTR_DebuggerILToNativeMap seqMap = pJitInfo->GetSequenceMap();
1293312965
for (unsigned int i = 0; i < pJitInfo->GetSequenceMapCount(); i++)
1293412966
{

src/coreclr/debug/ee/debugger.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,8 @@ class Debugger : public DebugInterface
19331933

19341934
bool IsJMCMethod(Module* pModule, mdMethodDef tkMethod);
19351935

1936+
int GetMethodEncNumber(MethodDesc * pMethod);
1937+
19361938

19371939
bool FirstChanceManagedException(Thread *pThread, SIZE_T currentIP, SIZE_T currentSP);
19381940

@@ -1978,7 +1980,7 @@ class Debugger : public DebugInterface
19781980
#endif // EnC_SUPPORTED
19791981

19801982
void GetVarInfo(MethodDesc * fd, // [IN] method of interest
1981-
CORDB_ADDRESS nativeCodeAddress, // [IN] which edit version
1983+
void *DebuggerVersionToken, // [IN] which edit version
19821984
SIZE_T * cVars, // [OUT] size of 'vars'
19831985
const ICorDebugInfo::NativeVarInfo **vars // [OUT] map telling where local vars are stored
19841986
);

src/coreclr/debug/ee/functioninfo.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,9 @@ DebuggerJitInfo *DebuggerMethodInfo::FindOrCreateInitAndAddJitInfo(MethodDesc* f
15651565
GC_NOTRIGGER;
15661566
}
15671567
CONTRACTL_END;
1568+
15681569
_ASSERTE(fd != NULL);
1570+
15691571
// The debugger doesn't track Lightweight-codegen methods b/c they have no metadata.
15701572
if (fd->IsDynamicMethod())
15711573
{
@@ -1574,8 +1576,16 @@ DebuggerJitInfo *DebuggerMethodInfo::FindOrCreateInitAndAddJitInfo(MethodDesc* f
15741576

15751577
if (startAddr == NULL)
15761578
{
1579+
// This will grab the start address for the current code version.
15771580
startAddr = g_pEEInterface->GetFunctionAddress(fd);
1578-
_ASSERTE(startAddr != NULL);
1581+
if (startAddr == NULL)
1582+
{
1583+
startAddr = fd->GetNativeCodeReJITAware();
1584+
if (startAddr == NULL)
1585+
{
1586+
return NULL;
1587+
}
1588+
}
15791589
}
15801590
else
15811591
{

src/coreclr/debug/inc/dbgipcevents.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,6 @@ struct MSLAYOUT DebuggerIPCEvent
20112011
SIZE_T offset;
20122012
SIZE_T encVersion;
20132013
LSPTR_METHODDESC nativeCodeMethodDescToken; // points to the MethodDesc if !isIL
2014-
CORDB_ADDRESS codeStartAddress;
20152014
} BreakpointData;
20162015

20172016
struct MSLAYOUT

src/coreclr/vm/dbginterface.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class DebugInterface
203203

204204
// Get debugger variable information for a specific version of a method
205205
virtual void GetVarInfo(MethodDesc * fd, // [IN] method of interest
206-
CORDB_ADDRESS nativeCodeAddress, // [IN] which edit version
206+
void *DebuggerVersionToken, // [IN] which edit version
207207
SIZE_T * cVars, // [OUT] size of 'vars'
208208
const ICorDebugInfo::NativeVarInfo **vars // [OUT] map telling where local vars are stored
209209
) = 0;
@@ -262,6 +262,11 @@ class DebugInterface
262262

263263
virtual bool IsJMCMethod(Module* pModule, mdMethodDef tkMethod) = 0;
264264

265+
// Given a method, get's its EnC version number. 1 if the method is not EnCed.
266+
// Note that MethodDescs are reused between versions so this will give us
267+
// the most recent EnC number.
268+
virtual int GetMethodEncNumber(MethodDesc * pMethod) = 0;
269+
265270
virtual void SendLogSwitchSetting (int iLevel,
266271
int iReason,
267272
_In_z_ LPCWSTR pLogSwitchName,

src/coreclr/vm/eedbginterfaceimpl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ PCODE EEDbgInterfaceImpl::GetFunctionAddress(MethodDesc *pFD)
630630
SUPPORTS_DAC;
631631
}
632632
CONTRACTL_END;
633+
633634
return pFD->GetNativeCode();
634635
}
635636

0 commit comments

Comments
 (0)