12 #ifndef SST_CORE_IMPL_INTERACTIVE_SIMPLEDEBUG_H 13 #define SST_CORE_IMPL_INTERACTIVE_SIMPLEDEBUG_H 16 #include "sst/core/eli/elementinfo.h" 20 #include <sst/core/interactiveConsole.h> 21 #include "sst/core/serialization/objectMapDeferred.h" 22 #include "sst/core/impl/interactive/cmdLineEditor.h" 23 #include <sst/core/watchPoint.h> 34 enum class ConsoleCommandGroup { GENERAL, NAVIGATION, STATE, WATCH, SIMULATION, LOGGING, MISC };
36 const std::map<ConsoleCommandGroup, std::string> GroupText {
37 { ConsoleCommandGroup::GENERAL,
"General" },
38 { ConsoleCommandGroup::NAVIGATION,
"Navigation" },
39 { ConsoleCommandGroup::STATE,
"State" },
40 { ConsoleCommandGroup::WATCH,
"Watch/Trace" },
41 { ConsoleCommandGroup::SIMULATION,
"Simulation" },
42 { ConsoleCommandGroup::LOGGING,
"Logging" },
43 { ConsoleCommandGroup::MISC,
"Misc" },
46 enum class VERBOSITY_MASK : uint32_t {
47 WATCHPOINTS = 0b0001
'0000 // 0x10 50 // Encapsulate a console command. 54 ConsoleCommand(std::string str_long, std::string str_short, std::string str_help, ConsoleCommandGroup group, 55 std::function<void(std::vector<std::string>& tokens)> func) : 57 str_short_(str_short), 62 const std::string& str_long() const { return str_long_; } 63 const std::string& str_short() const { return str_short_; } 64 const std::string& str_help() const { return str_help_; } 65 const ConsoleCommandGroup& group() const { return group_; } 66 void exec(std::vector<std::string>& tokens) { return func_(tokens); } 67 bool match(const std::string& token) 69 std::string lctoken = toLower(token); 70 if ( lctoken.size() == str_long_.size() && lctoken == toLower(str_long_) ) return true; 71 if ( lctoken.size() == str_short_.size() && lctoken == toLower(str_short_) ) return true; 75 friend std::ostream& operator<<(std::ostream& os, const ConsoleCommand c) 77 os << c.str_long_ << " (" << c.str_short_ << ") " << c.str_help_; 82 std::string str_long_; 83 std::string str_short_; 84 std::string str_help_; 85 ConsoleCommandGroup group_; 86 std::function<void(std::vector<std::string>& tokens)> func_; 87 std::string toLower(std::string s) 89 std::transform(s.begin(), s.end(), s.begin(), ::tolower); 94 class CommandHistoryBuffer 97 const int MAX_CMDS = 200; 98 CommandHistoryBuffer() { buf_.resize(MAX_CMDS); } 99 void append(std::string s); 101 std::vector<std::string>& getBuffer(); 102 enum BANG_RC { INVALID, ECHO_ONLY, EXEC, NOP }; 103 BANG_RC bang(const std::string& token, std::string& newcmd); 110 std::vector<std::pair<std::size_t, std::string>> buf_; // actual history with index number 111 std::vector<std::string> stringBuffer_; // copy of history strings provided to command line editor 112 // support for ! history retrieval 113 bool findEvent(const std::string& s, std::string& newcmd); 114 bool findOffset(const std::string& s, std::string& newcmd); 115 bool searchFirst(const std::string& s, std::string& newcmd); 116 bool searchAny(const std::string& s, std::string& newcmd); 119 class SimpleDebugger : public SST::InteractiveConsole 123 SST_ELI_REGISTER_INTERACTIVE_CONSOLE( 124 SimpleDebugger, // class 126 "interactive.simpledebug", // name 127 SST_ELI_ELEMENT_VERSION(1, 0, 0), 128 "{EXPERIMENTAL} Interactive console debug probe") 130 SST_ELI_DOCUMENT_PARAMS( 131 {"replayFile", "script for playback upon entering interactive debug console", ""} 137 explicit SimpleDebugger(Params& params);
140 void execute(const std::string& msg) override;
142 // Callbacks from command line completions
143 void get_listing_strings(std::list<std::string>&);
146 // This is the stack of where we are in the class hierarchy. This
147 // is needed because when we advance time, we'll need to
delete 151 std::vector<std::string> name_stack;
156 bool autoCompleteEnable =
true;
159 uint64_t spinner = 1;
162 std::ofstream loggingFile;
163 std::ifstream replayFile;
164 std::string loggingFilePath =
"sst-console.out";
165 std::string replayFilePath =
"sst-console.in";
166 bool enLogging =
false;
169 std::stringstream injectedCommand;
175 std::vector<std::pair<WatchPoint*, BaseComponent*>> watch_points_;
176 bool clear_watchlist();
179 std::vector<std::string> tokenize(std::vector<std::string>& tokens,
const std::string& input);
182 void cmd_help(std::vector<std::string>& UNUSED(tokens));
183 void cmd_verbose(std::vector<std::string>&(tokens));
184 void cmd_pwd(std::vector<std::string>& UNUSED(tokens));
185 void cmd_ls(std::vector<std::string>& UNUSED(tokens));
186 void cmd_cd(std::vector<std::string>& tokens);
189 void cmd_print(std::vector<std::string>& tokens);
190 void cmd_set(std::vector<std::string>& tokens);
191 void cmd_time(std::vector<std::string>& tokens);
192 void cmd_watch(std::vector<std::string>& tokens);
193 void cmd_unwatch(std::vector<std::string>& tokens);
196 void cmd_run(std::vector<std::string>& tokens);
197 void cmd_shutdown(std::vector<std::string>& tokens);
198 void cmd_exit(std::vector<std::string>& UNUSED(tokens));
201 void cmd_watchlist(std::vector<std::string>& tokens);
202 void cmd_trace(std::vector<std::string>& tokens);
203 void cmd_setHandler(std::vector<std::string>& tokens);
204 void cmd_addTraceVar(std::vector<std::string>& tokens);
205 void cmd_resetTraceBuffer(std::vector<std::string>& tokens);
206 void cmd_printTrace(std::vector<std::string>& tokens);
207 void cmd_printWatchpoint(std::vector<std::string>& tokens);
208 void cmd_setConfirm(std::vector<std::string>& tokens);
211 void cmd_logging(std::vector<std::string>& tokens);
212 void cmd_replay(std::vector<std::string>& tokens);
213 void cmd_history(std::vector<std::string>& tokens);
216 void cmd_autoComplete(std::vector<std::string>& UNUSED(tokens));
219 void cmd_clear(std::vector<std::string>& UNUSED(tokens));
222 void cmd_spinThread(std::vector<std::string>& tokens);
224 void dispatch_cmd(std::string& cmd);
227 std::vector<ConsoleCommand> cmdRegistry;
230 std::map<std::string, std::string> cmdHelp;
239 uint32_t verbosity = 0;
240 void msg(VERBOSITY_MASK mask, std::string message);
ObjectMap version that will delay building the internal data structures until the object is "selected...
Definition: objectMapDeferred.h:29
Base class for objects created by the serializer mapping mode used to map the variables for objects...
Definition: objectMap.h:158
The command line editor uses termios to detect key presses and perform auto-completions.
Definition: cmdLineEditor.h:43
Definition: simpleDebug.cc:33
Definition: simpleDebug.h:94