| e8555c89 Andy McCall |
1 |
#ifndef DEBUGGER_HH |
| 2 |
#define DEBUGGER_HH |
| 3 |
|
| 4 |
#include "Probe.hh" |
| 5 |
#include "Tracer.hh" |
| 6 |
|
| 7 |
#include "ImGuiWatchExpr.hh" |
| 8 |
#include "RecordedCommand.hh" |
| 9 |
#include "WatchPoint.hh" |
| 10 |
|
| 11 |
#include "hash_map.hh" |
| 12 |
#include "outer.hh" |
| 13 |
#include "xxhash.hh" |
| 14 |
|
| 15 |
#include <memory> |
| 16 |
#include <string_view> |
| 17 |
#include <vector> |
| 18 |
|
| 19 |
namespace openmsx { |
| 20 |
|
| 21 |
class BreakPoint; |
| 22 |
class DebugCondition; |
| 23 |
class Debuggable; |
| 24 |
class MSXCPU; |
| 25 |
class MSXMotherBoard; |
| 26 |
class ProbeBase; |
| 27 |
class ProbeBreakPoint; |
| 28 |
class SymbolManager; |
| 29 |
|
| 30 |
class Debugger |
| 31 |
{ |
| 32 |
public: |
| 33 |
explicit Debugger(MSXMotherBoard& motherBoard); |
| 34 |
Debugger(const Debugger&) = delete; |
| 35 |
Debugger(Debugger&&) = delete; |
| 36 |
Debugger& operator=(const Debugger&) = delete; |
| 37 |
Debugger& operator=(Debugger&&) = delete; |
| 38 |
~Debugger(); |
| 39 |
|
| 40 |
void registerDebuggable (std::string name, Debuggable& debuggable); |
| 41 |
void unregisterDebuggable (std::string_view name, Debuggable& debuggable); |
| 42 |
[[nodiscard]] Debuggable* findDebuggable(std::string_view name); |
| 43 |
[[nodiscard]] const auto& getDebuggables() const { return debuggables; } |
| 44 |
|
| 45 |
void registerProbe (ProbeBase& probe); |
| 46 |
void unregisterProbe(ProbeBase& probe); |
| 47 |
[[nodiscard]] ProbeBase* findProbe(std::string_view name); |
| 48 |
|
| 49 |
void removeProbeBreakPoint(ProbeBreakPoint& bp); |
| 50 |
void setCPU(MSXCPU* cpu_) { cpu = cpu_; } |
| 51 |
|
| 52 |
void transfer(Debugger& other); |
| 53 |
|
| 54 |
[[nodiscard]] MSXMotherBoard& getMotherBoard() { return motherBoard; } |
| 55 |
[[nodiscard]] Interpreter& getInterpreter(); |
| 56 |
[[nodiscard]] std::vector<ImGuiWatchExpr::WatchExpr>& getWatchExprs() const; |
| 57 |
|
| 58 |
[[nodiscard]] auto& getProbes() { return probes; } |
| 59 |
[[nodiscard]] Tracer& getTracer() { return tracer; } |
| 60 |
|
| 61 |
private: |
| 62 |
[[nodiscard]] Debuggable& getDebuggable(std::string_view name); |
| 63 |
[[nodiscard]] ProbeBase& getProbe(std::string_view name); |
| 64 |
|
| 65 |
std::string insertProbeBreakPoint( |
| 66 |
TclObject command, TclObject condition, |
| 67 |
ProbeBase& probe, bool once, unsigned newId = -1); |
| 68 |
void removeProbeBreakPoint(std::string_view name); |
| 69 |
|
| 70 |
MSXMotherBoard& motherBoard; |
| 71 |
|
| 72 |
class Cmd final : public RecordedCommand { |
| 73 |
public: |
| 74 |
Cmd(CommandController& commandController, |
| 75 |
StateChangeDistributor& stateChangeDistributor, |
| 76 |
Scheduler& scheduler); |
| 77 |
[[nodiscard]] bool needRecord(std::span<const TclObject> tokens) const override; |
| 78 |
void execute(std::span<const TclObject> tokens, |
| 79 |
TclObject& result, EmuTime time) override; |
| 80 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override; |
| 81 |
void tabCompletion(std::vector<std::string>& tokens) const override; |
| 82 |
|
| 83 |
private: |
| 84 |
[[nodiscard]] Debugger& debugger() { return OUTER(Debugger, cmd); } |
| 85 |
[[nodiscard]] const Debugger& debugger() const { return OUTER(Debugger, cmd); } |
| 86 |
[[nodiscard]] SymbolManager& getSymbolManager(); |
| 87 |
void list(TclObject& result); |
| 88 |
void desc(std::span<const TclObject> tokens, TclObject& result); |
| 89 |
void size(std::span<const TclObject> tokens, TclObject& result); |
| 90 |
void read(std::span<const TclObject> tokens, TclObject& result); |
| 91 |
void readBlock(std::span<const TclObject> tokens, TclObject& result); |
| 92 |
void write(std::span<const TclObject> tokens, TclObject& result); |
| 93 |
void writeBlock(std::span<const TclObject> tokens, TclObject& result); |
| 94 |
void disasm(std::span<const TclObject> tokens, TclObject& result, EmuTime time) const; |
| 95 |
void disasmBlob(std::span<const TclObject> tokens, TclObject& result) const; |
| 96 |
void breakPoint(std::span<const TclObject> tokens, TclObject& result); |
| 97 |
void watchPoint(std::span<const TclObject> tokens, TclObject& result); |
| 98 |
void watchExpr(std::span<const TclObject> tokens, TclObject& result); |
| 99 |
void condition (std::span<const TclObject> tokens, TclObject& result); |
| 100 |
[[nodiscard]] BreakPoint* lookupBreakPoint(std::string_view str); |
| 101 |
[[nodiscard]] std::shared_ptr<WatchPoint> lookupWatchPoint(std::string_view str); |
| 102 |
[[nodiscard]] ImGuiWatchExpr::WatchExpr* lookupWatchExpr(std::string_view str); |
| 103 |
[[nodiscard]] DebugCondition* lookupCondition(std::string_view str); |
| 104 |
void breakPointList(std::span<const TclObject> tokens, TclObject& result); |
| 105 |
void watchPointList(std::span<const TclObject> tokens, TclObject& result); |
| 106 |
void watchExprList(std::span<const TclObject> , TclObject& result); |
| 107 |
void conditionList (std::span<const TclObject> tokens, TclObject& result); |
| 108 |
void parseCreateBreakPoint(BreakPoint& bp, std::span<const TclObject> tokens); |
| 109 |
void parseCreateWatchPoint(WatchPoint& wp, std::span<const TclObject> tokens); |
| 110 |
void parseCreateWatchExpr(ImGuiWatchExpr::WatchExpr& we, std::span<const TclObject> tokens); |
| 111 |
void parseCreateCondition (DebugCondition& cond, std::span<const TclObject> tokens); |
| 112 |
void breakPointCreate(std::span<const TclObject> tokens, TclObject& result); |
| 113 |
void watchPointCreate(std::span<const TclObject> tokens, TclObject& result); |
| 114 |
void watchExprCreate(std::span<const TclObject> tokens, TclObject& result); |
| 115 |
void conditionCreate (std::span<const TclObject> tokens, TclObject& result); |
| 116 |
void breakPointConfigure(std::span<const TclObject> tokens, TclObject& result); |
| 117 |
void watchPointConfigure(std::span<const TclObject> tokens, TclObject& result); |
| 118 |
void watchExprConfigure(std::span<const TclObject> tokens, TclObject& result); |
| 119 |
void conditionConfigure (std::span<const TclObject> tokens, TclObject& result); |
| 120 |
void breakPointRemove(std::span<const TclObject> tokens, TclObject& result); |
| 121 |
void watchPointRemove(std::span<const TclObject> tokens, TclObject& result); |
| 122 |
void watchExprRemove(std::span<const TclObject> tokens, TclObject& result); |
| 123 |
void conditionRemove (std::span<const TclObject> tokens, TclObject& result); |
| 124 |
void setBreakPoint(std::span<const TclObject> tokens, TclObject& result); |
| 125 |
void removeBreakPoint(std::span<const TclObject> tokens, TclObject& result); |
| 126 |
void listBreakPoints(std::span<const TclObject> tokens, TclObject& result) const; |
| 127 |
[[nodiscard]] std::vector<std::string> getBreakPointIds() const; |
| 128 |
[[nodiscard]] std::vector<std::string> getWatchPointIds() const; |
| 129 |
[[nodiscard]] std::vector<std::string> getWatchExprIds() const; |
| 130 |
[[nodiscard]] std::vector<std::string> getConditionIds() const; |
| 131 |
void setWatchPoint(std::span<const TclObject> tokens, TclObject& result); |
| 132 |
void removeWatchPoint(std::span<const TclObject> tokens, TclObject& result); |
| 133 |
void listWatchPoints(std::span<const TclObject> tokens, TclObject& result); |
| 134 |
void setCondition(std::span<const TclObject> tokens, TclObject& result); |
| 135 |
void removeCondition(std::span<const TclObject> tokens, TclObject& result); |
| 136 |
void listConditions(std::span<const TclObject> tokens, TclObject& result) const; |
| 137 |
void probe(std::span<const TclObject> tokens, TclObject& result); |
| 138 |
void probeList(std::span<const TclObject> tokens, TclObject& result); |
| 139 |
void probeDesc(std::span<const TclObject> tokens, TclObject& result); |
| 140 |
void probeRead(std::span<const TclObject> tokens, TclObject& result); |
| 141 |
void probeSetBreakPoint(std::span<const TclObject> tokens, TclObject& result); |
| 142 |
void probeRemoveBreakPoint(std::span<const TclObject> tokens, TclObject& result); |
| 143 |
void probeListBreakPoints(std::span<const TclObject> tokens, TclObject& result); |
| 144 |
void symbols(std::span<const TclObject> tokens, TclObject& result); |
| 145 |
void symbolsTypes(std::span<const TclObject> tokens, TclObject& result) const; |
| 146 |
void symbolsLoad(std::span<const TclObject> tokens, TclObject& result); |
| 147 |
void symbolsRemove(std::span<const TclObject> tokens, TclObject& result); |
| 148 |
void symbolsFiles(std::span<const TclObject> tokens, TclObject& result); |
| 149 |
void symbolsLookup(std::span<const TclObject> tokens, TclObject& result); |
| 150 |
} cmd; |
| 151 |
|
| 152 |
Tracer tracer; |
| 153 |
friend class Tracer; |
| 154 |
|
| 155 |
hash_map<std::string, Debuggable*, XXHasher> debuggables; |
| 156 |
std::vector<ProbeBase*> probes; |
| 157 |
std::vector<std::unique_ptr<ProbeBreakPoint>> probeBreakPoints; |
| 158 |
MSXCPU* cpu = nullptr; |
| 159 |
}; |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
#endif |