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
8#include "hash_map.hh"
9#include "outer.hh"
10#include "xxhash.hh"
11
12#include <string_view>
13#include <vector>
14#include <memory>
15
16namespace openmsx {
17
18class MSXMotherBoard;
19class Debuggable;
20class ProbeBase;
21class ProbeBreakPoint;
22class MSXCPU;
23class SymbolManager;
24
26{
27public:
28 explicit Debugger(MSXMotherBoard& motherBoard);
29 Debugger(const Debugger&) = delete;
30 Debugger(Debugger&&) = delete;
31 Debugger& operator=(const Debugger&) = delete;
33 ~Debugger();
34
35 void registerDebuggable (std::string name, Debuggable& debuggable);
36 void unregisterDebuggable (std::string_view name, Debuggable& debuggable);
37 [[nodiscard]] Debuggable* findDebuggable(std::string_view name);
38 [[nodiscard]] const auto& getDebuggables() const { return debuggables; }
39
40 void registerProbe (ProbeBase& probe);
41 void unregisterProbe(ProbeBase& probe);
42 [[nodiscard]] ProbeBase* findProbe(std::string_view name);
43
44 unsigned setWatchPoint(TclObject command, TclObject condition,
46 unsigned beginAddr, unsigned endAddr,
47 bool once, unsigned newId = -1);
48
50 void setCPU(MSXCPU* cpu_) { cpu = cpu_; }
51
52 void transfer(Debugger& other);
53
54 [[nodiscard]] MSXMotherBoard& getMotherBoard() { return motherBoard; }
55
56private:
57 [[nodiscard]] Debuggable& getDebuggable(std::string_view name);
58 [[nodiscard]] ProbeBase& getProbe(std::string_view name);
59
60 unsigned insertProbeBreakPoint(
61 TclObject command, TclObject condition,
62 ProbeBase& probe, bool once, unsigned newId = -1);
63 void removeProbeBreakPoint(std::string_view name);
64
65 MSXMotherBoard& motherBoard;
66
67 class Cmd final : public RecordedCommand {
68 public:
69 Cmd(CommandController& commandController,
70 StateChangeDistributor& stateChangeDistributor,
71 Scheduler& scheduler);
72 [[nodiscard]] bool needRecord(std::span<const TclObject> tokens) const override;
73 void execute(std::span<const TclObject> tokens,
74 TclObject& result, EmuTime::param time) override;
75 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
76 void tabCompletion(std::vector<std::string>& tokens) const override;
77
78 private:
79 [[nodiscard]] Debugger& debugger() { return OUTER(Debugger, cmd); }
80 [[nodiscard]] const Debugger& debugger() const { return OUTER(Debugger, cmd); }
81 [[nodiscard]] SymbolManager& getSymbolManager();
82 void list(TclObject& result);
83 void desc(std::span<const TclObject> tokens, TclObject& result);
84 void size(std::span<const TclObject> tokens, TclObject& result);
85 void read(std::span<const TclObject> tokens, TclObject& result);
86 void readBlock(std::span<const TclObject> tokens, TclObject& result);
87 void write(std::span<const TclObject> tokens, TclObject& result);
88 void writeBlock(std::span<const TclObject> tokens, TclObject& result);
89 void setBreakPoint(std::span<const TclObject> tokens, TclObject& result);
90 void removeBreakPoint(std::span<const TclObject> tokens, TclObject& result);
91 void listBreakPoints(std::span<const TclObject> tokens, TclObject& result) const;
92 [[nodiscard]] std::vector<std::string> getBreakPointIds() const;
93 [[nodiscard]] std::vector<std::string> getWatchPointIds() const;
94 [[nodiscard]] std::vector<std::string> getConditionIds() const;
95 void setWatchPoint(std::span<const TclObject> tokens, TclObject& result);
96 void removeWatchPoint(std::span<const TclObject> tokens, TclObject& result);
97 void listWatchPoints(std::span<const TclObject> tokens, TclObject& result);
98 void setCondition(std::span<const TclObject> tokens, TclObject& result);
99 void removeCondition(std::span<const TclObject> tokens, TclObject& result);
100 void listConditions(std::span<const TclObject> tokens, TclObject& result) const;
101 void probe(std::span<const TclObject> tokens, TclObject& result);
102 void probeList(std::span<const TclObject> tokens, TclObject& result);
103 void probeDesc(std::span<const TclObject> tokens, TclObject& result);
104 void probeRead(std::span<const TclObject> tokens, TclObject& result);
105 void probeSetBreakPoint(std::span<const TclObject> tokens, TclObject& result);
106 void probeRemoveBreakPoint(std::span<const TclObject> tokens, TclObject& result);
107 void probeListBreakPoints(std::span<const TclObject> tokens, TclObject& result);
108 void symbols(std::span<const TclObject> tokens, TclObject& result);
109 void symbolsTypes(std::span<const TclObject> tokens, TclObject& result) const;
110 void symbolsLoad(std::span<const TclObject> tokens, TclObject& result);
111 void symbolsRemove(std::span<const TclObject> tokens, TclObject& result);
112 void symbolsFiles(std::span<const TclObject> tokens, TclObject& result);
113 void symbolsLookup(std::span<const TclObject> tokens, TclObject& result);
114 } cmd;
115
116 struct NameFromProbe {
117 [[nodiscard]] const std::string& operator()(const ProbeBase* p) const {
118 return p->getName();
119 }
120 };
121
124 std::vector<std::unique_ptr<ProbeBreakPoint>> probeBreakPoints; // unordered
125 MSXCPU* cpu = nullptr;
126};
127
128} // namespace openmsx
129
130#endif
Debugger(Debugger &&)=delete
void registerProbe(ProbeBase &probe)
Definition Debugger.cc:79
void setCPU(MSXCPU *cpu_)
Definition Debugger.hh:50
Debuggable * findDebuggable(std::string_view name)
Definition Debugger.cc:64
Debugger(const Debugger &)=delete
Debugger & operator=(Debugger &&)=delete
const auto & getDebuggables() const
Definition Debugger.hh:38
void transfer(Debugger &other)
Definition Debugger.cc:173
void unregisterProbe(ProbeBase &probe)
Definition Debugger.cc:85
void unregisterDebuggable(std::string_view name, Debuggable &debuggable)
Definition Debugger.cc:57
ProbeBase * findProbe(std::string_view name)
Definition Debugger.cc:91
MSXMotherBoard & getMotherBoard()
Definition Debugger.hh:54
void removeProbeBreakPoint(ProbeBreakPoint &bp)
Definition Debugger.cc:147
void registerDebuggable(std::string name, Debuggable &debuggable)
Definition Debugger.cc:51
Debugger & operator=(const Debugger &)=delete
unsigned setWatchPoint(TclObject command, TclObject condition, WatchPoint::Type type, unsigned beginAddr, unsigned endAddr, bool once, unsigned newId=-1)
Definition Debugger.cc:155
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:11
size_t size(std::string_view utf8)
#define OUTER(type, member)
Definition outer.hh:42