diff --git a/src/duckstation-qt/debuggercodeview.cpp b/src/duckstation-qt/debuggercodeview.cpp index 84d857bec..6b9bfeb69 100644 --- a/src/duckstation-qt/debuggercodeview.cpp +++ b/src/duckstation-qt/debuggercodeview.cpp @@ -103,22 +103,17 @@ void DebuggerCodeView::ensureAddressVisible(VirtualMemoryAddress address) } } -void DebuggerCodeView::setBreakpointState(VirtualMemoryAddress address, bool enabled) +void DebuggerCodeView::updateBreakpointList(const CPU::BreakpointList& bps) { - if (enabled) - { - if (std::find(m_breakpoints.begin(), m_breakpoints.end(), address) != m_breakpoints.end()) - return; + static constexpr auto pred = [](const CPU::Breakpoint& bp) { return (bp.type == CPU::BreakpointType::Execute); }; - m_breakpoints.push_back(address); - } - else - { - auto it = std::find(m_breakpoints.begin(), m_breakpoints.end(), address); - if (it == m_breakpoints.end()) - return; + m_breakpoints.clear(); + m_breakpoints.reserve(std::count_if(bps.begin(), bps.end(), pred)); - m_breakpoints.erase(it); + for (const CPU::Breakpoint& bp : bps) + { + if (pred(bp)) + m_breakpoints.push_back(bp.address); } viewport()->update(); diff --git a/src/duckstation-qt/debuggercodeview.h b/src/duckstation-qt/debuggercodeview.h index c2d0a2957..3d108ec27 100644 --- a/src/duckstation-qt/debuggercodeview.h +++ b/src/duckstation-qt/debuggercodeview.h @@ -4,14 +4,14 @@ #pragma once #include "core/bus.h" -#include "core/cpu_types.h" +#include "core/cpu_core.h" #include "core/types.h" #include #include -#include -#include #include +#include +#include #include #include @@ -37,7 +37,7 @@ public: void resetCodeView(VirtualMemoryAddress start_address); void setPC(VirtualMemoryAddress pc); void ensureAddressVisible(VirtualMemoryAddress address); - void setBreakpointState(VirtualMemoryAddress address, bool enabled); + void updateBreakpointList(const CPU::BreakpointList& bps); void clearBreakpoints(); VirtualMemoryAddress getPC() const { return m_last_pc; } bool hasBreakpointAtAddress(VirtualMemoryAddress address) const; @@ -83,36 +83,36 @@ private: // Address/row conversion methods int getRowForAddress(VirtualMemoryAddress address) const; VirtualMemoryAddress getAddressForRow(int row) const; - + // Memory region management bool updateRegion(VirtualMemoryAddress address); - + // Drawing methods void updateScrollBars(); void updateVisibleRange(); void calculateBranchArrows(); void drawBranchArrows(QPainter& painter, const QRect& visible_rect); void drawInstruction(QPainter& painter, VirtualMemoryAddress address, int y, bool is_selected, bool is_pc); - + int getVisibleRowCount() const; VirtualMemoryAddress getFirstVisibleAddress() const; VirtualMemoryAddress getLastVisibleAddress() const; int m_row_height = 1; int m_char_width = 0; - + VirtualMemoryAddress m_selected_address = 0; bool m_has_selection = false; - + std::vector m_branch_arrows; - + QPixmap m_pc_pixmap; QPixmap m_breakpoint_pixmap; - + // Scroll state VirtualMemoryAddress m_top_address = 0; int m_visible_rows = 0; - + // Code region state (from DebuggerCodeModel) Bus::MemoryRegion m_current_code_region = Bus::MemoryRegion::Count; CPU::Segment m_current_segment = CPU::Segment::KUSEG; diff --git a/src/duckstation-qt/debuggerwindow.cpp b/src/duckstation-qt/debuggerwindow.cpp index aeddd71c3..bc11a5feb 100644 --- a/src/duckstation-qt/debuggerwindow.cpp +++ b/src/duckstation-qt/debuggerwindow.cpp @@ -630,8 +630,7 @@ void DebuggerWindow::toggleBreakpoint(VirtualMemoryAddress address) return; } - Host::RunOnUIThread([this, address, new_bp_state, bps = CPU::CopyBreakpointList()]() { - m_ui.codeView->setBreakpointState(address, new_bp_state); + Host::RunOnUIThread([this, bps = CPU::CopyBreakpointList()]() { refreshBreakpointList(bps); }); }); @@ -696,13 +695,15 @@ void DebuggerWindow::refreshBreakpointList(const CPU::BreakpointList& bps) item->setData(2, Qt::UserRole, QVariant(static_cast(bp.type))); m_ui.breakpointsWidget->addTopLevelItem(item); } + + m_ui.codeView->updateBreakpointList(bps); } void DebuggerWindow::addBreakpoint(CPU::BreakpointType type, u32 address) { Host::RunOnCPUThread([this, address, type]() { const bool result = CPU::AddBreakpoint(type, address); - Host::RunOnUIThread([this, address, type, result, bps = CPU::CopyBreakpointList()]() { + Host::RunOnUIThread([this, result, bps = CPU::CopyBreakpointList()]() { if (!result) { QMessageBox::critical(this, windowTitle(), @@ -710,9 +711,6 @@ void DebuggerWindow::addBreakpoint(CPU::BreakpointType type, u32 address) return; } - if (type == CPU::BreakpointType::Execute) - m_ui.codeView->setBreakpointState(address, true); - refreshBreakpointList(bps); }); }); @@ -722,16 +720,13 @@ void DebuggerWindow::removeBreakpoint(CPU::BreakpointType type, u32 address) { Host::RunOnCPUThread([this, address, type]() { const bool result = CPU::RemoveBreakpoint(type, address); - Host::RunOnUIThread([this, address, type, result, bps = CPU::CopyBreakpointList()]() { + Host::RunOnUIThread([this, result, bps = CPU::CopyBreakpointList()]() { if (!result) { QMessageBox::critical(this, windowTitle(), tr("Failed to remove breakpoint. This breakpoint may not exist.")); return; } - if (type == CPU::BreakpointType::Execute) - m_ui.codeView->setBreakpointState(address, false); - refreshBreakpointList(bps); }); });