Skip to content

Commit eacb32e

Browse files
Put HasNativeCodeReJITAware into GetFunctionAddress (#90049)
* Remove calls to GetFunctionAddress with Null address and clarify method names
1 parent b0d4502 commit eacb32e

File tree

13 files changed

+40
-113
lines changed

13 files changed

+40
-113
lines changed

src/coreclr/debug/daccess/dacimpl.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,17 +1253,6 @@ 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-
12671256
HRESULT GetMethodExtents(MethodDesc* methodDesc,
12681257
METH_EXTENTS** extents);
12691258
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()->HasNativeCodeReJITAware())
5228+
if (!m_methodIter.Current()->HasNativeCodeAnyVersion())
52295229
{
52305230
goto NextMethod;
52315231
}
@@ -5243,7 +5243,7 @@ EnumMethodInstances::CdStart(MethodDesc* methodDesc,
52435243
CLRDATA_ENUM* handle)
52445244
{
52455245
if (!methodDesc->HasClassOrMethodInstantiation() &&
5246-
!methodDesc->HasNativeCodeReJITAware())
5246+
!(methodDesc->HasNativeCodeAnyVersion()))
52475247
{
52485248
*handle = 0;
52495249
return S_FALSE;

src/coreclr/debug/di/breakpoint.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,13 @@ HRESULT CordbFunctionBreakpoint::Activate(BOOL fActivate)
211211
if (codeIsIL)
212212
{
213213
pEvent->BreakpointData.nativeCodeMethodDescToken = pEvent->BreakpointData.nativeCodeMethodDescToken.NullPtr();
214+
pEvent->BreakpointData.codeStartAddress = 0;
214215
}
215216
else
216217
{
217218
pEvent->BreakpointData.nativeCodeMethodDescToken =
218219
(m_code.GetValue()->AsNativeCode())->GetVMNativeCodeMethodDescToken().ToLsPtr();
220+
pEvent->BreakpointData.codeStartAddress = (m_code.GetValue()->AsNativeCode())->GetAddress();
219221
}
220222

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

src/coreclr/debug/ee/controller.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,26 +1247,8 @@ bool DebuggerController::BindPatch(DebuggerControllerPatch *patch,
12471247
startAddr = (CORDB_ADDRESS_TYPE *) CORDB_ADDRESS_TO_PTR(patch->GetDJI()->m_addrOfCode);
12481248
_ASSERTE(startAddr != NULL);
12491249
}
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-
}
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);
12701252
}
12711253

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

src/coreclr/debug/ee/debugger.cpp

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

2844+
_ASSERTE(pNativeCodeStartAddress != NULL);
2845+
28442846
#ifdef PROFILING_SUPPORTED
28452847
// At this point, we're pulling in the debugger.
28462848
if (!HasLazyData())
@@ -3007,6 +3009,7 @@ HRESULT Debugger::GetILToNativeMappingIntoArrays(
30073009
_ASSERTE(pcMap != NULL);
30083010
_ASSERTE(prguiILOffset != NULL);
30093011
_ASSERTE(prguiNativeOffset != NULL);
3012+
_ASSERTE(pNativeCodeStartAddress != NULL);
30103013

30113014
// Any caller of GetILToNativeMappingIntoArrays had better call
30123015
// InitializeLazyDataIfNecessary first!
@@ -5411,28 +5414,6 @@ void Debugger::ReleaseAllRuntimeThreads(AppDomain *pAppDomain)
54115414
g_pEEInterface->ResumeFromDebug(pAppDomain);
54125415
}
54135416

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-
54365417
bool Debugger::IsJMCMethod(Module* pModule, mdMethodDef tkMethod)
54375418
{
54385419
CONTRACTL
@@ -6219,25 +6200,6 @@ void Debugger::LockAndSendEnCRemapCompleteEvent(MethodDesc *pMD)
62196200
Thread *thread = g_pEEInterface->GetThread();
62206201
// Note that the debugger lock is reentrant, so we may or may not hold it already.
62216202
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-
62416203
// Send an EnC remap complete event to the Right Side.
62426204
DebuggerIPCEvent* ipce = m_pRCThread->GetIPCEventSendBuffer();
62436205
InitIPCEvent(ipce,
@@ -7865,6 +7827,7 @@ void Debugger::FirstChanceManagedExceptionCatcherFound(Thread *pThread,
78657827
// Implements DebugInterface
78667828
// Call by EE/exception. Must be on managed thread
78677829
_ASSERTE(GetThreadNULLOk() != NULL);
7830+
_ASSERTE(pMethodAddr != NULL);
78687831

78697832
// Quick check.
78707833
if (!CORDebuggerAttached())
@@ -10498,7 +10461,7 @@ bool Debugger::HandleIPCEvent(DebuggerIPCEvent * pEvent)
1049810461
DebuggerJitInfo * pDJI = NULL;
1049910462
if ((pMethodDesc != NULL) && (pDMI != NULL))
1050010463
{
10501-
pDJI = pDMI->FindOrCreateInitAndAddJitInfo(pMethodDesc, NULL /* startAddr */);
10464+
pDJI = pDMI->FindOrCreateInitAndAddJitInfo(pMethodDesc, PINSTRToPCODE(dac_cast<TADDR>(pEvent->BreakpointData.codeStartAddress)));
1050210465
}
1050310466

1050410467
{
@@ -12625,7 +12588,7 @@ DWORD Debugger::GetThreadIdHelper(Thread *pThread)
1262512588
// does not own the memory provided via vars outparameter.
1262612589
//-----------------------------------------------------------------------------
1262712590
void Debugger::GetVarInfo(MethodDesc * fd, // [IN] method of interest
12628-
void *DebuggerVersionToken, // [IN] which edit version
12591+
CORDB_ADDRESS nativeCodeAddress, // [IN] which edit version
1262912592
SIZE_T * cVars, // [OUT] size of 'vars'
1263012593
const ICorDebugInfo::NativeVarInfo **vars // [OUT] map telling where local vars are stored
1263112594
)
@@ -12637,7 +12600,7 @@ void Debugger::GetVarInfo(MethodDesc * fd, // [IN] method of interest
1263712600
}
1263812601
CONTRACTL_END;
1263912602

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

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

1296212925
// For each offset in the IL->Native map, set a new EnC breakpoint on the
1296312926
// 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.
1296412932
PTR_DebuggerILToNativeMap seqMap = pJitInfo->GetSequenceMap();
1296512933
for (unsigned int i = 0; i < pJitInfo->GetSequenceMapCount(); i++)
1296612934
{

src/coreclr/debug/ee/debugger.h

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

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

1936-
int GetMethodEncNumber(MethodDesc * pMethod);
1937-
19381936

19391937
bool FirstChanceManagedException(Thread *pThread, SIZE_T currentIP, SIZE_T currentSP);
19401938

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

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

src/coreclr/debug/ee/functioninfo.cpp

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

15771575
if (startAddr == NULL)
15781576
{
1579-
// This will grab the start address for the current code version.
15801577
startAddr = g_pEEInterface->GetFunctionAddress(fd);
1581-
if (startAddr == NULL)
1582-
{
1583-
startAddr = fd->GetNativeCodeReJITAware();
1584-
if (startAddr == NULL)
1585-
{
1586-
return NULL;
1587-
}
1588-
}
1578+
_ASSERTE(startAddr != NULL);
15891579
}
15901580
else
15911581
{

src/coreclr/debug/inc/dbgipcevents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,7 @@ 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;
20142015
} BreakpointData;
20152016

20162017
struct MSLAYOUT

src/coreclr/vm/dbginterface.h

Lines changed: 1 addition & 6 deletions
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-
void *DebuggerVersionToken, // [IN] which edit version
206+
CORDB_ADDRESS nativeCodeAddress, // [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,11 +262,6 @@ 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-
270265
virtual void SendLogSwitchSetting (int iLevel,
271266
int iReason,
272267
_In_z_ LPCWSTR pLogSwitchName,

src/coreclr/vm/eedbginterfaceimpl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ PCODE EEDbgInterfaceImpl::GetFunctionAddress(MethodDesc *pFD)
630630
SUPPORTS_DAC;
631631
}
632632
CONTRACTL_END;
633-
634633
return pFD->GetNativeCode();
635634
}
636635

0 commit comments

Comments
 (0)