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
14namespace openmsx {
15
16class MSXMotherBoard;
17class Debuggable;
18class ProbeBase;
19class ProbeBreakPoint;
20class MSXCPU;
21
23{
24public:
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
46private:
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,
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(std::span<const TclObject> tokens) const override;
68 void execute(std::span<const TclObject> tokens,
69 TclObject& result, EmuTime::param time) override;
70 [[nodiscard]] std::string help(std::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(std::span<const TclObject> tokens, TclObject& result);
78 void size(std::span<const TclObject> tokens, TclObject& result);
79 void read(std::span<const TclObject> tokens, TclObject& result);
80 void readBlock(std::span<const TclObject> tokens, TclObject& result);
81 void write(std::span<const TclObject> tokens, TclObject& result);
82 void writeBlock(std::span<const TclObject> tokens, TclObject& result);
83 void setBreakPoint(std::span<const TclObject> tokens, TclObject& result);
84 void removeBreakPoint(std::span<const TclObject> tokens, TclObject& result);
85 void listBreakPoints(std::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(std::span<const TclObject> tokens, TclObject& result);
90 void removeWatchPoint(std::span<const TclObject> tokens, TclObject& result);
91 void listWatchPoints(std::span<const TclObject> tokens, TclObject& result);
92 void setCondition(std::span<const TclObject> tokens, TclObject& result);
93 void removeCondition(std::span<const TclObject> tokens, TclObject& result);
94 void listConditions(std::span<const TclObject> tokens, TclObject& result);
95 void probe(std::span<const TclObject> tokens, TclObject& result);
96 void probeList(std::span<const TclObject> tokens, TclObject& result);
97 void probeDesc(std::span<const TclObject> tokens, TclObject& result);
98 void probeRead(std::span<const TclObject> tokens, TclObject& result);
99 void probeSetBreakPoint(std::span<const TclObject> tokens, TclObject& result);
100 void probeRemoveBreakPoint(std::span<const TclObject> tokens, TclObject& result);
101 void probeListBreakPoints(std::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:73
void setCPU(MSXCPU *cpu_)
Definition: Debugger.hh:40
Debuggable * findDebuggable(std::string_view name)
Definition: Debugger.cc:58
Debugger(const Debugger &)=delete
void transfer(Debugger &other)
Definition: Debugger.cc:167
void unregisterProbe(ProbeBase &probe)
Definition: Debugger.cc:79
void unregisterDebuggable(std::string_view name, Debuggable &debuggable)
Definition: Debugger.cc:51
ProbeBase * findProbe(std::string_view name)
Definition: Debugger.cc:85
MSXMotherBoard & getMotherBoard()
Definition: Debugger.hh:44
void removeProbeBreakPoint(ProbeBreakPoint &bp)
Definition: Debugger.cc:141
void registerDebuggable(std::string name, Debuggable &debuggable)
Definition: Debugger.cc:45
Debugger & operator=(const Debugger &)=delete
Commands that directly influence the MSX state should send and events so that they can be recorded by...
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