yuzu-android/src/citra_qt/debugger/disassembler.cpp

161 lines
5.6 KiB
C++
Raw Normal View History

2014-03-31 19:26:50 -07:00
#include <QtGui>
2014-04-18 15:30:53 -07:00
#include "disassembler.hxx"
#include "../bootmanager.hxx"
#include "../hotkeys.hxx"
2014-03-31 19:26:50 -07:00
2014-04-10 17:50:10 -07:00
#include "common/common.h"
#include "core/mem_map.h"
2014-03-31 19:26:50 -07:00
2014-04-10 17:50:10 -07:00
#include "core/core.h"
#include "common/break_points.h"
2014-04-12 15:59:26 -07:00
#include "common/symbols.h"
2014-04-10 17:50:10 -07:00
#include "core/arm/interpreter/armdefs.h"
#include "core/arm/disassembler/arm_disasm.h"
2014-03-31 19:26:50 -07:00
2014-04-18 15:30:53 -07:00
DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread& emu_thread) : QDockWidget(parent), base_addr(0), emu_thread(emu_thread)
2014-03-31 19:26:50 -07:00
{
disasm_ui.setupUi(this);
breakpoints = new BreakPoints();
model = new QStandardItemModel(this);
2014-04-12 15:59:26 -07:00
model->setColumnCount(3);
2014-03-31 19:26:50 -07:00
disasm_ui.treeView->setModel(model);
2014-04-18 15:30:53 -07:00
disasm_ui.tableView->setModel(model);
2014-04-03 18:24:07 -07:00
RegisterHotkey("Disassembler", "Start/Stop", QKeySequence(Qt::Key_F5), Qt::ApplicationShortcut);
2014-03-31 19:26:50 -07:00
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);
connect(disasm_ui.button_breakpoint, SIGNAL(clicked()), this, SLOT(OnSetBreakpoint()));
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()));
2014-04-03 18:24:07 -07:00
connect(GetHotkey("Disassembler", "Start/Stop", this), SIGNAL(activated()), this, SLOT(OnToggleStartStop()));
2014-03-31 19:26:50 -07:00
connect(GetHotkey("Disassembler", "Step", this), SIGNAL(activated()), this, SLOT(OnStep()));
connect(GetHotkey("Disassembler", "Step into", this), SIGNAL(activated()), this, SLOT(OnStepInto()));
connect(GetHotkey("Disassembler", "Set Breakpoint", this), SIGNAL(activated()), this, SLOT(OnSetBreakpoint()));
}
2014-04-18 15:30:53 -07:00
void DisassemblerWidget::Init()
2014-04-03 18:24:07 -07:00
{
ARM_Disasm* disasm = new ARM_Disasm();
2014-04-03 18:24:07 -07:00
2014-04-10 17:50:10 -07:00
base_addr = Core::g_app_core->GetPC();
2014-04-03 18:24:07 -07:00
unsigned int curInstAddr = base_addr;
char result[255];
for (int i = 0; i < 10000; i++) // fixed for now
{
disasm->disasm(curInstAddr, Memory::Read32(curInstAddr), result);
model->setItem(i, 0, new QStandardItem(QString("0x%1").arg((uint)(curInstAddr), 8, 16, QLatin1Char('0'))));
model->setItem(i, 1, new QStandardItem(QString(result)));
2014-04-12 15:59:26 -07:00
if (Symbols::HasSymbol(curInstAddr))
{
TSymbol symbol = Symbols::GetSymbol(curInstAddr);
model->setItem(i, 2, new QStandardItem(QString("%1 - Size:%2").arg(QString::fromStdString(symbol.name))
.arg(symbol.size / 4))); // divide by 4 to get instruction count
}
2014-04-03 18:24:07 -07:00
curInstAddr += 4;
}
disasm_ui.treeView->resizeColumnToContents(0);
disasm_ui.treeView->resizeColumnToContents(1);
2014-04-18 15:30:53 -07:00
disasm_ui.treeView->resizeColumnToContents(2);
disasm_ui.tableView->resizeColumnToContents(0);
disasm_ui.tableView->resizeColumnToContents(1);
disasm_ui.tableView->resizeColumnToContents(2);
2014-04-03 18:24:07 -07:00
QModelIndex model_index = model->index(0, 0);
disasm_ui.treeView->scrollTo(model_index);
disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
2014-04-18 15:30:53 -07:00
disasm_ui.tableView->scrollTo(model_index);
disasm_ui.tableView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
2014-04-03 18:24:07 -07:00
}
2014-04-18 15:30:53 -07:00
void DisassemblerWidget::OnSetBreakpoint()
2014-03-31 19:26:50 -07:00
{
2014-04-03 18:24:07 -07:00
int selected_row = SelectedRow();
if (selected_row == -1)
2014-03-31 19:26:50 -07:00
return;
2014-04-03 18:24:07 -07:00
u32 address = base_addr + (selected_row * 4);
2014-03-31 19:26:50 -07:00
if (breakpoints->IsAddressBreakPoint(address))
{
breakpoints->Remove(address);
2014-04-03 18:24:07 -07:00
model->item(selected_row, 0)->setBackground(QBrush());
model->item(selected_row, 1)->setBackground(QBrush());
2014-03-31 19:26:50 -07:00
}
else
{
breakpoints->Add(address);
2014-04-03 18:24:07 -07:00
model->item(selected_row, 0)->setBackground(QBrush(QColor(0xFF, 0x99, 0x99)));
model->item(selected_row, 1)->setBackground(QBrush(QColor(0xFF, 0x99, 0x99)));
2014-03-31 19:26:50 -07:00
}
}
2014-04-18 15:30:53 -07:00
void DisassemblerWidget::OnContinue()
2014-04-03 18:24:07 -07:00
{
emu_thread.SetCpuRunning(true);
}
2014-04-18 15:30:53 -07:00
void DisassemblerWidget::OnStep()
2014-04-03 18:24:07 -07:00
{
OnStepInto(); // change later
}
2014-04-18 15:30:53 -07:00
void DisassemblerWidget::OnStepInto()
2014-03-31 19:26:50 -07:00
{
emu_thread.SetCpuRunning(false);
emu_thread.ExecStep();
}
2014-04-18 15:30:53 -07:00
void DisassemblerWidget::OnPause()
2014-03-31 19:26:50 -07:00
{
emu_thread.SetCpuRunning(false);
}
2014-04-18 15:30:53 -07:00
void DisassemblerWidget::OnToggleStartStop()
2014-03-31 19:26:50 -07:00
{
2014-04-03 18:24:07 -07:00
emu_thread.SetCpuRunning(!emu_thread.IsCpuRunning());
2014-03-31 19:26:50 -07:00
}
2014-04-18 15:30:53 -07:00
void DisassemblerWidget::OnCPUStepped()
2014-03-31 19:26:50 -07:00
{
2014-04-10 17:50:10 -07:00
ARMword next_instr = Core::g_app_core->GetPC();
2014-03-31 19:26:50 -07:00
2014-04-03 18:24:07 -07:00
if (breakpoints->IsAddressBreakPoint(next_instr))
{
emu_thread.SetCpuRunning(false);
2014-03-31 19:26:50 -07:00
}
2014-04-03 18:24:07 -07:00
unsigned int index = (next_instr - base_addr) / 4;
QModelIndex model_index = model->index(index, 0);
disasm_ui.treeView->scrollTo(model_index);
disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
2014-04-18 15:30:53 -07:00
disasm_ui.tableView->scrollTo(model_index);
disasm_ui.tableView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
disasm_ui.tableView->selectionModel()->select(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
2014-03-31 19:26:50 -07:00
}
2014-04-18 15:30:53 -07:00
int DisassemblerWidget::SelectedRow()
2014-03-31 19:26:50 -07:00
{
QModelIndex index = disasm_ui.treeView->selectionModel()->currentIndex();
if (!index.isValid())
return -1;
return model->itemFromIndex(disasm_ui.treeView->selectionModel()->currentIndex())->row();
2014-04-18 15:30:53 -07:00
}
/*
void DisassemblerWidget::paintEvent()
{
QPainter painter(this);
painter.drawRect(10, 10, 50, 50);
}
*/