From ba45daff354a7f328bbfe961d54458244f547433 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 23 Mar 2021 20:39:39 +0100 Subject: [PATCH] Qt: some cleanup in debugger --- rpcs3/Emu/Cell/PPUThread.cpp | 4 +- rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp | 41 ++++++++------- rpcs3/rpcs3qt/auto_pause_settings_dialog.h | 2 +- rpcs3/rpcs3qt/breakpoint_handler.cpp | 8 ++- rpcs3/rpcs3qt/breakpoint_handler.h | 1 - rpcs3/rpcs3qt/breakpoint_list.cpp | 55 ++++++++------------ rpcs3/rpcs3qt/call_stack_list.cpp | 8 +-- rpcs3/rpcs3qt/call_stack_list.h | 1 - rpcs3/rpcs3qt/cg_disasm_window.cpp | 7 +-- rpcs3/rpcs3qt/cg_disasm_window.h | 4 +- rpcs3/rpcs3qt/debugger_list.cpp | 43 ++++++++------- rpcs3/rpcs3qt/debugger_list.h | 2 +- rpcs3/rpcs3qt/instruction_editor_dialog.h | 2 - 13 files changed, 82 insertions(+), 96 deletions(-) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 34f8dc4e5a..f81cb56266 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -479,7 +479,7 @@ static bool ppu_break(ppu_thread& ppu, ppu_opcode_t) } // Set or remove breakpoint -extern void ppu_breakpoint(u32 addr, bool isAdding) +extern void ppu_breakpoint(u32 addr, bool is_adding) { if (g_cfg.core.ppu_decoder == ppu_decoder_type::llvm) { @@ -488,7 +488,7 @@ extern void ppu_breakpoint(u32 addr, bool isAdding) const u64 _break = reinterpret_cast(&ppu_break); - if (isAdding) + if (is_adding) { // Set breakpoint ppu_ref(addr) = _break; diff --git a/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp b/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp index bafa5f524a..245972274d 100644 --- a/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp @@ -19,14 +19,14 @@ auto_pause_settings_dialog::auto_pause_settings_dialog(QWidget *parent) : QDialo { QLabel *description = new QLabel(tr("To use auto pause: enter the ID(s) of a function or a system call.\nRestart of the game is required to apply. You can enable/disable this in the settings."), this); - pauseList = new QTableWidget(this); - pauseList->setColumnCount(2); - pauseList->setHorizontalHeaderLabels(QStringList() << tr("Call ID") << tr("Type")); - //pauseList->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - pauseList->setSelectionBehavior(QAbstractItemView::SelectRows); - pauseList->setContextMenuPolicy(Qt::CustomContextMenu); - pauseList->setItemDelegate(new table_item_delegate(this)); - pauseList->setShowGrid(false); + m_pause_list = new QTableWidget(this); + m_pause_list->setColumnCount(2); + m_pause_list->setHorizontalHeaderLabels(QStringList() << tr("Call ID") << tr("Type")); + //m_pause_list->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + m_pause_list->setSelectionBehavior(QAbstractItemView::SelectRows); + m_pause_list->setContextMenuPolicy(Qt::CustomContextMenu); + m_pause_list->setItemDelegate(new table_item_delegate(this)); + m_pause_list->setShowGrid(false); QPushButton *clearButton = new QPushButton(tr("Clear"), this); QPushButton *reloadButton = new QPushButton(tr("Reload"), this); @@ -43,7 +43,7 @@ auto_pause_settings_dialog::auto_pause_settings_dialog(QWidget *parent) : QDialo QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addWidget(description); - mainLayout->addWidget(pauseList); + mainLayout->addWidget(m_pause_list); mainLayout->addLayout(buttonsLayout); setLayout(mainLayout); @@ -52,7 +52,7 @@ auto_pause_settings_dialog::auto_pause_settings_dialog(QWidget *parent) : QDialo setObjectName("auto_pause_manager"); // Events - connect(pauseList, &QTableWidget::customContextMenuRequested, this, &auto_pause_settings_dialog::ShowContextMenu); + connect(m_pause_list, &QTableWidget::customContextMenuRequested, this, &auto_pause_settings_dialog::ShowContextMenu); connect(clearButton, &QAbstractButton::clicked, [this](){ m_entries.clear(); UpdateList(); }); connect(reloadButton, &QAbstractButton::clicked, [this](){ LoadEntries(); UpdateList(); }); connect(saveButton, &QAbstractButton::clicked, [this]() @@ -118,8 +118,8 @@ void auto_pause_settings_dialog::SaveEntries(void) void auto_pause_settings_dialog::UpdateList(void) { const int entries_size = static_cast(m_entries.size()); - pauseList->clearContents(); - pauseList->setRowCount(entries_size); + m_pause_list->clearContents(); + m_pause_list->setRowCount(entries_size); for (int i = 0; i < entries_size; ++i) { QTableWidgetItem* callItem = new QTableWidgetItem; @@ -144,14 +144,14 @@ void auto_pause_settings_dialog::UpdateList(void) typeItem->setData(Qt::DisplayRole, tr("Function Call")); } - pauseList->setItem(i, 0, callItem); - pauseList->setItem(i, 1, typeItem); + m_pause_list->setItem(i, 0, callItem); + m_pause_list->setItem(i, 1, typeItem); } } void auto_pause_settings_dialog::ShowContextMenu(const QPoint &pos) { - const int row = pauseList->indexAt(pos).row(); + const int row = m_pause_list->indexAt(pos).row(); QMenu myMenu; @@ -175,22 +175,23 @@ void auto_pause_settings_dialog::ShowContextMenu(const QPoint &pos) UpdateList(); }; - connect(add, &QAction::triggered, [=, this]() { + connect(add, &QAction::triggered, this, [=, this]() + { m_entries.emplace_back(0xFFFFFFFF); UpdateList(); int idx = static_cast(m_entries.size()) - 1; - pauseList->selectRow(idx); + m_pause_list->selectRow(idx); OnEntryConfig(idx, true); }); connect(remove, &QAction::triggered, this, &auto_pause_settings_dialog::OnRemove); - connect(config, &QAction::triggered, [=, this]() {OnEntryConfig(row, false); }); + connect(config, &QAction::triggered, this, [=, this]() {OnEntryConfig(row, false); }); - myMenu.exec(pauseList->viewport()->mapToGlobal(pos)); + myMenu.exec(m_pause_list->viewport()->mapToGlobal(pos)); } void auto_pause_settings_dialog::OnRemove() { - QModelIndexList selection = pauseList->selectionModel()->selectedRows(); + QModelIndexList selection = m_pause_list->selectionModel()->selectedRows(); std::sort(selection.begin(), selection.end()); for (int i = selection.count() - 1; i >= 0; i--) { diff --git a/rpcs3/rpcs3qt/auto_pause_settings_dialog.h b/rpcs3/rpcs3qt/auto_pause_settings_dialog.h index 766e6b61f7..91a600f907 100644 --- a/rpcs3/rpcs3qt/auto_pause_settings_dialog.h +++ b/rpcs3/rpcs3qt/auto_pause_settings_dialog.h @@ -20,10 +20,10 @@ class auto_pause_settings_dialog : public QDialog }; std::vector m_entries; + QTableWidget *m_pause_list; public: explicit auto_pause_settings_dialog(QWidget* parent); - QTableWidget *pauseList; void UpdateList(void); void LoadEntries(void); void SaveEntries(void); diff --git a/rpcs3/rpcs3qt/breakpoint_handler.cpp b/rpcs3/rpcs3qt/breakpoint_handler.cpp index ad553891ae..51333b545a 100644 --- a/rpcs3/rpcs3qt/breakpoint_handler.cpp +++ b/rpcs3/rpcs3qt/breakpoint_handler.cpp @@ -1,20 +1,18 @@ #include "breakpoint_handler.h" -extern void ppu_breakpoint(u32 loc, bool isAdding); +extern void ppu_breakpoint(u32 loc, bool is_adding); -breakpoint_handler::breakpoint_handler() :m_breakpoints() +breakpoint_handler::breakpoint_handler() { - } breakpoint_handler::~breakpoint_handler() { - } bool breakpoint_handler::HasBreakpoint(u32 loc) const { - return m_breakpoints.find(loc) != m_breakpoints.end(); + return m_breakpoints.contains(loc); } bool breakpoint_handler::AddBreakpoint(u32 loc) diff --git a/rpcs3/rpcs3qt/breakpoint_handler.h b/rpcs3/rpcs3qt/breakpoint_handler.h index e3e508f333..948d506125 100644 --- a/rpcs3/rpcs3qt/breakpoint_handler.h +++ b/rpcs3/rpcs3qt/breakpoint_handler.h @@ -31,7 +31,6 @@ public: */ bool AddBreakpoint(u32 loc); - /** * Returns true if removed breakpoint at loc successfully. */ diff --git a/rpcs3/rpcs3qt/breakpoint_list.cpp b/rpcs3/rpcs3qt/breakpoint_list.cpp index 4a8351c664..e9999dceab 100644 --- a/rpcs3/rpcs3qt/breakpoint_list.cpp +++ b/rpcs3/rpcs3qt/breakpoint_list.cpp @@ -64,17 +64,14 @@ void breakpoint_list::AddBreakpoint(u32 pc) m_disasm->disasm(pc); - QString breakpointItemText = qstr(m_disasm->last_opcode); + QString text = qstr(m_disasm->last_opcode); + text.remove(10, 13); - breakpointItemText.remove(10, 13); - - QListWidgetItem* breakpointItem = new QListWidgetItem(breakpointItemText); - breakpointItem->setForeground(m_text_color_bp); - breakpointItem->setBackground(m_color_bp); - QVariant pcVariant; - pcVariant.setValue(pc); - breakpointItem->setData(Qt::UserRole, pcVariant); - addItem(breakpointItem); + QListWidgetItem* breakpoint_item = new QListWidgetItem(text); + breakpoint_item->setForeground(m_text_color_bp); + breakpoint_item->setBackground(m_color_bp); + breakpoint_item->setData(Qt::UserRole, pc); + addItem(breakpoint_item); Q_EMIT RequestShowAddress(pc); } @@ -102,7 +99,7 @@ void breakpoint_list::HandleBreakpointRequest(u32 loc) void breakpoint_list::OnBreakpointListDoubleClicked() { - u32 address = currentItem()->data(Qt::UserRole).value(); + const u32 address = currentItem()->data(Qt::UserRole).value(); Q_EMIT RequestShowAddress(address); } @@ -117,36 +114,28 @@ void breakpoint_list::OnBreakpointListRightClicked(const QPoint &pos) if (selectedItems().count() == 1) { - menu->addAction("Rename"); + QAction* rename_action = menu->addAction(tr("&Rename")); + connect(rename_action, &QAction::triggered, this, [this]() + { + QListWidgetItem* current_item = selectedItems().first(); + current_item->setFlags(current_item->flags() | Qt::ItemIsEditable); + editItem(current_item); + }); menu->addSeparator(); } - QAction* m_breakpoint_list_delete = new QAction("Delete", this); - m_breakpoint_list_delete->setShortcut(Qt::Key_Delete); - m_breakpoint_list_delete->setShortcutContext(Qt::WidgetShortcut); - addAction(m_breakpoint_list_delete); - connect(m_breakpoint_list_delete, &QAction::triggered, this, &breakpoint_list::OnBreakpointListDelete); + QAction* delete_action = new QAction(tr("&Delete"), this); + delete_action->setShortcut(Qt::Key_Delete); + delete_action->setShortcutContext(Qt::WidgetShortcut); + connect(delete_action, &QAction::triggered, this, &breakpoint_list::OnBreakpointListDelete); + menu->addAction(delete_action); - menu->addAction(m_breakpoint_list_delete); - - QAction* selectedItem = menu->exec(viewport()->mapToGlobal(pos)); - if (selectedItem) - { - if (selectedItem->text() == "Rename") - { - QListWidgetItem* currentItem = selectedItems().at(0); - - currentItem->setFlags(currentItem->flags() | Qt::ItemIsEditable); - editItem(currentItem); - } - } + menu->exec(viewport()->mapToGlobal(pos)); } void breakpoint_list::OnBreakpointListDelete() { - int selectedCount = selectedItems().count(); - - for (int i = selectedCount - 1; i >= 0; i--) + for (int i = selectedItems().count() - 1; i >= 0; i--) { RemoveBreakpoint(item(i)->data(Qt::UserRole).value()); } diff --git a/rpcs3/rpcs3qt/call_stack_list.cpp b/rpcs3/rpcs3qt/call_stack_list.cpp index ed18a63101..43df4bd4d7 100644 --- a/rpcs3/rpcs3qt/call_stack_list.cpp +++ b/rpcs3/rpcs3qt/call_stack_list.cpp @@ -20,10 +20,10 @@ void call_stack_list::HandleUpdate(std::vector> call_stack) for (const auto& addr : call_stack) { - const QString call_stack_item_text = qstr(fmt::format("0x%08llx (sp=0x%08llx)", addr.first, addr.second)); - QListWidgetItem* callStackItem = new QListWidgetItem(call_stack_item_text); - callStackItem->setData(Qt::UserRole, { addr.first }); - addItem(callStackItem); + const QString text = qstr(fmt::format("0x%08llx (sp=0x%08llx)", addr.first, addr.second)); + QListWidgetItem* call_stack_item = new QListWidgetItem(text); + call_stack_item->setData(Qt::UserRole, { addr.first }); + addItem(call_stack_item); } } diff --git a/rpcs3/rpcs3qt/call_stack_list.h b/rpcs3/rpcs3qt/call_stack_list.h index deab5b3027..61bc6df1a6 100644 --- a/rpcs3/rpcs3qt/call_stack_list.h +++ b/rpcs3/rpcs3qt/call_stack_list.h @@ -3,7 +3,6 @@ #include "util/types.hpp" #include -#include #include class cpu_thread; diff --git a/rpcs3/rpcs3qt/cg_disasm_window.cpp b/rpcs3/rpcs3qt/cg_disasm_window.cpp index deafd86140..18a568a6c4 100644 --- a/rpcs3/rpcs3qt/cg_disasm_window.cpp +++ b/rpcs3/rpcs3qt/cg_disasm_window.cpp @@ -16,7 +16,8 @@ LOG_CHANNEL(gui_log, "GUI"); constexpr auto qstr = QString::fromStdString; inline std::string sstr(const QString& _in) { return _in.toStdString(); } -cg_disasm_window::cg_disasm_window(std::shared_ptr xSettings): xgui_settings(xSettings) +cg_disasm_window::cg_disasm_window(std::shared_ptr xSettings) + : m_gui_settings(xSettings) { setWindowTitle(tr("Cg Disasm")); setObjectName("cg_disasm"); @@ -26,7 +27,7 @@ cg_disasm_window::cg_disasm_window(std::shared_ptr xSettings): xgu setMinimumSize(QSize(200, 150)); // seems fine on win 10 resize(QSize(620, 395)); - m_path_last = xgui_settings->GetValue(gui::fd_cg_disasm).toString(); + m_path_last = m_gui_settings->GetValue(gui::fd_cg_disasm).toString(); m_disasm_text = new QTextEdit(this); m_disasm_text->setReadOnly(true); @@ -114,7 +115,7 @@ void cg_disasm_window::ShowDisasm() disasm.BuildShaderBody(); m_disasm_text->setText(qstr(disasm.GetArbShader())); m_glsl_text->setText(qstr(disasm.GetGlslShader())); - xgui_settings->SetValue(gui::fd_cg_disasm, m_path_last); + m_gui_settings->SetValue(gui::fd_cg_disasm, m_path_last); } else if (!m_path_last.isEmpty()) { diff --git a/rpcs3/rpcs3qt/cg_disasm_window.h b/rpcs3/rpcs3qt/cg_disasm_window.h index 03203f8bd2..3b336766c9 100644 --- a/rpcs3/rpcs3qt/cg_disasm_window.h +++ b/rpcs3/rpcs3qt/cg_disasm_window.h @@ -26,9 +26,7 @@ private: QTextEdit* m_disasm_text; QTextEdit* m_glsl_text; - QAction *openCgBinaryProgram; - - std::shared_ptr xgui_settings; + std::shared_ptr m_gui_settings; AsmHighlighter* sh_asm; GlslHighlighter* sh_glsl; diff --git a/rpcs3/rpcs3qt/debugger_list.cpp b/rpcs3/rpcs3qt/debugger_list.cpp index f8397651c0..e5c36adc5d 100644 --- a/rpcs3/rpcs3qt/debugger_list.cpp +++ b/rpcs3/rpcs3qt/debugger_list.cpp @@ -21,7 +21,7 @@ constexpr auto qstr = QString::fromStdString; debugger_list::debugger_list(QWidget* parent, std::shared_ptr settings, breakpoint_handler* handler) : QListWidget(parent) - , xgui_settings(settings) + , m_gui_settings(settings) , m_breakpoint_handler(handler) { setWindowTitle(tr("ASM")); @@ -50,7 +50,7 @@ void debugger_list::ShowAddress(u32 addr, bool force) return m_cpu && m_cpu->id_type() == 1 && m_breakpoint_handler->HasBreakpoint(pc); }; - bool center_pc = xgui_settings->GetValue(gui::d_centerPC).toBool(); + bool center_pc = m_gui_settings->GetValue(gui::d_centerPC).toBool(); // How many spaces addr can move down without us needing to move the entire view const u32 addr_margin = (m_item_count / (center_pc ? 2 : 1) - 4); // 4 is just a buffer of 4 spaces at the bottom @@ -74,16 +74,17 @@ void debugger_list::ShowAddress(u32 addr, bool force) } } - const auto default_foreground = palette().color(foregroundRole()); - const auto default_background = palette().color(backgroundRole()); + const auto& default_foreground = palette().color(foregroundRole()); + const auto& default_background = palette().color(backgroundRole()); if (!m_cpu || !m_disasm || +m_cpu->state + cpu_flag::exit + cpu_flag::wait == +m_cpu->state) { for (uint i = 0; i < m_item_count; ++i) { - item(i)->setText(qstr(fmt::format(" [%08x] ?? ?? ?? ??:", 0))); - item(i)->setForeground(default_foreground); - item(i)->setBackground(default_background); + QListWidgetItem* list_item = item(i); + list_item->setText(qstr(fmt::format(" [%08x] ?? ?? ?? ??:", 0))); + list_item->setForeground(default_foreground); + list_item->setBackground(default_background); } } else @@ -93,27 +94,29 @@ void debugger_list::ShowAddress(u32 addr, bool force) m_pc &= address_limits; u32 pc = m_pc; - for (uint i = 0, count = 4; iis_paused() && pc == m_cpu->get_pc()) { - item(i)->setForeground(m_text_color_pc); - item(i)->setBackground(m_color_pc); + list_item->setForeground(m_text_color_pc); + list_item->setBackground(m_color_pc); } else if (IsBreakpoint(pc)) { - item(i)->setForeground(m_text_color_bp); - item(i)->setBackground(m_color_bp); + list_item->setForeground(m_text_color_bp); + list_item->setBackground(m_color_bp); } else { - item(i)->setForeground(default_foreground); - item(i)->setBackground(default_background); + list_item->setForeground(default_foreground); + list_item->setBackground(default_background); } if (m_cpu->id_type() == 1 && !vm::check_addr(pc, 0)) { - item(i)->setText((IsBreakpoint(pc) ? ">> " : " ") + qstr(fmt::format("[%08x] ?? ?? ?? ??:", pc))); + list_item->setText((IsBreakpoint(pc) ? ">> " : " ") + qstr(fmt::format("[%08x] ?? ?? ?? ??:", pc))); count = 4; continue; } @@ -121,7 +124,7 @@ void debugger_list::ShowAddress(u32 addr, bool force) if (m_cpu->id_type() == 1 && !vm::check_addr(pc, vm::page_executable)) { const u32 data = *vm::get_super_ptr>(pc); - item(i)->setText((IsBreakpoint(pc) ? ">> " : " ") + qstr(fmt::format("[%08x] %02x %02x %02x %02x:", pc, + list_item->setText((IsBreakpoint(pc) ? ">> " : " ") + qstr(fmt::format("[%08x] %02x %02x %02x %02x:", pc, static_cast(data >> 24), static_cast(data >> 16), static_cast(data >> 8), @@ -134,12 +137,12 @@ void debugger_list::ShowAddress(u32 addr, bool force) if (!count) { - item(i)->setText((IsBreakpoint(pc) ? ">> " : " ") + qstr(fmt::format("[%08x] ??? ?? ??", pc))); + list_item->setText((IsBreakpoint(pc) ? ">> " : " ") + qstr(fmt::format("[%08x] ??? ?? ??", pc))); count = 4; continue; } - item(i)->setText((IsBreakpoint(pc) ? ">> " : " ") + qstr(m_disasm->last_opcode)); + list_item->setText((IsBreakpoint(pc) ? ">> " : " ") + qstr(m_disasm->last_opcode)); } } @@ -250,7 +253,7 @@ void debugger_list::mouseDoubleClickEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton) { - int i = currentRow(); + const int i = currentRow(); if (i < 0) return; const u32 pc = m_pc + i * 4; @@ -264,7 +267,7 @@ void debugger_list::mouseDoubleClickEvent(QMouseEvent* event) void debugger_list::wheelEvent(QWheelEvent* event) { - const QPoint numSteps = event->angleDelta() / 8 / 15; // http://doc.qt.io/qt-5/qwheelevent.html#pixelDelta + const QPoint numSteps = event->angleDelta() / 8 / 15; // http://doc.qt.io/qt-5/qwheelevent.html#pixelDelta const int value = numSteps.y(); const auto direction = (event->modifiers() == Qt::ControlModifier); diff --git a/rpcs3/rpcs3qt/debugger_list.h b/rpcs3/rpcs3qt/debugger_list.h index f1cab52d79..bdb184b824 100644 --- a/rpcs3/rpcs3qt/debugger_list.h +++ b/rpcs3/rpcs3qt/debugger_list.h @@ -46,7 +46,7 @@ private: */ u32 GetCenteredAddress(u32 address) const; - std::shared_ptr xgui_settings; + std::shared_ptr m_gui_settings; breakpoint_handler* m_breakpoint_handler; cpu_thread* m_cpu = nullptr; diff --git a/rpcs3/rpcs3qt/instruction_editor_dialog.h b/rpcs3/rpcs3qt/instruction_editor_dialog.h index cb7b2ac327..88e47f3cb6 100644 --- a/rpcs3/rpcs3qt/instruction_editor_dialog.h +++ b/rpcs3/rpcs3qt/instruction_editor_dialog.h @@ -6,8 +6,6 @@ #include #include -#include - class CPUDisAsm; class cpu_thread;