diff options
Diffstat (limited to 'src/citra_qt/debugger/disassembler.cpp')
-rw-r--r-- | src/citra_qt/debugger/disassembler.cpp | 134 |
1 files changed, 70 insertions, 64 deletions
diff --git a/src/citra_qt/debugger/disassembler.cpp b/src/citra_qt/debugger/disassembler.cpp index d4f72809d..b523fe9a7 100644 --- a/src/citra_qt/debugger/disassembler.cpp +++ b/src/citra_qt/debugger/disassembler.cpp @@ -5,20 +5,21 @@ #include <QShortcut> #include "citra_qt/bootmanager.h" -#include "citra_qt/hotkeys.h" #include "citra_qt/debugger/disassembler.h" +#include "citra_qt/hotkeys.h" #include "citra_qt/util/util.h" #include "common/break_points.h" #include "common/symbols.h" -#include "core/core.h" -#include "core/memory.h" #include "core/arm/arm_interface.h" #include "core/arm/disassembler/arm_disasm.h" +#include "core/core.h" +#include "core/memory.h" -DisassemblerModel::DisassemblerModel(QObject* parent) : - QAbstractListModel(parent), base_address(0), code_size(0), program_counter(0), selection(QModelIndex()) { +DisassemblerModel::DisassemblerModel(QObject* parent) + : QAbstractListModel(parent), base_address(0), code_size(0), program_counter(0), + selection(QModelIndex()) { } int DisassemblerModel::columnCount(const QModelIndex& parent) const { @@ -31,62 +32,60 @@ int DisassemblerModel::rowCount(const QModelIndex& parent) const { QVariant DisassemblerModel::data(const QModelIndex& index, int role) const { switch (role) { - case Qt::DisplayRole: - { - u32 address = base_address + index.row() * 4; - u32 instr = Memory::Read32(address); - std::string disassembly = ARM_Disasm::Disassemble(address, instr); - - if (index.column() == 0) { - return QString("0x%1").arg((uint)(address), 8, 16, QLatin1Char('0')); - } else if (index.column() == 1) { - return QString::fromStdString(disassembly); - } else if (index.column() == 2) { - if(Symbols::HasSymbol(address)) { - TSymbol symbol = Symbols::GetSymbol(address); - return QString("%1 - Size:%2").arg(QString::fromStdString(symbol.name)) - .arg(symbol.size / 4); // divide by 4 to get instruction count - } else if (ARM_Disasm::Decode(instr) == OP_BL) { - u32 offset = instr & 0xFFFFFF; - - // Sign-extend the 24-bit offset - if ((offset >> 23) & 1) - offset |= 0xFF000000; - - // Pre-compute the left-shift and the prefetch offset - offset <<= 2; - offset += 8; - - TSymbol symbol = Symbols::GetSymbol(address + offset); - return QString(" --> %1").arg(QString::fromStdString(symbol.name)); - } + case Qt::DisplayRole: { + u32 address = base_address + index.row() * 4; + u32 instr = Memory::Read32(address); + std::string disassembly = ARM_Disasm::Disassemble(address, instr); + + if (index.column() == 0) { + return QString("0x%1").arg((uint)(address), 8, 16, QLatin1Char('0')); + } else if (index.column() == 1) { + return QString::fromStdString(disassembly); + } else if (index.column() == 2) { + if (Symbols::HasSymbol(address)) { + TSymbol symbol = Symbols::GetSymbol(address); + return QString("%1 - Size:%2") + .arg(QString::fromStdString(symbol.name)) + .arg(symbol.size / 4); // divide by 4 to get instruction count + } else if (ARM_Disasm::Decode(instr) == OP_BL) { + u32 offset = instr & 0xFFFFFF; + + // Sign-extend the 24-bit offset + if ((offset >> 23) & 1) + offset |= 0xFF000000; + + // Pre-compute the left-shift and the prefetch offset + offset <<= 2; + offset += 8; + + TSymbol symbol = Symbols::GetSymbol(address + offset); + return QString(" --> %1").arg(QString::fromStdString(symbol.name)); } - - break; } - case Qt::BackgroundRole: - { - unsigned int address = base_address + 4 * index.row(); + break; + } - if (breakpoints.IsAddressBreakPoint(address)) - return QBrush(QColor(0xFF, 0xC0, 0xC0)); - else if (address == program_counter) - return QBrush(QColor(0xC0, 0xC0, 0xFF)); + case Qt::BackgroundRole: { + unsigned int address = base_address + 4 * index.row(); - break; - } + if (breakpoints.IsAddressBreakPoint(address)) + return QBrush(QColor(0xFF, 0xC0, 0xC0)); + else if (address == program_counter) + return QBrush(QColor(0xC0, 0xC0, 0xFF)); - case Qt::FontRole: - { - if (index.column() == 0 || index.column() == 1) { // 2 is the symbols column - return GetMonospaceFont(); - } - break; + break; + } + + case Qt::FontRole: { + if (index.column() == 0 || index.column() == 1) { // 2 is the symbols column + return GetMonospaceFont(); } + break; + } - default: - break; + default: + break; } return QVariant(); @@ -103,7 +102,7 @@ const BreakPoints& DisassemblerModel::GetBreakPoints() const { void DisassemblerModel::ParseFromAddress(unsigned int address) { // NOTE: A too large value causes lagging when scrolling the disassembly - const unsigned int chunk_size = 1000*500; + const unsigned int chunk_size = 1000 * 500; // If we haven't loaded anything yet, initialize base address to the parameter address if (code_size == 0) @@ -165,23 +164,26 @@ void DisassemblerModel::SetNextInstruction(unsigned int address) { emit dataChanged(prev_index, prev_index); } -DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread* emu_thread) : - QDockWidget(parent), base_addr(0), emu_thread(emu_thread) { +DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread* emu_thread) + : QDockWidget(parent), base_addr(0), emu_thread(emu_thread) { disasm_ui.setupUi(this); RegisterHotkey("Disassembler", "Start/Stop", QKeySequence(Qt::Key_F5), Qt::ApplicationShortcut); RegisterHotkey("Disassembler", "Step", QKeySequence(Qt::Key_F10), Qt::ApplicationShortcut); RegisterHotkey("Disassembler", "Step into", QKeySequence(Qt::Key_F11), Qt::ApplicationShortcut); - RegisterHotkey("Disassembler", "Set Breakpoint", QKeySequence(Qt::Key_F9), Qt::ApplicationShortcut); + RegisterHotkey("Disassembler", "Set Breakpoint", QKeySequence(Qt::Key_F9), + Qt::ApplicationShortcut); connect(disasm_ui.button_step, SIGNAL(clicked()), this, SLOT(OnStep())); connect(disasm_ui.button_pause, SIGNAL(clicked()), this, SLOT(OnPause())); connect(disasm_ui.button_continue, SIGNAL(clicked()), this, SLOT(OnContinue())); - connect(GetHotkey("Disassembler", "Start/Stop", this), SIGNAL(activated()), this, SLOT(OnToggleStartStop())); + connect(GetHotkey("Disassembler", "Start/Stop", this), SIGNAL(activated()), this, + SLOT(OnToggleStartStop())); connect(GetHotkey("Disassembler", "Step", this), SIGNAL(activated()), this, SLOT(OnStep())); - connect(GetHotkey("Disassembler", "Step into", this), SIGNAL(activated()), this, SLOT(OnStepInto())); + connect(GetHotkey("Disassembler", "Step into", this), SIGNAL(activated()), this, + SLOT(OnStepInto())); setEnabled(false); } @@ -195,7 +197,8 @@ void DisassemblerWidget::Init() { QModelIndex model_index = model->IndexFromAbsoluteAddress(Core::g_app_core->GetPC()); disasm_ui.treeView->scrollTo(model_index); - disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); + disasm_ui.treeView->selectionModel()->setCurrentIndex( + model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); } void DisassemblerWidget::OnContinue() { @@ -234,7 +237,8 @@ void DisassemblerWidget::OnDebugModeEntered() { QModelIndex model_index = model->IndexFromAbsoluteAddress(next_instr); disasm_ui.treeView->scrollTo(model_index); - disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); + disasm_ui.treeView->selectionModel()->setCurrentIndex( + model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); } void DisassemblerWidget::OnDebugModeLeft() { @@ -254,10 +258,12 @@ void DisassemblerWidget::OnEmulationStarting(EmuThread* emu_thread) { model = new DisassemblerModel(this); disasm_ui.treeView->setModel(model); - connect(disasm_ui.treeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), - model, SLOT(OnSelectionChanged(const QModelIndex&))); + connect(disasm_ui.treeView->selectionModel(), + SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), model, + SLOT(OnSelectionChanged(const QModelIndex&))); connect(disasm_ui.button_breakpoint, SIGNAL(clicked()), model, SLOT(OnSetOrUnsetBreakpoint())); - connect(GetHotkey("Disassembler", "Set Breakpoint", this), SIGNAL(activated()), model, SLOT(OnSetOrUnsetBreakpoint())); + connect(GetHotkey("Disassembler", "Set Breakpoint", this), SIGNAL(activated()), model, + SLOT(OnSetOrUnsetBreakpoint())); Init(); setEnabled(true); |