mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-03 10:26:36 +00:00
Starting to load symbols
This commit is contained in:
@@ -10,19 +10,21 @@
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <QMessageBox>
|
||||
#include <fstream>
|
||||
|
||||
using namespace ComSquare::CPU;
|
||||
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
CPUDebug::CPUDebug(CPU &basicCPU, SNES &snes)
|
||||
CPUDebug::CPUDebug(const CPU &basicCPU, SNES &snes)
|
||||
: CPU(basicCPU),
|
||||
_window(new ClosableWindow<CPUDebug>(*this, &CPUDebug::disableDebugger)),
|
||||
_ui(),
|
||||
_model(*this),
|
||||
_painter(*this),
|
||||
_stackModel(this->_bus, *this),
|
||||
_snes(snes)
|
||||
_snes(snes),
|
||||
_labels(this->_loadLabels(snes.cartridge->getRomPath()))
|
||||
{
|
||||
this->_window->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
this->_window->setAttribute(Qt::WA_QuitOnClose, false);
|
||||
@@ -306,6 +308,21 @@ namespace ComSquare::Debugger
|
||||
return "";
|
||||
return "[" + Utility::to_hex(valueAddr, Utility::AsmPrefix) + "]";
|
||||
}
|
||||
|
||||
std::vector<Label> CPUDebug::_loadLabels(std::filesystem::path romPath) const
|
||||
{
|
||||
std::vector<Label> labels;
|
||||
std::string symbolPath = romPath.replace_extension(".sym");
|
||||
std::ifstream sym(symbolPath);
|
||||
|
||||
if (sym) {
|
||||
std::vector<Label> symLabels = WlaDx.parse(sym);
|
||||
labels.insert(labels.end(),
|
||||
std::make_move_iterator(symLabels.begin()),
|
||||
std::make_move_iterator(symLabels.end()));
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
}
|
||||
|
||||
DisassemblyModel::DisassemblyModel(ComSquare::Debugger::CPUDebug &cpu) : QAbstractTableModel(), _cpu(cpu){ }
|
||||
|
||||
@@ -168,6 +168,16 @@ namespace ComSquare::Debugger
|
||||
bool oneTime;
|
||||
};
|
||||
|
||||
//! @brief Struct representing a label.
|
||||
struct Label {
|
||||
//! @brief The address of this label
|
||||
uint24_t address;
|
||||
//! @brief The name of this label
|
||||
std::string name;
|
||||
//! @brief The size of the definition related to this label
|
||||
std::optional<unsigned> size;
|
||||
};
|
||||
|
||||
//! @brief A custom CPU with a window that show it's registers and the disassembly.
|
||||
class CPUDebug : public CPU::CPU, public QObject {
|
||||
private:
|
||||
@@ -189,6 +199,11 @@ namespace ComSquare::Debugger
|
||||
bool _isStepping = false;
|
||||
//! @brief A reference to the snes (to disable the debugger).
|
||||
SNES &_snes;
|
||||
//! @brief A list of labels and their size.
|
||||
std::vector<Label> _labels;
|
||||
|
||||
//! @brief Load labels from a symbol file.
|
||||
std::vector<Label> _loadLabels(std::filesystem::path romPath) const;
|
||||
//! @brief Reimplement the basic instruction execution method to log instructions inside the logger view.
|
||||
unsigned _executeInstruction(uint8_t opcode) override;
|
||||
//! @brief Return a disassembly context representing the current state of the processor.
|
||||
@@ -239,7 +254,7 @@ namespace ComSquare::Debugger
|
||||
//! @brief Return a printable string corresponding to the value of a stack relative addressing mode.
|
||||
std::string _getStackRelativeValue(uint24_t pc);
|
||||
//! @brief Return a printable string corresponding to the value of a stack relative indirect indexed by y addressing mode.
|
||||
std::string _getStackRelativeIndiretIndexdeByYValue(uint24_t pc);
|
||||
std::string _getStackRelativeIndirectIndexedByYValue(uint24_t pc);
|
||||
//! @brief Return a printable string corresponding to the value of a absolute indirect addressing mode.
|
||||
std::string _getAbsoluteIndirectValue(uint24_t pc);
|
||||
//! @brief Return a printable string corresponding to the value of a absolute indirect indexed by x addressing mode.
|
||||
@@ -276,8 +291,10 @@ namespace ComSquare::Debugger
|
||||
uint16_t initialStackPointer = this->_registers.s;
|
||||
//! @brief Update the UI when resetting the CPU.
|
||||
int RESB() override;
|
||||
|
||||
|
||||
//! @brief Convert a basic CPU to a debugging CPU.
|
||||
explicit CPUDebug(ComSquare::CPU::CPU &cpu, SNES &snes);
|
||||
CPUDebug(const ComSquare::CPU::CPU &cpu, SNES &snes);
|
||||
CPUDebug(const CPUDebug &) = delete;
|
||||
CPUDebug &operator=(const CPUDebug &) = delete;
|
||||
~CPUDebug() override = default;
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace ComSquare::Debugger
|
||||
case StackRelative:
|
||||
return this->_getStackRelativeValue(pc);
|
||||
case StackRelativeIndirectIndexedByY:
|
||||
return this->_getStackRelativeIndiretIndexdeByYValue(pc);
|
||||
return this->_getStackRelativeIndirectIndexedByYValue(pc);
|
||||
case AbsoluteIndirect:
|
||||
return this->_getAbsoluteIndirectValue(pc);
|
||||
case AbsoluteIndirectIndexedByX:
|
||||
@@ -244,7 +244,7 @@ namespace ComSquare::Debugger
|
||||
return Utility::to_hex(this->_bus->read(pc, true), Utility::AsmPrefix) + ", s";
|
||||
}
|
||||
|
||||
std::string CPUDebug::_getStackRelativeIndiretIndexdeByYValue(uint24_t pc)
|
||||
std::string CPUDebug::_getStackRelativeIndirectIndexedByYValue(uint24_t pc)
|
||||
{
|
||||
return "(" + Utility::to_hex(this->_bus->read(pc, true), Utility::AsmPrefix) + ", s), y";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by Zoe Roux on 2/6/21.
|
||||
//
|
||||
|
||||
#include "WlaDx.hpp"
|
||||
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
std::vector<Label> WlaDx::parse(std::fstream symbolFile)
|
||||
{
|
||||
std::vector<Label> labels;
|
||||
|
||||
|
||||
return labels;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by Zoe Roux on 2/6/21.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../CPUDebug.hpp"
|
||||
#include <fstream>
|
||||
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
//! @brief Class to parse WLA-DX symbol files.
|
||||
class WlaDx {
|
||||
public:
|
||||
static std::vector<Label> parse(std::fstream symbolFile);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user