openMSX
Debugger.hh
Go to the documentation of this file.
1 #ifndef DEBUGGER_HH
2 #define DEBUGGER_HH
3 
4 #include "Probe.hh"
5 #include "RecordedCommand.hh"
6 #include "WatchPoint.hh"
7 #include "hash_map.hh"
8 #include "outer.hh"
9 #include "xxhash.hh"
10 #include <string_view>
11 #include <vector>
12 #include <memory>
13 
14 namespace openmsx {
15 
16 class MSXMotherBoard;
17 class Debuggable;
18 class ProbeBase;
19 class ProbeBreakPoint;
20 class MSXCPU;
21 
22 class Debugger
23 {
24 public:
25  Debugger(const Debugger&) = delete;
26  Debugger& operator=(const Debugger&) = delete;
27 
28  explicit Debugger(MSXMotherBoard& motherBoard);
29  ~Debugger();
30 
31  void registerDebuggable (std::string name, Debuggable& debuggable);
32  void unregisterDebuggable (std::string_view name, Debuggable& debuggable);
33  [[nodiscard]] Debuggable* findDebuggable(std::string_view name);
34 
35  void registerProbe (ProbeBase& probe);
36  void unregisterProbe(ProbeBase& probe);
37  [[nodiscard]] ProbeBase* findProbe(std::string_view name);
38 
40  void setCPU(MSXCPU* cpu_) { cpu = cpu_; }
41 
42  void transfer(Debugger& other);
43 
44  [[nodiscard]] MSXMotherBoard& getMotherBoard() { return motherBoard; }
45 
46 private:
47  [[nodiscard]] Debuggable& getDebuggable(std::string_view name);
48  [[nodiscard]] ProbeBase& getProbe(std::string_view name);
49 
50  unsigned insertProbeBreakPoint(
51  TclObject command, TclObject condition,
52  ProbeBase& probe, bool once, unsigned newId = -1);
53  void removeProbeBreakPoint(std::string_view name);
54 
55  unsigned setWatchPoint(TclObject command, TclObject condition,
56  WatchPoint::Type type,
57  unsigned beginAddr, unsigned endAddr,
58  bool once, unsigned newId = -1);
59 
60  MSXMotherBoard& motherBoard;
61 
62  class Cmd final : public RecordedCommand {
63  public:
64  Cmd(CommandController& commandController,
65  StateChangeDistributor& stateChangeDistributor,
66  Scheduler& scheduler);
67  [[nodiscard]] bool needRecord(span<const TclObject> tokens) const override;
68  void execute(span<const TclObject> tokens,
69  TclObject& result, EmuTime::param time) override;
70  [[nodiscard]] std::string help(span<const TclObject> tokens) const override;
71  void tabCompletion(std::vector<std::string>& tokens) const override;
72 
73  private:
74  [[nodiscard]] Debugger& debugger() { return OUTER(Debugger, cmd); }
75  [[nodiscard]] const Debugger& debugger() const { return OUTER(Debugger, cmd); }
76  void list(TclObject& result);
77  void desc(span<const TclObject> tokens, TclObject& result);
78  void size(span<const TclObject> tokens, TclObject& result);
79  void read(span<const TclObject> tokens, TclObject& result);
80  void readBlock(span<const TclObject> tokens, TclObject& result);
81  void write(span<const TclObject> tokens, TclObject& result);
82  void writeBlock(span<const TclObject> tokens, TclObject& result);
83  void setBreakPoint(span<const TclObject> tokens, TclObject& result);
84  void removeBreakPoint(span<const TclObject> tokens, TclObject& result);
85  void listBreakPoints(span<const TclObject> tokens, TclObject& result);
86  [[nodiscard]] std::vector<std::string> getBreakPointIds() const;
87  [[nodiscard]] std::vector<std::string> getWatchPointIds() const;
88  [[nodiscard]] std::vector<std::string> getConditionIds() const;
89  void setWatchPoint(span<const TclObject> tokens, TclObject& result);
90  void removeWatchPoint(span<const TclObject> tokens, TclObject& result);
91  void listWatchPoints(span<const TclObject> tokens, TclObject& result);
92  void setCondition(span<const TclObject> tokens, TclObject& result);
93  void removeCondition(span<const TclObject> tokens, TclObject& result);
94  void listConditions(span<const TclObject> tokens, TclObject& result);
95  void probe(span<const TclObject> tokens, TclObject& result);
96  void probeList(span<const TclObject> tokens, TclObject& result);
97  void probeDesc(span<const TclObject> tokens, TclObject& result);
98  void probeRead(span<const TclObject> tokens, TclObject& result);
99  void probeSetBreakPoint(span<const TclObject> tokens, TclObject& result);
100  void probeRemoveBreakPoint(span<const TclObject> tokens, TclObject& result);
101  void probeListBreakPoints(span<const TclObject> tokens, TclObject& result);
102  } cmd;
103 
104  struct NameFromProbe {
105  [[nodiscard]] const std::string& operator()(const ProbeBase* p) const {
106  return p->getName();
107  }
108  };
109 
112  std::vector<std::unique_ptr<ProbeBreakPoint>> probeBreakPoints; // unordered
113  MSXCPU* cpu = nullptr;
114 };
115 
116 } // namespace openmsx
117 
118 #endif
void registerProbe(ProbeBase &probe)
Definition: Debugger.cc:75
void setCPU(MSXCPU *cpu_)
Definition: Debugger.hh:40
Debuggable * findDebuggable(std::string_view name)
Definition: Debugger.cc:60
Debugger(const Debugger &)=delete
void transfer(Debugger &other)
Definition: Debugger.cc:162
void unregisterProbe(ProbeBase &probe)
Definition: Debugger.cc:81
void unregisterDebuggable(std::string_view name, Debuggable &debuggable)
Definition: Debugger.cc:53
ProbeBase * findProbe(std::string_view name)
Definition: Debugger.cc:87
void removeProbeBreakPoint(ProbeBreakPoint &bp)
Definition: Debugger.cc:138
MSXMotherBoard & getMotherBoard()
Definition: Debugger.hh:44
void registerDebuggable(std::string name, Debuggable &debuggable)
Definition: Debugger.cc:47
Debugger & operator=(const Debugger &)=delete
Commands that directly influence the MSX state should send and events so that they can be recorded by...
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9
size_t size(std::string_view utf8)
#define OUTER(type, member)
Definition: outer.hh:41