SST 15.0
Structural Simulation Toolkit
watchPoint.h
1// Copyright 2009-2025 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-2025, 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 Class that can attach to Clock and Event Handlers to monitor the
24 state of variables
25 */
26class WatchPoint : public Clock::HandlerBase::AttachPoint, public Event::HandlerBase::AttachPoint
27{
28public:
29 /**
30 Base class for performing comparisons and logic operations for
31 determining when the WatchPoint triggers
32 */
33 class Logic
34 {
35 public:
36 virtual bool check() = 0;
37 virtual ~Logic() = default;
38 };
39
40 WatchPoint(const std::string& name, Core::Serialization::ObjectMapComparison* obj) :
41 Clock::HandlerBase::AttachPoint(),
42 Event::HandlerBase::AttachPoint(),
43 obj_(obj),
44 name_(name)
45 {}
46
47 ~WatchPoint() { delete obj_; }
48
49 // Inherited from both Event and Clock handler AttachPoints.
50 // WatchPoint doesn't use the key, so just return 0.
51 uintptr_t registerHandler(const AttachPointMetaData& UNUSED(mdata)) override { return 0; }
52
53 // Functions inherited from Event::HandlerBase::AttachPoint
54 void beforeHandler(uintptr_t UNUSED(key), const Event* UNUSED(ev)) override { check(); }
55
56 void afterHandler(uintptr_t UNUSED(key)) override {}
57
58 // Functions inherited from Clock::HandlerBase::AttachPoint
59 void beforeHandler(uintptr_t UNUSED(key), const Cycle_t& UNUSED(cycle)) override {}
60
61 void afterHandler(uintptr_t UNUSED(key), const bool& UNUSED(ret)) override { check(); }
62
63 std::string getName() { return name_; }
64
65protected:
66 void setEnterInteractive();
67 void setInteractiveMsg(const std::string& msg);
68
69private:
70 Core::Serialization::ObjectMapComparison* obj_;
71 std::string name_;
72
73 void check()
74 {
75 if ( obj_->compare() ) {
76 setEnterInteractive();
77 setInteractiveMsg(format_string("Watch point %s triggered", name_.c_str()));
78 }
79 }
80};
81
82} // namespace SST
83
84#endif // SST_CORE_WATCHPOINT_H
A Clock class.
Definition clock.h:34
Base class for interacting with data from ObjectMap.
Definition objectMap.h:74
Base class for Events - Items sent across links to communicate between components.
Definition event.h:35
Base class for performing comparisons and logic operations for determining when the WatchPoint trigge...
Definition watchPoint.h:34
Class that can attach to Clock and Event Handlers to monitor the state of variables.
Definition watchPoint.h:27