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