diff options
Diffstat (limited to '')
| -rw-r--r-- | src/citra_qt/debugger/disassembler.cpp | 223 | ||||
| -rw-r--r-- | src/citra_qt/debugger/disassembler.hxx | 41 |
2 files changed, 204 insertions, 60 deletions
diff --git a/src/citra_qt/debugger/disassembler.cpp b/src/citra_qt/debugger/disassembler.cpp index 4e8f841f4..507a35718 100644 --- a/src/citra_qt/debugger/disassembler.cpp +++ b/src/citra_qt/debugger/disassembler.cpp | |||
| @@ -1,5 +1,3 @@ | |||
| 1 | #include <QtGui> | ||
| 2 | |||
| 3 | #include "disassembler.hxx" | 1 | #include "disassembler.hxx" |
| 4 | 2 | ||
| 5 | #include "../bootmanager.hxx" | 3 | #include "../bootmanager.hxx" |
| @@ -14,14 +12,161 @@ | |||
| 14 | #include "core/arm/interpreter/armdefs.h" | 12 | #include "core/arm/interpreter/armdefs.h" |
| 15 | #include "core/arm/disassembler/arm_disasm.h" | 13 | #include "core/arm/disassembler/arm_disasm.h" |
| 16 | 14 | ||
| 15 | DisassemblerModel::DisassemblerModel(QObject* parent) : QAbstractItemModel(parent), base_address(0), code_size(0), program_counter(0), selection(QModelIndex()) { | ||
| 16 | |||
| 17 | } | ||
| 18 | |||
| 19 | QModelIndex DisassemblerModel::index(int row, int column, const QModelIndex& parent) const { | ||
| 20 | return createIndex(row, column); | ||
| 21 | } | ||
| 22 | |||
| 23 | QModelIndex DisassemblerModel::parent(const QModelIndex& child) const { | ||
| 24 | return QModelIndex(); | ||
| 25 | } | ||
| 26 | |||
| 27 | int DisassemblerModel::columnCount(const QModelIndex& parent) const { | ||
| 28 | return 3; | ||
| 29 | } | ||
| 30 | |||
| 31 | int DisassemblerModel::rowCount(const QModelIndex& parent) const { | ||
| 32 | return code_size; | ||
| 33 | } | ||
| 34 | |||
| 35 | QVariant DisassemblerModel::data(const QModelIndex& index, int role) const { | ||
| 36 | switch (role) { | ||
| 37 | case Qt::DisplayRole: | ||
| 38 | { | ||
| 39 | static char result[255]; | ||
| 40 | |||
| 41 | u32 address = base_address + index.row() * 4; | ||
| 42 | u32 instr = Memory::Read32(address); | ||
| 43 | ARM_Disasm::disasm(address, instr, result); | ||
| 44 | |||
| 45 | if (index.column() == 0) { | ||
| 46 | return QString("0x%1").arg((uint)(address), 8, 16, QLatin1Char('0')); | ||
| 47 | } else if (index.column() == 1) { | ||
| 48 | return QString::fromLatin1(result); | ||
| 49 | } else if (index.column() == 2) { | ||
| 50 | if(Symbols::HasSymbol(address)) { | ||
| 51 | TSymbol symbol = Symbols::GetSymbol(address); | ||
| 52 | return QString("%1 - Size:%2").arg(QString::fromStdString(symbol.name)) | ||
| 53 | .arg(symbol.size / 4); // divide by 4 to get instruction count | ||
| 54 | } else if (ARM_Disasm::decode(instr) == OP_BL) { | ||
| 55 | u32 offset = instr & 0xFFFFFF; | ||
| 56 | |||
| 57 | // Sign-extend the 24-bit offset | ||
| 58 | if ((offset >> 23) & 1) | ||
| 59 | offset |= 0xFF000000; | ||
| 60 | |||
| 61 | // Pre-compute the left-shift and the prefetch offset | ||
| 62 | offset <<= 2; | ||
| 63 | offset += 8; | ||
| 64 | |||
| 65 | TSymbol symbol = Symbols::GetSymbol(address + offset); | ||
| 66 | return QString(" --> %1").arg(QString::fromStdString(symbol.name)); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | break; | ||
| 71 | } | ||
| 72 | |||
| 73 | case Qt::BackgroundRole: | ||
| 74 | { | ||
| 75 | unsigned int address = base_address + 4 * index.row(); | ||
| 76 | |||
| 77 | if (breakpoints.IsAddressBreakPoint(address)) | ||
| 78 | return QBrush(QColor(0xFF, 0xC0, 0xC0)); | ||
| 79 | else if (address == program_counter) | ||
| 80 | return QBrush(QColor(0xC0, 0xC0, 0xFF)); | ||
| 81 | |||
| 82 | break; | ||
| 83 | } | ||
| 84 | |||
| 85 | default: | ||
| 86 | break; | ||
| 87 | } | ||
| 88 | |||
| 89 | return QVariant(); | ||
| 90 | } | ||
| 91 | |||
| 92 | QModelIndex DisassemblerModel::IndexFromAbsoluteAddress(unsigned int address) const { | ||
| 93 | return index((address - base_address) / 4, 0); | ||
| 94 | } | ||
| 95 | |||
| 96 | const BreakPoints& DisassemblerModel::GetBreakPoints() const { | ||
| 97 | return breakpoints; | ||
| 98 | } | ||
| 99 | |||
| 100 | void DisassemblerModel::ParseFromAddress(unsigned int address) { | ||
| 101 | |||
| 102 | // NOTE: A too large value causes lagging when scrolling the disassembly | ||
| 103 | const unsigned int chunk_size = 1000*500; | ||
| 104 | |||
| 105 | // If we haven't loaded anything yet, initialize base address to the parameter address | ||
| 106 | if (code_size == 0) | ||
| 107 | base_address = address; | ||
| 108 | |||
| 109 | // If the new area is already loaded, just continue | ||
| 110 | if (base_address + code_size > address + chunk_size && base_address <= address) | ||
| 111 | return; | ||
| 112 | |||
| 113 | // Insert rows before currently loaded data | ||
| 114 | if (base_address > address) { | ||
| 115 | unsigned int num_rows = (address - base_address) / 4; | ||
| 116 | |||
| 117 | beginInsertRows(QModelIndex(), 0, num_rows); | ||
| 118 | code_size += num_rows; | ||
| 119 | base_address = address; | ||
| 120 | |||
| 121 | endInsertRows(); | ||
| 122 | } | ||
| 123 | |||
| 124 | // Insert rows after currently loaded data | ||
| 125 | if (base_address + code_size < address + chunk_size) { | ||
| 126 | unsigned int num_rows = (base_address + chunk_size - code_size - address) / 4; | ||
| 127 | |||
| 128 | beginInsertRows(QModelIndex(), 0, num_rows); | ||
| 129 | code_size += num_rows; | ||
| 130 | endInsertRows(); | ||
| 131 | } | ||
| 132 | |||
| 133 | SetNextInstruction(address); | ||
| 134 | } | ||
| 135 | |||
| 136 | void DisassemblerModel::OnSelectionChanged(const QModelIndex& new_selection) { | ||
| 137 | selection = new_selection; | ||
| 138 | } | ||
| 139 | |||
| 140 | void DisassemblerModel::OnSetOrUnsetBreakpoint() { | ||
| 141 | if (!selection.isValid()) | ||
| 142 | return; | ||
| 143 | |||
| 144 | unsigned int address = base_address + selection.row() * 4; | ||
| 145 | |||
| 146 | if (breakpoints.IsAddressBreakPoint(address)) { | ||
| 147 | breakpoints.Remove(address); | ||
| 148 | } else { | ||
| 149 | breakpoints.Add(address); | ||
| 150 | } | ||
| 151 | |||
| 152 | emit dataChanged(selection, selection); | ||
| 153 | } | ||
| 154 | |||
| 155 | void DisassemblerModel::SetNextInstruction(unsigned int address) { | ||
| 156 | QModelIndex cur_index = IndexFromAbsoluteAddress(program_counter); | ||
| 157 | QModelIndex prev_index = IndexFromAbsoluteAddress(address); | ||
| 158 | |||
| 159 | program_counter = address; | ||
| 160 | |||
| 161 | emit dataChanged(cur_index, cur_index); | ||
| 162 | emit dataChanged(prev_index, prev_index); | ||
| 163 | } | ||
| 164 | |||
| 17 | DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread& emu_thread) : QDockWidget(parent), base_addr(0), emu_thread(emu_thread) | 165 | DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread& emu_thread) : QDockWidget(parent), base_addr(0), emu_thread(emu_thread) |
| 18 | { | 166 | { |
| 19 | disasm_ui.setupUi(this); | 167 | disasm_ui.setupUi(this); |
| 20 | 168 | ||
| 21 | breakpoints = new BreakPoints(); | 169 | model = new DisassemblerModel(this); |
| 22 | |||
| 23 | model = new QStandardItemModel(this); | ||
| 24 | model->setColumnCount(3); | ||
| 25 | disasm_ui.treeView->setModel(model); | 170 | disasm_ui.treeView->setModel(model); |
| 26 | 171 | ||
| 27 | RegisterHotkey("Disassembler", "Start/Stop", QKeySequence(Qt::Key_F5), Qt::ApplicationShortcut); | 172 | RegisterHotkey("Disassembler", "Start/Stop", QKeySequence(Qt::Key_F5), Qt::ApplicationShortcut); |
| @@ -29,70 +174,33 @@ DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread& emu_thread) : | |||
| 29 | RegisterHotkey("Disassembler", "Step into", QKeySequence(Qt::Key_F11), Qt::ApplicationShortcut); | 174 | RegisterHotkey("Disassembler", "Step into", QKeySequence(Qt::Key_F11), Qt::ApplicationShortcut); |
| 30 | RegisterHotkey("Disassembler", "Set Breakpoint", QKeySequence(Qt::Key_F9), Qt::ApplicationShortcut); | 175 | RegisterHotkey("Disassembler", "Set Breakpoint", QKeySequence(Qt::Key_F9), Qt::ApplicationShortcut); |
| 31 | 176 | ||
| 32 | connect(disasm_ui.button_breakpoint, SIGNAL(clicked()), this, SLOT(OnSetBreakpoint())); | 177 | connect(disasm_ui.button_breakpoint, SIGNAL(clicked()), model, SLOT(OnSetOrUnsetBreakpoint())); |
| 33 | connect(disasm_ui.button_step, SIGNAL(clicked()), this, SLOT(OnStep())); | 178 | connect(disasm_ui.button_step, SIGNAL(clicked()), this, SLOT(OnStep())); |
| 34 | connect(disasm_ui.button_pause, SIGNAL(clicked()), this, SLOT(OnPause())); | 179 | connect(disasm_ui.button_pause, SIGNAL(clicked()), this, SLOT(OnPause())); |
| 35 | connect(disasm_ui.button_continue, SIGNAL(clicked()), this, SLOT(OnContinue())); | 180 | connect(disasm_ui.button_continue, SIGNAL(clicked()), this, SLOT(OnContinue())); |
| 36 | 181 | ||
| 182 | connect(disasm_ui.treeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), | ||
| 183 | model, SLOT(OnSelectionChanged(const QModelIndex&))); | ||
| 184 | |||
| 37 | connect(GetHotkey("Disassembler", "Start/Stop", this), SIGNAL(activated()), this, SLOT(OnToggleStartStop())); | 185 | connect(GetHotkey("Disassembler", "Start/Stop", this), SIGNAL(activated()), this, SLOT(OnToggleStartStop())); |
| 38 | connect(GetHotkey("Disassembler", "Step", this), SIGNAL(activated()), this, SLOT(OnStep())); | 186 | connect(GetHotkey("Disassembler", "Step", this), SIGNAL(activated()), this, SLOT(OnStep())); |
| 39 | connect(GetHotkey("Disassembler", "Step into", this), SIGNAL(activated()), this, SLOT(OnStepInto())); | 187 | connect(GetHotkey("Disassembler", "Step into", this), SIGNAL(activated()), this, SLOT(OnStepInto())); |
| 40 | connect(GetHotkey("Disassembler", "Set Breakpoint", this), SIGNAL(activated()), this, SLOT(OnSetBreakpoint())); | 188 | connect(GetHotkey("Disassembler", "Set Breakpoint", this), SIGNAL(activated()), model, SLOT(OnSetOrUnsetBreakpoint())); |
| 41 | } | 189 | } |
| 42 | 190 | ||
| 43 | void DisassemblerWidget::Init() | 191 | void DisassemblerWidget::Init() |
| 44 | { | 192 | { |
| 45 | ARM_Disasm* disasm = new ARM_Disasm(); | 193 | model->ParseFromAddress(Core::g_app_core->GetPC()); |
| 46 | |||
| 47 | base_addr = Core::g_app_core->GetPC(); | ||
| 48 | unsigned int curInstAddr = base_addr; | ||
| 49 | char result[255]; | ||
| 50 | |||
| 51 | for (int i = 0; i < 20000; i++) // fixed for now | ||
| 52 | { | ||
| 53 | disasm->disasm(curInstAddr, Memory::Read32(curInstAddr), result); | ||
| 54 | model->setItem(i, 0, new QStandardItem(QString("0x%1").arg((uint)(curInstAddr), 8, 16, QLatin1Char('0')))); | ||
| 55 | model->setItem(i, 1, new QStandardItem(QString(result))); | ||
| 56 | if (Symbols::HasSymbol(curInstAddr)) | ||
| 57 | { | ||
| 58 | TSymbol symbol = Symbols::GetSymbol(curInstAddr); | ||
| 59 | model->setItem(i, 2, new QStandardItem(QString("%1 - Size:%2").arg(QString::fromStdString(symbol.name)) | ||
| 60 | .arg(symbol.size / 4))); // divide by 4 to get instruction count | ||
| 61 | 194 | ||
| 62 | } | ||
| 63 | curInstAddr += 4; | ||
| 64 | } | ||
| 65 | disasm_ui.treeView->resizeColumnToContents(0); | 195 | disasm_ui.treeView->resizeColumnToContents(0); |
| 66 | disasm_ui.treeView->resizeColumnToContents(1); | 196 | disasm_ui.treeView->resizeColumnToContents(1); |
| 67 | disasm_ui.treeView->resizeColumnToContents(2); | 197 | disasm_ui.treeView->resizeColumnToContents(2); |
| 68 | 198 | ||
| 69 | QModelIndex model_index = model->index(0, 0); | 199 | QModelIndex model_index = model->IndexFromAbsoluteAddress(Core::g_app_core->GetPC()); |
| 70 | disasm_ui.treeView->scrollTo(model_index); | 200 | disasm_ui.treeView->scrollTo(model_index); |
| 71 | disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | 201 | disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); |
| 72 | } | 202 | } |
| 73 | 203 | ||
| 74 | void DisassemblerWidget::OnSetBreakpoint() | ||
| 75 | { | ||
| 76 | int selected_row = SelectedRow(); | ||
| 77 | |||
| 78 | if (selected_row == -1) | ||
| 79 | return; | ||
| 80 | |||
| 81 | u32 address = base_addr + (selected_row * 4); | ||
| 82 | if (breakpoints->IsAddressBreakPoint(address)) | ||
| 83 | { | ||
| 84 | breakpoints->Remove(address); | ||
| 85 | model->item(selected_row, 0)->setBackground(QBrush()); | ||
| 86 | model->item(selected_row, 1)->setBackground(QBrush()); | ||
| 87 | } | ||
| 88 | else | ||
| 89 | { | ||
| 90 | breakpoints->Add(address); | ||
| 91 | model->item(selected_row, 0)->setBackground(QBrush(QColor(0xFF, 0x99, 0x99))); | ||
| 92 | model->item(selected_row, 1)->setBackground(QBrush(QColor(0xFF, 0x99, 0x99))); | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | void DisassemblerWidget::OnContinue() | 204 | void DisassemblerWidget::OnContinue() |
| 97 | { | 205 | { |
| 98 | emu_thread.SetCpuRunning(true); | 206 | emu_thread.SetCpuRunning(true); |
| @@ -112,6 +220,9 @@ void DisassemblerWidget::OnStepInto() | |||
| 112 | void DisassemblerWidget::OnPause() | 220 | void DisassemblerWidget::OnPause() |
| 113 | { | 221 | { |
| 114 | emu_thread.SetCpuRunning(false); | 222 | emu_thread.SetCpuRunning(false); |
| 223 | |||
| 224 | // TODO: By now, the CPU might not have actually stopped... | ||
| 225 | model->SetNextInstruction(Core::g_app_core->GetPC()); | ||
| 115 | } | 226 | } |
| 116 | 227 | ||
| 117 | void DisassemblerWidget::OnToggleStartStop() | 228 | void DisassemblerWidget::OnToggleStartStop() |
| @@ -123,13 +234,15 @@ void DisassemblerWidget::OnCPUStepped() | |||
| 123 | { | 234 | { |
| 124 | ARMword next_instr = Core::g_app_core->GetPC(); | 235 | ARMword next_instr = Core::g_app_core->GetPC(); |
| 125 | 236 | ||
| 126 | if (breakpoints->IsAddressBreakPoint(next_instr)) | 237 | // TODO: Make BreakPoints less crappy (i.e. const-correct) so that this doesn't need a const_cast. |
| 238 | if (const_cast<BreakPoints&>(model->GetBreakPoints()).IsAddressBreakPoint(next_instr)) | ||
| 127 | { | 239 | { |
| 128 | emu_thread.SetCpuRunning(false); | 240 | emu_thread.SetCpuRunning(false); |
| 129 | } | 241 | } |
| 130 | 242 | ||
| 131 | unsigned int index = (next_instr - base_addr) / 4; | 243 | model->SetNextInstruction(next_instr); |
| 132 | QModelIndex model_index = model->index(index, 0); | 244 | |
| 245 | QModelIndex model_index = model->IndexFromAbsoluteAddress(next_instr); | ||
| 133 | disasm_ui.treeView->scrollTo(model_index); | 246 | disasm_ui.treeView->scrollTo(model_index); |
| 134 | disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | 247 | disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); |
| 135 | } | 248 | } |
| @@ -140,5 +253,5 @@ int DisassemblerWidget::SelectedRow() | |||
| 140 | if (!index.isValid()) | 253 | if (!index.isValid()) |
| 141 | return -1; | 254 | return -1; |
| 142 | 255 | ||
| 143 | return model->itemFromIndex(disasm_ui.treeView->selectionModel()->currentIndex())->row(); | 256 | return disasm_ui.treeView->selectionModel()->currentIndex().row(); |
| 144 | } \ No newline at end of file | 257 | } |
diff --git a/src/citra_qt/debugger/disassembler.hxx b/src/citra_qt/debugger/disassembler.hxx index e668bbbeb..a842da956 100644 --- a/src/citra_qt/debugger/disassembler.hxx +++ b/src/citra_qt/debugger/disassembler.hxx | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | #include <QAbstractItemModel> | ||
| 1 | #include <QDockWidget> | 2 | #include <QDockWidget> |
| 2 | #include "ui_disassembler.h" | 3 | #include "ui_disassembler.h" |
| 3 | 4 | ||
| @@ -5,9 +6,41 @@ | |||
| 5 | #include "common/break_points.h" | 6 | #include "common/break_points.h" |
| 6 | 7 | ||
| 7 | class QAction; | 8 | class QAction; |
| 8 | class QStandardItemModel; | ||
| 9 | class EmuThread; | 9 | class EmuThread; |
| 10 | 10 | ||
| 11 | class DisassemblerModel : public QAbstractItemModel | ||
| 12 | { | ||
| 13 | Q_OBJECT | ||
| 14 | |||
| 15 | public: | ||
| 16 | DisassemblerModel(QObject* parent); | ||
| 17 | |||
| 18 | QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; | ||
| 19 | QModelIndex parent(const QModelIndex& child) const override; | ||
| 20 | int columnCount(const QModelIndex& parent = QModelIndex()) const override; | ||
| 21 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
| 22 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
| 23 | |||
| 24 | QModelIndex IndexFromAbsoluteAddress(unsigned int address) const; | ||
| 25 | const BreakPoints& GetBreakPoints() const; | ||
| 26 | |||
| 27 | public slots: | ||
| 28 | void ParseFromAddress(unsigned int address); | ||
| 29 | void OnSelectionChanged(const QModelIndex&); | ||
| 30 | void OnSetOrUnsetBreakpoint(); | ||
| 31 | void SetNextInstruction(unsigned int address); | ||
| 32 | |||
| 33 | private: | ||
| 34 | unsigned int base_address; | ||
| 35 | unsigned int code_size; | ||
| 36 | unsigned int program_counter; | ||
| 37 | |||
| 38 | QModelIndex selection; | ||
| 39 | |||
| 40 | // TODO: Make BreakPoints less crappy (i.e. const-correct) so that this needn't be mutable. | ||
| 41 | mutable BreakPoints breakpoints; | ||
| 42 | }; | ||
| 43 | |||
| 11 | class DisassemblerWidget : public QDockWidget | 44 | class DisassemblerWidget : public QDockWidget |
| 12 | { | 45 | { |
| 13 | Q_OBJECT | 46 | Q_OBJECT |
| @@ -18,7 +51,6 @@ public: | |||
| 18 | void Init(); | 51 | void Init(); |
| 19 | 52 | ||
| 20 | public slots: | 53 | public slots: |
| 21 | void OnSetBreakpoint(); | ||
| 22 | void OnContinue(); | 54 | void OnContinue(); |
| 23 | void OnStep(); | 55 | void OnStep(); |
| 24 | void OnStepInto(); | 56 | void OnStepInto(); |
| @@ -32,11 +64,10 @@ private: | |||
| 32 | int SelectedRow(); | 64 | int SelectedRow(); |
| 33 | 65 | ||
| 34 | Ui::DockWidget disasm_ui; | 66 | Ui::DockWidget disasm_ui; |
| 35 | QStandardItemModel* model; | ||
| 36 | 67 | ||
| 37 | u32 base_addr; | 68 | DisassemblerModel* model; |
| 38 | 69 | ||
| 39 | BreakPoints* breakpoints; | 70 | u32 base_addr; |
| 40 | 71 | ||
| 41 | EmuThread& emu_thread; | 72 | EmuThread& emu_thread; |
| 42 | }; | 73 | }; |