Qt/Debugger: Implement patch instruction preview

This commit is contained in:
spycrab 2019-04-23 21:42:37 +02:00
parent 2abe333ce9
commit f6e73a0aec
5 changed files with 110 additions and 8 deletions

View File

@ -84,6 +84,7 @@ add_executable(dolphin-emu
Debugger/MemoryViewWidget.cpp Debugger/MemoryViewWidget.cpp
Debugger/MemoryWidget.cpp Debugger/MemoryWidget.cpp
Debugger/NewBreakpointDialog.cpp Debugger/NewBreakpointDialog.cpp
Debugger/PatchInstructionDialog.cpp
Debugger/RegisterColumn.cpp Debugger/RegisterColumn.cpp
Debugger/RegisterWidget.cpp Debugger/RegisterWidget.cpp
Debugger/WatchWidget.cpp Debugger/WatchWidget.cpp

View File

@ -26,6 +26,7 @@
#include "Core/PowerPC/PPCAnalyst.h" #include "Core/PowerPC/PPCAnalyst.h"
#include "Core/PowerPC/PPCSymbolDB.h" #include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "DolphinQt/Debugger/PatchInstructionDialog.h"
#include "DolphinQt/Resources.h" #include "DolphinQt/Resources.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
@ -463,17 +464,12 @@ void CodeViewWidget::OnReplaceInstruction()
if (!read_result.valid) if (!read_result.valid)
return; return;
bool good; PatchInstructionDialog dialog(this, addr, PowerPC::debug_interface.ReadInstruction(addr));
QString name = QInputDialog::getText(
this, tr("Change instruction"), tr("New instruction:"), QLineEdit::Normal,
QStringLiteral("%1").arg(read_result.hex, 8, 16, QLatin1Char('0')), &good);
u32 code = name.toUInt(&good, 16); if (dialog.exec() == QDialog::Accepted)
if (good)
{ {
PowerPC::debug_interface.UnsetPatch(addr); PowerPC::debug_interface.UnsetPatch(addr);
PowerPC::debug_interface.SetPatch(addr, code); PowerPC::debug_interface.SetPatch(addr, dialog.GetCode());
Update(); Update();
} }
} }

View File

@ -0,0 +1,67 @@
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "DolphinQt/Debugger/PatchInstructionDialog.h"
#include <QDialogButtonBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include "Common/GekkoDisassembler.h"
PatchInstructionDialog::PatchInstructionDialog(QWidget* parent, u32 address, u32 value)
: QDialog(parent), m_address(address)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowModality(Qt::WindowModal);
setWindowTitle(tr("Instruction"));
CreateWidgets();
ConnectWidgets();
m_input_edit->setText(QStringLiteral("%1").arg(value, 8, 16, QLatin1Char('0')));
}
void PatchInstructionDialog::CreateWidgets()
{
auto* layout = new QVBoxLayout;
m_input_edit = new QLineEdit;
m_preview_label = new QLabel;
m_button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
layout->addWidget(new QLabel(tr("New instruction:")));
layout->addWidget(m_input_edit);
layout->addWidget(m_preview_label);
layout->addWidget(m_button_box);
setLayout(layout);
}
void PatchInstructionDialog::ConnectWidgets()
{
connect(m_button_box, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(m_input_edit, &QLineEdit::textChanged, this, &PatchInstructionDialog::OnEditChanged);
}
void PatchInstructionDialog::OnEditChanged()
{
bool good;
m_code = m_input_edit->text().toUInt(&good, 16);
m_button_box->button(QDialogButtonBox::Ok)->setEnabled(good);
m_preview_label->setText(
tr("Instruction: %1")
.arg(QString::fromStdString(Common::GekkoDisassembler::Disassemble(m_code, m_address))));
}
u32 PatchInstructionDialog::GetCode() const
{
return m_code;
}

View File

@ -0,0 +1,35 @@
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <QDialog>
#include "Common/CommonTypes.h"
class QDialogButtonBox;
class QLabel;
class QLineEdit;
class PatchInstructionDialog : public QDialog
{
Q_OBJECT
public:
explicit PatchInstructionDialog(QWidget* parent, u32 address, u32 value);
u32 GetCode() const;
private:
void CreateWidgets();
void ConnectWidgets();
void OnEditChanged();
u32 m_code;
u32 m_address;
QLineEdit* m_input_edit;
QLabel* m_preview_label;
QDialogButtonBox* m_button_box;
};

View File

@ -126,6 +126,7 @@
<QtMoc Include="Debugger\MemoryWidget.h" /> <QtMoc Include="Debugger\MemoryWidget.h" />
<QtMoc Include="Debugger\MemoryViewWidget.h" /> <QtMoc Include="Debugger\MemoryViewWidget.h" />
<QtMoc Include="Debugger\NewBreakpointDialog.h" /> <QtMoc Include="Debugger\NewBreakpointDialog.h" />
<QtMoc Include="Debugger\PatchInstructionDialog.h" />
<QtMoc Include="Debugger\RegisterWidget.h" /> <QtMoc Include="Debugger\RegisterWidget.h" />
<QtMoc Include="Debugger\WatchWidget.h" /> <QtMoc Include="Debugger\WatchWidget.h" />
<QtMoc Include="GCMemcardManager.h" /> <QtMoc Include="GCMemcardManager.h" />
@ -255,6 +256,7 @@
<ClCompile Include="$(QtMocOutPrefix)NewPatchDialog.cpp" /> <ClCompile Include="$(QtMocOutPrefix)NewPatchDialog.cpp" />
<ClCompile Include="$(QtMocOutPrefix)PadMappingDialog.cpp" /> <ClCompile Include="$(QtMocOutPrefix)PadMappingDialog.cpp" />
<ClCompile Include="$(QtMocOutPrefix)PatchesWidget.cpp" /> <ClCompile Include="$(QtMocOutPrefix)PatchesWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)PatchInstructionDialog.cpp" />
<ClCompile Include="$(QtMocOutPrefix)PathPane.cpp" /> <ClCompile Include="$(QtMocOutPrefix)PathPane.cpp" />
<ClCompile Include="$(QtMocOutPrefix)PostProcessingConfigWindow.cpp" /> <ClCompile Include="$(QtMocOutPrefix)PostProcessingConfigWindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)PropertiesDialog.cpp" /> <ClCompile Include="$(QtMocOutPrefix)PropertiesDialog.cpp" />
@ -351,6 +353,7 @@
<ClCompile Include="TAS\IRWidget.cpp" /> <ClCompile Include="TAS\IRWidget.cpp" />
<ClCompile Include="Debugger\BreakpointWidget.cpp" /> <ClCompile Include="Debugger\BreakpointWidget.cpp" />
<ClCompile Include="Debugger\NewBreakpointDialog.cpp" /> <ClCompile Include="Debugger\NewBreakpointDialog.cpp" />
<ClCompile Include="Debugger\PatchInstructionDialog.cpp" />
<ClCompile Include="Debugger\RegisterColumn.cpp" /> <ClCompile Include="Debugger\RegisterColumn.cpp" />
<ClCompile Include="Debugger\RegisterWidget.cpp" /> <ClCompile Include="Debugger\RegisterWidget.cpp" />
<ClCompile Include="Debugger\WatchWidget.cpp" /> <ClCompile Include="Debugger\WatchWidget.cpp" />