Fix mixed mode debugging for PInvoke by adding PInvokeStubManager#123411
Fix mixed mode debugging for PInvoke by adding PInvokeStubManager#123411max-charlamb merged 10 commits intomainfrom
Conversation
711ba31 to
a205749
Compare
|
@copilot , update the PR title and summary to reflect the new changes. Instead of connecting the ILStubMethodDesc to the PInvokeStub, I implemented a |
Updated the PR title and description to accurately reflect the PInvokeStubManager implementation. The new approach handles PInvokeMethodDesc directly, which works for both JIT and R2R scenarios. |
|
@copilot , there are now several spots where we want to check if the MethodDesc corresponds to an "interop method call" including if Then we can simplify the code diff to utilize this option when applicable. |
Add MethodDesc::IsInteropStub() that returns true for both IL stubs and PInvoke methods. Updated debug code to use this new helper method instead of checking both conditions separately. Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
Implemented |
jkotas
left a comment
There was a problem hiding this comment.
Assuming you have tested that the stepping works fine for both JIT and R2R code with this fix.
|
@copilot , address feedback |
Description
PR #117901 changed PInvoke ILStub code to return
PInvokeMethodDescdirectly fromExecutionManager::GetCodeMethodDesc()instead ofDynamicMethodDesc. This broke mixed mode debugger step-in for PInvoke calls becauseILStubManager::CheckIsStub_Internal()only checkedpMD->IsILStub(), which returns false forPInvokeMethodDesc.Changes
Implemented a dedicated
PInvokeStubManagerto handle PInvoke stubs directly:stubmgr.h: Added
PInvokeStubManagerclass extendingStubManagerCheckIsStub_Internal(): Recognizes PInvoke stubs by checkingpMD->IsPInvoke()DoTraceStub(): Traces to the native target viaPInvokeMethodDesc::GetPInvokeTarget()stubmgr.cpp: Implemented PInvokeStubManager methods
Init(): Registers the stub manager during system initializationDoEnumMemoryRegions()appdomain.cpp: Added
PInvokeStubManager::Init()call during system domain initializationvptr_list.h: Added
VPTR_CLASS(PInvokeStubManager)for vtable supportmethod.hpp: Added
IsInteropStub()helper methodtruefor both IL stubs (IsILStub()) and PInvoke methods (IsPInvoke())controller.cpp, frameinfo.cpp: Updated debugger code to use
IsInteropStub()IsILStub() || IsPInvoke()with cleanerIsInteropStub()callsfIsILStubvariable tofIsInteropStubto accurately reflect that it checks for interop stubs (both IL stubs and PInvoke methods)This approach handles
PInvokeMethodDescdirectly without requiring a reverse mapping toDynamicMethodDesc, making it work for both JIT-compiled and R2R (ReadyToRun) PInvoke stubs.Testing
Built CoreCLR successfully. The PInvokeStubManager is registered at startup and properly integrates with the debugger's stub manager infrastructure to handle all PInvoke stub recognition and tracing. The new
IsInteropStub()helper method provides a consistent API for identifying interop stubs throughout the codebase.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.