diff options
Diffstat (limited to 'src/citra_qt/debugger/disassembler.cpp')
| -rw-r--r-- | src/citra_qt/debugger/disassembler.cpp | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/src/citra_qt/debugger/disassembler.cpp b/src/citra_qt/debugger/disassembler.cpp new file mode 100644 index 000000000..cc4cb13fa --- /dev/null +++ b/src/citra_qt/debugger/disassembler.cpp | |||
| @@ -0,0 +1,161 @@ | |||
| 1 | #include <QtGui> | ||
| 2 | |||
| 3 | #include "disassembler.hxx" | ||
| 4 | |||
| 5 | #include "../bootmanager.hxx" | ||
| 6 | #include "../hotkeys.hxx" | ||
| 7 | |||
| 8 | #include "common/common.h" | ||
| 9 | #include "core/mem_map.h" | ||
| 10 | |||
| 11 | #include "core/core.h" | ||
| 12 | #include "common/break_points.h" | ||
| 13 | #include "common/symbols.h" | ||
| 14 | #include "core/arm/interpreter/armdefs.h" | ||
| 15 | #include "core/arm/disassembler/arm_disasm.h" | ||
| 16 | |||
| 17 | DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread& emu_thread) : QDockWidget(parent), base_addr(0), emu_thread(emu_thread) | ||
| 18 | { | ||
| 19 | disasm_ui.setupUi(this); | ||
| 20 | |||
| 21 | breakpoints = new BreakPoints(); | ||
| 22 | |||
| 23 | model = new QStandardItemModel(this); | ||
| 24 | model->setColumnCount(3); | ||
| 25 | disasm_ui.treeView->setModel(model); | ||
| 26 | disasm_ui.tableView->setModel(model); | ||
| 27 | RegisterHotkey("Disassembler", "Start/Stop", QKeySequence(Qt::Key_F5), Qt::ApplicationShortcut); | ||
| 28 | RegisterHotkey("Disassembler", "Step", QKeySequence(Qt::Key_F10), Qt::ApplicationShortcut); | ||
| 29 | RegisterHotkey("Disassembler", "Step into", QKeySequence(Qt::Key_F11), Qt::ApplicationShortcut); | ||
| 30 | RegisterHotkey("Disassembler", "Set Breakpoint", QKeySequence(Qt::Key_F9), Qt::ApplicationShortcut); | ||
| 31 | |||
| 32 | connect(disasm_ui.button_breakpoint, SIGNAL(clicked()), this, SLOT(OnSetBreakpoint())); | ||
| 33 | connect(disasm_ui.button_step, SIGNAL(clicked()), this, SLOT(OnStep())); | ||
| 34 | connect(disasm_ui.button_pause, SIGNAL(clicked()), this, SLOT(OnPause())); | ||
| 35 | connect(disasm_ui.button_continue, SIGNAL(clicked()), this, SLOT(OnContinue())); | ||
| 36 | |||
| 37 | connect(GetHotkey("Disassembler", "Start/Stop", this), SIGNAL(activated()), this, SLOT(OnToggleStartStop())); | ||
| 38 | connect(GetHotkey("Disassembler", "Step", this), SIGNAL(activated()), this, SLOT(OnStep())); | ||
| 39 | connect(GetHotkey("Disassembler", "Step into", this), SIGNAL(activated()), this, SLOT(OnStepInto())); | ||
| 40 | connect(GetHotkey("Disassembler", "Set Breakpoint", this), SIGNAL(activated()), this, SLOT(OnSetBreakpoint())); | ||
| 41 | } | ||
| 42 | |||
| 43 | void DisassemblerWidget::Init() | ||
| 44 | { | ||
| 45 | ARM_Disasm* disasm = new ARM_Disasm(); | ||
| 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 < 10000; 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 | |||
| 62 | } | ||
| 63 | curInstAddr += 4; | ||
| 64 | } | ||
| 65 | disasm_ui.treeView->resizeColumnToContents(0); | ||
| 66 | disasm_ui.treeView->resizeColumnToContents(1); | ||
| 67 | disasm_ui.treeView->resizeColumnToContents(2); | ||
| 68 | disasm_ui.tableView->resizeColumnToContents(0); | ||
| 69 | disasm_ui.tableView->resizeColumnToContents(1); | ||
| 70 | disasm_ui.tableView->resizeColumnToContents(2); | ||
| 71 | |||
| 72 | QModelIndex model_index = model->index(0, 0); | ||
| 73 | disasm_ui.treeView->scrollTo(model_index); | ||
| 74 | disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | ||
| 75 | |||
| 76 | disasm_ui.tableView->scrollTo(model_index); | ||
| 77 | disasm_ui.tableView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | ||
| 78 | } | ||
| 79 | |||
| 80 | void DisassemblerWidget::OnSetBreakpoint() | ||
| 81 | { | ||
| 82 | int selected_row = SelectedRow(); | ||
| 83 | |||
| 84 | if (selected_row == -1) | ||
| 85 | return; | ||
| 86 | |||
| 87 | u32 address = base_addr + (selected_row * 4); | ||
| 88 | if (breakpoints->IsAddressBreakPoint(address)) | ||
| 89 | { | ||
| 90 | breakpoints->Remove(address); | ||
| 91 | model->item(selected_row, 0)->setBackground(QBrush()); | ||
| 92 | model->item(selected_row, 1)->setBackground(QBrush()); | ||
| 93 | } | ||
| 94 | else | ||
| 95 | { | ||
| 96 | breakpoints->Add(address); | ||
| 97 | model->item(selected_row, 0)->setBackground(QBrush(QColor(0xFF, 0x99, 0x99))); | ||
| 98 | model->item(selected_row, 1)->setBackground(QBrush(QColor(0xFF, 0x99, 0x99))); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | void DisassemblerWidget::OnContinue() | ||
| 103 | { | ||
| 104 | emu_thread.SetCpuRunning(true); | ||
| 105 | } | ||
| 106 | |||
| 107 | void DisassemblerWidget::OnStep() | ||
| 108 | { | ||
| 109 | OnStepInto(); // change later | ||
| 110 | } | ||
| 111 | |||
| 112 | void DisassemblerWidget::OnStepInto() | ||
| 113 | { | ||
| 114 | emu_thread.SetCpuRunning(false); | ||
| 115 | emu_thread.ExecStep(); | ||
| 116 | } | ||
| 117 | |||
| 118 | void DisassemblerWidget::OnPause() | ||
| 119 | { | ||
| 120 | emu_thread.SetCpuRunning(false); | ||
| 121 | } | ||
| 122 | |||
| 123 | void DisassemblerWidget::OnToggleStartStop() | ||
| 124 | { | ||
| 125 | emu_thread.SetCpuRunning(!emu_thread.IsCpuRunning()); | ||
| 126 | } | ||
| 127 | |||
| 128 | void DisassemblerWidget::OnCPUStepped() | ||
| 129 | { | ||
| 130 | ARMword next_instr = Core::g_app_core->GetPC(); | ||
| 131 | |||
| 132 | if (breakpoints->IsAddressBreakPoint(next_instr)) | ||
| 133 | { | ||
| 134 | emu_thread.SetCpuRunning(false); | ||
| 135 | } | ||
| 136 | |||
| 137 | unsigned int index = (next_instr - base_addr) / 4; | ||
| 138 | QModelIndex model_index = model->index(index, 0); | ||
| 139 | disasm_ui.treeView->scrollTo(model_index); | ||
| 140 | disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | ||
| 141 | |||
| 142 | disasm_ui.tableView->scrollTo(model_index); | ||
| 143 | disasm_ui.tableView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | ||
| 144 | disasm_ui.tableView->selectionModel()->select(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | ||
| 145 | } | ||
| 146 | |||
| 147 | int DisassemblerWidget::SelectedRow() | ||
| 148 | { | ||
| 149 | QModelIndex index = disasm_ui.treeView->selectionModel()->currentIndex(); | ||
| 150 | if (!index.isValid()) | ||
| 151 | return -1; | ||
| 152 | |||
| 153 | return model->itemFromIndex(disasm_ui.treeView->selectionModel()->currentIndex())->row(); | ||
| 154 | } | ||
| 155 | /* | ||
| 156 | void DisassemblerWidget::paintEvent() | ||
| 157 | { | ||
| 158 | QPainter painter(this); | ||
| 159 | painter.drawRect(10, 10, 50, 50); | ||
| 160 | } | ||
| 161 | */ \ No newline at end of file | ||