Skip to content

Commit 4e4d4e5

Browse files
committed
Add watchpoint action class and add set var val action
1 parent f3b172a commit 4e4d4e5

File tree

2 files changed

+130
-85
lines changed

2 files changed

+130
-85
lines changed

src/sst/core/serialization/objectMap.h

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@ class ObjectMapComparison
134134
virtual void print() = 0;
135135
std::string getName() { return name_; }
136136

137-
#if 0
138-
void * getVar() {
139-
if ( obj_ != nullptr && obj_->isFundamental() )
140-
return nullptr; //obj_->getAddr(); }
141-
#endif
142137
virtual void* getVar() = 0;
143138

144139
protected:
@@ -206,7 +201,7 @@ class ObjectMap
206201
Function that will get called when this object is deactivated
207202
(i.e selectParent() is called)
208203
*/
209-
virtual void deactivate_callback() {}
204+
virtual void deactivate_callback() {}
210205

211206
private:
212207
/**
@@ -242,6 +237,13 @@ class ObjectMap
242237
*/
243238
void setReadOnly(bool state = true) { read_only_ = state; }
244239

240+
/**
241+
Check if value string is valid for this type
242+
243+
@param value Value to set the object to expressed as a string
244+
*/
245+
virtual bool checkValue(const std::string& UNUSED(value)) { return false; }
246+
245247

246248
/**
247249
Get the name of the variable represented by this ObjectMap. If
@@ -326,12 +328,6 @@ class ObjectMap
326328
{
327329
return nullptr;
328330
}
329-
#if 0
330-
virtual TraceBuffer* getTraceBuffer(ObjectMap* UNUSED(obj), size_t UNUSED(sz), size_t UNUSED(pdelay)) // Add name
331-
{
332-
return nullptr;
333-
}
334-
#endif
335331

336332
virtual ObjectBuffer* getObjectBuffer(const std::string& UNUSED(name), size_t UNUSED(sz)) { return nullptr; }
337333

@@ -1089,6 +1085,24 @@ class ObjectMapFundamental : public ObjectMap
10891085
*/
10901086
virtual void set_impl(const std::string& value) override { *addr_ = SST::Core::from_string<T>(value); }
10911087

1088+
virtual bool checkValue(const std::string& value) override {
1089+
bool ret = false;
1090+
try {
1091+
T v = SST::Core::from_string<T>(value);
1092+
ret = static_cast<bool>(v);
1093+
}
1094+
catch (const std::invalid_argument& e) {
1095+
std::cerr << "Error: Invalid value: " << value << std::endl;
1096+
return false;
1097+
}
1098+
catch (const std::out_of_range& e) {
1099+
std::cerr << "Error: Value is out of range: " << value << std::endl;
1100+
return false;
1101+
}
1102+
ret = true;
1103+
return ret;
1104+
}
1105+
10921106
/**
10931107
Get the value of the object as a string
10941108
*/
@@ -1141,13 +1155,6 @@ class ObjectMapFundamental : public ObjectMap
11411155
{
11421156
return new ObjectMapComparison_impl<T>(name, addr_, op, value);
11431157
}
1144-
#if 0
1145-
TraceBuffer* getTraceBuffer(ObjectMap* obj, size_t sz, size_t pdelay) override // Add name
1146-
{
1147-
1148-
return new TraceBuffer(obj, sz, pdelay);
1149-
}
1150-
#endif
11511158

11521159
ObjectBuffer* getObjectBuffer(const std::string& name, size_t sz) override
11531160
{

src/sst/core/watchPoint.h

Lines changed: 104 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ class WatchPoint : public Clock::HandlerBase::AttachPoint, public Event::Handler
7171
trigger = false;
7272
if ( invoke ) {
7373
setBufferReset();
74-
invokeAction();
74+
wpAction->invokeAction(this);
7575
}
7676
}
7777
else {
7878
printf(" No trace buffer\n");
7979
if ( trigger ) {
80-
invokeAction();
80+
wpAction->invokeAction(this);
8181
}
8282
}
8383
} // if AFTER_EVENT
@@ -100,13 +100,13 @@ class WatchPoint : public Clock::HandlerBase::AttachPoint, public Event::Handler
100100
trigger = false;
101101
if ( invoke ) {
102102
setBufferReset();
103-
invokeAction();
103+
wpAction->invokeAction(this);
104104
}
105105
}
106106
else {
107107
printf(" No trace buffer\n");
108108
if ( trigger ) {
109-
invokeAction();
109+
wpAction->invokeAction(this);
110110
}
111111
}
112112
} // if AFTER_EVENT
@@ -129,13 +129,13 @@ class WatchPoint : public Clock::HandlerBase::AttachPoint, public Event::Handler
129129
trigger = false;
130130
if ( invoke ) {
131131
setBufferReset();
132-
invokeAction();
132+
wpAction->invokeAction(this);
133133
}
134134
}
135135
else {
136136
printf(" No trace buffer\n");
137137
if ( trigger ) {
138-
invokeAction();
138+
wpAction->invokeAction(this);
139139
}
140140
}
141141
} // if AFTER_CLOCK
@@ -157,13 +157,13 @@ class WatchPoint : public Clock::HandlerBase::AttachPoint, public Event::Handler
157157
trigger = false;
158158
if ( invoke ) {
159159
setBufferReset();
160-
invokeAction();
160+
wpAction->invokeAction(this);
161161
}
162162
}
163163
else {
164164
printf(" No trace buffer\n");
165165
if ( trigger ) {
166-
invokeAction();
166+
wpAction->invokeAction(this);
167167
}
168168
}
169169
} // if AFTER_CLOCK
@@ -241,38 +241,108 @@ class WatchPoint : public Clock::HandlerBase::AttachPoint, public Event::Handler
241241
}
242242
}
243243

244+
bool checkReset() { return reset_; }
244245

245-
enum WPACTION : unsigned { // Watchpoint Action
246-
INTERACTIVE = 0,
247-
PRINT_TRACE = 1,
248-
CHECKPOINT = 2,
249-
PRINT_STATUS = 3,
250-
HEARTBEAT = 4,
251-
INVALID = 5
246+
class WPAction
247+
{
248+
public:
249+
WPAction() {}
250+
virtual ~WPAction() = default;
251+
252+
virtual std::string actionToString() = 0;
253+
virtual void invokeAction(WatchPoint* wp) = 0;
252254
};
253255

254-
std::string actionToString(WPACTION wpa)
255-
{
256+
class InteractiveWPAction : public WPAction {
257+
public:
258+
InteractiveWPAction() {}
259+
virtual ~InteractiveWPAction() = default;
260+
261+
std::string actionToString() override { return "interactive"; }
256262

257-
switch ( wpa ) {
258-
case INTERACTIVE:
259-
return "interactive";
260-
case PRINT_TRACE:
261-
return "printTrace";
262-
case CHECKPOINT:
263-
return "checkpoint";
264-
case HEARTBEAT:
265-
return "heartbeat";
266-
case INVALID:
267-
return "invalid action";
268-
default:
269-
return "undefined action";
263+
void invokeAction(WatchPoint* wp) override {
264+
printf(" SetInteractive\n");
265+
wp->setEnterInteractive(); // Trigger action
266+
wp->setInteractiveMsg(format_string("Watch point %s buffer", wp->name_.c_str()));
267+
// Note that the interactive action is delayed and
268+
// we want to be able to print the Trace Buffer there.
269+
// So, resetTraceBuffer for this case is in handlers
270270
}
271-
}
271+
};
272272

273-
void setAction(WPACTION actionType) { wpAction = actionType; }
273+
class PrintTraceWPAction : public WPAction {
274+
public:
275+
PrintTraceWPAction() {}
276+
virtual ~PrintTraceWPAction() = default;
277+
278+
std::string actionToString() override { return "printTrace"; }
279+
280+
void invokeAction(WatchPoint* wp) override {
281+
wp->printTrace();
282+
if (wp->checkReset()) wp->resetTraceBuffer();
283+
}
284+
};
285+
286+
class CheckpointWPAction : public WPAction {
287+
public:
288+
CheckpointWPAction() {}
289+
virtual ~CheckpointWPAction() = default;
290+
291+
std::string actionToString() override { return "checkpoint"; }
292+
293+
void invokeAction(WatchPoint* wp) override {
294+
wp->setCheckpoint();
295+
if (wp->checkReset()) wp->resetTraceBuffer();
296+
}
297+
};
298+
299+
class PrintStatusWPAction : public WPAction {
300+
public:
301+
PrintStatusWPAction() {}
302+
virtual ~PrintStatusWPAction() = default;
274303

275-
void printAction() { std::cout << actionToString(wpAction); }
304+
std::string actionToString() override { return "printStatus"; }
305+
306+
void invokeAction(WatchPoint* wp) override {
307+
wp->printStatus();
308+
if (wp->checkReset()) wp->resetTraceBuffer();
309+
}
310+
};
311+
312+
class SetVarWPAction : public WPAction {
313+
public:
314+
SetVarWPAction(std::string vname, Core::Serialization::ObjectMap* obj, std::string tval):
315+
name_(vname),
316+
obj_(obj),
317+
valStr_(tval)
318+
{}
319+
320+
virtual ~SetVarWPAction() = default;
321+
322+
std::string actionToString() override {
323+
return "set " + name_ + " " + valStr_; }
324+
325+
void invokeAction(WatchPoint* wp) override {
326+
try {
327+
obj_->set(valStr_);
328+
}
329+
catch (std::exception& e) {
330+
printf("Invalid set var: %s\n", valStr_.c_str());
331+
return;
332+
}
333+
334+
if (wp->checkReset()) wp->resetTraceBuffer();
335+
}
336+
337+
private:
338+
std::string name_ = "";
339+
Core::Serialization::ObjectMap* obj_ = nullptr;
340+
std::string valStr_ = "";
341+
};
342+
343+
void setAction(WPAction* action) { wpAction = action; }
344+
345+
void printAction() { std::cout << wpAction->actionToString(); }
276346

277347
void addTraceBuffer(Core::Serialization::TraceBuffer* tb) { tb_ = tb; }
278348

@@ -313,7 +383,7 @@ class WatchPoint : public Clock::HandlerBase::AttachPoint, public Event::Handler
313383
unsigned handler = ALL;
314384
bool trigger = false;
315385
bool reset_ = false;
316-
WPACTION wpAction = INTERACTIVE;
386+
WPAction* wpAction;
317387

318388
void setBufferReset()
319389
{
@@ -324,38 +394,6 @@ class WatchPoint : public Clock::HandlerBase::AttachPoint, public Event::Handler
324394
}
325395
}
326396

327-
void invokeAction()
328-
{
329-
switch ( wpAction ) {
330-
case INTERACTIVE:
331-
printf(" SetInteractive\n");
332-
setEnterInteractive(); // Trigger action
333-
setInteractiveMsg(format_string("Watch point %s buffer", name_.c_str()));
334-
// Note that the interactive action is delayed and
335-
// we want to be able to print the Trace Buffer there.
336-
// So, resetTraceBuffer for this case is in handlers
337-
break;
338-
case PRINT_TRACE:
339-
tb_->dumpTraceBufferT();
340-
if ( reset_ ) resetTraceBuffer();
341-
break;
342-
case CHECKPOINT:
343-
setCheckpoint();
344-
if ( reset_ ) resetTraceBuffer();
345-
break;
346-
case PRINT_STATUS:
347-
printStatus();
348-
if ( reset_ ) resetTraceBuffer();
349-
break;
350-
case HEARTBEAT:
351-
heartbeat();
352-
if ( reset_ ) resetTraceBuffer();
353-
break;
354-
default:
355-
printf("ERROR: invalid watchpoint action\n");
356-
}
357-
}
358-
359397
void check()
360398
{
361399
bool result = false;

0 commit comments

Comments
 (0)