| 1 | #ifndef DEBUGGERFORM_H |
| 2 | #define DEBUGGERFORM_H |
| 3 | |
| 4 | #include "DockableWidgetArea.h" |
| 5 | #include "DockManager.h" |
| 6 | #include "DebugSession.h" |
| 7 | #include "SymbolManager.h" |
| 8 | #include "CommandDialog.h" |
| 9 | #include <QMainWindow> |
| 10 | #include <QMap> |
| 11 | #include <QPointer> |
| 12 | #include <cstdint> |
| 13 | #include <memory> |
| 14 | |
| 15 | class DisasmViewer; |
| 16 | class MainMemoryViewer; |
| 17 | class CPURegsViewer; |
| 18 | class FlagsViewer; |
| 19 | class StackViewer; |
| 20 | class SlotViewer; |
| 21 | class CommClient; |
| 22 | class QAction; |
| 23 | class QMenu; |
| 24 | class QToolBar; |
| 25 | class VDPStatusRegViewer; |
| 26 | class VDPRegViewer; |
| 27 | class VDPCommandRegViewer; |
| 28 | class BreakpointViewer; |
| 29 | |
| 30 | |
| 31 | class DebuggerForm : public QMainWindow |
| 32 | { |
| 33 | Q_OBJECT |
| 34 | public: |
| 35 | DebuggerForm(QWidget* parent = nullptr); |
| 36 | |
| 37 | void showAbout(); |
| 38 | void reloadBreakpoints(bool merge = false); |
| 39 | void onSlotsUpdated(bool slotsChanged); |
| 40 | void onPCChanged(uint16_t address); |
| 41 | |
| 42 | private: |
| 43 | void closeEvent(QCloseEvent* e) override; |
| 44 | |
| 45 | void createActions(); |
| 46 | void createMenus(); |
| 47 | void createToolbars(); |
| 48 | void createStatusbar(); |
| 49 | void createForm(); |
| 50 | |
| 51 | void openSession(const QString& file); |
| 52 | void updateRecentFiles(); |
| 53 | void addRecentFile(const QString& file); |
| 54 | void removeRecentFile(const QString& file); |
| 55 | |
| 56 | void finalizeConnection(bool halted); |
| 57 | void pauseStatusChanged(bool isPaused); |
| 58 | void breakOccured(); |
| 59 | void setRunMode(); |
| 60 | void updateData(); |
| 61 | |
| 62 | void refreshBreakpoints(); |
| 63 | |
| 64 | struct AddressSlotResult { |
| 65 | uint8_t ps; |
| 66 | std::optional<uint8_t> ss; |
| 67 | std::optional<uint8_t> segment; |
| 68 | }; |
| 69 | AddressSlotResult addressSlot(int addr) const; |
| 70 | |
| 71 | QMenu* fileMenu; |
| 72 | QMenu* editMenu; |
| 73 | QMenu* systemMenu; |
| 74 | QMenu* searchMenu; |
| 75 | QMenu* viewMenu; |
| 76 | QMenu* viewVDPDialogsMenu; |
| 77 | QMenu* viewFloatingWidgetsMenu; |
| 78 | QMenu* executeMenu; |
| 79 | QMenu* breakpointMenu; |
| 80 | QMenu* commandMenu; |
| 81 | QMenu* helpMenu; |
| 82 | QDialog* commandDialog; |
| 83 | |
| 84 | QToolBar* systemToolbar; |
| 85 | QToolBar* executeToolbar; |
| 86 | QToolBar* userToolbar; |
| 87 | |
| 88 | QAction* fileNewSessionAction; |
| 89 | QAction* fileOpenSessionAction; |
| 90 | QAction* fileSaveSessionAction; |
| 91 | QAction* fileSaveSessionAsAction; |
| 92 | QAction* fileQuitAction; |
| 93 | |
| 94 | QAction* copyCodeViewAction; |
| 95 | |
| 96 | enum { MaxRecentFiles = 5 }; |
| 97 | QAction* recentFileActions[MaxRecentFiles]; |
| 98 | QAction* recentFileSeparator; |
| 99 | |
| 100 | QAction* systemConnectAction; |
| 101 | QAction* systemDisconnectAction; |
| 102 | QAction* systemPauseAction; |
| 103 | QAction* systemRebootAction; |
| 104 | QAction* systemSymbolManagerAction; |
| 105 | QAction* systemPreferencesAction; |
| 106 | |
| 107 | QAction* searchGotoAction; |
| 108 | |
| 109 | QAction* viewRegistersAction; |
| 110 | QAction* viewFlagsAction; |
| 111 | QAction* viewStackAction; |
| 112 | QAction* viewSlotsAction; |
| 113 | QAction* viewMemoryAction; |
| 114 | QAction* viewBreakpointsAction; |
| 115 | QAction* viewDebuggableViewerAction; |
| 116 | |
| 117 | QAction* viewBitMappedAction; |
| 118 | QAction* viewCharMappedAction; |
| 119 | QAction* viewSpritesAction; |
| 120 | QAction* viewVDPStatusRegsAction; |
| 121 | QAction* viewVDPRegsAction; |
| 122 | QAction* viewVDPCommandRegsAction; |
| 123 | |
| 124 | QAction* executeBreakAction; |
| 125 | QAction* executeRunAction; |
| 126 | QAction* executeStepAction; |
| 127 | QAction* executeStepOverAction; |
| 128 | QAction* executeRunToAction; |
| 129 | QAction* executeStepOutAction; |
| 130 | QAction* executeStepBackAction; |
| 131 | |
| 132 | QAction* breakpointToggleAction; |
| 133 | QAction* breakpointAddAction; |
| 134 | QAction* commandAction; |
| 135 | QAction* helpAboutAction; |
| 136 | |
| 137 | DockManager dockMan; |
| 138 | std::unique_ptr<DockableWidgetArea> mainArea; |
| 139 | QStringList recentFiles; |
| 140 | |
| 141 | DisasmViewer* disasmView; |
| 142 | MainMemoryViewer* mainMemoryView; |
| 143 | CPURegsViewer* regsView; |
| 144 | FlagsViewer* flagsView; |
| 145 | StackViewer* stackView; |
| 146 | SlotViewer* slotView; |
| 147 | VDPStatusRegViewer* VDPStatusRegView; |
| 148 | VDPRegViewer* VDPRegView; |
| 149 | VDPCommandRegViewer* VDPCommandRegView; |
| 150 | BreakpointViewer* bpView; |
| 151 | QPointer<SymbolManager> symManager; |
| 152 | |
| 153 | CommClient& comm; |
| 154 | DebugSession session; |
| 155 | MemoryLayout memLayout; |
| 156 | uint8_t mainMemory[0x10000 + 4] = {}; // 4 extra to avoid wrap-check during disasm |
| 157 | |
| 158 | bool mergeBreakpoints; |
| 159 | QMap<QString, int> debuggables; |
| 160 | |
| 161 | static int counter; |
| 162 | enum {RESET = 0, SLOTS_CHECKED, PC_CHANGED, SLOTS_CHANGED} disasmStatus = RESET; |
| 163 | uint16_t disasmAddress; |
| 164 | |
| 165 | QList<CommandRef> commands; |
| 166 | void updateCustomActions(); |
| 167 | |
| 168 | void fileNewSession(); |
| 169 | void fileOpenSession(); |
| 170 | void fileSaveSession(); |
| 171 | void fileSaveSessionAs(); |
| 172 | void fileRecentOpen(); |
| 173 | void copyCodeView(); |
| 174 | void systemConnect(); |
| 175 | void systemDisconnect(); |
| 176 | void systemPause(); |
| 177 | void systemReboot(); |
| 178 | void systemSymbolManager(); |
| 179 | void systemPreferences(); |
| 180 | void searchGoto(); |
| 181 | void toggleBreakpointsDisplay(); |
| 182 | void toggleRegisterDisplay(); |
| 183 | void toggleFlagsDisplay(); |
| 184 | void toggleStackDisplay(); |
| 185 | void toggleSlotsDisplay(); |
| 186 | void toggleMemoryDisplay(); |
| 187 | void toggleBitMappedDisplay(); |
| 188 | void toggleCharMappedDisplay(); |
| 189 | void toggleSpritesDisplay(); |
| 190 | void toggleVDPRegsDisplay(); |
| 191 | void toggleVDPStatusRegsDisplay(); |
| 192 | void toggleVDPCommandRegsDisplay(); |
| 193 | void addDebuggableViewer(); |
| 194 | void executeBreak(); |
| 195 | void executeRun(); |
| 196 | void executeStep(); |
| 197 | void executeStepOver(); |
| 198 | void executeRunTo(); |
| 199 | void executeStepOut(); |
| 200 | void executeStepBack(); |
| 201 | |
| 202 | void toggleBreakpoint(); |
| 203 | void toggleBreakpointAddress(uint16_t addr); |
| 204 | void addBreakpoint(); |
| 205 | |
| 206 | void manageCommandButtons(); |
| 207 | void manageCommandButtonsFinished(int result); |
| 208 | |
| 209 | void toggleView(DockableWidget* widget); |
| 210 | void initConnection(); |
| 211 | void handleUpdate(const QString& type, const QString& name, |
| 212 | const QString& message); |
| 213 | void setDebuggables(const QString& list); |
| 214 | void setDebuggableSize(const QString& debuggable, int size); |
| 215 | void connectionClosed(); |
| 216 | void dockWidgetVisibilityChanged(DockableWidget* w); |
| 217 | void updateViewMenu(); |
| 218 | void updateVDPViewMenu(); |
| 219 | void updateViewFloatingWidgetsMenu(); |
| 220 | void updateWindowTitle(); |
| 221 | void symbolFileChanged(); |
| 222 | void showFloatingWidget(); |
| 223 | void processBreakpoints(const QString& message); |
| 224 | void processMerge(const QString& message); |
| 225 | |
| 226 | QByteArray saveCommands() const; |
| 227 | void restoreCommands(const QByteArray& input); |
| 228 | |
| 229 | friend class QueryPauseHandler; |
| 230 | friend class QueryBreakedHandler; |
| 231 | friend class ListBreakPointsHandler; |
| 232 | friend class CPURegRequest; |
| 233 | friend class ListDebuggablesHandler; |
| 234 | friend class DebuggableSizeHandler; |
| 235 | |
| 236 | signals: |
| 237 | void connected(); |
| 238 | void settingsChanged(); |
| 239 | void symbolsChanged(); |
| 240 | void symbolFilesChanged(); |
| 241 | void runStateEntered(); |
| 242 | void breakStateEntered(); |
| 243 | void breakpointsUpdated(); |
| 244 | void debuggablesChanged(const QMap<QString, int>& list); |
| 245 | }; |
| 246 | |
| 247 | #endif // DEBUGGERFORM_H |