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  Debuggable* findDebuggable(std::string_view name);
34 
35  void registerProbe (ProbeBase& probe);
36  void unregisterProbe(ProbeBase& probe);
37  ProbeBase* findProbe(std::string_view name);
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(std::string_view name);
48  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  bool needRecord(span<const TclObject> tokens) const override;
68  void execute(span<const 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(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  std::vector<std::string> getBreakPointIds() const;
87  std::vector<std::string> getWatchPointIds() const;
88  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  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
openmsx::Debugger::registerProbe
void registerProbe(ProbeBase &probe)
Definition: Debugger.cc:76
openmsx::Scheduler
Definition: Scheduler.hh:33
xxhash.hh
openmsx::CommandController
Definition: CommandController.hh:17
openmsx::Debugger::transfer
void transfer(Debugger &other)
Definition: Debugger.cc:168
utf8::unchecked::size
size_t size(std::string_view utf8)
Definition: utf8_unchecked.hh:227
openmsx::Debugger
Definition: Debugger.hh:22
openmsx::StateChangeDistributor
Definition: StateChangeDistributor.hh:14
Probe.hh
openmsx::Debugger::registerDebuggable
void registerDebuggable(std::string name, Debuggable &debuggable)
Definition: Debugger.cc:48
openmsx::MSXCPU
MSXCPU
Definition: MSXCPU.cc:563
openmsx::Debugger::findDebuggable
Debuggable * findDebuggable(std::string_view name)
Definition: Debugger.cc:61
WatchPoint.hh
openmsx::Debugger::setCPU
void setCPU(MSXCPU *cpu_)
Definition: Debugger.hh:40
span
Definition: span.hh:34
openmsx::Debugger::unregisterProbe
void unregisterProbe(ProbeBase &probe)
Definition: Debugger.cc:82
openmsx::Debuggable
Definition: Debuggable.hh:9
OUTER
#define OUTER(type, member)
Definition: outer.hh:41
RecordedCommand.hh
openmsx::Debugger::~Debugger
~Debugger()
Definition: Debugger.cc:42
openmsx::Debugger::findProbe
ProbeBase * findProbe(std::string_view name)
Definition: Debugger.cc:88
openmsx::WatchPoint::Type
Type
Definition: WatchPoint.hh:16
openmsx::ProbeBreakPoint
Definition: ProbeBreakPoint.hh:12
openmsx::Debugger::operator=
Debugger & operator=(const Debugger &)=delete
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:59
openmsx::MSXCPU
Definition: MSXCPU.hh:28
openmsx::Debugger::getMotherBoard
MSXMotherBoard & getMotherBoard()
Definition: Debugger.hh:44
openmsx::Debugger::Debugger
Debugger(const Debugger &)=delete
hash_map.hh
outer.hh
openmsx::RecordedCommand
Commands that directly influence the MSX state should send and events so that they can be recorded by...
Definition: RecordedCommand.hh:45
hash_set
Definition: hash_set.hh:265
openmsx::ProbeBase
Definition: Probe.hh:12
openmsx::Debugger::removeProbeBreakPoint
void removeProbeBreakPoint(ProbeBreakPoint &bp)
Definition: Debugger.cc:144
openmsx::TclObject
Definition: TclObject.hh:21
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
hash_map
Definition: hash_map.hh:31
openmsx::Debugger::unregisterDebuggable
void unregisterDebuggable(std::string_view name, Debuggable &debuggable)
Definition: Debugger.cc:54