@@ -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