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 "string_ref.hh"
9 #include "outer.hh"
10 #include "xxhash.hh"
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& interface);
32  void unregisterDebuggable (string_ref name, Debuggable& interface);
34 
35  void registerProbe (ProbeBase& probe);
36  void unregisterProbe(ProbeBase& probe);
38 
40  void setCPU(MSXCPU* cpu_) { cpu = cpu_; }
41 
42  void transfer(Debugger& other);
43 
44  MSXMotherBoard& getMotherBoard() { return motherBoard; }
45 
46 private:
47  Debuggable& getDebuggable(string_ref name);
48  ProbeBase& getProbe(string_ref name);
49 
50  unsigned insertProbeBreakPoint(
51  TclObject command, TclObject condition,
52  ProbeBase& probe, unsigned newId = -1);
54 
55  unsigned setWatchPoint(TclObject command, TclObject condition,
56  WatchPoint::Type type,
57  unsigned beginAddr, unsigned endAddr,
58  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  bool needRecord(array_ref<TclObject> tokens) const override;
68  void execute(array_ref<TclObject> tokens,
69  TclObject& result, EmuTime::param time) override;
70  std::string help(const std::vector<std::string>& tokens) const override;
71  void tabCompletion(std::vector<std::string>& tokens) const override;
72 
73  private:
74  Debugger& debugger() { return OUTER(Debugger, cmd); }
75  const Debugger& debugger() const { return OUTER(Debugger, cmd); }
76  void list(TclObject& result);
77  void desc(array_ref<TclObject> tokens, TclObject& result);
78  void size(array_ref<TclObject> tokens, TclObject& result);
79  void read(array_ref<TclObject> tokens, TclObject& result);
80  void readBlock(array_ref<TclObject> tokens, TclObject& result);
81  void write(array_ref<TclObject> tokens, TclObject& result);
82  void writeBlock(array_ref<TclObject> tokens, TclObject& result);
83  void setBreakPoint(array_ref<TclObject> tokens, TclObject& result);
84  void removeBreakPoint(array_ref<TclObject> tokens, TclObject& result);
85  void listBreakPoints(array_ref<TclObject> tokens, TclObject& result);
86  std::vector<std::string> getBreakPointIds() const;
87  std::vector<std::string> getWatchPointIds() const;
88  std::vector<std::string> getConditionIds() const;
89  void setWatchPoint(array_ref<TclObject> tokens, TclObject& result);
90  void removeWatchPoint(array_ref<TclObject> tokens, TclObject& result);
91  void listWatchPoints(array_ref<TclObject> tokens, TclObject& result);
92  void setCondition(array_ref<TclObject> tokens, TclObject& result);
93  void removeCondition(array_ref<TclObject> tokens, TclObject& result);
94  void listConditions(array_ref<TclObject> tokens, TclObject& result);
95  void probe(array_ref<TclObject> tokens, TclObject& result);
96  void probeList(array_ref<TclObject> tokens, TclObject& result);
97  void probeDesc(array_ref<TclObject> tokens, TclObject& result);
98  void probeRead(array_ref<TclObject> tokens, TclObject& result);
99  void probeSetBreakPoint(array_ref<TclObject> tokens, TclObject& result);
100  void probeRemoveBreakPoint(array_ref<TclObject> tokens, TclObject& result);
101  void probeListBreakPoints(array_ref<TclObject> tokens, TclObject& result);
102  } cmd;
103 
104  struct NameFromProbe {
105  const std::string& operator()(const ProbeBase* p) const {
106  return p->getName();
107  }
108  };
109 
112  using ProbeBreakPoints = std::vector<std::unique_ptr<ProbeBreakPoint>>;
113  ProbeBreakPoints probeBreakPoints; // unordered
114  MSXCPU* cpu;
115 };
116 
117 } // namespace openmsx
118 
119 #endif
MSXMotherBoard & getMotherBoard()
Definition: Debugger.hh:44
Debugger & operator=(const Debugger &)=delete
Commands that directly influence the MSX state should send and events so that they can be recorded by...
void setCPU(MSXCPU *cpu_)
Definition: Debugger.hh:40
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
void removeProbeBreakPoint(ProbeBreakPoint &bp)
Definition: Debugger.cc:142
This class implements a subset of the proposal for std::array_ref (proposed for the next c++ standard...
Definition: array_ref.hh:19
Debuggable * findDebuggable(string_ref name)
Definition: Debugger.cc:59
Debugger(const Debugger &)=delete
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
size_t size() const
void transfer(Debugger &other)
Definition: Debugger.cc:166
void unregisterProbe(ProbeBase &probe)
Definition: Debugger.cc:80
void registerProbe(ProbeBase &probe)
Definition: Debugger.cc:74
void unregisterDebuggable(string_ref name, Debuggable &interface)
Definition: Debugger.cc:52
#define OUTER(type, member)
Definition: outer.hh:38
const std::string & getName() const
Definition: Probe.hh:15
ProbeBase * findProbe(string_ref name)
Definition: Debugger.cc:86
void registerDebuggable(std::string name, Debuggable &interface)
Definition: Debugger.cc:46