26#define LLDB_OPTIONS_watchpoint_command_add
27#include "CommandOptions.inc"
34 "Add a set of LLDB commands to a watchpoint, to be "
35 "executed whenever the watchpoint is hit. "
36 "The commands added to the watchpoint replace any "
37 "commands previously added to it.",
38 nullptr, eCommandRequiresTarget),
43General information about entering watchpoint commands
44------------------------------------------------------
47 "This command will prompt for commands to be executed when the specified \
48watchpoint is hit. Each command is typed on its own line following the '> ' \
49prompt until 'DONE' is entered."
53 "Syntactic errors may not be detected when initially entered, and many \
54malformed commands can silently fail when executed. If your watchpoint commands \
55do not appear to be executing, double-check the command syntax."
59 "Note: You may enter any debugger command exactly as you would at the debugger \
60prompt. There is no limit to the number of commands supplied, but do NOT enter \
61more than one command per line."
64Special information about PYTHON watchpoint commands
65----------------------------------------------------
68 "You may enter either one or more lines of Python, including function \
69definitions or calls to functions that will have been imported by the time \
70the code executes. Single line watchpoint commands will be interpreted 'as is' \
71when the watchpoint is hit. Multiple lines of Python will be wrapped in a \
72generated function, and a call to the function will be attached to the watchpoint."
75This auto-generated function is passed in three arguments:
77 frame: an lldb.SBFrame object for the frame which hit the watchpoint.
79 wp: the watchpoint that was hit.
82 "When specifying a python function with the --python-function option, you need \
83to supply the function name prepended by the module name:"
86 --python-function myutils.watchpoint_callback
88The function itself must have the following prototype:
90def watchpoint_callback(frame, wp):
94 "The arguments are the same as the arguments passed to generated functions as \
95described above. Note that the global variable 'lldb.frame' will NOT be updated when \
96this function is called, so be sure to use the 'frame' argument. The 'frame' argument \
97can get you to the thread via frame.GetThread(), the thread can get you to the \
98process via thread.GetProcess(), and the process can get you back to the target \
99via process.GetTarget()."
103 "Important Note: As Python code gets collected into functions, access to global \
104variables requires explicit scoping using the 'global' keyword. Be sure to use correct \
105Python syntax, including indentation, when entering Python watchpoint commands."
108Example Python one-line watchpoint command:
110(lldb) watchpoint command add -s python 1
111Enter your Python command(s). Type 'DONE' to end.
112> print "Hit this watchpoint!"
115As a convenience, this also works for a short Python one-liner:
117(lldb) watchpoint command add -s python 1 -o 'import time; print time.asctime()'
119Launching '.../a.out' (x86_64)
120(lldb) Fri Sep 10 12:17:45 2010
122* thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = watchpoint 1.1, queue = com.apple.main-thread
126 39 -> return val + 3;
129 42 int main (int argc, char const *argv[])
131Example multiple line Python watchpoint command, using function definition:
133(lldb) watchpoint command add -s python 1
134Enter your Python command(s). Type 'DONE' to end.
135> def watchpoint_output (wp_no):
136> out_string = "Hit watchpoint number " + repr (wp_no)
139> watchpoint_output (1)
142Example multiple line Python watchpoint command, using 'loose' Python:
144(lldb) watchpoint command add -s p 1
145Enter your Python command(s). Type 'DONE' to end.
147> wp_count = wp_count + 1
148> print "Hit this watchpoint " + repr(wp_count) + " times!"
152 "In this case, since there is a reference to a global variable, \
153'wp_count', you will also need to make sure 'wp_count' exists and is \
162 "Final Note: A warning that no watchpoint command was generated when there \
163are no syntax errors may indicate that a function was declared but never called.");
174 if (output_sp && interactive) {
175 output_sp->PutCString(
176 "Enter your debugger command(s). Type 'DONE' to end.\n");
182 std::string &line)
override {
190 std::unique_ptr<WatchpointOptions::CommandData> data_up(
193 data_up->user_source.SplitIntoLines(line);
194 auto baton_sp = std::make_shared<WatchpointOptions::CommandBaton>(
212 const char *oneliner) {
213 std::unique_ptr<WatchpointOptions::CommandData> data_up(
220 data_up->user_source.AppendString(oneliner);
221 data_up->script_source.assign(oneliner);
225 std::make_shared<WatchpointOptions::CommandBaton>(std::move(data_up));
233 bool ret_value =
true;
234 if (baton ==
nullptr)
243 Target *target = exe_ctx.GetTargetPtr();
253 result.SetImmediateOutputStream(output_stream);
254 result.SetImmediateErrorStream(error_stream);
266 result.GetImmediateOutputStream()->Flush();
267 result.GetImmediateErrorStream()->Flush();
284 switch (short_option) {
308 bool success =
false;
312 error.SetErrorStringWithFormat(
313 "invalid value for stop-on-error: \"%s\"",
314 option_arg.str().c_str());
323 llvm_unreachable(
"Unimplemented option");
340 return llvm::ArrayRef(g_watchpoint_command_add_options);
361 size_t num_watchpoints = watchpoints.
GetSize();
363 if (num_watchpoints == 0) {
364 result.
AppendError(
"No watchpoints exist to have commands added");
375 std::vector<uint32_t> valid_wp_ids;
378 result.
AppendError(
"Invalid watchpoints specification.");
383 const size_t count = valid_wp_ids.size();
384 for (
size_t i = 0; i < count; ++i) {
385 uint32_t cur_wp_id = valid_wp_ids.at(i);
394 if (wp_options ==
nullptr)
415 function_signature +=
"(frame, wp, internal_dict)";
417 wp_options, function_signature.c_str(),
true);
444 "Delete the set of commands from a watchpoint.",
445 nullptr, eCommandRequiresTarget) {
456 size_t num_watchpoints = watchpoints.
GetSize();
458 if (num_watchpoints == 0) {
459 result.
AppendError(
"No watchpoints exist to have commands deleted");
465 "No watchpoint specified from which to delete the commands");
469 std::vector<uint32_t> valid_wp_ids;
472 result.
AppendError(
"Invalid watchpoints specification.");
477 const size_t count = valid_wp_ids.size();
478 for (
size_t i = 0; i < count; ++i) {
479 uint32_t cur_wp_id = valid_wp_ids.at(i);
498 "List the script or set of commands to be executed "
499 "when the watchpoint is hit.",
500 nullptr, eCommandRequiresTarget) {
511 size_t num_watchpoints = watchpoints.
GetSize();
513 if (num_watchpoints == 0) {
514 result.
AppendError(
"No watchpoints exist for which to list commands");
520 "No watchpoint specified for which to list the commands");
524 std::vector<uint32_t> valid_wp_ids;
527 result.
AppendError(
"Invalid watchpoints specification.");
532 const size_t count = valid_wp_ids.size();
533 for (
size_t i = 0; i < count; ++i) {
534 uint32_t cur_wp_id = valid_wp_ids.at(i);
551 "Watchpoint %u does not have an associated command.\n",
570 interpreter,
"command",
571 "Commands for adding, removing and examining LLDB commands "
572 "executed when the watchpoint is hit (watchpoint 'commands').",
573 "command <sub-command> [<sub-command-options>] <watchpoint-id>") {
581 add_command_object->SetCommandName(
"watchpoint command add");
582 delete_command_object->SetCommandName(
"watchpoint command delete");
583 list_command_object->SetCommandName(
"watchpoint command list");
static llvm::raw_ostream & error(Stream &strm)
~CommandOptions() override=default
std::string m_function_name
bool m_use_script_language
void OptionParsingStarting(ExecutionContext *execution_context) override
lldb::ScriptLanguage m_script_language
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void SetWatchpointCommandCallback(WatchpointOptions *wp_options, const char *oneliner)
Set a one-liner as the callback for the watchpoint.
CommandObjectWatchpointCommandAdd(CommandInterpreter &interpreter)
static bool WatchpointOptionsCallbackFunction(void *baton, StoppointCallbackContext *context, lldb::user_id_t watch_id)
~CommandObjectWatchpointCommandAdd() override=default
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override
void DoExecute(Args &command, CommandReturnObject &result) override
void IOHandlerInputComplete(IOHandler &io_handler, std::string &line) override
Called when a line or lines have been retrieved.
Options * GetOptions() override
void CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options, CommandReturnObject &result)
CommandObjectWatchpointCommandDelete(CommandInterpreter &interpreter)
~CommandObjectWatchpointCommandDelete() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectWatchpointCommandList(CommandInterpreter &interpreter)
~CommandObjectWatchpointCommandList() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
A command line argument class.
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
A class designed to wrap callback batons so they can cleanup any acquired resources.
virtual void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level, unsigned indentation) const =0
void SetStopOnContinue(bool stop_on_continue)
void SetPrintErrors(bool print_errors)
void SetEchoCommands(bool echo_commands)
void SetAddToHistory(bool add_to_history)
void SetStopOnError(bool stop_on_error)
void SetPrintResults(bool print_results)
void GetLLDBCommandsFromIOHandler(const char *prompt, IOHandlerDelegate &delegate, void *baton=nullptr)
void HandleCommands(const StringList &commands, const ExecutionContext &context, const CommandInterpreterRunOptions &options, CommandReturnObject &result)
Execute a list of commands in sequence.
static bool VerifyWatchpointIDs(Target &target, Args &args, std::vector< uint32_t > &wp_ids)
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
~CommandObjectWatchpointCommand() override
CommandObjectWatchpointCommand(CommandInterpreter &interpreter)
virtual void SetHelpLong(llvm::StringRef str)
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
CommandInterpreter & m_interpreter
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
Stream & GetOutputStream()
A class to manage flag bits.
lldb::StreamSP GetAsyncOutputStream()
CommandInterpreter & GetCommandInterpreter()
lldb::StreamSP GetAsyncErrorStream()
lldb::ScriptLanguage GetScriptLanguage() const
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A delegate class for use with IOHandler subclasses.
lldb::StreamFileSP GetOutputStreamFileSP()
A command line option parsing protocol class.
std::vector< Option > m_getopt_table
virtual void SetWatchpointCommandCallback(WatchpointOptions *wp_options, const char *user_input, bool is_callback)
Set a one-liner as the callback for the watchpoint.
virtual void CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options, CommandReturnObject &result)
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
ExecutionContextRef exe_ctx_ref
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
unsigned GetIndentLevel() const
Get the current indentation level.
WatchpointList & GetWatchpointList()
This class is used by Watchpoint to manage a list of watchpoints,.
lldb::WatchpointSP FindByID(lldb::watch_id_t watchID) const
Returns a shared pointer to the watchpoint with id watchID, const version.
size_t GetSize() const
Returns the number of elements in this watchpoint list.
"lldb/Breakpoint/WatchpointOptions.h" Class that manages the options on a watchpoint.
void SetCallback(WatchpointHitCallback callback, const lldb::BatonSP &baton_sp, bool synchronous=false)
Adds a callback to the watchpoint option set.
Baton * GetBaton()
Fetch the baton from the callback.
WatchpointOptions * GetOptions()
Returns the WatchpointOptions structure set for this watchpoint.
#define LLDB_INVALID_WATCH_ID
A class that represents a running process on the host machine.
ScriptLanguage
Script interpreter types.
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
std::shared_ptr< lldb_private::Stream > StreamSP
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
std::shared_ptr< lldb_private::StreamFile > StreamFileSP
static int64_t ToOptionEnum(llvm::StringRef s, const OptionEnumValues &enum_values, int32_t fail_value, Status &error)
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)