-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[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
Open
rcj1
wants to merge
13
commits into
main
Choose a base branch
from
copilot/cdac-enc-getnativecodeinfo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
352ebcc
[cDAC] Implement DacDbi GetNativeCodeInfo / GetNativeCodeInfoForAddr
rcj1 794e87e
Update IDacDbiInterface.cs
rcj1 1a185ec
Apply suggestions from code review
rcj1 51fe617
Potential fix for pull request finding
rcj1 109f48f
ccr
rcj1 efc62f0
Add EnC unit tests for cDAC DacDbi native code APIs
Copilot 7f0ded6
fix buidl break
rcj1 a948fbc
Add EnC contract unit tests
Copilot 5d7dd6f
Refine EnC contract test names
Copilot dfaa609
Polish EnC contract unit test scaffolding
Copilot 575085a
Rename EnC contract tests for clarity
Copilot e7644f1
Tidy EnC unit test naming
Copilot 2b2c1a8
Clarify EnC unit test locals
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 */); | ||
| } | ||
| ``` | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||||
|
|
||||
|
|
||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.