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