SST 16.0.0
Structural Simulation Toolkit
watchPoint.h
1// Copyright 2009-2026 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2026, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_WATCHPOINT_H
13#define SST_CORE_WATCHPOINT_H
14
15#include "sst/core/clock.h"
16#include "sst/core/event.h"
17#include "sst/core/serialization/objectMap.h"
18#include "sst/core/stringize.h"
19
20namespace SST {
21
22
23/**
24 Class that can attach to Clock and Event Handlers to monitor the
25 state of variables
26 */
27class WatchPoint : public Clock::HandlerBase::AttachPoint, public Event::HandlerBase::AttachPoint
28{
29public:
30 static const uint32_t VMASK = 0x10; // see debugConsole.h::VERBOSITY_MASK
31
32 /**
33 Base class for performing comparisons and logic operations for
34 determining when the WatchPoint triggers
35 */
36 class Logic
37 {
38 public:
39 virtual bool check() = 0;
40 virtual ~Logic() = default;
41 }; // class Logic
42
43 /**
44 WatchPoint Action Inner Classes
45 */
46 class WPAction
47 {
48 public:
49 WPAction() {}
50 virtual ~WPAction() = default;
51 virtual std::string actionToString() = 0;
52 virtual void invokeAction(WatchPoint* wp) = 0;
53 inline void setVerbosity(uint32_t v) { verbosity = v; }
54
55 protected:
56 uint32_t verbosity = 0;
57 inline void msg(const std::string& msg)
58 {
59 if ( WatchPoint::VMASK & verbosity ) std::cout << msg << std::endl;
60 }
61 }; // class WPAction
62
63 class InteractiveWPAction : public WPAction
64 {
65 public:
66 InteractiveWPAction() {}
67 virtual ~InteractiveWPAction() = default;
68 inline std::string actionToString() override { return "interactive"; }
69 void invokeAction(WatchPoint* wp) override;
70 }; // class InteractiveWPAction
71
72 class PrintTraceWPAction : public WPAction
73 {
74 public:
75 PrintTraceWPAction() {}
76 virtual ~PrintTraceWPAction() = default;
77 inline std::string actionToString() override { return "printTrace"; }
78 void invokeAction(WatchPoint* wp) override;
79 }; // class PrintTraceWPAction
80
81 class CheckpointWPAction : public WPAction
82 {
83 public:
84 CheckpointWPAction() {}
85 virtual ~CheckpointWPAction() = default;
86 inline std::string actionToString() override { return "checkpoint"; }
87 void invokeAction(WatchPoint* wp) override;
88 }; // class CheckpointWPAction
89
90 class PrintStatusWPAction : public WPAction
91 {
92 public:
93 PrintStatusWPAction() {}
94 virtual ~PrintStatusWPAction() = default;
95 inline std::string actionToString() override { return "printStatus"; }
96 void invokeAction(WatchPoint* wp) override;
97 }; // class PrintStatusWPAction
98
99 class SetVarWPAction : public WPAction
100 {
101 public:
102 SetVarWPAction(std::string vname, Core::Serialization::ObjectMap* obj, std::string tval) :
103 name_(vname),
104 obj_(obj),
105 valStr_(tval)
106 {}
107 virtual ~SetVarWPAction() = default;
108 inline std::string actionToString() override { return "set " + name_ + " " + valStr_; }
109 void invokeAction(WatchPoint* wp) override;
110
111 private:
112 std::string name_ = "";
113 Core::Serialization::ObjectMap* obj_ = nullptr;
114 std::string valStr_ = "";
115 }; // class SetVarWPAction
116
117 class ShutdownWPAction : public WPAction
118 {
119 public:
120 ShutdownWPAction() {}
121 virtual ~ShutdownWPAction() = default;
122 inline std::string actionToString() override { return "shutdown"; }
123 void invokeAction(WatchPoint* wp) override;
124 }; // class ShutdownWPAction
125
126 // Construction
127 WatchPoint(size_t index, const std::string& name, Core::Serialization::ObjectMapComparison* obj);
128 ~WatchPoint() = default;
129
130 // Inherited from both Event and Clock handler AttachPoints.
131 // WatchPoint doesn't use the key, so just return 0
132 uintptr_t registerHandler(const AttachPointMetaData& UNUSED(mdata)) override { return 0; }
133
134 // Functions inherited from Event::HandlerBase::AttachPoint
135 void beforeHandler(uintptr_t UNUSED(key), const Event* UNUSED(ev)) override;
136 void afterHandler(uintptr_t UNUSED(key)) override;
137
138 // Functions inherited from Clock::HandlerBase::AttachPoint
139 void beforeHandler(uintptr_t UNUSED(key), const Cycle_t& UNUSED(cycle)) override;
140 void afterHandler(uintptr_t UNUSED(key), const bool& UNUSED(ret)) override;
141
142 // Local
143 inline std::string getName() { return name_; }
144 size_t getBufferSize();
145 void printTriggerRecord();
146 void printTrace();
147
148 enum HANDLER : unsigned {
149 // Select which handlers do check and sample
150 NONE = 0,
151 BEFORE_CLOCK = 1,
152 AFTER_CLOCK = 2,
153 BEFORE_EVENT = 4,
154 AFTER_EVENT = 8,
155 ALL = 15
156 };
157
158 // TODO can we avoid code duplication in WatchPoint and the WatchPointAction?
159 inline void setVerbosity(uint32_t v)
160 {
161 verbosity = v;
162 wpAction->setVerbosity(v);
163 }
164 inline void msg(const std::string& msg)
165 {
166 if ( VMASK & verbosity ) std::cout << msg << std::endl;
167 }
168 void setHandler(unsigned handlerType);
169 std::string handlerToString(HANDLER h);
170 void printHandler(std::stringstream& ss);
171 void genericHandler(HANDLER h);
172 void printWatchpoint(std::stringstream& ss);
173 void resetTraceBuffer();
174 inline bool checkReset() { return reset_; }
175 void printAction(std::stringstream& ss);
176 void addTraceBuffer(Core::Serialization::TraceBuffer* tb);
177 void addObjectBuffer(Core::Serialization::ObjectBuffer* ob);
178 void addComparison(Core::Serialization::ObjectMapComparison* cmp);
179
180 enum LogicOp : unsigned { // Logical Op for trigger tests
181 AND = 0,
182 OR = 1,
183 UNDEFINED = 2
184 };
185 inline void addLogicOp(LogicOp op) { logicOps_.push_back(op); }
186 inline void setAction(WPAction* action) { wpAction = action; }
187
188protected:
189 bool getInteractive();
190 void setEnterInteractive();
191 void setInteractiveMsg(const std::string& msg);
192 SimTime_t getCurrentSimCycle();
193 void setCheckpoint();
194 void printStatus();
195 void heartbeat();
196 void simulationShutdown();
197
198private:
199 size_t numCmpObj_ = 0;
200 std::vector<Core::Serialization::ObjectMapComparison*> cmpObjects_;
201 std::vector<LogicOp> logicOps_;
202 std::string name_;
203 Core::Serialization::TraceBuffer* tb_ = nullptr;
204 size_t wpIndex;
205 HANDLER handler = ALL;
206 bool trigger = false;
207 HANDLER triggerHandler = HANDLER::NONE;
208 size_t triggerCount = 0;
209 bool reset_ = false;
210 WPAction* wpAction;
211
212 void setBufferReset();
213 void check();
214 uint32_t verbosity = 0;
215
216
217}; // class WatchPoint
218
219
220} // namespace SST
221
222
223#endif // SST_CORE_WATCHPOINT_H
Base class for interacting with data from ObjectMap.
Definition objectMap.h:117
Base class for objects created by the serializer mapping mode used to map the variables for objects.
Definition objectMap.h:188
Base class for Events - Items sent across links to communicate between components.
Definition event.h:41
Base class for performing comparisons and logic operations for determining when the WatchPoint trigge...
Definition watchPoint.h:37
WatchPoint Action Inner Classes.
Definition watchPoint.h:47
Struct used as a base class for all AttachPoint metadata passed to registration functions.
Definition sst_types.h:201