28#define LLDB_OPTIONS_watchpoint_command_add
29#include "CommandOptions.inc"
36 "Add a set of LLDB commands to a watchpoint, to be "
37 "executed whenever the watchpoint is hit. "
38 "The commands added to the watchpoint replace any "
39 "commands previously added to it.",
40 nullptr, eCommandRequiresTarget),
45General information about entering watchpoint commands
46------------------------------------------------------
49 "This command will prompt for commands to be executed when the specified \
50watchpoint is hit. Each command is typed on its own line following the '> ' \
51prompt until 'DONE' is entered."
55 "Syntactic errors may not be detected when initially entered, and many \
56malformed commands can silently fail when executed. If your watchpoint commands \
57do not appear to be executing, double-check the command syntax."
61 "Note: You may enter any debugger command exactly as you would at the debugger \
62prompt. There is no limit to the number of commands supplied, but do NOT enter \
63more than one command per line."
66Special information about PYTHON watchpoint commands
67----------------------------------------------------
70 "You may enter either one or more lines of Python, including function \
71definitions or calls to functions that will have been imported by the time \
72the code executes. Single line watchpoint commands will be interpreted 'as is' \
73when the watchpoint is hit. Multiple lines of Python will be wrapped in a \
74generated function, and a call to the function will be attached to the watchpoint."
77This auto-generated function is passed in three arguments:
79 frame: an lldb.SBFrame object for the frame which hit the watchpoint.
81 wp: the watchpoint that was hit.
84 "When specifying a python function with the --python-function option, you need \
85to supply the function name prepended by the module name:"
88 --python-function myutils.watchpoint_callback
90The function itself must have the following prototype:
92def watchpoint_callback(frame, wp):
96 "The arguments are the same as the arguments passed to generated functions as \
97described above. Note that the global variable 'lldb.frame' will NOT be updated when \
98this function is called, so be sure to use the 'frame' argument. The 'frame' argument \
99can get you to the thread via frame.GetThread(), the thread can get you to the \
100process via thread.GetProcess(), and the process can get you back to the target \
101via process.GetTarget()."
105 "Important Note: As Python code gets collected into functions, access to global \
106variables requires explicit scoping using the 'global' keyword. Be sure to use correct \
107Python syntax, including indentation, when entering Python watchpoint commands."
110Example Python one-line watchpoint command:
112(lldb) watchpoint command add -s python 1
113Enter your Python command(s). Type 'DONE' to end.
114> print "Hit this watchpoint!"
117As a convenience, this also works for a short Python one-liner:
119(lldb) watchpoint command add -s python 1 -o 'import time; print time.asctime()'
121Launching '.../a.out' (x86_64)
122(lldb) Fri Sep 10 12:17:45 2010
124* thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = watchpoint 1.1, queue = com.apple.main-thread
128 39 -> return val + 3;
131 42 int main (int argc, char const *argv[])
133Example multiple line Python watchpoint command, using function definition:
135(lldb) watchpoint command add -s python 1
136Enter your Python command(s). Type 'DONE' to end.
137> def watchpoint_output (wp_no):
138> out_string = "Hit watchpoint number " + repr (wp_no)
141> watchpoint_output (1)
144Example multiple line Python watchpoint command, using 'loose' Python:
146(lldb) watchpoint command add -s p 1
147Enter your Python command(s). Type 'DONE' to end.
149> wp_count = wp_count + 1
150> print "Hit this watchpoint " + repr(wp_count) + " times!"
154 "In this case, since there is a reference to a global variable, \
155'wp_count', you will also need to make sure 'wp_count' exists and is \
164 "Final Note: A warning that no watchpoint command was generated when there \
165are no syntax errors may indicate that a function was declared but never called.");
178 LockedStreamFile locked_stream = output_sp->Lock();
180 "Enter your debugger command(s). Type 'DONE' to end.\n");
186 std::string &line)
override {
191 WatchpointOptions *wp_options =
194 std::unique_ptr<WatchpointOptions::CommandData> data_up(
197 data_up->user_source.SplitIntoLines(line);
198 auto baton_sp = std::make_shared<WatchpointOptions::CommandBaton>(
206 CommandReturnObject &result) {
216 const char *oneliner) {
217 std::unique_ptr<WatchpointOptions::CommandData> data_up(
218 new WatchpointOptions::CommandData());
224 data_up->user_source.AppendString(oneliner);
225 data_up->script_source.assign(oneliner);
226 data_up->stop_on_error =
m_options.m_stop_on_error;
229 std::make_shared<WatchpointOptions::CommandBaton>(std::move(data_up));
235 StoppointCallbackContext *context,
237 bool ret_value =
true;
238 if (baton ==
nullptr)
241 WatchpointOptions::CommandData *data =
242 (WatchpointOptions::CommandData *)baton;
247 Target *target = exe_ctx.GetTargetPtr();
286 switch (short_option) {
310 bool success =
false;
315 "invalid value for stop-on-error: \"{0}\"", option_arg);
324 llvm_unreachable(
"Unimplemented option");
341 return llvm::ArrayRef(g_watchpoint_command_add_options);
362 size_t num_watchpoints = watchpoints.
GetSize();
364 if (num_watchpoints == 0) {
365 result.
AppendError(
"No watchpoints exist to have commands added");
369 if (!
m_options.m_function_name.empty()) {
376 std::vector<uint32_t> valid_wp_ids;
379 result.
AppendError(
"invalid watchpoints specification");
384 const size_t count = valid_wp_ids.size();
385 for (
size_t i = 0; i < count; ++i) {
386 uint32_t cur_wp_id = valid_wp_ids.at(i);
393 WatchpointOptions *wp_options = wp->
GetOptions();
395 if (wp_options ==
nullptr)
407 wp_options,
m_options.m_one_liner.c_str(),
414 else if (!
m_options.m_function_name.empty()) {
415 std::string function_signature =
m_options.m_function_name;
416 function_signature +=
"(frame, wp, internal_dict)";
418 wp_options, function_signature.c_str(),
true);
445 "Delete the set of commands from a watchpoint.",
446 nullptr, eCommandRequiresTarget) {
457 size_t num_watchpoints = watchpoints.
GetSize();
459 if (num_watchpoints == 0) {
460 result.
AppendError(
"No watchpoints exist to have commands deleted");
466 "No watchpoint specified from which to delete the commands");
470 std::vector<uint32_t> valid_wp_ids;
473 result.
AppendError(
"invalid watchpoints specification");
478 const size_t count = valid_wp_ids.size();
479 for (
size_t i = 0; i < count; ++i) {
480 uint32_t cur_wp_id = valid_wp_ids.at(i);
499 "List the script or set of commands to be executed "
500 "when the watchpoint is hit.",
501 nullptr, eCommandRequiresTarget) {
512 size_t num_watchpoints = watchpoints.
GetSize();
514 if (num_watchpoints == 0) {
515 result.
AppendError(
"No watchpoints exist for which to list commands");
521 "No watchpoint specified for which to list the commands");
525 std::vector<uint32_t> valid_wp_ids;
528 result.
AppendError(
"invalid watchpoints specification");
533 const size_t count = valid_wp_ids.size();
534 for (
size_t i = 0; i < count; ++i) {
535 uint32_t cur_wp_id = valid_wp_ids.at(i);
552 "Watchpoint %u does not have an associated command.\n",
571 interpreter,
"command",
572 "Commands for adding, removing and examining LLDB commands "
573 "executed when the watchpoint is hit (watchpoint 'commands').",
574 "command <sub-command> [<sub-command-options>] <watchpoint-id>") {
582 add_command_object->SetCommandName(
"watchpoint command add");
583 delete_command_object->SetCommandName(
"watchpoint command delete");
584 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 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
CommandObjectMultiword(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
friend class CommandInterpreter
CommandObjectParsed(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
~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 SetImmediateErrorStream(const lldb::StreamSP &stream_sp)
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void SetImmediateOutputStream(const lldb::StreamSP &stream_sp)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
lldb::StreamSP GetImmediateErrorStream() const
lldb::StreamSP GetImmediateOutputStream() const
Stream & GetOutputStream()
A class to manage flag bits.
CommandInterpreter & GetCommandInterpreter()
lldb::StreamUP GetAsyncErrorStream()
lldb::ScriptLanguage GetScriptLanguage() const
lldb::StreamUP GetAsyncOutputStream()
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
IOHandlerDelegateMultiline(llvm::StringRef end_line, Completion completion=Completion::None)
A delegate class for use with IOHandler subclasses.
lldb::LockableStreamFileSP 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)
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
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.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
unsigned GetIndentLevel() const
Get the current indentation level.
Debugger & GetDebugger() const
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
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
std::shared_ptr< lldb_private::LockableStreamFile > LockableStreamFileSP
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)