duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

debuggermodels.h (3811B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
      3 
      4 #pragma once
      5 
      6 #include "ui_debuggeraddbreakpointdialog.h"
      7 
      8 #include "core/bus.h"
      9 #include "core/cpu_core.h"
     10 #include "core/cpu_types.h"
     11 
     12 #include <QtCore/QAbstractListModel>
     13 #include <QtCore/QAbstractTableModel>
     14 #include <QtGui/QPixmap>
     15 #include <QtWidgets/QDialog>
     16 #include <map>
     17 
     18 class DebuggerCodeModel final : public QAbstractTableModel
     19 {
     20   Q_OBJECT
     21 
     22 public:
     23   DebuggerCodeModel(QObject* parent = nullptr);
     24   ~DebuggerCodeModel() override;
     25 
     26   int rowCount(const QModelIndex& parent = QModelIndex()) const override;
     27   int columnCount(const QModelIndex& parent = QModelIndex()) const override;
     28   QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
     29   QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
     30 
     31   // Returns the row for this instruction pointer
     32   void resetCodeView(VirtualMemoryAddress start_address);
     33   int getRowForAddress(VirtualMemoryAddress address) const;
     34   int getRowForPC() const;
     35   VirtualMemoryAddress getAddressForRow(int row) const;
     36   VirtualMemoryAddress getAddressForIndex(QModelIndex index) const;
     37   void setPC(VirtualMemoryAddress pc);
     38   void ensureAddressVisible(VirtualMemoryAddress address);
     39   void setBreakpointList(std::vector<VirtualMemoryAddress> bps);
     40   void setBreakpointState(VirtualMemoryAddress address, bool enabled);
     41   void clearBreakpoints();
     42 
     43 private:
     44   bool updateRegion(VirtualMemoryAddress address);
     45   bool emitDataChangedForAddress(VirtualMemoryAddress address);
     46   bool hasBreakpointAtAddress(VirtualMemoryAddress address) const;
     47 
     48   Bus::MemoryRegion m_current_code_region = Bus::MemoryRegion::Count;
     49   CPU::Segment m_current_segment = CPU::Segment::KUSEG;
     50   VirtualMemoryAddress m_code_region_start = 0;
     51   VirtualMemoryAddress m_code_region_end = 0;
     52   VirtualMemoryAddress m_last_pc = 0;
     53   std::vector<VirtualMemoryAddress> m_breakpoints;
     54 
     55   QPixmap m_pc_pixmap;
     56   QPixmap m_breakpoint_pixmap;
     57 };
     58 
     59 class DebuggerRegistersModel final : public QAbstractListModel
     60 {
     61   Q_OBJECT
     62 
     63 public:
     64   DebuggerRegistersModel(QObject* parent = nullptr);
     65   ~DebuggerRegistersModel() override;
     66 
     67   int rowCount(const QModelIndex& parent = QModelIndex()) const override;
     68   int columnCount(const QModelIndex& parent = QModelIndex()) const override;
     69   QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
     70   QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
     71 
     72   void updateValues();
     73   void saveCurrentValues();
     74 
     75 private:
     76   std::array<u32, CPU::NUM_DEBUGGER_REGISTER_LIST_ENTRIES> m_reg_values = {};
     77   std::array<u32, CPU::NUM_DEBUGGER_REGISTER_LIST_ENTRIES> m_old_reg_values = {};
     78 };
     79 
     80 class DebuggerStackModel final : public QAbstractListModel
     81 {
     82   Q_OBJECT
     83 
     84 public:
     85   DebuggerStackModel(QObject* parent = nullptr);
     86   ~DebuggerStackModel() override;
     87 
     88   int rowCount(const QModelIndex& parent = QModelIndex()) const override;
     89   int columnCount(const QModelIndex& parent = QModelIndex()) const override;
     90   QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
     91   QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
     92 
     93   void invalidateView();
     94 };
     95 
     96 class DebuggerAddBreakpointDialog final : public QDialog
     97 {
     98   Q_OBJECT
     99 
    100 public:
    101   DebuggerAddBreakpointDialog(QWidget* parent = nullptr);
    102   ~DebuggerAddBreakpointDialog() override;
    103 
    104   u32 getAddress() const { return m_address; }
    105   CPU::BreakpointType getType() const { return m_type; }
    106 
    107 private Q_SLOTS:
    108   void okClicked();
    109 
    110 private:
    111   Ui::DebuggerAddBreakpointDialog m_ui;
    112   u32 m_address = 0;
    113   CPU::BreakpointType m_type = CPU::BreakpointType::Execute;
    114 };