Starting to load symbols

This commit is contained in:
Zoe Roux
2021-02-06 18:29:15 +01:00
parent 0e16f81042
commit a826168eb2
8 changed files with 90 additions and 8 deletions
+1 -1
View File
@@ -220,7 +220,7 @@ add_executable(ComSquare
ui/registersView.ui
sources/Debugger/RegisterViewer.cpp
sources/Debugger/RegisterViewer.hpp
sources/Memory/IMemory.hpp)
sources/Memory/IMemory.hpp sources/Debugger/CPU/SymbolLoaders/WlaDx.cpp sources/Debugger/CPU/SymbolLoaders/WlaDx.hpp)
target_compile_definitions(ComSquare PUBLIC DEBUGGER_ENABLED)
+7 -1
View File
@@ -12,7 +12,8 @@
namespace ComSquare::Cartridge
{
Cartridge::Cartridge(const std::string &romPath)
: Ram::Ram(0, Rom, "Cartridge")
: Ram::Ram(0, Rom, "Cartridge"),
_romPath(romPath)
{
if (romPath.empty())
throw InvalidRomException("Path is empty.");
@@ -48,6 +49,11 @@ namespace ComSquare::Cartridge
throw InvalidAction("Witting to the ROM is not allowed.");
}
std::filesystem::path Cartridge::getRomPath() const
{
return this->_romPath;
}
Header Cartridge::_mapHeader(uint32_t headerAddress)
{
Header head;
+7
View File
@@ -5,6 +5,7 @@
#pragma once
#include <string>
#include <filesystem>
#include "../Memory/AMemory.hpp"
#include "../Models/Int24.hpp"
#include "../Memory/ARectangleMemory.hpp"
@@ -65,6 +66,8 @@ namespace ComSquare::Cartridge
//! @brief Contains the rom's memory/instructions.
class Cartridge : public Ram::Ram {
private:
//! @brief The path of the currently loaded rom.
std::string _romPath;
//! @brief Sometime the rom's data has an offset for a SMC header. This value indicate the start of the real rom discarding this header.
uint16_t _romStart = 0;
@@ -104,5 +107,9 @@ namespace ComSquare::Cartridge
//! @param data The data to write.
//! @throw InvalidAddress will be thrown if the address is more than the size of the rom's memory.
void write(uint24_t addr, uint8_t data) override;
//! @brief The path of the rom file
//! @return The path of the currently loaded rom file.
std::filesystem::path getRomPath() const;
};
}
+19 -2
View File
@@ -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){ }
+19 -2
View File
@@ -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;
+2 -2
View File
@@ -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);
};
}