| 1 |
#ifndef TRACER_HH |
| 2 |
#define TRACER_HH |
| 3 |
|
| 4 |
#include "EmuTime.hh" |
| 5 |
#include "StateChangeListener.hh" |
| 6 |
#include "TclObject.hh" |
| 7 |
#include "TraceValue.hh" |
| 8 |
|
| 9 |
#include "Observer.hh" |
| 10 |
|
| 11 |
#include <memory> |
| 12 |
|
| 13 |
namespace openmsx { |
| 14 |
|
| 15 |
class Command; |
| 16 |
class Debugger; |
| 17 |
class MSXMotherBoard; |
| 18 |
class ProbeBase; |
| 19 |
class StateChangeDistributor; |
| 20 |
|
| 21 |
class Tracer final : public StateChangeListener |
| 22 |
{ |
| 23 |
public: |
| 24 |
struct Event { |
| 25 |
EmuTime time; |
| 26 |
TraceValue value; |
| 27 |
}; |
| 28 |
struct Trace final : Observer<ProbeBase> { |
| 29 |
|
| 30 |
enum class Type : uint8_t { MONOSTATE = 0, BOOL = 1, INTEGER = 2, DOUBLE = 3, STRING = 4 }; |
| 31 |
|
| 32 |
|
| 33 |
enum class Format : uint8_t { BIN, DEC, HEX }; |
| 34 |
|
| 35 |
explicit Trace(std::string name_) : name(std::move(name_)) {} |
| 36 |
|
| 37 |
void addEvent(EmuTime t, TraceValue v, bool merge); |
| 38 |
void clear(); |
| 39 |
void attachProbe(Debugger& debugger, ProbeBase& probe); |
| 40 |
void detachProbe(ProbeBase& probe); |
| 41 |
void update(const ProbeBase& subject) noexcept override; |
| 42 |
|
| 43 |
[[nodiscard]] bool isBool() const { return type == Type::BOOL; } |
| 44 |
[[nodiscard]] Type getType() const { return type; } |
| 45 |
[[nodiscard]] Format getFormat() const { return format; } |
| 46 |
void setFormat(Format f) { format = f; } |
| 47 |
[[nodiscard]] bool isProbe() const { return motherBoard != nullptr; } |
| 48 |
[[nodiscard]] bool isUserTrace() const { return !isProbe(); } |
| 49 |
|
| 50 |
std::string name; |
| 51 |
std::string description; |
| 52 |
std::vector<Event> events; |
| 53 |
MSXMotherBoard* motherBoard = nullptr; |
| 54 |
Type type = Type::MONOSTATE; |
| 55 |
Format format = Format::DEC; |
| 56 |
}; |
| 57 |
|
| 58 |
public: |
| 59 |
explicit Tracer(Debugger& debugger); |
| 60 |
~Tracer(); |
| 61 |
Tracer(const Tracer&) = delete; |
| 62 |
Tracer(Tracer&&) = delete; |
| 63 |
Tracer& operator=(const Tracer&) = delete; |
| 64 |
Tracer& operator=(Tracer&&) = delete; |
| 65 |
|
| 66 |
void execute(Debugger& debugger, std::span<const TclObject> tokens, TclObject& result, EmuTime time); |
| 67 |
void tabCompletion(const Debugger& debugger, std::vector<std::string>& tokens) const; |
| 68 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const; |
| 69 |
|
| 70 |
[[nodiscard]] const auto& getTraces() const { return traces; } |
| 71 |
[[nodiscard]] Trace* findTrace(std::string_view name); |
| 72 |
void probeCreated(Debugger& debugger, ProbeBase& probe); |
| 73 |
void probeRemoved(ProbeBase& probe); |
| 74 |
void selectProbe (Debugger& debugger, std::string_view name); |
| 75 |
void unselectProbe(Debugger& debugger, std::string_view name); |
| 76 |
|
| 77 |
void exportVCD(zstring_view filename); |
| 78 |
|
| 79 |
void transfer(Debugger& oldDebugger, Debugger& newDebugger); |
| 80 |
|
| 81 |
private: |
| 82 |
[[nodiscard]] Trace& getOrCreateTrace(Debugger& debugger, std::string_view name); |
| 83 |
void add (Debugger& debugger, std::span<const TclObject> tokens, TclObject& result, EmuTime time); |
| 84 |
void list (Command& cmd, std::span<const TclObject> tokens, TclObject& result); |
| 85 |
void drop (Debugger& debugger, std::span<const TclObject> tokens, TclObject& result); |
| 86 |
void probe(Debugger& debugger, std::span<const TclObject> tokens, TclObject& result); |
| 87 |
void dropTrace(Debugger& debugger, std::string_view name); |
| 88 |
|
| 89 |
|
| 90 |
void signalStateChange(const StateChange& ) override {} |
| 91 |
void stopReplay(EmuTime time) noexcept override; |
| 92 |
|
| 93 |
private: |
| 94 |
StateChangeDistributor& stateChangeDistributor; |
| 95 |
std::vector<std::unique_ptr<Trace>> traces; |
| 96 |
}; |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
#endif |