From 15afa4aefb9e2b38b851aa3abd3f455ec1feea5c Mon Sep 17 00:00:00 2001 From: Kingcom Date: Tue, 13 Jan 2015 11:23:48 +0100 Subject: [PATCH] citra-qt: Edit and copy register values --- src/citra_qt/debugger/register_view.cpp | 44 ++++++++++++++++++++++--- src/citra_qt/debugger/register_view.h | 11 +++++++ src/citra_qt/debugger/registers.cpp | 3 ++ src/citra_qt/debugger/util.cpp | 11 +++++++ src/citra_qt/debugger/util.h | 4 +++ 5 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/citra_qt/debugger/register_view.cpp b/src/citra_qt/debugger/register_view.cpp index 7c29967a9..9c98cbffe 100644 --- a/src/citra_qt/debugger/register_view.cpp +++ b/src/citra_qt/debugger/register_view.cpp @@ -5,6 +5,9 @@ #include #include #include +#include +#include +#include #include "core/debugger/debug_interface.h" @@ -29,13 +32,17 @@ RegisterView::RegisterView(QWidget* parent) : QFrame(parent) { last_pc = 0; selection = 0; - QShortcut* up_shortcut = new QShortcut(QKeySequence(Qt::Key_Up), this); + QShortcut* up_shortcut = new QShortcut(QKeySequence("Up"), this); up_shortcut->setContext(Qt::WidgetShortcut); - connect(up_shortcut, SIGNAL(activated()), this, SLOT(previousRegister())); + connect(up_shortcut, SIGNAL(activated()), this, SLOT(moveSelectionUp())); - QShortcut* down_shortcut = new QShortcut(QKeySequence(Qt::Key_Down), this); + QShortcut* down_shortcut = new QShortcut(QKeySequence("Down"), this); down_shortcut->setContext(Qt::WidgetShortcut); - connect(down_shortcut, SIGNAL(activated()), this, SLOT(nextRegister())); + connect(down_shortcut, SIGNAL(activated()), this, SLOT(moveSelectionDown())); + + QShortcut* copy_shortcut = new QShortcut(QKeySequence("Ctrl+C"), this); + down_shortcut->setContext(Qt::WidgetShortcut); + connect(copy_shortcut, SIGNAL(activated()), this, SLOT(copyRegisterValue())); setFocusPolicy(Qt::FocusPolicy::ClickFocus); } @@ -157,6 +164,11 @@ void RegisterView::mouseMoveEvent(QMouseEvent* event) { } } +void RegisterView::mouseDoubleClickEvent(QMouseEvent* event) { + if (event->button() == Qt::MouseButton::LeftButton) + editRegisterValue(); +} + void RegisterView::moveSelectionUp() { selection = qMax(0, selection - 1); update(); @@ -166,3 +178,27 @@ void RegisterView::moveSelectionDown() { selection = qMin(registers.size() - 1, selection + 1); update(); } + +void RegisterView::copyRegisterValue() { + QString value; + + Register& reg = registers[selection]; + value.sprintf("0x%08X", g_debug->GetRegValue(reg.category, reg.index)); + QApplication::clipboard()->setText(value); +} + +void RegisterView::editRegisterValue() { + QString value; + + Register& reg = registers[selection]; + value.sprintf("0x%08X", g_debug->GetRegValue(reg.category, reg.index)); + + QString result = QInputDialog::getText(this,"Input value","Input new value",QLineEdit::EchoMode::Normal,value); + + u32 newValue; + if (!result.isEmpty() && parseExpression(result,newValue)) { + g_debug->SetRegValue(reg.category,reg.index,newValue); + emit registerValueChanged(); + update(); + } +} diff --git a/src/citra_qt/debugger/register_view.h b/src/citra_qt/debugger/register_view.h index 2451f5b18..506f9e849 100644 --- a/src/citra_qt/debugger/register_view.h +++ b/src/citra_qt/debugger/register_view.h @@ -16,6 +16,7 @@ protected: void paintEvent(QPaintEvent* event) override; void mousePressEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; + void mouseDoubleClickEvent(QMouseEvent* event) override; private slots: // Select previous register @@ -24,6 +25,16 @@ private slots: // Select next register void moveSelectionDown(); + // Copies a string representation of the selected + // register's value to the clipboard + void copyRegisterValue(); + + void editRegisterValue(); + +signals: + // Emitted when the value of a register was changed by the user + void registerValueChanged(); + private: // Reloads register values if necessary void refreshChangedRegs(); diff --git a/src/citra_qt/debugger/registers.cpp b/src/citra_qt/debugger/registers.cpp index 4726ac19b..3ed054282 100644 --- a/src/citra_qt/debugger/registers.cpp +++ b/src/citra_qt/debugger/registers.cpp @@ -24,6 +24,9 @@ RegistersWidget::RegistersWidget(QWidget* parent) : QDockWidget(parent) } cpu_regs_ui.flags->addItem(new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding)); + + // reload cpsr flags when register values have been changed + connect(cpu_regs_ui.registerView,SIGNAL(registerValueChanged()),this,SLOT(OnDebugModeEntered())); } void RegistersWidget::OnFlagToggled(int state) diff --git a/src/citra_qt/debugger/util.cpp b/src/citra_qt/debugger/util.cpp index 1cdcab7c1..ff22729ad 100644 --- a/src/citra_qt/debugger/util.cpp +++ b/src/citra_qt/debugger/util.cpp @@ -4,6 +4,8 @@ #include +#include "core/debugger/debug_interface.h" + #include "util.h" DebuggerFont::DebuggerFont() { @@ -27,3 +29,12 @@ void DebuggerFont::updateMetrics() { height = metrics.height(); descent = metrics.descent(); } + + +bool parseExpression(QString& exp, u32& dest) { + PostfixExpression postfix; + if (!g_debug->InitExpression(exp.toLatin1().data(),postfix)) + return false; + + return g_debug->ParseExpression(postfix,dest); +} diff --git a/src/citra_qt/debugger/util.h b/src/citra_qt/debugger/util.h index f43b46095..91aa5f26a 100644 --- a/src/citra_qt/debugger/util.h +++ b/src/citra_qt/debugger/util.h @@ -6,6 +6,8 @@ #include #include +#include "common/common_types.h" + // Abstracts font calculations used by some // debugger widgets class DebuggerFont { @@ -31,3 +33,5 @@ private: int height; int descent; }; + +bool parseExpression(QString& exp, u32& dest);