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
ExecutionEngineException when using step-by-step #63199
When trying to find the source of an "CancelledOperationException" being thrown in background in my app, I stumbled on a weird bug.
When I step in a specific place, it will throw a ExecutionEngineException, and if I try to continue the program execution it will freeze VS2022 (and I must kill it with taskmanager).
As I don't know where the issue come from, I created the issue here.
Reproduction Steps
Clone my repo Kuinox/CK-LogViewer@ac8a945 and checkout on the commit linked (it was the develop branch when this issue was opened).
Run LogSampleGenerator until it hit the Debugger.Break().
Now due to this issue: dotnet/sdk#1458, 3 pdb must be loaded by hand in VS, they are located in the nuget cache: %userprofile%\.nuget\packages\ck.mqtt.abstractions\0.10.0\lib\net6.0 %userprofile%\.nuget\packages\ck.mqtt.common\0.10.0\lib\net6.0 %userprofile%\.nuget\packages\ck.mqtt.client\0.10.0\lib\net6.0
Now navigate to
CK.MQTT.Client.dll!CK.MQTT.SmallOutgoingApplicationMessageExtensions.PublishAsync(CK.MQTT.IMqtt3Client client, CK.Core.IActivityMonitor m, string topic, CK.MQTT.QualityOfService qos, bool retain, System.ReadOnlyMemory<byte> payload) Line 13 C#
CK.Monitoring.MQTT.dll!CK.Monitoring.MQTT.MQTT.DoHandleAsync(CK.Core.IActivityMonitor m, CK.Monitoring.IMulticastLogEntry entry) Line 29 C#
Now trying to step in SendPacketAsync throw the ExecutionEngineException.
Pressing F5/F10 here lead to VS freezing.
HI @Kuinox I'm not able to reproduce the issue. Under Debug->Options, I have Just My Code disabled and Suppress JIT optimization on module load enabled. Without those settings I was not able to step into the SendPacketAsync function. I am seeing that an InvalidOperationException is being thrown from that function:
If you are still able to reproduce the issue, would you mind capturing a dump and uploading it through a VS Feedback Ticket (to protect your privacy)? Once the feedback ticket is created, please paste a link to in in this Github issue and we'll be able to find it.
@Kuinox I've sent out an urgent request internally to try to get it deleted. I'm not sure why it's public -- if I remember a correctly there's a checkbox that makes it public.
@Kuinox I've sent out an urgent request internally to try to get it deleted. I'm not sure why it's public -- if I remember a correctly there's a checkbox that makes it public.
Thanks ! I don't think there is anything important as it's not my work machine, but it's better be safe.
I was not sure it would be public, and didn't found any checkbox to make it public or private, in fact there is even a "secured" (what does it mean ?) indicator next to the form:
@Kuinox Thanks again for the dump. This issue will require more investigation. Here's my rough notes so far. It looks like the debugger hit a breakpoint and it working to determine where the stub leads to, and in that process it hit an Access Violation (AV). AV's in the runtime are translated to ExecutionEngineException's. Is this failing deterministically for you? For us to understand this better we can provide you with an instrumented runtime that will provide better logging which should help us understand the root cause better.
@Kuinox This item is on our backlog but we don't have time right now to work on this. In the meantime, please try working around the issue by manually setting breakpoints on target methods. instead of stepping into the method causes the app/VS to freeze.
@davidwrighton@AaronRobinsonMSFT@jkoritzinsky - this bug appears to be a long-standing issue with IL stubs, I'm not sure who the owner of that is these days? The short version is that ILStubManager::TraceManager doesn't appear to correctly handle all the ILStubs that the runtime creates. A few years ago we encountered a very similar problem with a different type of ILStub that this method didn't handle so this appears to be a repeating problem.
Investigating the dump that @Kuinox sent us, this is the long version of what I think likely has happened:
The debugger is initially stopped in the PublishAsync() method shown above and then we do a step-in operation.
In order to do the step operation the debugger repeatedly predicts forward in the disassembly to determine where execution will go, sets a breakpoint, and then runs to that point. If the scenario had worked properly the debugger would eventually determine that it had executed far enough and break out of the loop, but we don't get that far in this case.
While still in that loop the debugger executes to IP 00007ffae9037c31 and tries to determine where execution will go next.
// this is part of the disassembly for the source code line "return await client.SendPacketAsync<object>(...)
0:035> u 00007ffa`e9037c11
CK_MQTT_Client!CK.MQTT.SmallOutgoingApplicationMessageExtensions+<PublishAsync>d__0.MoveNext()+0x141:
00007ffa`e9037c11 e86a4bee5e call coreclr!JIT_VirtualFunctionPointer (00007ffb`47f1c780)
00007ffa`e9037c16 48894580 mov qword ptr [rbp-80h],rax
00007ffa`e9037c1a 488d9568ffffff lea rdx,[rbp-98h]
00007ffa`e9037c21 488b4d90 mov rcx,qword ptr [rbp-70h]
00007ffa`e9037c25 4c8b4588 mov r8,qword ptr [rbp-78h]
00007ffa`e9037c29 4c8b4d98 mov r9,qword ptr [rbp-68h]
00007ffa`e9037c2d 488b4580 mov rax,qword ptr [rbp-80h]
00007ffa`e9037c31 ffd0 call rax // <--------------- execution reached here
That call at the end will lead to executing the jitted code for the IL instantiating stub for SendPacketAsync(...)
The debugger observes the call opcode and knows the current value of rax, so it invokes TrapStepInHelper to try figuring out where execution will go to and set a breakpoint. This calls TrapStepInto, which calls into StubManager::TraceStub(). The IP in rax points to 00007ffae9038da0, an IL instantiating stub:
StubManager::TraceStub() determines that the target address belongs to the ILStubManager because ILStubManager::CheckIsStub_Internal claims all addresses that map to MethodDescs where MethodDesc::IsILStub() is TRUE.
StubManager::TraceStub then asks ILStubManager to predict where the stub will execute to by calling ILStubManager::DoTraceStub(). The implementation of this method returns something called "ManagerPush" with the stub start address (00007ffae9038da0). This is intended for cases where the stub manager can't predict the destination of the stub given its IP alone. Instead the StubManager is requesting that the debugger set a breakpoint at the address it returned, then call back to the stub manager later once execution has reached that address. At that point the debugger will be able to provide a complete CONTEXT rather than the IP alone.
StubManager code returns back to the debugger, the debugger sets the breakpoint at 00007ffae9038da0 as requested, and returns back through the vectored exception handler which ultimately resumes execution in the jitted user code at 00007ffae9037c31:
00007ffa`e9037c31 ffd0 call rax
The processor executes the call instruction, immediately arriving at 00007ffae9038da0 and triggering the breakpoint placed by the debugger. This generates an exception that calls back into vectored exception handler and works it way back to the debugger code.
0:035> u
CK_MQTT_Client!ILStubClass.IL_STUB_InstantiatingStub(CK.Core.IActivityMonitor, CK.MQTT.IOutgoingPacket):
00007ffa`e9038da0 cc int 3 // <--------------- execution has now advanced to here
00007ffa`e9038da1 4883ec30 sub rsp,30h
00007ffa`e9038da5 488d6c2430 lea rbp,[rsp+30h]
00007ffa`e9038daa 48894d10 mov qword ptr [rbp+10h],rcx
00007ffa`e9038dae 48895518 mov qword ptr [rbp+18h],rdx
00007ffa`e9038db2 4c894520 mov qword ptr [rbp+20h],r8
00007ffa`e9038db6 4c894d28 mov qword ptr [rbp+28h],r9
00007ffa`e9038dba 48b9787603e9fa7f0000 mov rcx,offset CLRStub[MethodDescPrestub]@7ffae9037678 (00007ffa`e9037678)
The debugger recognizes that it placed this breakpoint at the request of the ILStubManager, and now that it has reached the requested address it invokes back to the ILStubManager again wanting a prediction on where execution will go. This time the debugger provides a complete CONTEXT:
ILStubManager::TraceManager incorrectly classifies the stub as being either a p/invoke or a CLR-to-COM call because it is the default case of a large if/else if chain:
if(pStubMD->IsMulticastStub()) { ... }
else if(pStubMD->IsReverseStub()) { ... }
else if(pStubMD->IsDelegateStub()) { ... }
else if(pStubMD->IsStubCALLIStub()) { ... }
else if(pStubMD->IsStructMarshalStub() { ... }
else
{
// This case is only intended to handle p/invoke and CLR-to-COM call, however no earlier condition matched
// IL instantiated stub so execution enters here.
}
I'm pretty sure the bug is right here in the incorrect classification, but execution continues a little further doing calculations based on garbage data...
ILStubManager::TraceManager calculates arg, the hidden argument, by reading from R10 in the CONTEXT above: 0x000001b0e462f170.
pMD = arg
pCMD = pMD
pCMD->m_pComPlusCallInfo = 00007ffa4f977cc5
As best I understand R10 is not part of the expected calling convention for invoking an instantiating stub so these computations are based on whatever arbitrary value happened to be in the register at the time.
Inside ILStubManager::GetCOMTarget
the runtime evaluates the expression pComPlusCallInfo->m_pInterfaceMT which is what ultimately triggers the AV that surfaces back to the developer as the ExecutionEngineException
Ah thanks! I had some recollection talking about this issue before, but I missed #38777 and found only #36248. My take is that each of these issues represents a distinct type of ILStub so they aren't quite duplicates, but a common solution that would cover all of them would be to ensure that StubManager::TraceManager handles all ILStub types produced by the runtime.
Create a new console app project with this code in Visual Studio targetting .NET 6
IClientclient=newClient();client.SendPacketAsync<object>(1,2,3,4);client.PublishAsync();staticclassExtensions{publicstaticvoidPublishAsync(thisIClientclient){client.SendPacketAsync<object>(1,2,3,4);// <----- set breakpoint here}}interfaceIClient{publicvoidSendPacketAsync<T>(intarg1,intarg2,intarg3,intarg4);}classClient:IClient{publicvoidSendPacketAsync<T>(intarg1,intarg2,intarg3,intarg4){Console.WriteLine(typeof(T).Name);}}
Set breakpoint at the commented line
Turn off JMC
Run the program under the debugger (F5)
When the code reaches the breakpoint, step in
Expected result: execution pauses inside SendPacketAsync()
Actual result: VS shows a dialog for an unhandled ExecutionEngineException
Reacted by Aaron R Robinson
ghost added
in-prThere is an active PR which will close this issue when it is merged
Activity
Kuinox commentedon Dec 30, 2021
Tell me if you successfully reproduced it or if you want that I make a more minimal reproduction.
tommcdon commentedon Dec 30, 2021
HI @Kuinox I'm not able to reproduce the issue. Under Debug->Options, I have Just My Code disabled and Suppress JIT optimization on module load enabled. Without those settings I was not able to step into the

SendPacketAsyncfunction. I am seeing that an InvalidOperationException is being thrown from that function:If you are still able to reproduce the issue, would you mind capturing a dump and uploading it through a VS Feedback Ticket (to protect your privacy)? Once the feedback ticket is created, please paste a link to in in this Github issue and we'll be able to find it.
tommcdon commentedon Dec 30, 2021
@Kuinox I hit send too soon above. To collect a dump, please choose Debug->Save Dump As in VS.

Kuinox commentedon Dec 30, 2021
Oh sorry ! I forgot that it had to connect to a mosquitto server running on localhost :(.


Looks like I can't create a dump.
Kuinox commentedon Dec 30, 2021
I created a dump using dotnet-dump cli tool and made a ticket on VS Feedback, sadly it looks like the ticket & dump file is public and I can't find a way to make it not public :/
https://developercommunity.visualstudio.com/t/ExecutionEngineException-when-using-step/1626148
danmoseley commentedon Dec 30, 2021
@Kuinox I've sent out an urgent request internally to try to get it deleted. I'm not sure why it's public -- if I remember a correctly there's a checkbox that makes it public.
Kuinox commentedon Dec 30, 2021
Thanks ! I don't think there is anything important as it's not my work machine, but it's better be safe.
I was not sure it would be public, and didn't found any checkbox to make it public or private, in fact there is even a "secured" (what does it mean ?) indicator next to the form:

tommcdon commentedon Dec 30, 2021
Thanks @danmoseley! @Kuinox I've downloaded the dump so it's safe to delete the uploaded files.
Kuinox commentedon Dec 30, 2021
Ok, I edited the ticket to remove the link to the uploaded dump.
tommcdon commentedon Dec 31, 2021
@Kuinox Thanks again for the dump. This issue will require more investigation. Here's my rough notes so far. It looks like the debugger hit a breakpoint and it working to determine where the stub leads to, and in that process it hit an Access Violation (AV). AV's in the runtime are translated to ExecutionEngineException's. Is this failing deterministically for you? For us to understand this better we can provide you with an instrumented runtime that will provide better logging which should help us understand the root cause better.
Kuinox commentedon Dec 31, 2021
Yes more or less, when VS doesn't simply freeze while stepping into this code, it reproduce the exception everytime.
Kuinox commentedon Dec 31, 2021
Yes, what should I do ?
tommcdon commentedon Jan 18, 2022
@Kuinox This item is on our backlog but we don't have time right now to work on this. In the meantime, please try working around the issue by manually setting breakpoints on target methods. instead of stepping into the method causes the app/VS to freeze.
Kuinox commentedon Jan 18, 2022
Ok ok, thanks for the update.
noahfalk commentedon Feb 24, 2022
@davidwrighton @AaronRobinsonMSFT @jkoritzinsky - this bug appears to be a long-standing issue with IL stubs, I'm not sure who the owner of that is these days? The short version is that ILStubManager::TraceManager doesn't appear to correctly handle all the ILStubs that the runtime creates. A few years ago we encountered a very similar problem with a different type of ILStub that this method didn't handle so this appears to be a repeating problem.
Investigating the dump that @Kuinox sent us, this is the long version of what I think likely has happened:
00007ffae9037c31and tries to determine where execution will go next.That call at the end will lead to executing the jitted code for the IL instantiating stub for SendPacketAsync(...)
00007ffae9038da0, an IL instantiating stub:StubManager::TraceStub() determines that the target address belongs to the ILStubManager because ILStubManager::CheckIsStub_Internal claims all addresses that map to MethodDescs where MethodDesc::IsILStub() is TRUE.
StubManager::TraceStub then asks ILStubManager to predict where the stub will execute to by calling ILStubManager::DoTraceStub(). The implementation of this method returns something called "ManagerPush" with the stub start address (
00007ffae9038da0). This is intended for cases where the stub manager can't predict the destination of the stub given its IP alone. Instead the StubManager is requesting that the debugger set a breakpoint at the address it returned, then call back to the stub manager later once execution has reached that address. At that point the debugger will be able to provide a complete CONTEXT rather than the IP alone.StubManager code returns back to the debugger, the debugger sets the breakpoint at
00007ffae9038da0as requested, and returns back through the vectored exception handler which ultimately resumes execution in the jitted user code at00007ffae9037c31:00007ffae9038da0and triggering the breakpoint placed by the debugger. This generates an exception that calls back into vectored exception handler and works it way back to the debugger code.I'm pretty sure the bug is right here in the incorrect classification, but execution continues a little further doing calculations based on garbage data...
arg, the hidden argument, by reading from R10 in the CONTEXT above:0x000001b0e462f170.pMD = arg
pCMD = pMD
pCMD->m_pComPlusCallInfo = 00007ffa4f977cc5
As best I understand R10 is not part of the expected calling convention for invoking an instantiating stub so these computations are based on whatever arbitrary value happened to be in the register at the time.
the runtime evaluates the expression pComPlusCallInfo->m_pInterfaceMT which is what ultimately triggers the AV that surfaces back to the developer as the ExecutionEngineException
The AV occurs at
00007ffb48118e04which is dereferencing r14+8 =0x00007ffa4f977cc5+8 =0x00007ffa4f977ccdjkotas commentedon Feb 24, 2022
Duplicate of #38777 ? The proposed fix: #38777 (comment)
AaronRobinsonMSFT commentedon Feb 24, 2022
/cc @dotnet/interop-contrib
noahfalk commentedon Feb 24, 2022
Ah thanks! I had some recollection talking about this issue before, but I missed #38777 and found only #36248. My take is that each of these issues represents a distinct type of ILStub so they aren't quite duplicates, but a common solution that would cover all of them would be to ensure that StubManager::TraceManager handles all ILStub types produced by the runtime.
noahfalk commentedon Feb 26, 2022
Here is a simplified repro case:
Expected result: execution pauses inside SendPacketAsync()
Actual result: VS shows a dialog for an unhandled ExecutionEngineException
Kuinox commentedon Mar 4, 2022
Thanks !