SST 16.1.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/impl/interactive/ObjTreeHelpers.h"
18#include "sst/core/serialization/objectMap.h"
19#include "sst/core/stringize.h"
20
21namespace SST {
22
23
24/**
25 Class that can attach to Clock and Event Handlers to monitor the
26 state of variables
27 */
28class WatchPoint : public Clock::HandlerBase::AttachPoint, public Event::HandlerBase::AttachPoint
29{
30public:
31 static const uint32_t VMASK = 0x10; // see debugConsole.h::VERBOSITY_MASK
32
33 /**
34 Base class for performing comparisons and logic operations for
35 determining when the WatchPoint triggers
36 */
37 class Logic
38 {
39 public:
40 virtual bool check() = 0;
41 virtual ~Logic() = default;
42 }; // class Logic
43
44 /**
45 WatchPoint Action Inner Classes
46 */
47 class WPAction
48 {
49 public:
50 WPAction() {}
51 virtual ~WPAction() = default;
52 virtual std::string actionToString() = 0;
53 virtual void invokeAction(WatchPoint* wp) = 0;
54 inline void setVerbosity(uint32_t v) { verbosity = v; }
55
56 protected:
57 uint32_t verbosity = 0;
58 inline void msg(const std::string& msg)
59 {
60 if ( WatchPoint::VMASK & verbosity ) std::cout << msg << std::endl;
61 }
62 }; // class WPAction
63
64 class InteractiveWPAction : public WPAction
65 {
66 public:
67 InteractiveWPAction() {}
68 virtual ~InteractiveWPAction() = default;
69 inline std::string actionToString() override { return "interactive"; }
70 void invokeAction(WatchPoint* wp) override;
71 }; // class InteractiveWPAction
72
73 class PrintTraceWPAction : public WPAction
74 {
75 public:
76 PrintTraceWPAction() {}
77 virtual ~PrintTraceWPAction() = default;
78 inline std::string actionToString() override { return "printTrace"; }
79 void invokeAction(WatchPoint* wp) override;
80 }; // class PrintTraceWPAction
81
82 class CheckpointWPAction : public WPAction
83 {
84 public:
85 CheckpointWPAction() {}
86 virtual ~CheckpointWPAction() = default;
87 inline std::string actionToString() override { return "checkpoint"; }
88 void invokeAction(WatchPoint* wp) override;
89 }; // class CheckpointWPAction
90
91 class PrintStatusWPAction : public WPAction
92 {
93 public:
94 PrintStatusWPAction() {}
95 virtual ~PrintStatusWPAction() = default;
96 inline std::string actionToString() override { return "printStatus"; }
97 void invokeAction(WatchPoint* wp) override;
98 }; // class PrintStatusWPAction
99
100 class SetVarWPAction : public WPAction
101 {
102 public:
103 SetVarWPAction(std::string vname, Core::Serialization::ObjTreeCont* obj, std::string tval) :
104 name_(vname),
105 obj_(obj),
106 valStr_(tval)
107 {}
108 virtual ~SetVarWPAction() = default;
109 inline std::string actionToString() override { return "set " + name_ + " " + valStr_; }
110 void invokeAction(WatchPoint* wp) override;
111
112 private:
113 std::string name_ = "";
114 Core::Serialization::ObjTreeCont* obj_ = nullptr;
115 std::string valStr_ = "";
116 }; // class SetVarWPAction
117
118 class ShutdownWPAction : public WPAction
119 {
120 public:
121 ShutdownWPAction() {}
122 virtual ~ShutdownWPAction() = default;
123 inline std::string actionToString() override { return "shutdown"; }
124 void invokeAction(WatchPoint* wp) override;
125 }; // class ShutdownWPAction
126
127 // Construction
128 WatchPoint(size_t index, const std::string& name, Core::Serialization::ObjTreeComparison* obj);
129 ~WatchPoint() = default;
130
131 // Inherited from both Event and Clock handler AttachPoints.
132 // WatchPoint doesn't use the key, so just return 0
133 uintptr_t registerHandler(const AttachPointMetaData& UNUSED(mdata)) override { return 0; }
134
135 // Functions inherited from Event::HandlerBase::AttachPoint
136 void beforeHandler(uintptr_t UNUSED(key), const Event* UNUSED(ev)) override;
137 void afterHandler(uintptr_t UNUSED(key)) override;
138
139 // Functions inherited from Clock::HandlerBase::AttachPoint
140 void beforeHandler(uintptr_t UNUSED(key), const Cycle_t& UNUSED(cycle)) override;
141 void afterHandler(uintptr_t UNUSED(key), const bool& UNUSED(ret)) override;
142
143 // Local
144 inline std::string getName() { return name_; }
145 size_t getBufferSize();
146 void printTriggerRecord();
147 void printTrace(std::ostream& os = std::cout);
148
149 enum HANDLER : unsigned {
150 // Select which handlers do check and sample
151 NONE = 0,
152 BEFORE_CLOCK = 1,
153 AFTER_CLOCK = 2,
154 BEFORE_EVENT = 4,
155 AFTER_EVENT = 8,
156 ALL = 15
157 };
158
159 // TODO can we avoid code duplication in WatchPoint and the WatchPointAction?
160 inline void setVerbosity(uint32_t v)
161 {
162 verbosity = v;
163 wpAction->setVerbosity(v);
164 }
165 inline void msg(const std::string& msg)
166 {
167 if ( VMASK & verbosity ) std::cout << msg << std::endl;
168 }
169 void setHandler(unsigned handlerType);
170 std::string handlerToString(HANDLER h);
171 void printHandler(std::stringstream& ss);
172 void genericHandler(HANDLER h);
173 void printWatchpoint(std::stringstream& ss);
174 void resetTraceBuffer();
175 inline bool checkReset() { return reset_; }
176 void printAction(std::stringstream& ss);
177 void addTraceBuffer(Core::Serialization::ObjTreeTraceBuffer* tb);
178 void addObjectBuffer(std::unique_ptr<Core::Serialization::ObjTreeCont> ob);
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::unique_ptr<Core::Serialization::ObjTreeComparison> cmpObjects_;
201 std::vector<LogicOp> logicOps_;
202 std::string name_;
203 Core::Serialization::ObjTreeTraceBuffer* 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
Definition ObjTreeHelpers.h:34
The Object Tree (ObjTree) is intended to be a developer friendly interface to SST’s existing serializ...
Definition ObjTreeLeaves.h:41
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:38
WatchPoint Action Inner Classes.
Definition watchPoint.h:48
Struct used as a base class for all AttachPoint metadata passed to registration functions.
Definition sst_types.h:201