You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stepping into multidimensional array of tuples in debug causes internal CLR error #38777
Trying to step into any statement involving getting value from multidimensional array of tuples causes System.ExecutionEngineException and subsequently internal CLR error. However stepping over or checking the value through locals window does not.
Configuration
.Net Core 3.1 (also happens in 3.0)
Windows
Any CPU
Code example
var array = new (int a, bool b)[2, 2];
array[0, 0] = (1, true); // Stepping in causes Internal CLR error. (0x80131506)
var k = array[0, 0]; // Stepping in causes Internal CLR error. (0x80131506)
var c = array[1, 1].a; // Stepping in causes Internal CLR error. (0x80131506)
From what I can see, it enters the ILStubClass.IL_STUB_Array_Set method and there's a breakpoint (INT 3) at the very beginning of the method; I presume this is because we asked to step in? From what I see CLR tries to hand this over to the debugger, but in ILStubManager::TraceManager it looks like it tries to dereference an invalid pointer and this gets propagated as an EEE. I can provide dump of this thing if it can't be repro'd.
This happened while dispatching the notification for the breakpoint for the step into, and we reach DispatchPatchOrSingleStep and start looking for possible triggers for this, finding one which gets classified as a break at a stub at offset 0. When we started looking for possible triggers, we had a context with R10 was already set to a value that the StubManager would use as the MethodDesc* that caused the AV. We get the context from GetThreadFilterContext, and I see the correct IP for the stub, and that Entry2MethodDesc gives back the correct MD. The extended flags for it are 0x00010006 which is nomdILStub | mcArray | mcNDirect, so it's going to need to take the branch that it's failing on. I just don't know why R10 is not valid (not sure if it's related to being at the pure start of the stub and us getting TRACE_MGR_PUSH meaning that the patch's trace is left to the manager instead of the frame that gets us here).
Maybe @jkoritzinsky or @AaronRobinsonMSFT may have some tips for us on why R10 is not what's expected here? I am not very familiar with ABI's here so any pointers are appreciated
It looks like ILStubManager::TraceManager doesn't special-case array IL stubs. Considering we had to fix #36249 a few months ago, it's possible that the debugger changed a code path that causes more stub types to go down this route. I think ILStubManager::TraceManager needs to either be updated to handle array IL stubs, or it should be updated to not assume that NDirect is the fallback and instead explicitly check for NDirect methods and otherwise assume that an unknown IL stub type needs to return false.
Also, it looks like the array IL stubs shouldn't be marked as mcNDirect since they don't call into a "target" native method, but instead should be just marked as nomdILStub | mcArray.
I realized I misread the flags. Flags are mcDynamic | mdcRequiresFullSlotNumber | mdcHasNonVtableSlot and extended flags are mdPublic | DynamicMethodDesc::nomdILStub, all of which make sense, except I would have expected to see mcArray in there as well.
@noahfalk what's the expected behavior for these stubs? If I add this we step over and there's no AV:
index 3477154b664..92e3908dc8e 100644
--- a/src/coreclr/src/vm/stubmgr.cpp+++ b/src/coreclr/src/vm/stubmgr.cpp@@ -1793,6 +1793,14 @@ BOOL ILStubManager::TraceManager(Thread *thread,
// so we have nowhere to tell the debugger to move the breakpoint.
return FALSE;
}
+#ifdef FEATURE_ARRAYSTUB_AS_IL+ else if (pStubMD->GetILStubResolver()->GetStubType() == ILStubResolver::ArrayOpStub)+ {+ // These stubs are generated by the JIT. There's no code backing+ // them, so there's no target to relocate the breakpoint to.+ return FALSE;+ }+#endif
else
{
// This is either direct forward P/Invoke or a CLR-to-COM call, the argument is MD
Is there any case where we'd want to let the user step through the native stub (say disassembly mode if they do a step in)?
Debugger should be treating these stubs as black box ie return FALSE from this method.
It would be better to check for the forward P/Invoke or a CLR-to-COM call stub explicitly before going into "This is either direct forward P/Invoke or a CLR-to-COM call, the argument is MD" path. Once you do that, you can also delete the existing IsStructMarshalStub check and the code would be robust against unexpected types of stubs.
Agreed with @jkotas. Not certain if it was clear but I think Jan's suggestion assumes that we add an else { return FALSE } at the end of the chain to avoid the return TRUE that is lurking after it. The logic would look like this:
if(pStubMD->IsMulticastStub()) { ... }
else if(pStubMD->IsReverseStub()) { ... }
else if(pStubMD->IsDelegateStub()) { ... }
else if(pStubMD->IsCALLIStub()) { ... }
else if(pStubMD->IsPInvokeStub()) { pMD = arg; _ASSERTE(pMD->IsNDirect()); ... }
else if(pStubMD->IsCLRToCOMStub()) { pMD = arg; _ASSERTE(pMD->IsComPlusCall()); ... }
else
{
return FALSE; // Any unrecognized stub we should assume it doesn't have managed code
// Even if we are miscategorizing it the worst case is we step over code we should
// have stepped into. Much better than a crash.
}
return TRUE;
It looks like IsCLRToCOMStub and IsPinvoke (all that assume HasMDContextArg) are not quite right - currently the DynamicMethodDesc that we use for array stubs falls under IsCLRToCOMStub. I could add the original code that worked around the AV, but I have a feeling issues are running deeper here. I'd rather address that, so I'll come back to this in a bit.
Activity
Dotnet-GitSync-Bot commentedon Jul 3, 2020
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
tommcdon commentedon Jul 3, 2020
@sdmaclea
Gnbrkm41 commentedon Jul 4, 2020
Can also reproduce with 5.0.100-preview.8.20351.5 with VS2019 16.7 P3.1. This happens with "Just My Code" disabled.
Gnbrkm41 commentedon Jul 5, 2020
From what I can see, it enters the
ILStubClass.IL_STUB_Array_Setmethod and there's a breakpoint (INT 3) at the very beginning of the method; I presume this is because we asked to step in? From what I see CLR tries to hand this over to the debugger, but inILStubManager::TraceManagerit looks like it tries to dereference an invalid pointer and this gets propagated as an EEE. I can provide dump of this thing if it can't be repro'd.hoyosjs commentedon Jul 5, 2020
Thanks @Gnbrkm41 I also see this and the
int 3in that stub. I see this too:Stack for assert
Looks like this line checking if a MD corresponds to an NDirect call is triggering an AV because it was called with a bogus
MethodDesc*:runtime/src/coreclr/src/vm/method.hpp
Line 1872 in 312c758
This happened while dispatching the notification for the breakpoint for the step into, and we reach
DispatchPatchOrSingleStepand start looking for possible triggers for this, finding one which gets classified as a break at a stub at offset 0. When we started looking for possible triggers, we had a context with R10 was already set to a value that theStubManagerwould use as theMethodDesc*that caused the AV. We get the context fromGetThreadFilterContext, and I see the correct IP for the stub, and thatEntry2MethodDescgives back the correct MD. The extended flags for it are0x00010006which isnomdILStub | mcArray | mcNDirect, so it's going to need to take the branch that it's failing on. I just don't know why R10 is not valid (not sure if it's related to being at the pure start of the stub and us gettingTRACE_MGR_PUSHmeaning that the patch's trace is left to the manager instead of the frame that gets us here).Maybe @jkoritzinsky or @AaronRobinsonMSFT may have some tips for us on why R10 is not what's expected here? I am not very familiar with ABI's here so any pointers are appreciated
jkoritzinsky commentedon Jul 6, 2020
It looks like
ILStubManager::TraceManagerdoesn't special-case array IL stubs. Considering we had to fix #36249 a few months ago, it's possible that the debugger changed a code path that causes more stub types to go down this route. I thinkILStubManager::TraceManagerneeds to either be updated to handle array IL stubs, or it should be updated to not assume that NDirect is the fallback and instead explicitly check for NDirect methods and otherwise assume that an unknown IL stub type needs to return false.Also, it looks like the array IL stubs shouldn't be marked as
mcNDirectsince they don't call into a "target" native method, but instead should be just marked asnomdILStub | mcArray.hoyosjs commentedon Jul 7, 2020
I realized I misread the flags. Flags are
mcDynamic | mdcRequiresFullSlotNumber | mdcHasNonVtableSlotand extended flags aremdPublic | DynamicMethodDesc::nomdILStub, all of which make sense, except I would have expected to seemcArrayin there as well.@noahfalk what's the expected behavior for these stubs? If I add this we step over and there's no AV:
Is there any case where we'd want to let the user step through the native stub (say disassembly mode if they do a step in)?
jkotas commentedon Jul 7, 2020
Debugger should be treating these stubs as black box ie return
FALSEfrom this method.It would be better to check for the forward P/Invoke or a CLR-to-COM call stub explicitly before going into "This is either direct forward P/Invoke or a CLR-to-COM call, the argument is MD" path. Once you do that, you can also delete the existing
IsStructMarshalStubcheck and the code would be robust against unexpected types of stubs.noahfalk commentedon Jul 8, 2020
Agreed with @jkotas. Not certain if it was clear but I think Jan's suggestion assumes that we add an else { return FALSE } at the end of the chain to avoid the return TRUE that is lurking after it. The logic would look like this:
hoyosjs commentedon Jul 22, 2020
It looks like
IsCLRToCOMStubandIsPinvoke(all that assumeHasMDContextArg) are not quite right - currently theDynamicMethodDescthat we use for array stubs falls underIsCLRToCOMStub. I could add the original code that worked around the AV, but I have a feeling issues are running deeper here. I'd rather address that, so I'll come back to this in a bit.