2024-07-30 11:42:36 +00:00
|
|
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
2022-12-24 06:51:44 +00:00
|
|
|
|
|
|
|
#include "DisassemblyWidget.h"
|
|
|
|
|
|
|
|
#include "DebugTools/DebugInterface.h"
|
|
|
|
#include "DebugTools/DisassemblyManager.h"
|
|
|
|
#include "DebugTools/Breakpoints.h"
|
|
|
|
#include "DebugTools/MipsAssembler.h"
|
|
|
|
|
|
|
|
#include "QtUtils.h"
|
|
|
|
#include "QtHost.h"
|
|
|
|
#include <QtGui/QMouseEvent>
|
|
|
|
#include <QtWidgets/QMenu>
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
#include <QtWidgets/QInputDialog>
|
|
|
|
#include <QtWidgets/QMessageBox>
|
2024-08-26 20:57:31 +00:00
|
|
|
#include "SymbolTree/NewSymbolDialogs.h"
|
2022-12-24 06:51:44 +00:00
|
|
|
|
|
|
|
using namespace QtUtils;
|
|
|
|
|
|
|
|
DisassemblyWidget::DisassemblyWidget(QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
connect(this, &DisassemblyWidget::customContextMenuRequested, this, &DisassemblyWidget::customMenuRequested);
|
|
|
|
}
|
|
|
|
|
|
|
|
DisassemblyWidget::~DisassemblyWidget() = default;
|
|
|
|
|
|
|
|
void DisassemblyWidget::contextCopyAddress()
|
|
|
|
{
|
|
|
|
QGuiApplication::clipboard()->setText(FetchSelectionInfo(SelectionInfo::ADDRESS));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::contextCopyInstructionHex()
|
|
|
|
{
|
|
|
|
QGuiApplication::clipboard()->setText(FetchSelectionInfo(SelectionInfo::INSTRUCTIONHEX));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::contextCopyInstructionText()
|
|
|
|
{
|
|
|
|
QGuiApplication::clipboard()->setText(FetchSelectionInfo(SelectionInfo::INSTRUCTIONTEXT));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::contextAssembleInstruction()
|
|
|
|
{
|
|
|
|
if (!m_cpu->isCpuPaused())
|
|
|
|
{
|
2022-12-24 11:17:52 +00:00
|
|
|
QMessageBox::warning(this, tr("Assemble Error"), tr("Unable to change assembly while core is running"));
|
2022-12-24 06:51:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisassemblyLineInfo line;
|
|
|
|
bool ok;
|
|
|
|
m_disassemblyManager.getLine(m_selectedAddressStart, false, line);
|
2022-12-24 11:17:52 +00:00
|
|
|
QString instruction = QInputDialog::getText(this, tr("Assemble Instruction"), "",
|
2022-12-24 06:51:44 +00:00
|
|
|
QLineEdit::Normal, QString("%1 %2").arg(line.name.c_str()).arg(line.params.c_str()), &ok);
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
|
|
|
u32 encodedInstruction;
|
|
|
|
std::string errorText;
|
|
|
|
bool valid = MipsAssembleOpcode(instruction.toLocal8Bit().constData(), m_cpu, m_selectedAddressStart, encodedInstruction, errorText);
|
|
|
|
|
|
|
|
if (!valid)
|
|
|
|
{
|
2022-12-24 11:17:52 +00:00
|
|
|
QMessageBox::warning(this, tr("Assemble Error"), QString::fromStdString(errorText));
|
2022-12-24 06:51:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Host::RunOnCPUThread([this, start = m_selectedAddressStart, end = m_selectedAddressEnd, cpu = m_cpu, val = encodedInstruction] {
|
|
|
|
for (u32 i = start; i <= end; i += 4)
|
|
|
|
{
|
2023-10-10 01:02:07 +00:00
|
|
|
this->m_nopedInstructions.insert({i, cpu->read32(i)});
|
2022-12-24 06:51:44 +00:00
|
|
|
cpu->write32(i, val);
|
|
|
|
}
|
2024-04-07 20:48:28 +00:00
|
|
|
emit VMUpdate();
|
2022-12-24 06:51:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-01 04:24:39 +00:00
|
|
|
void DisassemblyWidget::contextNoopInstruction()
|
|
|
|
{
|
|
|
|
Host::RunOnCPUThread([this, start = m_selectedAddressStart, end = m_selectedAddressEnd, cpu = m_cpu] {
|
|
|
|
for (u32 i = start; i <= end; i += 4)
|
|
|
|
{
|
2023-10-10 01:02:07 +00:00
|
|
|
this->m_nopedInstructions.insert({i, cpu->read32(i)});
|
2023-01-01 04:24:39 +00:00
|
|
|
cpu->write32(i, 0x00);
|
|
|
|
}
|
2024-04-07 20:48:28 +00:00
|
|
|
emit VMUpdate();
|
2023-01-01 04:24:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-10-10 01:02:07 +00:00
|
|
|
void DisassemblyWidget::contextRestoreInstruction()
|
|
|
|
{
|
|
|
|
Host::RunOnCPUThread([this, start = m_selectedAddressStart, end = m_selectedAddressEnd, cpu = m_cpu] {
|
|
|
|
for (u32 i = start; i <= end; i += 4)
|
|
|
|
{
|
|
|
|
if (this->m_nopedInstructions.find(i) != this->m_nopedInstructions.end())
|
|
|
|
{
|
|
|
|
cpu->write32(i, this->m_nopedInstructions[i]);
|
|
|
|
this->m_nopedInstructions.erase(i);
|
|
|
|
}
|
|
|
|
}
|
2024-04-07 20:48:28 +00:00
|
|
|
emit VMUpdate();
|
2023-10-10 01:02:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-24 06:51:44 +00:00
|
|
|
void DisassemblyWidget::contextRunToCursor()
|
|
|
|
{
|
2024-04-07 20:48:28 +00:00
|
|
|
const u32 selectedAddressStart = m_selectedAddressStart;
|
|
|
|
Host::RunOnCPUThread([cpu = m_cpu, selectedAddressStart] {
|
|
|
|
CBreakPoints::AddBreakPoint(cpu->getCpuType(), selectedAddressStart, true);
|
|
|
|
cpu->resumeCpu();
|
2023-07-26 23:51:06 +00:00
|
|
|
});
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::contextJumpToCursor()
|
|
|
|
{
|
|
|
|
m_cpu->setPc(m_selectedAddressStart);
|
|
|
|
this->repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::contextToggleBreakpoint()
|
|
|
|
{
|
2023-01-01 03:43:54 +00:00
|
|
|
if (!m_cpu->isAlive())
|
|
|
|
return;
|
|
|
|
|
2024-04-07 20:48:28 +00:00
|
|
|
const u32 selectedAddressStart = m_selectedAddressStart;
|
|
|
|
const BreakPointCpu cpuType = m_cpu->getCpuType();
|
|
|
|
if (CBreakPoints::IsAddressBreakPoint(cpuType, selectedAddressStart))
|
2022-12-24 06:51:44 +00:00
|
|
|
{
|
2024-04-07 20:48:28 +00:00
|
|
|
Host::RunOnCPUThread([cpuType, selectedAddressStart] { CBreakPoints::RemoveBreakPoint(cpuType, selectedAddressStart); });
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-07 20:48:28 +00:00
|
|
|
Host::RunOnCPUThread([cpuType, selectedAddressStart] { CBreakPoints::AddBreakPoint(cpuType, selectedAddressStart); });
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
breakpointsChanged();
|
|
|
|
this->repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::contextFollowBranch()
|
|
|
|
{
|
|
|
|
DisassemblyLineInfo line;
|
|
|
|
|
|
|
|
m_disassemblyManager.getLine(m_selectedAddressStart, true, line);
|
|
|
|
|
|
|
|
if (line.type == DISTYPE_OPCODE || line.type == DISTYPE_MACRO)
|
|
|
|
{
|
|
|
|
if (line.info.isBranch)
|
2024-08-26 19:23:03 +00:00
|
|
|
gotoAddressAndSetFocus(line.info.branchTarget);
|
2022-12-24 06:51:44 +00:00
|
|
|
else if (line.info.hasRelevantAddress)
|
2024-08-26 19:23:03 +00:00
|
|
|
gotoAddressAndSetFocus(line.info.releventAddress);
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::contextGoToAddress()
|
|
|
|
{
|
|
|
|
bool ok;
|
2022-12-24 11:17:52 +00:00
|
|
|
const QString targetString = QInputDialog::getText(this, tr("Go to address"), "",
|
2022-12-24 06:51:44 +00:00
|
|
|
QLineEdit::Normal, "", &ok);
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const u32 targetAddress = targetString.toUInt(&ok, 16) & ~3;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
2022-12-24 11:17:52 +00:00
|
|
|
QMessageBox::warning(this, tr("Go to address error"), tr("Invalid address"));
|
2022-12-24 06:51:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-08-26 19:23:03 +00:00
|
|
|
gotoAddressAndSetFocus(targetAddress);
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::contextAddFunction()
|
|
|
|
{
|
2024-08-26 20:57:31 +00:00
|
|
|
NewFunctionDialog* dialog = new NewFunctionDialog(*m_cpu, this);
|
|
|
|
dialog->setName(QString("func_%1").arg(m_selectedAddressStart, 8, 16, QChar('0')));
|
|
|
|
dialog->setAddress(m_selectedAddressStart);
|
|
|
|
if (m_selectedAddressEnd != m_selectedAddressStart)
|
|
|
|
dialog->setCustomSize(m_selectedAddressEnd - m_selectedAddressStart + 4);
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
update();
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
|
2023-11-21 04:29:01 +00:00
|
|
|
void DisassemblyWidget::contextCopyFunctionName()
|
|
|
|
{
|
2024-08-26 19:23:03 +00:00
|
|
|
std::string name = m_cpu->GetSymbolGuardian().FunctionStartingAtAddress(m_selectedAddressStart).name;
|
|
|
|
QGuiApplication::clipboard()->setText(QString::fromStdString(name));
|
2023-11-21 04:29:01 +00:00
|
|
|
}
|
|
|
|
|
2022-12-24 06:51:44 +00:00
|
|
|
void DisassemblyWidget::contextRemoveFunction()
|
|
|
|
{
|
2024-08-26 19:23:03 +00:00
|
|
|
m_cpu->GetSymbolGuardian().ReadWrite([&](ccc::SymbolDatabase& database) {
|
|
|
|
ccc::Function* curFunc = database.functions.symbol_overlapping_address(m_selectedAddressStart);
|
|
|
|
if (!curFunc)
|
|
|
|
return;
|
2022-12-24 06:51:44 +00:00
|
|
|
|
2024-08-26 19:23:03 +00:00
|
|
|
ccc::Function* previousFunc = database.functions.symbol_overlapping_address(curFunc->address().value - 4);
|
|
|
|
if (previousFunc)
|
|
|
|
previousFunc->set_size(curFunc->size() + previousFunc->size());
|
2022-12-24 06:51:44 +00:00
|
|
|
|
2024-08-26 19:23:03 +00:00
|
|
|
database.functions.mark_symbol_for_destruction(curFunc->handle(), &database);
|
|
|
|
database.destroy_marked_symbols();
|
|
|
|
});
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::contextRenameFunction()
|
|
|
|
{
|
2024-08-26 19:23:03 +00:00
|
|
|
const FunctionInfo curFunc = m_cpu->GetSymbolGuardian().FunctionOverlappingAddress(m_selectedAddressStart);
|
2022-12-24 06:51:44 +00:00
|
|
|
|
2024-08-26 19:23:03 +00:00
|
|
|
if (!curFunc.address.valid())
|
2022-12-24 06:51:44 +00:00
|
|
|
{
|
2022-12-24 11:17:52 +00:00
|
|
|
QMessageBox::warning(this, tr("Rename Function Error"), tr("No function / symbol is currently selected."));
|
2024-08-26 19:23:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString oldName = QString::fromStdString(curFunc.name);
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
QString newName = QInputDialog::getText(this, tr("Rename Function"), tr("Function name"), QLineEdit::Normal, oldName, &ok);
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (newName.isEmpty())
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Rename Function Error"), tr("Function name cannot be nothing."));
|
|
|
|
return;
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
2024-08-26 19:23:03 +00:00
|
|
|
|
|
|
|
m_cpu->GetSymbolGuardian().ReadWrite([&](ccc::SymbolDatabase& database) {
|
|
|
|
database.functions.rename_symbol(curFunc.handle, newName.toStdString());
|
|
|
|
});
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 00:31:49 +00:00
|
|
|
void DisassemblyWidget::contextStubFunction()
|
|
|
|
{
|
2024-08-26 19:23:03 +00:00
|
|
|
FunctionInfo function = m_cpu->GetSymbolGuardian().FunctionOverlappingAddress(m_selectedAddressStart);
|
|
|
|
u32 address = function.address.valid() ? function.address.value : m_selectedAddressStart;
|
|
|
|
|
|
|
|
Host::RunOnCPUThread([this, address, cpu = m_cpu] {
|
|
|
|
this->m_stubbedFunctions.insert({address, {cpu->read32(address), cpu->read32(address + 4)}});
|
|
|
|
cpu->write32(address, 0x03E00008); // jr ra
|
|
|
|
cpu->write32(address + 4, 0x00000000); // nop
|
|
|
|
emit VMUpdate();
|
|
|
|
});
|
2023-10-10 00:31:49 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 01:02:07 +00:00
|
|
|
void DisassemblyWidget::contextRestoreFunction()
|
|
|
|
{
|
2024-08-26 19:23:03 +00:00
|
|
|
u32 address = m_selectedAddressStart;
|
|
|
|
m_cpu->GetSymbolGuardian().Read([&](const ccc::SymbolDatabase& database) {
|
|
|
|
const ccc::Function* function = database.functions.symbol_overlapping_address(m_selectedAddressStart);
|
|
|
|
if (function)
|
|
|
|
address = function->address().value;
|
|
|
|
});
|
|
|
|
|
|
|
|
auto stub = m_stubbedFunctions.find(address);
|
|
|
|
if (stub != m_stubbedFunctions.end())
|
2023-10-26 22:40:53 +00:00
|
|
|
{
|
2024-08-26 19:23:03 +00:00
|
|
|
Host::RunOnCPUThread([this, address, cpu = m_cpu, stub] {
|
|
|
|
auto [first_instruction, second_instruction] = stub->second;
|
|
|
|
cpu->write32(address, first_instruction);
|
|
|
|
cpu->write32(address + 4, second_instruction);
|
|
|
|
this->m_stubbedFunctions.erase(address);
|
2024-04-07 20:48:28 +00:00
|
|
|
emit VMUpdate();
|
2023-10-26 22:40:53 +00:00
|
|
|
});
|
|
|
|
}
|
2023-10-10 01:02:07 +00:00
|
|
|
else
|
|
|
|
{
|
2023-10-26 22:40:53 +00:00
|
|
|
QMessageBox::warning(this, tr("Restore Function Error"), tr("Unable to stub selected address."));
|
2023-10-10 01:02:07 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-21 23:51:10 +00:00
|
|
|
|
|
|
|
void DisassemblyWidget::contextShowOpcode()
|
|
|
|
{
|
|
|
|
m_showInstructionOpcode = !m_showInstructionOpcode;
|
|
|
|
this->repaint();
|
|
|
|
}
|
|
|
|
|
2022-12-24 06:51:44 +00:00
|
|
|
void DisassemblyWidget::SetCpu(DebugInterface* cpu)
|
|
|
|
{
|
|
|
|
m_cpu = cpu;
|
|
|
|
m_disassemblyManager.setCpu(cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DisassemblyWidget::GetLineDisasm(u32 address)
|
|
|
|
{
|
|
|
|
DisassemblyLineInfo lineInfo;
|
|
|
|
m_disassemblyManager.getLine(address, true, lineInfo);
|
|
|
|
return QString("%1 %2").arg(lineInfo.name.c_str()).arg(lineInfo.params.c_str());
|
|
|
|
};
|
|
|
|
|
|
|
|
// Here we go!
|
|
|
|
void DisassemblyWidget::paintEvent(QPaintEvent* event)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
|
|
|
const u32 w = painter.device()->width() - 1;
|
|
|
|
const u32 h = painter.device()->height() - 1;
|
|
|
|
|
|
|
|
// Get the current font size
|
|
|
|
const QFontMetrics fm = painter.fontMetrics();
|
|
|
|
|
|
|
|
// Get the row height
|
|
|
|
m_rowHeight = fm.height() + 2;
|
|
|
|
|
|
|
|
// Find the amount of visible rows
|
|
|
|
m_visibleRows = h / m_rowHeight;
|
|
|
|
|
|
|
|
m_disassemblyManager.analyze(m_visibleStart, m_disassemblyManager.getNthNextAddress(m_visibleStart, m_visibleRows) - m_visibleStart);
|
|
|
|
|
|
|
|
// Draw the rows
|
|
|
|
bool inSelectionBlock = false;
|
|
|
|
bool alternate = m_visibleStart % 8;
|
|
|
|
|
|
|
|
const u32 curPC = m_cpu->getPC(); // Get the PC here, because it'll change when we are drawing and make it seem like there are two PCs
|
|
|
|
|
|
|
|
for (u32 i = 0; i <= m_visibleRows; i++)
|
|
|
|
{
|
|
|
|
const u32 rowAddress = (i * 4) + m_visibleStart;
|
|
|
|
// Row backgrounds
|
|
|
|
|
|
|
|
if (inSelectionBlock || (m_selectedAddressStart <= rowAddress && rowAddress <= m_selectedAddressEnd))
|
|
|
|
{
|
|
|
|
painter.fillRect(0, i * m_rowHeight, w, m_rowHeight, this->palette().highlight());
|
|
|
|
inSelectionBlock = m_selectedAddressEnd != rowAddress;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
painter.fillRect(0, i * m_rowHeight, w, m_rowHeight, alternate ? this->palette().base() : this->palette().alternateBase());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Row text
|
|
|
|
painter.setPen(GetAddressFunctionColor(rowAddress));
|
2023-10-10 01:38:04 +00:00
|
|
|
QString lineString = DisassemblyStringFromAddress(rowAddress, painter.font(), curPC, rowAddress == m_selectedAddressStart);
|
2022-12-24 06:51:44 +00:00
|
|
|
|
|
|
|
painter.drawText(2, i * m_rowHeight, w, m_rowHeight, Qt::AlignLeft, lineString);
|
2023-10-15 01:22:32 +00:00
|
|
|
|
|
|
|
// Breakpoint marker
|
|
|
|
bool enabled;
|
2023-10-15 15:56:52 +00:00
|
|
|
if (CBreakPoints::IsAddressBreakPoint(m_cpu->getCpuType(), rowAddress, &enabled) && !CBreakPoints::IsTempBreakPoint(m_cpu->getCpuType(), rowAddress))
|
2023-10-15 01:22:32 +00:00
|
|
|
{
|
2023-10-15 15:56:52 +00:00
|
|
|
if (enabled)
|
2023-10-15 01:22:32 +00:00
|
|
|
{
|
|
|
|
painter.setPen(Qt::green);
|
|
|
|
painter.drawText(2, i * m_rowHeight, w, m_rowHeight, Qt::AlignLeft, "\u25A0");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
painter.drawText(2, i * m_rowHeight, w, m_rowHeight, Qt::AlignLeft, "\u2612");
|
|
|
|
}
|
|
|
|
}
|
2022-12-24 06:51:44 +00:00
|
|
|
alternate = !alternate;
|
|
|
|
}
|
|
|
|
// Draw the branch lines
|
|
|
|
// This is where it gets a little scary
|
|
|
|
// It's been mostly copied from the wx implementation
|
|
|
|
|
|
|
|
u32 visibleEnd = m_disassemblyManager.getNthNextAddress(m_visibleStart, m_visibleRows);
|
|
|
|
std::vector<BranchLine> branchLines = m_disassemblyManager.getBranchLines(m_visibleStart, visibleEnd - m_visibleStart);
|
|
|
|
|
|
|
|
s32 branchCount = 0;
|
|
|
|
for (const auto& branchLine : branchLines)
|
|
|
|
{
|
2024-02-21 23:51:10 +00:00
|
|
|
if (branchCount == (m_showInstructionOpcode ? 3 : 5))
|
2022-12-24 06:51:44 +00:00
|
|
|
break;
|
|
|
|
const int winBottom = this->height();
|
|
|
|
|
2024-02-21 23:51:10 +00:00
|
|
|
const int x = this->width() - 10 - (branchCount * 10);
|
2022-12-24 06:51:44 +00:00
|
|
|
|
|
|
|
int top, bottom;
|
|
|
|
// If the start is technically 'above' our address view
|
|
|
|
if (branchLine.first < m_visibleStart)
|
|
|
|
{
|
|
|
|
top = -1;
|
|
|
|
}
|
|
|
|
// If the start is technically 'below' our address view
|
|
|
|
else if (branchLine.first >= visibleEnd)
|
|
|
|
{
|
|
|
|
top = winBottom + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Explaination
|
|
|
|
// ((branchLine.first - m_visibleStart) -> Find the amount of bytes from the top of the view
|
|
|
|
// / 4 -> Convert that into rowss in instructions
|
|
|
|
// * m_rowHeight -> convert that into rows in pixels
|
|
|
|
// + (m_rowHeight / 2) -> Add half a row in pixels to center the arrow
|
|
|
|
top = (((branchLine.first - m_visibleStart) / 4) * m_rowHeight) + (m_rowHeight / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (branchLine.second < m_visibleStart)
|
|
|
|
{
|
|
|
|
bottom = -1;
|
|
|
|
}
|
|
|
|
else if (branchLine.second >= visibleEnd)
|
|
|
|
{
|
|
|
|
bottom = winBottom + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bottom = (((branchLine.second - m_visibleStart) / 4) * m_rowHeight) + (m_rowHeight / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
branchCount++;
|
|
|
|
|
|
|
|
if (branchLine.first == m_selectedAddressStart || branchLine.second == m_selectedAddressStart)
|
|
|
|
{
|
|
|
|
painter.setPen(QColor(0xFF257AFA));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
painter.setPen(QColor(0xFFFF3020));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (top < 0) // first is not visible, but second is
|
|
|
|
{
|
|
|
|
painter.drawLine(x - 2, bottom, x + 2, bottom);
|
|
|
|
painter.drawLine(x + 2, bottom, x + 2, 0);
|
|
|
|
|
|
|
|
if (branchLine.type == LINE_DOWN)
|
|
|
|
{
|
|
|
|
painter.drawLine(x, bottom - 4, x - 4, bottom);
|
|
|
|
painter.drawLine(x - 4, bottom, x + 1, bottom + 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bottom > winBottom) // second is not visible, but first is
|
|
|
|
{
|
|
|
|
painter.drawLine(x - 2, top, x + 2, top);
|
|
|
|
painter.drawLine(x + 2, top, x + 2, winBottom);
|
|
|
|
|
|
|
|
if (branchLine.type == LINE_UP)
|
|
|
|
{
|
|
|
|
painter.drawLine(x, top - 4, x - 4, top);
|
|
|
|
painter.drawLine(x - 4, top, x + 1, top + 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // both are visible
|
|
|
|
if (branchLine.type == LINE_UP)
|
|
|
|
{
|
|
|
|
painter.drawLine(x - 2, bottom, x + 2, bottom);
|
|
|
|
painter.drawLine(x + 2, bottom, x + 2, top);
|
|
|
|
painter.drawLine(x + 2, top, x - 4, top);
|
|
|
|
|
|
|
|
painter.drawLine(x, top - 4, x - 4, top);
|
|
|
|
painter.drawLine(x - 4, top, x + 1, top + 5);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
painter.drawLine(x - 2, top, x + 2, top);
|
|
|
|
painter.drawLine(x + 2, top, x + 2, bottom);
|
|
|
|
painter.drawLine(x + 2, bottom, x - 4, bottom);
|
|
|
|
|
|
|
|
painter.drawLine(x, bottom - 4, x - 4, bottom);
|
|
|
|
painter.drawLine(x - 4, bottom, x + 1, bottom + 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Draw a border
|
|
|
|
painter.setPen(this->palette().shadow().color());
|
|
|
|
painter.drawRect(0, 0, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
2023-01-13 02:41:16 +00:00
|
|
|
const u32 selectedAddress = (static_cast<int>(event->position().y()) / m_rowHeight * 4) + m_visibleStart;
|
2022-12-24 06:51:44 +00:00
|
|
|
if (event->buttons() & Qt::LeftButton)
|
|
|
|
{
|
|
|
|
if (event->modifiers() & Qt::ShiftModifier)
|
|
|
|
{
|
|
|
|
if (selectedAddress < m_selectedAddressStart)
|
|
|
|
{
|
|
|
|
m_selectedAddressStart = selectedAddress;
|
|
|
|
}
|
|
|
|
else if (selectedAddress > m_visibleStart)
|
|
|
|
{
|
|
|
|
m_selectedAddressEnd = selectedAddress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_selectedAddressStart = selectedAddress;
|
|
|
|
m_selectedAddressEnd = selectedAddress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->buttons() & Qt::RightButton)
|
|
|
|
{
|
|
|
|
if (m_selectedAddressStart == m_selectedAddressEnd)
|
|
|
|
{
|
|
|
|
m_selectedAddressStart = selectedAddress;
|
|
|
|
m_selectedAddressEnd = selectedAddress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::mouseDoubleClickEvent(QMouseEvent* event)
|
|
|
|
{
|
2023-01-01 03:43:54 +00:00
|
|
|
if (!m_cpu->isAlive())
|
|
|
|
return;
|
|
|
|
|
2023-01-13 02:41:16 +00:00
|
|
|
const u32 selectedAddress = (static_cast<int>(event->position().y()) / m_rowHeight * 4) + m_visibleStart;
|
2024-04-07 20:48:28 +00:00
|
|
|
const BreakPointCpu cpuType = m_cpu->getCpuType();
|
|
|
|
if (CBreakPoints::IsAddressBreakPoint(cpuType, selectedAddress))
|
2022-12-24 06:51:44 +00:00
|
|
|
{
|
2024-04-07 20:48:28 +00:00
|
|
|
Host::RunOnCPUThread([cpuType, selectedAddress] { CBreakPoints::RemoveBreakPoint(cpuType, selectedAddress); });
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-07 20:48:28 +00:00
|
|
|
Host::RunOnCPUThread([cpuType, selectedAddress] { CBreakPoints::AddBreakPoint(cpuType, selectedAddress); });
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
breakpointsChanged();
|
|
|
|
this->repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::wheelEvent(QWheelEvent* event)
|
|
|
|
{
|
|
|
|
if (event->angleDelta().y() < 0) // todo: max address bounds check?
|
|
|
|
{
|
|
|
|
m_visibleStart += 4;
|
|
|
|
}
|
|
|
|
else if (event->angleDelta().y() && m_visibleStart > 0)
|
|
|
|
{
|
|
|
|
m_visibleStart -= 4;
|
|
|
|
}
|
|
|
|
this->repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::keyPressEvent(QKeyEvent* event)
|
|
|
|
{
|
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Up:
|
|
|
|
{
|
|
|
|
m_selectedAddressStart -= 4;
|
|
|
|
if (!(event->modifiers() & Qt::ShiftModifier))
|
|
|
|
m_selectedAddressEnd = m_selectedAddressStart;
|
|
|
|
|
|
|
|
// Auto scroll
|
|
|
|
if (m_visibleStart > m_selectedAddressStart)
|
|
|
|
m_visibleStart -= 4;
|
|
|
|
}
|
|
|
|
break;
|
2022-12-27 08:29:16 +00:00
|
|
|
case Qt::Key_PageUp:
|
|
|
|
{
|
|
|
|
m_selectedAddressStart -= m_visibleRows * 4;
|
|
|
|
m_selectedAddressEnd = m_selectedAddressStart;
|
|
|
|
m_visibleStart -= m_visibleRows * 4;
|
|
|
|
}
|
|
|
|
break;
|
2022-12-24 06:51:44 +00:00
|
|
|
case Qt::Key_Down:
|
|
|
|
{
|
|
|
|
m_selectedAddressEnd += 4;
|
|
|
|
if (!(event->modifiers() & Qt::ShiftModifier))
|
|
|
|
m_selectedAddressStart = m_selectedAddressEnd;
|
|
|
|
|
|
|
|
// Purposely scroll on the second to last row. It's possible to
|
|
|
|
// size the window so part of a row is visible and we don't want to have half a row selected and cut off!
|
|
|
|
if (m_visibleStart + ((m_visibleRows - 1) * 4) < m_selectedAddressEnd)
|
|
|
|
m_visibleStart += 4;
|
2022-12-27 08:29:16 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Qt::Key_PageDown:
|
|
|
|
{
|
|
|
|
m_selectedAddressStart += m_visibleRows * 4;
|
|
|
|
m_selectedAddressEnd = m_selectedAddressStart;
|
|
|
|
m_visibleStart += m_visibleRows * 4;
|
|
|
|
break;
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
case Qt::Key_G:
|
|
|
|
contextGoToAddress();
|
|
|
|
break;
|
2024-02-21 23:51:10 +00:00
|
|
|
case Qt::Key_J:
|
|
|
|
contextJumpToCursor();
|
|
|
|
break;
|
2022-12-24 06:51:44 +00:00
|
|
|
case Qt::Key_C:
|
|
|
|
contextCopyInstructionText();
|
|
|
|
break;
|
|
|
|
case Qt::Key_B:
|
2023-10-15 00:57:55 +00:00
|
|
|
case Qt::Key_Space:
|
2022-12-24 06:51:44 +00:00
|
|
|
contextToggleBreakpoint();
|
|
|
|
break;
|
|
|
|
case Qt::Key_M:
|
|
|
|
contextAssembleInstruction();
|
|
|
|
break;
|
|
|
|
case Qt::Key_Right:
|
|
|
|
contextFollowBranch();
|
|
|
|
break;
|
|
|
|
case Qt::Key_Left:
|
2024-08-26 19:23:03 +00:00
|
|
|
gotoAddressAndSetFocus(m_cpu->getPC());
|
2022-12-24 06:51:44 +00:00
|
|
|
break;
|
2024-02-21 23:51:10 +00:00
|
|
|
case Qt::Key_O:
|
|
|
|
m_showInstructionOpcode = !m_showInstructionOpcode;
|
|
|
|
break;
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this->repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::customMenuRequested(QPoint pos)
|
|
|
|
{
|
2023-01-01 03:43:54 +00:00
|
|
|
if (!m_cpu->isAlive())
|
|
|
|
return;
|
|
|
|
|
2023-10-10 01:02:07 +00:00
|
|
|
QMenu* contextMenu = new QMenu(this);
|
|
|
|
|
|
|
|
QAction* action = 0;
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Copy Address"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextCopyAddress);
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Copy Instruction Hex"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextCopyInstructionHex);
|
2024-02-21 23:51:10 +00:00
|
|
|
contextMenu->addAction(action = new QAction(tr("&Copy Instruction Text"), this));
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_C));
|
2023-10-10 01:02:07 +00:00
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextCopyInstructionText);
|
2024-08-26 19:23:03 +00:00
|
|
|
if (m_cpu->GetSymbolGuardian().FunctionExistsWithStartingAddress(m_selectedAddressStart))
|
2023-11-21 04:29:01 +00:00
|
|
|
{
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Copy Function Name"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextCopyFunctionName);
|
|
|
|
}
|
2023-10-10 01:02:07 +00:00
|
|
|
contextMenu->addSeparator();
|
|
|
|
if (AddressCanRestore(m_selectedAddressStart, m_selectedAddressEnd))
|
|
|
|
{
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Restore Instruction(s)"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextRestoreInstruction);
|
|
|
|
}
|
2024-02-21 23:51:10 +00:00
|
|
|
contextMenu->addAction(action = new QAction(tr("Asse&mble new Instruction(s)"), this));
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_M));
|
2023-10-10 01:02:07 +00:00
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextAssembleInstruction);
|
|
|
|
contextMenu->addAction(action = new QAction(tr("NOP Instruction(s)"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextNoopInstruction);
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Run to Cursor"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextRunToCursor);
|
2024-02-21 23:51:10 +00:00
|
|
|
contextMenu->addAction(action = new QAction(tr("&Jump to Cursor"), this));
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_J));
|
2023-10-10 01:02:07 +00:00
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextJumpToCursor);
|
2024-02-21 23:51:10 +00:00
|
|
|
contextMenu->addAction(action = new QAction(tr("Toggle &Breakpoint"), this));
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_B));
|
2023-10-10 01:02:07 +00:00
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextToggleBreakpoint);
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Follow Branch"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextFollowBranch);
|
|
|
|
contextMenu->addSeparator();
|
2024-02-21 23:51:10 +00:00
|
|
|
contextMenu->addAction(action = new QAction(tr("&Go to Address"), this));
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_G));
|
2023-10-10 01:02:07 +00:00
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextGoToAddress);
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Go to in Memory View"), this));
|
|
|
|
connect(action, &QAction::triggered, this, [this]() { gotoInMemory(m_selectedAddressStart); });
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Add Function"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextAddFunction);
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Rename Function"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextRenameFunction);
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Remove Function"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextRemoveFunction);
|
|
|
|
if (FunctionCanRestore(m_selectedAddressStart))
|
|
|
|
{
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Restore Function"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextRestoreFunction);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Stub (NOP) Function"), this));
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextStubFunction);
|
|
|
|
}
|
2024-02-21 23:51:10 +00:00
|
|
|
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction(action = new QAction(tr("Show &Opcode"), this));
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_O));
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setChecked(m_showInstructionOpcode);
|
|
|
|
connect(action, &QAction::triggered, this, &DisassemblyWidget::contextShowOpcode);
|
|
|
|
|
2023-10-10 01:02:07 +00:00
|
|
|
contextMenu->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
contextMenu->popup(this->mapToGlobal(pos));
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 01:38:04 +00:00
|
|
|
inline QString DisassemblyWidget::DisassemblyStringFromAddress(u32 address, QFont font, u32 pc, bool selected)
|
2022-12-24 06:51:44 +00:00
|
|
|
{
|
|
|
|
DisassemblyLineInfo line;
|
|
|
|
|
|
|
|
if (!m_cpu->isValidAddress(address))
|
2022-12-24 11:17:52 +00:00
|
|
|
return tr("%1 NOT VALID ADDRESS").arg(address, 8, 16, QChar('0')).toUpper();
|
2022-12-24 06:51:44 +00:00
|
|
|
// Todo? support non symbol view?
|
|
|
|
m_disassemblyManager.getLine(address, true, line);
|
|
|
|
|
|
|
|
const bool isConditional = line.info.isConditional && m_cpu->getPC() == address;
|
|
|
|
const bool isConditionalMet = line.info.conditionMet;
|
|
|
|
const bool isCurrentPC = m_cpu->getPC() == address;
|
|
|
|
|
2024-08-26 19:23:03 +00:00
|
|
|
FunctionInfo function = m_cpu->GetSymbolGuardian().FunctionStartingAtAddress(address);
|
|
|
|
SymbolInfo symbol = m_cpu->GetSymbolGuardian().SymbolStartingAtAddress(address);
|
2024-02-23 05:34:27 +00:00
|
|
|
const bool showOpcode = m_showInstructionOpcode && m_cpu->isAlive();
|
2023-10-10 01:52:12 +00:00
|
|
|
|
2024-02-21 23:51:10 +00:00
|
|
|
QString lineString;
|
2024-02-23 05:34:27 +00:00
|
|
|
if (showOpcode)
|
2024-02-21 23:51:10 +00:00
|
|
|
{
|
2024-02-23 18:39:31 +00:00
|
|
|
lineString = QString(" %1 %2 %3 %4 %5 %6 %7");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lineString = QString(" %1 %2 %3 %4 %5 %6");
|
|
|
|
}
|
|
|
|
|
2024-08-26 19:23:03 +00:00
|
|
|
if (function.is_no_return)
|
2024-02-23 18:39:31 +00:00
|
|
|
{
|
|
|
|
lineString = lineString.arg("NR");
|
2024-02-21 23:51:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-23 18:39:31 +00:00
|
|
|
lineString = lineString.arg(" ");
|
2024-02-21 23:51:10 +00:00
|
|
|
}
|
2022-12-24 06:51:44 +00:00
|
|
|
|
2024-08-26 19:23:03 +00:00
|
|
|
if (symbol.name.empty())
|
2022-12-24 06:51:44 +00:00
|
|
|
lineString = lineString.arg(address, 8, 16, QChar('0')).toUpper();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QFontMetrics metric(font);
|
2024-08-26 19:23:03 +00:00
|
|
|
QString symbolString = QString::fromStdString(symbol.name);
|
2023-10-15 15:56:52 +00:00
|
|
|
|
2024-02-23 18:39:31 +00:00
|
|
|
lineString = lineString.arg(metric.elidedText(symbolString, Qt::ElideRight, (selected ? 32 : 7) * font.pointSize()));
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
|
2024-02-23 05:34:27 +00:00
|
|
|
if (showOpcode)
|
|
|
|
{
|
|
|
|
const u32 opcode = m_cpu->read32(address);
|
2024-02-21 23:51:10 +00:00
|
|
|
lineString = lineString.arg(QtUtils::FilledQStringFromValue(opcode, 16));
|
2024-02-23 05:34:27 +00:00
|
|
|
}
|
2024-02-21 23:51:10 +00:00
|
|
|
|
2022-12-24 06:51:44 +00:00
|
|
|
lineString = lineString.leftJustified(4, ' ') // Address / symbol
|
|
|
|
.arg(line.name.c_str())
|
|
|
|
.arg(line.params.c_str()) // opcode + arguments
|
|
|
|
.arg(isConditional ? (isConditionalMet ? "# true" : "# false") : "")
|
|
|
|
.arg(isCurrentPC ? "<--" : "");
|
|
|
|
|
|
|
|
return lineString;
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor DisassemblyWidget::GetAddressFunctionColor(u32 address)
|
|
|
|
{
|
|
|
|
// This is an attempt to figure out if the current palette is dark or light
|
2024-02-21 23:51:10 +00:00
|
|
|
// We calculate the luminance of the alternateBase colour
|
2022-12-24 06:51:44 +00:00
|
|
|
// and swap between our darker and lighter function colours
|
|
|
|
|
|
|
|
std::array<QColor, 6> colors;
|
|
|
|
const QColor base = this->palette().alternateBase().color();
|
|
|
|
|
2022-12-27 08:29:16 +00:00
|
|
|
const auto Y = (base.redF() * 0.33) + (0.5 * base.greenF()) + (0.16 * base.blueF());
|
2022-12-24 06:51:44 +00:00
|
|
|
|
|
|
|
if (Y > 0.5)
|
|
|
|
{
|
|
|
|
colors = {
|
|
|
|
QColor::fromRgba(0xFFFA3434),
|
|
|
|
QColor::fromRgba(0xFF206b6b),
|
|
|
|
QColor::fromRgba(0xFF858534),
|
|
|
|
QColor::fromRgba(0xFF378c37),
|
|
|
|
QColor::fromRgba(0xFF783278),
|
|
|
|
QColor::fromRgba(0xFF21214a),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
colors = {
|
|
|
|
QColor::fromRgba(0xFFe05555),
|
|
|
|
QColor::fromRgba(0xFF55e0e0),
|
|
|
|
QColor::fromRgba(0xFFe8e855),
|
|
|
|
QColor::fromRgba(0xFF55e055),
|
|
|
|
QColor::fromRgba(0xFFe055e0),
|
|
|
|
QColor::fromRgba(0xFFC2C2F5),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-08-26 19:23:03 +00:00
|
|
|
ccc::FunctionHandle handle = m_cpu->GetSymbolGuardian().FunctionOverlappingAddress(address).handle;
|
|
|
|
if (!handle.valid())
|
|
|
|
return palette().text().color();
|
2022-12-24 06:51:44 +00:00
|
|
|
|
2024-08-26 19:23:03 +00:00
|
|
|
return colors[handle.value % colors.size()];
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString DisassemblyWidget::FetchSelectionInfo(SelectionInfo selInfo)
|
|
|
|
{
|
|
|
|
QString infoBlock;
|
|
|
|
for (u32 i = m_selectedAddressStart; i <= m_selectedAddressEnd; i += 4)
|
|
|
|
{
|
|
|
|
if (i != m_selectedAddressStart)
|
|
|
|
infoBlock += '\n';
|
|
|
|
if (selInfo == SelectionInfo::ADDRESS)
|
|
|
|
{
|
|
|
|
infoBlock += FilledQStringFromValue(i, 16);
|
|
|
|
}
|
|
|
|
else if (selInfo == SelectionInfo::INSTRUCTIONTEXT)
|
|
|
|
{
|
|
|
|
DisassemblyLineInfo line;
|
|
|
|
m_disassemblyManager.getLine(i, true, line);
|
|
|
|
infoBlock += QString("%1 %2").arg(line.name.c_str()).arg(line.params.c_str());
|
|
|
|
}
|
|
|
|
else // INSTRUCTIONHEX
|
|
|
|
{
|
|
|
|
infoBlock += FilledQStringFromValue(m_cpu->read32(i), 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return infoBlock;
|
|
|
|
}
|
|
|
|
|
2024-08-26 19:23:03 +00:00
|
|
|
void DisassemblyWidget::gotoAddressAndSetFocus(u32 address)
|
|
|
|
{
|
|
|
|
gotoAddress(address, true);
|
|
|
|
}
|
|
|
|
|
2023-12-14 19:40:23 +00:00
|
|
|
void DisassemblyWidget::gotoAddress(u32 address, bool should_set_focus)
|
2022-12-24 06:51:44 +00:00
|
|
|
{
|
|
|
|
const u32 destAddress = address & ~3;
|
|
|
|
// Center the address
|
|
|
|
m_visibleStart = (destAddress - (m_visibleRows * 4 / 2)) & ~3;
|
|
|
|
m_selectedAddressStart = destAddress;
|
|
|
|
m_selectedAddressEnd = destAddress;
|
|
|
|
|
|
|
|
this->repaint();
|
2024-02-21 23:51:10 +00:00
|
|
|
if (should_set_focus)
|
2023-12-14 19:40:23 +00:00
|
|
|
this->setFocus();
|
2022-12-24 06:51:44 +00:00
|
|
|
}
|
2023-10-10 01:02:07 +00:00
|
|
|
|
|
|
|
bool DisassemblyWidget::AddressCanRestore(u32 start, u32 end)
|
|
|
|
{
|
|
|
|
for (u32 i = start; i <= end; i += 4)
|
|
|
|
{
|
|
|
|
if (this->m_nopedInstructions.find(i) != this->m_nopedInstructions.end())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisassemblyWidget::FunctionCanRestore(u32 address)
|
|
|
|
{
|
2024-08-26 19:23:03 +00:00
|
|
|
FunctionInfo function = m_cpu->GetSymbolGuardian().FunctionOverlappingAddress(address);
|
|
|
|
if (function.address.valid())
|
|
|
|
address = function.address.value;
|
2023-10-10 01:02:07 +00:00
|
|
|
|
2024-08-26 19:23:03 +00:00
|
|
|
return m_stubbedFunctions.find(address) != m_stubbedFunctions.end();
|
2023-10-10 01:02:07 +00:00
|
|
|
}
|