-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[cDAC] Implement DacDbi GetNativeCodeInfo / GetNativeCodeInfoForAddr #128338
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
352ebcc
794e87e
1a185ec
51fe617
109f48f
efc62f0
7f0ded6
a948fbc
5d7dd6f
dfaa609
575085a
e7644f1
2b2c1a8
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 |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # Contract EnC | ||
|
|
||
| This contract reports Edit and Continue (EnC) function version numbers for jitted | ||
| managed methods. EnC function versions are 1-based monotonically increasing counters | ||
| that the runtime assigns to each `EnC`-emitted instance of a method body. | ||
|
|
||
| ## APIs of contract | ||
|
|
||
| ``` csharp | ||
| // Returns the latest EnC version number associated with the method identified by | ||
| // (module, methodDef). If no EnC-jitted instance exists for that method, returns | ||
| // the default EnC function version (1). | ||
| TargetNUInt GetLatestEnCVersion(TargetPointer module, uint methodDef); | ||
|
|
||
| // Returns the EnC version number for the specific jitted instance of the method | ||
| // identified by (module, methodDef) whose hot region starts at the given native | ||
| // code address. If no matching jitted instance exists (for example, the method | ||
| // was never EnC-edited), returns the default EnC function version (1). | ||
| TargetNUInt GetEnCVersion(TargetPointer module, uint methodDef, TargetCodePointer nativeCodeAddress); | ||
| ``` | ||
|
|
||
| ## Version 1 | ||
|
|
||
| Data descriptors used: | ||
| | Data Descriptor Name | Field | Type | Purpose | | ||
| | --- | --- | --- | --- | | ||
| | `Module` | `EnCDataList` | nuint | Head of the singly linked list of `EnCData` entries for jitted EnC-versioned methods in this module | | ||
| | `EnCData` | `AddrOfCode` | nuint | Native code start (TADDR) for the jitted instance | | ||
| | `EnCData` | `Token` | uint32 | `mdMethodDef` token of the method | | ||
| | `EnCData` | `EnCVersion` | nuint | EnC function version number for this jitted instance | | ||
| | `EnCData` | `Next` | nuint | Next entry in the module's `EnCData` list, or null | | ||
|
|
||
| Global variables used: | ||
| | Global Name | Type | Purpose | | ||
| | --- | --- | --- | | ||
| | `CorDBDefaultEnCFunctionVersion` | nuint | Default EnC function version reported for methods that have never been EnC-edited (matches `CorDB_DEFAULT_ENC_FUNCTION_VERSION` in `src/coreclr/inc/cordbpriv.h`) | | ||
|
|
||
| Contracts used: none | ||
|
|
||
| ``` csharp | ||
| // Returns the address of the first EnCData entry on module's EnCDataList whose Token | ||
| // matches methodDef and (when addrOrZero is non-null) whose AddrOfCode matches | ||
| // addrOrZero. Returns TargetPointer.Null if no entry matches. | ||
| TargetPointer FindEnCDataEntry(TargetPointer module, uint methodDef, | ||
| TargetPointer addrOrZero) | ||
| { | ||
| TargetPointer cur = _target.ReadPointer(module + /* Module::EnCDataList offset */); | ||
| while (cur != TargetPointer.Null) | ||
| { | ||
| uint token = _target.Read<uint>(cur + /* EnCData::Token offset */); | ||
| TargetPointer addrOfCode = _target.ReadPointer(cur + /* EnCData::AddrOfCode offset */); | ||
| if (token == methodDef && | ||
| (addrOrZero == TargetPointer.Null || addrOfCode == addrOrZero)) | ||
| { | ||
| return cur; | ||
| } | ||
| cur = _target.ReadPointer(cur + /* EnCData::Next offset */); | ||
| } | ||
| return TargetPointer.Null; | ||
| } | ||
| ``` | ||
|
|
||
| ``` csharp | ||
| TargetNUInt GetLatestEnCVersion(TargetPointer module, uint methodDef) | ||
| { | ||
| TargetPointer entry = FindEnCDataEntry(module, methodDef, TargetPointer.Null); | ||
| if (entry == TargetPointer.Null) | ||
| return new TargetNUInt(/* CorDBDefaultEnCFunctionVersion global */); | ||
|
|
||
| return _target.ReadNUInt(entry + /* EnCData::EnCVersion offset */); | ||
| } | ||
| ``` | ||
|
|
||
| ``` csharp | ||
| TargetNUInt GetEnCVersion(TargetPointer module, uint methodDef, | ||
| TargetCodePointer nativeCodeAddress) | ||
| { | ||
| if (nativeCodeAddress.Value == 0) | ||
| return new TargetNUInt(/* CorDBDefaultEnCFunctionVersion global */); | ||
|
|
||
| TargetPointer entry = FindEnCDataEntry(module, methodDef, | ||
| new TargetPointer(nativeCodeAddress.Value)); | ||
| if (entry == TargetPointer.Null) | ||
| return new TargetNUInt(/* CorDBDefaultEnCFunctionVersion global */); | ||
|
|
||
| return _target.ReadNUInt(entry + /* EnCData::EnCVersion offset */); | ||
| } | ||
| ``` | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1255,8 +1255,7 @@ HRESULT STDMETHODCALLTYPE DacDbiInterfaceImpl::GetNativeCodeInfo(VMPTR_Assembly | |
| if (pCodeInfo->m_rgCodeRegions[kHot].pAddress != (CORDB_ADDRESS)NULL) | ||
| { | ||
| pCodeInfo->isInstantiatedGeneric = pMethodDesc->HasClassOrMethodInstantiation(); | ||
| LookupEnCVersions(pModule, | ||
| pCodeInfo->vmNativeCodeMethodDescToken, | ||
| LookupEnCVersions(pCodeInfo->vmNativeCodeMethodDescToken, | ||
| functionToken, | ||
| pCodeInfo->m_rgCodeRegions[kHot].pAddress, | ||
| &(pCodeInfo->encVersion)); | ||
|
|
@@ -1337,11 +1336,10 @@ HRESULT STDMETHODCALLTYPE DacDbiInterfaceImpl::GetNativeCodeInfoForAddr(CORDB_AD | |
| pCodeInfo->isInstantiatedGeneric = pMethodDesc->HasClassOrMethodInstantiation(); | ||
| pCodeInfo->vmNativeCodeMethodDescToken = vmMethodDesc; | ||
|
|
||
| SIZE_T unusedLatestEncVersion; | ||
| ULONG64 unusedLatestEncVersion; | ||
| Module * pModule = pMethodDesc->GetModule(); | ||
| _ASSERTE(pModule != NULL); | ||
| LookupEnCVersions(pModule, | ||
| vmMethodDesc, | ||
| LookupEnCVersions(vmMethodDesc, | ||
| pMethodDesc->GetMemberDef(), | ||
| codeStartAddr, | ||
| &unusedLatestEncVersion, //unused by caller | ||
|
|
@@ -5602,60 +5600,33 @@ HRESULT STDMETHODCALLTYPE DacDbiInterfaceImpl::GetPartialUserState(VMPTR_Thread | |
| // thinking is that some of the RS data structures will remain, most likely in a reduced form. | ||
| // | ||
|
|
||
| void DacDbiInterfaceImpl::LookupEnCVersions(Module* pModule, | ||
| VMPTR_MethodDesc vmMethodDesc, | ||
| void DacDbiInterfaceImpl::LookupEnCVersions(VMPTR_MethodDesc vmMethodDesc, | ||
| mdMethodDef mdMethod, | ||
| CORDB_ADDRESS pNativeStartAddress, | ||
| SIZE_T * pLatestEnCVersion, | ||
| SIZE_T * pJittedInstanceEnCVersion /* = NULL */) | ||
| ULONG64 * pLatestEnCVersion, | ||
| ULONG64 * pJittedInstanceEnCVersion /* = NULL */) | ||
| { | ||
| MethodDesc * pMD = vmMethodDesc.GetDacPtr(); | ||
|
|
||
| // make sure the vmMethodDesc and mdMethod match | ||
| _ASSERTE(pMD->GetMemberDef() == mdMethod); | ||
|
|
||
| MethodDesc * pMD = vmMethodDesc.GetDacPtr(); | ||
| _ASSERTE(pLatestEnCVersion != NULL); | ||
|
|
||
| // @dbgtodo inspection - once we do EnC, stop using DMIs. | ||
| // If the method wasn't EnCed, DMIs may not exist. And since this is DAC, we can't create them. | ||
|
|
||
| // We may not have the memory for the DebuggerMethodInfos in a minidump. | ||
| // When dump debugging EnC information isn't very useful so just fallback | ||
| // to default version. | ||
| DebuggerMethodInfo * pDMI = NULL; | ||
| DebuggerJitInfo * pDJI = NULL; | ||
| EX_TRY_ALLOW_DATATARGET_MISSING_MEMORY | ||
| #ifndef FEATURE_METADATA_UPDATER | ||
| if (pJittedInstanceEnCVersion != NULL) | ||
| { | ||
| if (g_pDebugger != NULL) | ||
| { | ||
| pDMI = g_pDebugger->GetOrCreateMethodInfo(pModule, mdMethod); | ||
| if (pDMI != NULL) | ||
| { | ||
| pDJI = pDMI->FindJitInfo(pMD, CORDB_ADDRESS_TO_TADDR(pNativeStartAddress)); | ||
| } | ||
| } | ||
| *pJittedInstanceEnCVersion = CorDB_DEFAULT_ENC_FUNCTION_VERSION; | ||
| } | ||
| EX_END_CATCH_ALLOW_DATATARGET_MISSING_MEMORY; | ||
| if (pDJI != NULL) | ||
| if (pLatestEnCVersion != NULL) | ||
| { | ||
| if (pJittedInstanceEnCVersion != NULL) | ||
| { | ||
| *pJittedInstanceEnCVersion = pDJI->m_encVersion; | ||
| } | ||
| *pLatestEnCVersion = pDMI->GetCurrentEnCVersion(); | ||
| *pLatestEnCVersion = CorDB_DEFAULT_ENC_FUNCTION_VERSION; | ||
| } | ||
| else | ||
| #else | ||
| Module* pLoaderModule = pMD->GetLoaderModule(); | ||
| PTR_EnCData pEnCData = pLoaderModule->FindEncData(mdMethod, CORDB_ADDRESS_TO_TADDR(pNativeStartAddress)); | ||
| PTR_EnCData pLatestEncData = pLoaderModule->FindLatestEncData(mdMethod); | ||
|
Comment on lines
+5621
to
+5623
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 this is fine now because heap dumps will include this as it is off the loader allocator
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. What about mini or triage dumps? I would not expect them to contain all the memory from the loader allocator.
rcj1 marked this conversation as resolved.
|
||
| if (pJittedInstanceEnCVersion != NULL) | ||
| { | ||
| // If we have no DMI/DJI, then we must never have EnCed. So we can use default EnC info | ||
| // Several cases where we don't have a DMI/DJI: | ||
| // - LCG methods | ||
| // - method was never "touched" by debugger. (DJIs are created lazily). | ||
| if (pJittedInstanceEnCVersion != NULL) | ||
| { | ||
| *pJittedInstanceEnCVersion = CorDB_DEFAULT_ENC_FUNCTION_VERSION; | ||
| } | ||
| *pLatestEnCVersion = CorDB_DEFAULT_ENC_FUNCTION_VERSION; | ||
| *pJittedInstanceEnCVersion = (pEnCData != NULL) ? pEnCData->encVersion : CorDB_DEFAULT_ENC_FUNCTION_VERSION; | ||
| } | ||
| *pLatestEnCVersion = (pLatestEncData != NULL) ? pLatestEncData->encVersion : CorDB_DEFAULT_ENC_FUNCTION_VERSION; | ||
| #endif // FEATURE_METADATA_UPDATER | ||
| } | ||
|
|
||
| // Get the address of the Debugger control block on the helper thread | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -1226,6 +1226,17 @@ void DebuggerJitInfo::Init(TADDR newAddress) | |||
| this->m_sizeOfCode = this->m_codeRegionInfo.getSizeOfTotalCode(); | ||||
|
|
||||
| this->m_encVersion = this->m_methodInfo->GetCurrentEnCVersion(); | ||||
| #ifdef FEATURE_METADATA_UPDATER | ||||
| if (this->m_encVersion != CorDB_DEFAULT_ENC_FUNCTION_VERSION) | ||||
| { | ||||
| Module* pModule = this->m_pLoaderModule; | ||||
| EnCData* pEnCData = (EnCData*)(void*)pModule->GetLoaderAllocator()->GetLowFrequencyHeap()->AllocMem(S_SIZE_T(sizeof(EnCData))); | ||||
| pEnCData->addrOfCode = (TADDR)this->m_addrOfCode; | ||||
| pEnCData->token = this->m_methodInfo->m_token; | ||||
| pEnCData->encVersion = this->m_encVersion; | ||||
| pModule->AddEncData(pEnCData); | ||||
|
rcj1 marked this conversation as resolved.
Comment on lines
1228
to
+1237
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. good catch. Only possibly relevant in runtime/src/coreclr/debug/di/divalue.cpp Line 2748 in 3206a8e
|
||||
| } | ||||
| #endif // FEATURE_METADATA_UPDATER | ||||
|
|
||||
| this->InitFuncletAddress(); | ||||
|
|
||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.