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 disasm(std::span<const TclObject> tokens, TclObject& result, EmuTime::param time) const;
90 void disasmBlob(std::span<const TclObject> tokens, TclObject& result) const;
91 void setBreakPoint(std::span<const TclObject> tokens, TclObject& result);
92 void removeBreakPoint(std::span<const TclObject> tokens, TclObject& result);
93 void listBreakPoints(std::span<const TclObject> tokens, TclObject& result) const;
94 [[nodiscard]] std::vector<std::string> getBreakPointIds() const;
95 [[nodiscard]] std::vector<std::string> getWatchPointIds() const;
96 [[nodiscard]] std::vector<std::string> getConditionIds() const;
97 void setWatchPoint(std::span<const TclObject> tokens, TclObject& result);
98 void removeWatchPoint(std::span<const TclObject> tokens, TclObject& result);
99 void listWatchPoints(std::span<const TclObject> tokens, TclObject& result);
100 void setCondition(std::span<const TclObject> tokens, TclObject& result);
101 void removeCondition(std::span<const TclObject> tokens, TclObject& result);
102 void listConditions(std::span<const TclObject> tokens, TclObject& result) const;
103 void probe(std::span<const TclObject> tokens, TclObject& result);
104 void probeList(std::span<const TclObject> tokens, TclObject& result);
105 void probeDesc(std::span<const TclObject> tokens, TclObject& result);
106 void probeRead(std::span<const TclObject> tokens, TclObject& result);
107 void probeSetBreakPoint(std::span<const TclObject> tokens, TclObject& result);
108 void probeRemoveBreakPoint(std::span<const TclObject> tokens, TclObject& result);
109 void probeListBreakPoints(std::span<const TclObject> tokens, TclObject& result);
110 void symbols(std::span<const TclObject> tokens, TclObject& result);
111 void symbolsTypes(std::span<const TclObject> tokens, TclObject& result) const;
112 void symbolsLoad(std::span<const TclObject> tokens, TclObject& result);
113 void symbolsRemove(std::span<const TclObject> tokens, TclObject& result);
114 void symbolsFiles(std::span<const TclObject> tokens, TclObject& result);
115 void symbolsLookup(std::span<const TclObject> tokens, TclObject& result);
116 } cmd;
117
118 struct NameFromProbe {
119 [[nodiscard]] const std::string& operator()(const ProbeBase* p) const {
120 return p->getName();
121 }
122 };
123
126 std::vector<std::unique_ptr<ProbeBreakPoint>> probeBreakPoints; // unordered
127 MSXCPU* cpu = nullptr;
128};
129
130} // namespace openmsx
131
132#endif
Debugger(Debugger &&)=delete
void registerProbe(ProbeBase &probe)
Definition Debugger.cc:81
void setCPU(MSXCPU *cpu_)
Definition Debugger.hh:50
Debuggable * findDebuggable(std::string_view name)
Definition Debugger.cc:66
Debugger(const Debugger &)=delete
Debugger & operator=(Debugger &&)=delete
const auto & getDebuggables() const
Definition Debugger.hh:38
void transfer(Debugger &other)
Definition Debugger.cc:175
void unregisterProbe(ProbeBase &probe)
Definition Debugger.cc:87
void unregisterDebuggable(std::string_view name, Debuggable &debuggable)
Definition Debugger.cc:59
ProbeBase * findProbe(std::string_view name)
Definition Debugger.cc:93
MSXMotherBoard & getMotherBoard()
Definition Debugger.hh:54
void removeProbeBreakPoint(ProbeBreakPoint &bp)
Definition Debugger.cc:149
void registerDebuggable(std::string name, Debuggable &debuggable)
Definition Debugger.cc:53
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:157
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