Skip to content

Commit e551a96

Browse files
committed
Qt: Don't disable debugger code view while running
Gets rid of the flicker.
1 parent da18a95 commit e551a96

File tree

4 files changed

+78
-35
lines changed

4 files changed

+78
-35
lines changed

src/duckstation-qt/debuggercodeview.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ void DebuggerCodeView::setPC(VirtualMemoryAddress pc)
9494
}
9595
}
9696

97+
void DebuggerCodeView::invalidatePC()
98+
{
99+
// something that will always pass the test above
100+
m_last_pc = 0xFFFFFFFFu;
101+
viewport()->update();
102+
}
103+
97104
void DebuggerCodeView::ensureAddressVisible(VirtualMemoryAddress address)
98105
{
99106
const bool region_changed = updateRegion(address);

src/duckstation-qt/debuggercodeview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class DebuggerCodeView : public QAbstractScrollArea
3636
// Code model functionality integrated
3737
void resetCodeView(VirtualMemoryAddress start_address);
3838
void setPC(VirtualMemoryAddress pc);
39+
void invalidatePC();
3940
void ensureAddressVisible(VirtualMemoryAddress address);
4041
void updateBreakpointList(const CPU::BreakpointList& bps);
4142
void clearBreakpoints();

src/duckstation-qt/debuggerwindow.cpp

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "debuggerwindow.h"
55
#include "debuggermodels.h"
6+
#include "mainwindow.h"
67
#include "qthost.h"
78
#include "qtutils.h"
89

@@ -60,6 +61,7 @@ void DebuggerWindow::onSystemPaused()
6061
void DebuggerWindow::onSystemResumed()
6162
{
6263
setUIEnabled(false, true);
64+
m_ui.codeView->invalidatePC();
6365

6466
{
6567
QSignalBlocker sb(m_ui.actionPause);
@@ -149,18 +151,30 @@ void DebuggerWindow::onDumpAddressTriggered()
149151

150152
void DebuggerWindow::onTraceTriggered()
151153
{
152-
if (!CPU::IsTraceEnabled())
153-
{
154-
QMessageBox::critical(
155-
this, windowTitle(),
156-
tr("Trace logging started to cpu_log.txt.\nThis file can be several gigabytes, so be aware of SSD wear."));
157-
CPU::StartTrace();
158-
}
159-
else
160-
{
161-
CPU::StopTrace();
162-
QMessageBox::critical(this, windowTitle(), tr("Trace logging to cpu_log.txt stopped."));
163-
}
154+
Host::RunOnCPUThread([]() {
155+
const bool trace_enabled = !CPU::IsTraceEnabled();
156+
if (trace_enabled)
157+
CPU::StartTrace();
158+
else
159+
CPU::StopTrace();
160+
161+
Host::RunOnUIThread([trace_enabled]() {
162+
DebuggerWindow* const win = g_main_window->getDebuggerWindow();
163+
if (!win)
164+
return;
165+
166+
if (trace_enabled)
167+
{
168+
QMessageBox::critical(
169+
win, win->windowTitle(),
170+
tr("Trace logging started to cpu_log.txt.\nThis file can be several gigabytes, so be aware of SSD wear."));
171+
}
172+
else
173+
{
174+
QMessageBox::critical(win, win->windowTitle(), tr("Trace logging to cpu_log.txt stopped."));
175+
}
176+
});
177+
});
164178
}
165179

166180
void DebuggerWindow::onAddBreakpointTriggered()
@@ -532,30 +546,30 @@ void DebuggerWindow::createModels()
532546

533547
void DebuggerWindow::setUIEnabled(bool enabled, bool allow_pause)
534548
{
535-
const bool memory_view_enabled = (enabled || allow_pause);
549+
const bool read_only_views = (enabled || allow_pause);
536550

537551
m_ui.actionPause->setEnabled(allow_pause);
538552

539553
// Disable all UI elements that depend on execution state
540-
m_ui.codeView->setEnabled(enabled);
541-
m_ui.registerView->setEnabled(enabled);
542-
m_ui.stackView->setEnabled(enabled);
543-
m_ui.memoryView->setEnabled(memory_view_enabled);
554+
m_ui.codeView->setEnabled(read_only_views);
555+
m_ui.registerView->setEnabled(read_only_views);
556+
m_ui.stackView->setEnabled(read_only_views);
557+
m_ui.memoryView->setEnabled(read_only_views);
544558
m_ui.actionRunToCursor->setEnabled(enabled);
545559
m_ui.actionAddBreakpoint->setEnabled(enabled);
546560
m_ui.actionToggleBreakpoint->setEnabled(enabled);
547561
m_ui.actionClearBreakpoints->setEnabled(enabled);
548-
m_ui.actionDumpAddress->setEnabled(memory_view_enabled);
562+
m_ui.actionDumpAddress->setEnabled(read_only_views);
549563
m_ui.actionStepInto->setEnabled(enabled);
550564
m_ui.actionStepOver->setEnabled(enabled);
551565
m_ui.actionStepOut->setEnabled(enabled);
552566
m_ui.actionGoToAddress->setEnabled(enabled);
553567
m_ui.actionGoToPC->setEnabled(enabled);
554568
m_ui.actionTrace->setEnabled(enabled);
555-
m_ui.memoryRegionRAM->setEnabled(memory_view_enabled);
556-
m_ui.memoryRegionEXP1->setEnabled(memory_view_enabled);
557-
m_ui.memoryRegionScratchpad->setEnabled(memory_view_enabled);
558-
m_ui.memoryRegionBIOS->setEnabled(memory_view_enabled);
569+
m_ui.memoryRegionRAM->setEnabled(read_only_views);
570+
m_ui.memoryRegionEXP1->setEnabled(read_only_views);
571+
m_ui.memoryRegionScratchpad->setEnabled(read_only_views);
572+
m_ui.memoryRegionBIOS->setEnabled(read_only_views);
559573

560574
// Partial/timer refreshes only active when not paused.
561575
const bool timer_active = (!enabled && allow_pause);
@@ -617,7 +631,7 @@ void DebuggerWindow::setMemoryViewRegion(Bus::MemoryRegion region)
617631

618632
void DebuggerWindow::toggleBreakpoint(VirtualMemoryAddress address)
619633
{
620-
Host::RunOnCPUThread([this, address]() {
634+
Host::RunOnCPUThread([address]() {
621635
const bool new_bp_state = !CPU::HasBreakpointAtAddress(CPU::BreakpointType::Execute, address);
622636
if (new_bp_state)
623637
{
@@ -630,8 +644,12 @@ void DebuggerWindow::toggleBreakpoint(VirtualMemoryAddress address)
630644
return;
631645
}
632646

633-
Host::RunOnUIThread([this, bps = CPU::CopyBreakpointList()]() {
634-
refreshBreakpointList(bps);
647+
Host::RunOnUIThread([bps = CPU::CopyBreakpointList()]() {
648+
DebuggerWindow* const win = g_main_window->getDebuggerWindow();
649+
if (!win)
650+
return;
651+
652+
win->refreshBreakpointList(bps);
635653
});
636654
});
637655
}
@@ -672,8 +690,15 @@ bool DebuggerWindow::scrollToMemoryAddress(VirtualMemoryAddress address)
672690

673691
void DebuggerWindow::refreshBreakpointList()
674692
{
675-
Host::RunOnCPUThread(
676-
[this]() { Host::RunOnUIThread([this, bps = CPU::CopyBreakpointList()]() { refreshBreakpointList(bps); }); });
693+
Host::RunOnCPUThread([]() {
694+
Host::RunOnUIThread([bps = CPU::CopyBreakpointList()]() {
695+
DebuggerWindow* const win = g_main_window->getDebuggerWindow();
696+
if (!win)
697+
return;
698+
699+
win->refreshBreakpointList(bps);
700+
});
701+
});
677702
}
678703

679704
void DebuggerWindow::refreshBreakpointList(const CPU::BreakpointList& bps)
@@ -701,33 +726,42 @@ void DebuggerWindow::refreshBreakpointList(const CPU::BreakpointList& bps)
701726

702727
void DebuggerWindow::addBreakpoint(CPU::BreakpointType type, u32 address)
703728
{
704-
Host::RunOnCPUThread([this, address, type]() {
729+
Host::RunOnCPUThread([address, type]() {
705730
const bool result = CPU::AddBreakpoint(type, address);
706-
Host::RunOnUIThread([this, result, bps = CPU::CopyBreakpointList()]() {
731+
Host::RunOnUIThread([bps = CPU::CopyBreakpointList(), result]() {
732+
DebuggerWindow* const win = g_main_window->getDebuggerWindow();
733+
if (!win)
734+
return;
735+
707736
if (!result)
708737
{
709-
QMessageBox::critical(this, windowTitle(),
738+
QMessageBox::critical(win, win->windowTitle(),
710739
tr("Failed to add breakpoint. A breakpoint may already exist at this address."));
711740
return;
712741
}
713742

714-
refreshBreakpointList(bps);
743+
win->refreshBreakpointList(bps);
715744
});
716745
});
717746
}
718747

719748
void DebuggerWindow::removeBreakpoint(CPU::BreakpointType type, u32 address)
720749
{
721-
Host::RunOnCPUThread([this, address, type]() {
750+
Host::RunOnCPUThread([address, type]() {
722751
const bool result = CPU::RemoveBreakpoint(type, address);
723-
Host::RunOnUIThread([this, result, bps = CPU::CopyBreakpointList()]() {
752+
Host::RunOnUIThread([bps = CPU::CopyBreakpointList(), result]() {
753+
DebuggerWindow* const win = g_main_window->getDebuggerWindow();
754+
if (!win)
755+
return;
756+
724757
if (!result)
725758
{
726-
QMessageBox::critical(this, windowTitle(), tr("Failed to remove breakpoint. This breakpoint may not exist."));
759+
QMessageBox::critical(win, win->windowTitle(),
760+
tr("Failed to remove breakpoint. This breakpoint may not exist."));
727761
return;
728762
}
729763

730-
refreshBreakpointList(bps);
764+
win->refreshBreakpointList(bps);
731765
});
732766
});
733767
}

src/duckstation-qt/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class MainWindow final : public QMainWindow
105105
ALWAYS_INLINE QLabel* getStatusFPSWidget() const { return m_status_fps_widget; }
106106
ALWAYS_INLINE QLabel* getStatusVPSWidget() const { return m_status_vps_widget; }
107107
ALWAYS_INLINE AutoUpdaterWindow* getAutoUpdaterDialog() const { return m_auto_updater_dialog; }
108+
ALWAYS_INLINE DebuggerWindow* getDebuggerWindow() const { return m_debugger_window; }
108109

109110
/// Opens the editor for a specific input profile.
110111
void openInputProfileEditor(const std::string_view name);

0 commit comments

Comments
 (0)