I am trying to display the stack traces of RTOS fibers running in a C++ solution in VS2022. Since upgrading to Windows 11 there seems to be a problem in the implementation. The existing approach, which has worked with VS2013 and VS2019 uses context switching to switch the context of the fiber with a dummy thread (that is always suspended)
I have written a VSPackage that uses debugger events to handle the context switching and react to events. When the debugger stops I switch the contexts and then when execution starts I restore the original thread context. If the debugger stops at a breakpoint everything is fine and the dummy threads stacks are correct. If I step in/out/over or hit the pause execution even though the context have been switched it displays incorrectly.
One method I have tried is to use a worker thread within my VSPackage is to freeze/suspend all but one thread, try and step the code for that thread, and then thaw/resume the other threads. However, I have found this method to be unreliable. What I want to do is force the VS2022 threads window to update but AI suggests it cannot be done.
My question is: has anyone else tried something similar and have they had any success?
Providing code would be far to complex but the basic pseudo code is given below. It is written in C#
//Contains fiber information plus the dummy thread ID
// for each fiber and fiber and thread contexts
FiberArray[];
//Debugger event
public int OnModeChange(DBGMODE mode)
{
if (DBGMODE.DBGMODE_Break == mode)
{
SwitchFiberContexts();
}
else if (DBGMODE.DBGMODE_Run == mode)
{
for (int f = 0; f < FiberArray.Count, ++f)
{
RestoreWindowsThreadContext(FiberArray[f]);
}
}
}
private void SwitchFiberContexts()
{
//Read register contexts for fibers from process being debugged
//...
//...
for (int f = 0; f < FiberArray.Count, ++f)
{
StoreWindowsThreadContext(FiberArray[f]);
//Replace dummy thread context with fiber context
ReplaceWindowsThreadContext(FiberArray[f]);
}
}