1
0
Fork 0

Quietly switch threads when following in call stack view

This commit is contained in:
Duncan Ogilvie 2026-07-16 13:18:45 +02:00
parent 9db0f46476
commit 60d8f9632d
3 changed files with 31 additions and 13 deletions

View File

@ -6,6 +6,8 @@ Switch the internal current thread to another thread (resulting in different cal
`[arg1]` ThreadId of the thread to switch to (see the Threads tab). When not specified, the main thread is used.
`[arg2]` Options. If it contains "silent" or "quiet", the "Thread switched!" message is suppressed and the GUI update completes before the command returns. This allows callers such as the Call Stack view to perform follow-up navigation without it being overridden by a pending thread-switch update.
## result
This command does not set any result variables.

View File

@ -52,18 +52,30 @@ bool cbDebugSwitchthread(int argc, char* argv[])
if(argc > 1)
if(!valfromstring(argv[1], &threadid, false))
return false;
auto options = argc > 2 ? argv[2] : "";
bool quiet = !!strstr(options, "silent") || !!strstr(options, "quiet");
if(!ThreadIsValid((DWORD)threadid)) //check if the thread is valid
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Invalid thread %s\n"), formatpidtid((DWORD)threadid).c_str());
return false;
}
//switch thread
if(GetDebugData()->dwThreadId != threadid)
auto newThread = ThreadGetHandle((DWORD)threadid);
if(hActiveThread != newThread)
{
hActiveThread = ThreadGetHandle((DWORD)threadid);
hActiveThread = newThread;
HistoryClear();
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
dputs(QT_TRANSLATE_NOOP("DBG", "Thread switched!"));
if(!quiet)
{
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
dputs(QT_TRANSLATE_NOOP("DBG", "Thread switched!"));
}
else
{
// Update synchronously so a caller can perform follow-up navigation
// without a pending CIP update overriding it.
DebugUpdateGui(GetContextDataEx(hActiveThread, UE_CIP), true);
}
}
return true;
}

View File

@ -315,15 +315,21 @@ void CallStackView::contextMenuSlot(const QPoint pos)
void CallStackView::followAddressSlot()
{
QString addrText = getCellContent(getInitialSelection(), ColAddress);
DbgCmdExecDirect(QString("sdump " + addrText));
switchThread();
if(!addrText.isEmpty() && isSelectionValid())
{
switchThread();
DbgCmdExecDirect(QString("sdump " + addrText));
}
}
void CallStackView::followToSlot()
{
QString addrText = getCellContent(getInitialSelection(), ColTo);
DbgCmdExecDirect(QString("disasm " + addrText));
switchThread();
if(!addrText.isEmpty() && isSelectionValid())
{
switchThread();
DbgCmdExecDirect(QString("disasm " + addrText));
}
}
void CallStackView::followFromSlot()
@ -332,8 +338,8 @@ void CallStackView::followFromSlot()
// Double click signal is recieved by this as well, so we must check again.
if(!addrText.isEmpty() && isSelectionValid())
{
DbgCmdExecDirect(QString("disasm " + addrText));
switchThread();
DbgCmdExecDirect(QString("disasm " + addrText));
}
}
@ -468,11 +474,9 @@ duint CallStackView::getSelectionVa()
return 0;
}
// Switch to the new thread if it is not the current thread
// Switch to the selected thread if needed
void CallStackView::switchThread()
{
DWORD currentThread = DbgGetThreadId();
DWORD newThread = getCellUserdata(getInitialSelection(), ColThread);
if(currentThread != newThread)
DbgCmdExecDirect(QString("switchthread %1").arg(ToHexString(newThread)).toUtf8().constData());
DbgCmdExecDirect(QString("switchthread %1, quiet").arg(ToHexString(newThread)).toUtf8().constData());
}