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