Debian Codegraph @

Source/Core/DolphinQt/Debugger/BranchWatchTableModel.h

raw symbols SCIP
1 // Copyright 2024 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <cstdio>
7
8 #include <QAbstractTableModel>
9 #include <QFont>
10 #include <QList>
11 #include <QVariant>
12
13 #include "Common/SymbolDB.h"
14
15 namespace Core
16 {
17 class BranchWatch;
18 enum class BranchWatchSelectionInspection : u8;
19 struct BranchWatchSelectionValueType;
20 class CPUThreadGuard;
21 class System;
22 } // namespace Core
23 class PPCSymbolDB;
24
25 namespace BranchWatchTableModelColumn
26 {
27 enum EnumType : int
28 {
29 Instruction = 0,
30 Condition,
31 Origin,
32 Destination,
33 RecentHits,
34 TotalHits,
35 OriginSymbol,
36 DestinSymbol,
37 NumberOfColumns,
38 };
39 }
40
41 namespace BranchWatchTableModelUserRole
42 {
43 enum EnumType : int
44 {
45 ClickRole = Qt::UserRole,
46 SortRole,
47 };
48 }
49
50 struct BranchWatchTableModelSymbolListValueType
51 {
52 explicit BranchWatchTableModelSymbolListValueType(const Common::Symbol* const origin_symbol,
53 const Common::Symbol* const destin_symbol)
54 : origin_name(origin_symbol ? QString::fromStdString(origin_symbol->name) : QVariant{}),
55 origin_addr(origin_symbol ? origin_symbol->address : QVariant{}),
56 destin_name(destin_symbol ? QString::fromStdString(destin_symbol->name) : QVariant{}),
57 destin_addr(destin_symbol ? destin_symbol->address : QVariant{})
58 {
59 }
60 QVariant origin_name, origin_addr;
61 QVariant destin_name, destin_addr;
62 };
63
64 class BranchWatchTableModel final : public QAbstractTableModel
65 {
66 Q_OBJECT
67
68 public:
69 using Column = BranchWatchTableModelColumn::EnumType;
70 using UserRole = BranchWatchTableModelUserRole::EnumType;
71 using SymbolListValueType = BranchWatchTableModelSymbolListValueType;
72 using SymbolList = QList<SymbolListValueType>;
73
74 explicit BranchWatchTableModel(Core::System& system, Core::BranchWatch& branch_watch,
75 PPCSymbolDB& ppc_symbol_db, QObject* parent = nullptr)
76 : QAbstractTableModel(parent), m_system(system), m_branch_watch(branch_watch),
77 m_ppc_symbol_db(ppc_symbol_db)
78 {
79 }
80 ~BranchWatchTableModel() override = default;
81
82 BranchWatchTableModel(const BranchWatchTableModel&) = delete;
83 BranchWatchTableModel(BranchWatchTableModel&&) = delete;
84 BranchWatchTableModel& operator=(const BranchWatchTableModel&) = delete;
85 BranchWatchTableModel& operator=(BranchWatchTableModel&&) = delete;
86
87 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
88 QVariant headerData(int section, Qt::Orientation orientation,
89 int role = Qt::DisplayRole) const override;
90 int rowCount(const QModelIndex& parent = QModelIndex{}) const override;
91 int columnCount(const QModelIndex& parent = QModelIndex{}) const override;
92 bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex{}) override;
93 void setFont(const QFont& font) { m_font = font; }
94
95 void OnClearBranchWatch(const Core::CPUThreadGuard& guard);
96 void OnCodePathWasTaken(const Core::CPUThreadGuard& guard);
97 void OnCodePathNotTaken(const Core::CPUThreadGuard& guard);
98 void OnBranchWasOverwritten(const Core::CPUThreadGuard& guard);
99 void OnBranchNotOverwritten(const Core::CPUThreadGuard& guard);
100 void OnWipeRecentHits();
101 void OnWipeInspection();
102 void OnDebugFontChanged(const QFont& font);
103 void OnPPCSymbolsChanged();
104
105 void Save(const Core::CPUThreadGuard& guard, std::FILE* file) const;
106 void Load(const Core::CPUThreadGuard& guard, std::FILE* file);
107 void UpdateSymbols();
108 void UpdateHits();
109 void SetInspected(const QModelIndex& index);
110
111 const Core::BranchWatchSelectionValueType&
112 GetBranchWatchSelection(const QModelIndex& index) const;
113 const SymbolList& GetSymbolList() const { return m_symbol_list; }
114
115 private:
116 void SetInspected(const QModelIndex& index, Core::BranchWatchSelectionInspection inspection);
117 void SetOriginInspected(u32 origin_addr);
118 void SetDestinInspected(u32 destin_addr, bool nested);
119 void SetSymbolInspected(u32 symbol_addr, bool nested);
120 void PrefetchSymbols();
121
122 [[nodiscard]] QVariant DisplayRoleData(const QModelIndex& index) const;
123 [[nodiscard]] QVariant FontRoleData(const QModelIndex& index) const;
124 [[nodiscard]] QVariant TextAlignmentRoleData(const QModelIndex& index) const;
125 [[nodiscard]] QVariant ForegroundRoleData(const QModelIndex& index) const;
126 [[nodiscard]] QVariant ClickRoleData(const QModelIndex& index) const;
127 [[nodiscard]] QVariant SortRoleData(const QModelIndex& index) const;
128
129 Core::System& m_system;
130 Core::BranchWatch& m_branch_watch;
131 PPCSymbolDB& m_ppc_symbol_db;
132
133 SymbolList m_symbol_list;
134 mutable QFont m_font;
135 };