| 1 |
#ifndef IMGUI_DEBUGGER_HH |
| 2 |
#define IMGUI_DEBUGGER_HH |
| 3 |
|
| 4 |
#include "FileListWidget.hh" |
| 5 |
#include "ImGuiPart.hh" |
| 6 |
|
| 7 |
#include "CPURegs.hh" |
| 8 |
#include "EmuTime.hh" |
| 9 |
|
| 10 |
#include <array> |
| 11 |
#include <cstdint> |
| 12 |
#include <memory> |
| 13 |
#include <optional> |
| 14 |
#include <vector> |
| 15 |
|
| 16 |
namespace openmsx { |
| 17 |
|
| 18 |
class DebuggableEditor; |
| 19 |
class Debugger; |
| 20 |
class ImGuiBitmapViewer; |
| 21 |
class ImGuiCharacter; |
| 22 |
class ImGuiDisassembly; |
| 23 |
class ImGuiSpriteViewer; |
| 24 |
class MSXCPUInterface; |
| 25 |
|
| 26 |
class ImGuiDebugger final : public ImGuiPart |
| 27 |
{ |
| 28 |
public: |
| 29 |
struct PageInfo { |
| 30 |
uint8_t ps = 0; |
| 31 |
std::optional<uint8_t> ss; |
| 32 |
std::string segment; |
| 33 |
}; |
| 34 |
using SlotInfo = std::array<PageInfo, 4>; |
| 35 |
|
| 36 |
public: |
| 37 |
explicit ImGuiDebugger(ImGuiManager& manager); |
| 38 |
~ImGuiDebugger(); |
| 39 |
|
| 40 |
static void loadIcons(); |
| 41 |
|
| 42 |
[[nodiscard]] zstring_view iniName() const override { return "debugger"; } |
| 43 |
void save(ImGuiTextBuffer& buf) override; |
| 44 |
void loadStart() override; |
| 45 |
void loadEnd() override; |
| 46 |
void loadLine(std::string_view name, zstring_view value) override; |
| 47 |
void showMenu(MSXMotherBoard* motherBoard) override; |
| 48 |
void paint(MSXMotherBoard* motherBoard) override; |
| 49 |
|
| 50 |
void signalBreak(); |
| 51 |
void signalContinue(); |
| 52 |
void signalQuit(); |
| 53 |
void setGotoTarget(uint16_t target); |
| 54 |
void checkShortcuts(MSXCPUInterface& cpuInterface, MSXMotherBoard& motherBoard, |
| 55 |
ImGuiDisassembly* disassembly); |
| 56 |
|
| 57 |
[[nodiscard]] bool needSnapshot() const { return showChanges == SHOW_ALWAYS; } |
| 58 |
[[nodiscard]] bool needDrawChanges() const; |
| 59 |
[[nodiscard]] auto getChangesColor() const { return ImGui::ColorConvertFloat4ToU32(changesColor); } |
| 60 |
void configureChangesMenu(); |
| 61 |
|
| 62 |
private: |
| 63 |
SlotInfo getSlotInfo(MSXCPUInterface& cpuInterface, Debugger& debugger) const; |
| 64 |
|
| 65 |
void drawControl(MSXCPUInterface& cpuInterface, MSXMotherBoard& motherBoard); |
| 66 |
void drawSlots(MSXCPUInterface& cpuInterface, Debugger& debugger); |
| 67 |
void drawStack(const CPURegs& regs, const MSXCPUInterface& cpuInterface, EmuTime time); |
| 68 |
void drawRegisters(CPURegs& regs); |
| 69 |
void drawFlags(CPURegs& regs); |
| 70 |
|
| 71 |
void actionBreakContinue(MSXCPUInterface& cpuInterface); |
| 72 |
void actionStepIn(MSXCPUInterface& cpuInterface); |
| 73 |
void actionStepOver(); |
| 74 |
void actionStepOut(); |
| 75 |
void actionStepBack(); |
| 76 |
|
| 77 |
enum LoadSave { LOAD, SAVE }; |
| 78 |
void loadSaveBreakpoints(LoadSave loadSave); |
| 79 |
|
| 80 |
private: |
| 81 |
std::vector<std::unique_ptr<ImGuiDisassembly>> disassemblyViewers; |
| 82 |
std::vector<std::unique_ptr<ImGuiBitmapViewer>> bitmapViewers; |
| 83 |
std::vector<std::unique_ptr<ImGuiCharacter>> tileViewers; |
| 84 |
std::vector<std::unique_ptr<ImGuiSpriteViewer>> spriteViewers; |
| 85 |
std::vector<std::unique_ptr<DebuggableEditor>> hexEditors; |
| 86 |
|
| 87 |
std::optional<SlotInfo> slotSnapshot; |
| 88 |
std::optional<CPURegs> cpuRegsSnapshot; |
| 89 |
int showChangesFrameCounter = 0; |
| 90 |
enum ShowChanges : int { SHOW_NEVER, SHOW_DURING_BREAK, SHOW_ALWAYS }; |
| 91 |
int showChanges = SHOW_DURING_BREAK; |
| 92 |
gl::vec4 changesColor{1.0f, 0.0f, 0.0f, 1.0f}; |
| 93 |
|
| 94 |
bool showControl = false; |
| 95 |
bool showSlots = false; |
| 96 |
bool showStack = false; |
| 97 |
bool showRegisters = false; |
| 98 |
bool showFlags = false; |
| 99 |
bool showXYFlags = false; |
| 100 |
int flagsLayout = 1; |
| 101 |
std::string breakpointFile; |
| 102 |
bool reloadBreakpoints = false; |
| 103 |
|
| 104 |
FileListWidget saveBreakpoints; |
| 105 |
FileListWidget loadBreakpoints; |
| 106 |
|
| 107 |
static constexpr auto persistentElements = std::tuple{ |
| 108 |
PersistentElement{"showControl", &ImGuiDebugger::showControl}, |
| 109 |
PersistentElement{"showRegisters", &ImGuiDebugger::showRegisters}, |
| 110 |
PersistentElement{"showSlots", &ImGuiDebugger::showSlots}, |
| 111 |
PersistentElement{"showStack", &ImGuiDebugger::showStack}, |
| 112 |
PersistentElement{"showFlags", &ImGuiDebugger::showFlags}, |
| 113 |
PersistentElement{"showXYFlags", &ImGuiDebugger::showXYFlags}, |
| 114 |
PersistentElementMax{"flagsLayout", &ImGuiDebugger::flagsLayout, 2}, |
| 115 |
PersistentElement{"showChanges", &ImGuiDebugger::showChanges}, |
| 116 |
PersistentElement{"changesColor", &ImGuiDebugger::changesColor}, |
| 117 |
PersistentElement{"breakpointFile", &ImGuiDebugger::breakpointFile}, |
| 118 |
PersistentElement{"reloadBreakpoints", &ImGuiDebugger::reloadBreakpoints}, |
| 119 |
|
| 120 |
|
| 121 |
}; |
| 122 |
}; |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
#endif |