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 @@ | |||
| 5 | #include <QShortcut> | 5 | #include <QShortcut> |
| 6 | 6 | ||
| 7 | #include "citra_qt/bootmanager.h" | 7 | #include "citra_qt/bootmanager.h" |
| 8 | #include "citra_qt/hotkeys.h" | ||
| 9 | #include "citra_qt/debugger/disassembler.h" | 8 | #include "citra_qt/debugger/disassembler.h" |
| 9 | #include "citra_qt/hotkeys.h" | ||
| 10 | #include "citra_qt/util/util.h" | 10 | #include "citra_qt/util/util.h" |
| 11 | 11 | ||
| 12 | #include "common/break_points.h" | 12 | #include "common/break_points.h" |
| 13 | #include "common/symbols.h" | 13 | #include "common/symbols.h" |
| 14 | 14 | ||
| 15 | #include "core/core.h" | ||
| 16 | #include "core/memory.h" | ||
| 17 | #include "core/arm/arm_interface.h" | 15 | #include "core/arm/arm_interface.h" |
| 18 | #include "core/arm/disassembler/arm_disasm.h" | 16 | #include "core/arm/disassembler/arm_disasm.h" |
| 17 | #include "core/core.h" | ||
| 18 | #include "core/memory.h" | ||
| 19 | 19 | ||
| 20 | DisassemblerModel::DisassemblerModel(QObject* parent) : | 20 | DisassemblerModel::DisassemblerModel(QObject* parent) |
| 21 | QAbstractListModel(parent), base_address(0), code_size(0), program_counter(0), selection(QModelIndex()) { | 21 | : QAbstractListModel(parent), base_address(0), code_size(0), program_counter(0), |
| 22 | selection(QModelIndex()) { | ||
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | int DisassemblerModel::columnCount(const QModelIndex& parent) const { | 25 | int DisassemblerModel::columnCount(const QModelIndex& parent) const { |
| @@ -31,62 +32,60 @@ int DisassemblerModel::rowCount(const QModelIndex& parent) const { | |||
| 31 | 32 | ||
| 32 | QVariant DisassemblerModel::data(const QModelIndex& index, int role) const { | 33 | QVariant DisassemblerModel::data(const QModelIndex& index, int role) const { |
| 33 | switch (role) { | 34 | switch (role) { |
| 34 | case Qt::DisplayRole: | 35 | case Qt::DisplayRole: { |
| 35 | { | 36 | u32 address = base_address + index.row() * 4; |
| 36 | u32 address = base_address + index.row() * 4; | 37 | u32 instr = Memory::Read32(address); |
| 37 | u32 instr = Memory::Read32(address); | 38 | std::string disassembly = ARM_Disasm::Disassemble(address, instr); |
| 38 | std::string disassembly = ARM_Disasm::Disassemble(address, instr); | 39 | |
| 39 | 40 | if (index.column() == 0) { | |
| 40 | if (index.column() == 0) { | 41 | return QString("0x%1").arg((uint)(address), 8, 16, QLatin1Char('0')); |
| 41 | return QString("0x%1").arg((uint)(address), 8, 16, QLatin1Char('0')); | 42 | } else if (index.column() == 1) { |
| 42 | } else if (index.column() == 1) { | 43 | return QString::fromStdString(disassembly); |
| 43 | return QString::fromStdString(disassembly); | 44 | } else if (index.column() == 2) { |
| 44 | } else if (index.column() == 2) { | 45 | if (Symbols::HasSymbol(address)) { |
| 45 | if(Symbols::HasSymbol(address)) { | 46 | TSymbol symbol = Symbols::GetSymbol(address); |
| 46 | TSymbol symbol = Symbols::GetSymbol(address); | 47 | return QString("%1 - Size:%2") |
| 47 | return QString("%1 - Size:%2").arg(QString::fromStdString(symbol.name)) | 48 | .arg(QString::fromStdString(symbol.name)) |
| 48 | .arg(symbol.size / 4); // divide by 4 to get instruction count | 49 | .arg(symbol.size / 4); // divide by 4 to get instruction count |
| 49 | } else if (ARM_Disasm::Decode(instr) == OP_BL) { | 50 | } else if (ARM_Disasm::Decode(instr) == OP_BL) { |
| 50 | u32 offset = instr & 0xFFFFFF; | 51 | u32 offset = instr & 0xFFFFFF; |
| 51 | 52 | ||
| 52 | // Sign-extend the 24-bit offset | 53 | // Sign-extend the 24-bit offset |
| 53 | if ((offset >> 23) & 1) | 54 | if ((offset >> 23) & 1) |
| 54 | offset |= 0xFF000000; | 55 | offset |= 0xFF000000; |
| 55 | 56 | ||
| 56 | // Pre-compute the left-shift and the prefetch offset | 57 | // Pre-compute the left-shift and the prefetch offset |
| 57 | offset <<= 2; | 58 | offset <<= 2; |
| 58 | offset += 8; | 59 | offset += 8; |
| 59 | 60 | ||
| 60 | TSymbol symbol = Symbols::GetSymbol(address + offset); | 61 | TSymbol symbol = Symbols::GetSymbol(address + offset); |
| 61 | return QString(" --> %1").arg(QString::fromStdString(symbol.name)); | 62 | return QString(" --> %1").arg(QString::fromStdString(symbol.name)); |
| 62 | } | ||
| 63 | } | 63 | } |
| 64 | |||
| 65 | break; | ||
| 66 | } | 64 | } |
| 67 | 65 | ||
| 68 | case Qt::BackgroundRole: | 66 | break; |
| 69 | { | 67 | } |
| 70 | unsigned int address = base_address + 4 * index.row(); | ||
| 71 | 68 | ||
| 72 | if (breakpoints.IsAddressBreakPoint(address)) | 69 | case Qt::BackgroundRole: { |
| 73 | return QBrush(QColor(0xFF, 0xC0, 0xC0)); | 70 | unsigned int address = base_address + 4 * index.row(); |
| 74 | else if (address == program_counter) | ||
| 75 | return QBrush(QColor(0xC0, 0xC0, 0xFF)); | ||
| 76 | 71 | ||
| 77 | break; | 72 | if (breakpoints.IsAddressBreakPoint(address)) |
| 78 | } | 73 | return QBrush(QColor(0xFF, 0xC0, 0xC0)); |
| 74 | else if (address == program_counter) | ||
| 75 | return QBrush(QColor(0xC0, 0xC0, 0xFF)); | ||
| 79 | 76 | ||
| 80 | case Qt::FontRole: | 77 | break; |
| 81 | { | 78 | } |
| 82 | if (index.column() == 0 || index.column() == 1) { // 2 is the symbols column | 79 | |
| 83 | return GetMonospaceFont(); | 80 | case Qt::FontRole: { |
| 84 | } | 81 | if (index.column() == 0 || index.column() == 1) { // 2 is the symbols column |
| 85 | break; | 82 | return GetMonospaceFont(); |
| 86 | } | 83 | } |
| 84 | break; | ||
| 85 | } | ||
| 87 | 86 | ||
| 88 | default: | 87 | default: |
| 89 | break; | 88 | break; |
| 90 | } | 89 | } |
| 91 | 90 | ||
| 92 | return QVariant(); | 91 | return QVariant(); |
| @@ -103,7 +102,7 @@ const BreakPoints& DisassemblerModel::GetBreakPoints() const { | |||
| 103 | void DisassemblerModel::ParseFromAddress(unsigned int address) { | 102 | void DisassemblerModel::ParseFromAddress(unsigned int address) { |
| 104 | 103 | ||
| 105 | // NOTE: A too large value causes lagging when scrolling the disassembly | 104 | // NOTE: A too large value causes lagging when scrolling the disassembly |
| 106 | const unsigned int chunk_size = 1000*500; | 105 | const unsigned int chunk_size = 1000 * 500; |
| 107 | 106 | ||
| 108 | // If we haven't loaded anything yet, initialize base address to the parameter address | 107 | // If we haven't loaded anything yet, initialize base address to the parameter address |
| 109 | if (code_size == 0) | 108 | if (code_size == 0) |
| @@ -165,23 +164,26 @@ void DisassemblerModel::SetNextInstruction(unsigned int address) { | |||
| 165 | emit dataChanged(prev_index, prev_index); | 164 | emit dataChanged(prev_index, prev_index); |
| 166 | } | 165 | } |
| 167 | 166 | ||
| 168 | DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread* emu_thread) : | 167 | DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread* emu_thread) |
| 169 | QDockWidget(parent), base_addr(0), emu_thread(emu_thread) { | 168 | : QDockWidget(parent), base_addr(0), emu_thread(emu_thread) { |
| 170 | 169 | ||
| 171 | disasm_ui.setupUi(this); | 170 | disasm_ui.setupUi(this); |
| 172 | 171 | ||
| 173 | RegisterHotkey("Disassembler", "Start/Stop", QKeySequence(Qt::Key_F5), Qt::ApplicationShortcut); | 172 | RegisterHotkey("Disassembler", "Start/Stop", QKeySequence(Qt::Key_F5), Qt::ApplicationShortcut); |
| 174 | RegisterHotkey("Disassembler", "Step", QKeySequence(Qt::Key_F10), Qt::ApplicationShortcut); | 173 | RegisterHotkey("Disassembler", "Step", QKeySequence(Qt::Key_F10), Qt::ApplicationShortcut); |
| 175 | RegisterHotkey("Disassembler", "Step into", QKeySequence(Qt::Key_F11), Qt::ApplicationShortcut); | 174 | RegisterHotkey("Disassembler", "Step into", QKeySequence(Qt::Key_F11), Qt::ApplicationShortcut); |
| 176 | RegisterHotkey("Disassembler", "Set Breakpoint", QKeySequence(Qt::Key_F9), Qt::ApplicationShortcut); | 175 | RegisterHotkey("Disassembler", "Set Breakpoint", QKeySequence(Qt::Key_F9), |
| 176 | Qt::ApplicationShortcut); | ||
| 177 | 177 | ||
| 178 | connect(disasm_ui.button_step, SIGNAL(clicked()), this, SLOT(OnStep())); | 178 | connect(disasm_ui.button_step, SIGNAL(clicked()), this, SLOT(OnStep())); |
| 179 | connect(disasm_ui.button_pause, SIGNAL(clicked()), this, SLOT(OnPause())); | 179 | connect(disasm_ui.button_pause, SIGNAL(clicked()), this, SLOT(OnPause())); |
| 180 | connect(disasm_ui.button_continue, SIGNAL(clicked()), this, SLOT(OnContinue())); | 180 | connect(disasm_ui.button_continue, SIGNAL(clicked()), this, SLOT(OnContinue())); |
| 181 | 181 | ||
| 182 | connect(GetHotkey("Disassembler", "Start/Stop", this), SIGNAL(activated()), this, SLOT(OnToggleStartStop())); | 182 | connect(GetHotkey("Disassembler", "Start/Stop", this), SIGNAL(activated()), this, |
| 183 | SLOT(OnToggleStartStop())); | ||
| 183 | connect(GetHotkey("Disassembler", "Step", this), SIGNAL(activated()), this, SLOT(OnStep())); | 184 | connect(GetHotkey("Disassembler", "Step", this), SIGNAL(activated()), this, SLOT(OnStep())); |
| 184 | connect(GetHotkey("Disassembler", "Step into", this), SIGNAL(activated()), this, SLOT(OnStepInto())); | 185 | connect(GetHotkey("Disassembler", "Step into", this), SIGNAL(activated()), this, |
| 186 | SLOT(OnStepInto())); | ||
| 185 | 187 | ||
| 186 | setEnabled(false); | 188 | setEnabled(false); |
| 187 | } | 189 | } |
| @@ -195,7 +197,8 @@ void DisassemblerWidget::Init() { | |||
| 195 | 197 | ||
| 196 | QModelIndex model_index = model->IndexFromAbsoluteAddress(Core::g_app_core->GetPC()); | 198 | QModelIndex model_index = model->IndexFromAbsoluteAddress(Core::g_app_core->GetPC()); |
| 197 | disasm_ui.treeView->scrollTo(model_index); | 199 | disasm_ui.treeView->scrollTo(model_index); |
| 198 | disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | 200 | disasm_ui.treeView->selectionModel()->setCurrentIndex( |
| 201 | model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | ||
| 199 | } | 202 | } |
| 200 | 203 | ||
| 201 | void DisassemblerWidget::OnContinue() { | 204 | void DisassemblerWidget::OnContinue() { |
| @@ -234,7 +237,8 @@ void DisassemblerWidget::OnDebugModeEntered() { | |||
| 234 | 237 | ||
| 235 | QModelIndex model_index = model->IndexFromAbsoluteAddress(next_instr); | 238 | QModelIndex model_index = model->IndexFromAbsoluteAddress(next_instr); |
| 236 | disasm_ui.treeView->scrollTo(model_index); | 239 | disasm_ui.treeView->scrollTo(model_index); |
| 237 | disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | 240 | disasm_ui.treeView->selectionModel()->setCurrentIndex( |
| 241 | model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | ||
| 238 | } | 242 | } |
| 239 | 243 | ||
| 240 | void DisassemblerWidget::OnDebugModeLeft() { | 244 | void DisassemblerWidget::OnDebugModeLeft() { |
| @@ -254,10 +258,12 @@ void DisassemblerWidget::OnEmulationStarting(EmuThread* emu_thread) { | |||
| 254 | model = new DisassemblerModel(this); | 258 | model = new DisassemblerModel(this); |
| 255 | disasm_ui.treeView->setModel(model); | 259 | disasm_ui.treeView->setModel(model); |
| 256 | 260 | ||
| 257 | connect(disasm_ui.treeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), | 261 | connect(disasm_ui.treeView->selectionModel(), |
| 258 | model, SLOT(OnSelectionChanged(const QModelIndex&))); | 262 | SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), model, |
| 263 | SLOT(OnSelectionChanged(const QModelIndex&))); | ||
| 259 | connect(disasm_ui.button_breakpoint, SIGNAL(clicked()), model, SLOT(OnSetOrUnsetBreakpoint())); | 264 | connect(disasm_ui.button_breakpoint, SIGNAL(clicked()), model, SLOT(OnSetOrUnsetBreakpoint())); |
| 260 | connect(GetHotkey("Disassembler", "Set Breakpoint", this), SIGNAL(activated()), model, SLOT(OnSetOrUnsetBreakpoint())); | 265 | connect(GetHotkey("Disassembler", "Set Breakpoint", this), SIGNAL(activated()), model, |
| 266 | SLOT(OnSetOrUnsetBreakpoint())); | ||
| 261 | 267 | ||
| 262 | Init(); | 268 | Init(); |
| 263 | setEnabled(true); | 269 | setEnabled(true); |