From c6e4cd1702689962a9a3b60100a814ee6565ab9e Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Thu, 14 May 2020 15:51:48 +0200 Subject: [PATCH] Fixing a segfault with the bus & cpu's debugger together --- sources/CPU/CPU.cpp | 2 -- sources/CPU/CPU.hpp | 2 +- sources/Debugger/CPU/CPUDebug.cpp | 19 ++++++++++++++----- sources/Debugger/CPU/CPUDebug.hpp | 10 ++++++++-- ui/ui_cpu.h | 2 +- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp index 8116408..cd9ddca 100644 --- a/sources/CPU/CPU.cpp +++ b/sources/CPU/CPU.cpp @@ -6,9 +6,7 @@ #include #include -#include "../Exceptions/NotImplementedException.hpp" #include "../Exceptions/InvalidAddress.hpp" -#include "../Exceptions/InvalidOpcode.hpp" namespace ComSquare::CPU { diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp index 26dde23..f127d41 100644 --- a/sources/CPU/CPU.hpp +++ b/sources/CPU/CPU.hpp @@ -713,7 +713,7 @@ namespace ComSquare::CPU virtual bool isDebugger(); //! @brief Change the memory bus used by the CPU. - void setMemoryBus(std::shared_ptr bus); + virtual void setMemoryBus(std::shared_ptr bus); }; } diff --git a/sources/Debugger/CPU/CPUDebug.cpp b/sources/Debugger/CPU/CPUDebug.cpp index 5be3734..6bcb800 100644 --- a/sources/Debugger/CPU/CPUDebug.cpp +++ b/sources/Debugger/CPU/CPUDebug.cpp @@ -5,11 +5,9 @@ #include "CPUDebug.hpp" #include "../../Utility/Utility.hpp" #include "../../Exceptions/InvalidOpcode.hpp" -#include "../../CPU/CPU.hpp" #include #include #include -#include using namespace ComSquare::CPU; @@ -21,7 +19,7 @@ namespace ComSquare::Debugger _ui(), _model(*this), _painter(*this), - _stackModel(*this->_bus, *this), + _stackModel(this->_bus, *this), _snes(snes) { this->_window->setContextMenuPolicy(Qt::NoContextMenu); @@ -70,6 +68,12 @@ namespace ComSquare::Debugger this->_snes.disableCPUDebugging(); } + void CPUDebug::setMemoryBus(std::shared_ptr bus) + { + this->_stackModel.setMemoryBus(bus); + CPU::setMemoryBus(bus); + } + unsigned CPUDebug::update() { try { @@ -379,7 +383,12 @@ QSize RowPainter::sizeHint(const QStyleOptionViewItem &, const QModelIndex &) co return QSize(); } -StackModel::StackModel(ComSquare::Memory::MemoryBus &bus, ComSquare::Debugger::CPUDebug &cpu) : _bus(bus), _cpu(cpu) { } +StackModel::StackModel(std::shared_ptr bus, ComSquare::Debugger::CPUDebug &cpu) : _bus(bus), _cpu(cpu) { } + +void StackModel::setMemoryBus(std::shared_ptr bus) +{ + this->_bus = std::move(bus); +} int StackModel::rowCount(const QModelIndex &) const { @@ -405,7 +414,7 @@ QVariant StackModel::data(const QModelIndex &index, int role) const return QVariant(); uint16_t addr = index.row() * 2 + index.column(); try { - uint8_t value = this->_bus.read(addr); + uint8_t value = this->_bus->read(addr); return (ComSquare::Utility::to_hex(value, ComSquare::Utility::NoPrefix).c_str()); } catch (std::exception &) { return "??"; diff --git a/sources/Debugger/CPU/CPUDebug.hpp b/sources/Debugger/CPU/CPUDebug.hpp index ab596d0..db00d37 100644 --- a/sources/Debugger/CPU/CPUDebug.hpp +++ b/sources/Debugger/CPU/CPUDebug.hpp @@ -34,10 +34,10 @@ class StackModel : public QAbstractTableModel { Q_OBJECT private: - ComSquare::Memory::MemoryBus &_bus; + std::shared_ptr _bus; ComSquare::Debugger::CPUDebug &_cpu; public: - explicit StackModel(ComSquare::Memory::MemoryBus &bus, ComSquare::Debugger::CPUDebug &cpu); + explicit StackModel(std::shared_ptr bus, ComSquare::Debugger::CPUDebug &cpu); StackModel(const StackModel &) = delete; const StackModel &operator=(const StackModel &) = delete; ~StackModel() override = default; @@ -50,6 +50,9 @@ public: QVariant data(const QModelIndex &index, int role) const override; //! @brief Override the headers to use hex values. QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + + //! @brief Change the memory bus used by the view. + void setMemoryBus(std::shared_ptr bus); }; //! @brief The qt model that show the history. @@ -285,6 +288,9 @@ namespace ComSquare::Debugger //! @brief Override the basic cpu's update to allow pausing of the CPU only. unsigned update() override; + + //! @brief Change the memory bus used by the CPU. + void setMemoryBus(std::shared_ptr bus) override; }; } diff --git a/ui/ui_cpu.h b/ui/ui_cpu.h index 97769dd..b7aafd0 100644 --- a/ui/ui_cpu.h +++ b/ui/ui_cpu.h @@ -1,7 +1,7 @@ /******************************************************************************** ** Form generated from reading UI file 'cpu.ui' ** -** Created by: Qt User Interface Compiler version 5.14.1 +** Created by: Qt User Interface Compiler version 5.14.2 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/