| 1 | #ifndef DEBUGGERDATA_H |
| 2 | #define DEBUGGERDATA_H |
| 3 | |
| 4 | #include <QString> |
| 5 | #include <QXmlStreamReader> |
| 6 | #include <QXmlStreamWriter> |
| 7 | #include <optional> |
| 8 | #include <vector> |
| 9 | |
| 10 | struct MemoryLayout |
| 11 | { |
| 12 | MemoryLayout(); |
| 13 | |
| 14 | int primarySlot[4]; |
| 15 | int secondarySlot[4]; |
| 16 | int mapperSegment[4]; |
| 17 | int romBlock[8]; |
| 18 | |
| 19 | bool isSubslotted[4]; |
| 20 | int mapperSize[4][4]; |
| 21 | }; |
| 22 | |
| 23 | struct AddressRange { |
| 24 | explicit AddressRange(uint16_t addr) : start(addr) {} |
| 25 | AddressRange(uint16_t b, std::optional<uint16_t> e) : start(b), end(e) {} |
| 26 | |
| 27 | uint16_t start; // a single address when end is not used |
| 28 | std::optional<uint16_t> end; // end point is inclusive |
| 29 | |
| 30 | [[nodiscard]] bool contains(uint16_t addr) const { |
| 31 | if (!end) return start == addr; |
| 32 | return start <= addr && addr <= *end; |
| 33 | } |
| 34 | |
| 35 | constexpr bool operator==(const AddressRange &other) const |
| 36 | { |
| 37 | if (start != other.start) return false; |
| 38 | if (end != other.end) return false; |
| 39 | return true; |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | struct Slot { |
| 44 | std::optional<int8_t> ps; // primary slot, always 0..3 or empty if it is a mask |
| 45 | std::optional<int8_t> ss; // secundary slot, 0..3 or empty when the primary slot is not expanded |
| 46 | }; |
| 47 | |
| 48 | struct Breakpoint { |
| 49 | enum Type { BREAKPOINT, WATCHPOINT_MEMREAD, WATCHPOINT_MEMWRITE, |
| 50 | WATCHPOINT_IOREAD, WATCHPOINT_IOWRITE, CONDITION }; |
| 51 | Type type; |
| 52 | QString id; |
| 53 | std::optional<AddressRange> range; |
| 54 | // GUI specific condition variables |
| 55 | Slot slot; |
| 56 | std::optional<uint8_t> segment; |
| 57 | // general condition |
| 58 | QString condition; |
| 59 | // compare content |
| 60 | bool operator==(const Breakpoint &bp) const; |
| 61 | |
| 62 | void setAddress(uint16_t start, std::optional<uint16_t> rangeEnd = {}) { |
| 63 | range = AddressRange(start, rangeEnd); |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | class Breakpoints |
| 68 | { |
| 69 | public: |
| 70 | void clear(); |
| 71 | |
| 72 | void setMemoryLayout(MemoryLayout* ml); |
| 73 | void setBreakpoints(const QString& str); |
| 74 | QString mergeBreakpoints(const QString& str); |
| 75 | int breakpointCount(); |
| 76 | bool isBreakpoint(uint16_t addr, QString *id = nullptr, bool checkSlot = true); |
| 77 | bool isWatchpoint(uint16_t addr, QString *id = nullptr, bool checkSlot = true); |
| 78 | |
| 79 | /* xml session file functions */ |
| 80 | void saveBreakpoints(QXmlStreamWriter& xml); |
| 81 | void loadBreakpoints(QXmlStreamReader& xml); |
| 82 | |
| 83 | std::optional<uint16_t> findBreakpoint(uint16_t addr); |
| 84 | |
| 85 | static QString createSetCommand(Breakpoint::Type type, std::optional<AddressRange> range = {}, |
| 86 | Slot slot = {}, std::optional<uint8_t> segment = {}, |
| 87 | QString condition = {}); |
| 88 | static QString createRemoveCommand(const QString& id); |
| 89 | |
| 90 | const Breakpoint& getBreakpoint(int index); |
| 91 | bool inCurrentSlot(const Breakpoint& bp); |
| 92 | private: |
| 93 | |
| 94 | std::vector<Breakpoint> breakpoints; |
| 95 | MemoryLayout* memLayout = nullptr; |
| 96 | |
| 97 | void parseCondition(Breakpoint& bp); |
| 98 | void insertBreakpoint(Breakpoint& bp); |
| 99 | }; |
| 100 | |
| 101 | #endif // DEBUGGERDATA_H |