26#define LLDB_OPTIONS_breakpoint_command_add
27#include "CommandOptions.inc"
34 "Add LLDB commands to a breakpoint, to be executed "
35 "whenever the breakpoint is hit. "
36 "The commands added to the breakpoint replace any "
37 "commands previously added to it."
38 " If no breakpoint is specified, adds the "
39 "commands to the last created breakpoint.",
46General information about entering breakpoint commands
47------------------------------------------------------
50 "This command will prompt for commands to be executed when the specified \
51breakpoint is hit. Each command is typed on its own line following the '> ' \
52prompt until 'DONE' is entered."
56 "Syntactic errors may not be detected when initially entered, and many \
57malformed commands can silently fail when executed. If your breakpoint commands \
58do not appear to be executing, double-check the command syntax."
62 "Note: You may enter any debugger command exactly as you would at the debugger \
63prompt. There is no limit to the number of commands supplied, but do NOT enter \
64more than one command per line."
67Special information about PYTHON breakpoint commands
68----------------------------------------------------
71 "You may enter either one or more lines of Python, including function \
72definitions or calls to functions that will have been imported by the time \
73the code executes. Single line breakpoint commands will be interpreted 'as is' \
74when the breakpoint is hit. Multiple lines of Python will be wrapped in a \
75generated function, and a call to the function will be attached to the breakpoint."
78This auto-generated function is passed in three arguments:
80 frame: an lldb.SBFrame object for the frame which hit breakpoint.
82 bp_loc: an lldb.SBBreakpointLocation object that represents the breakpoint location that was hit.
84 dict: the python session dictionary hit.
87 "When specifying a python function with the --python-function option, you need \
88to supply the function name prepended by the module name:"
91 --python-function myutils.breakpoint_callback
93The function itself must have either of the following prototypes:
95def breakpoint_callback(frame, bp_loc, internal_dict):
100def breakpoint_callback(frame, bp_loc, extra_args, internal_dict):
101 # Your code goes here
104 "The arguments are the same as the arguments passed to generated functions as \
105described above. In the second form, any -k and -v pairs provided to the command will \
106be packaged into a SBDictionary in an SBStructuredData and passed as the extra_args parameter. \
108Note that the global variable 'lldb.frame' will NOT be updated when \
109this function is called, so be sure to use the 'frame' argument. The 'frame' argument \
110can get you to the thread via frame.GetThread(), the thread can get you to the \
111process via thread.GetProcess(), and the process can get you back to the target \
112via process.GetTarget()."
116 "Important Note: As Python code gets collected into functions, access to global \
117variables requires explicit scoping using the 'global' keyword. Be sure to use correct \
118Python syntax, including indentation, when entering Python breakpoint commands."
121Example Python one-line breakpoint command:
123(lldb) breakpoint command add -s python 1
124Enter your Python command(s). Type 'DONE' to end.
125def function (frame, bp_loc, internal_dict):
126 """frame: the lldb.SBFrame for the location at which you stopped
127 bp_loc: an lldb.SBBreakpointLocation for the breakpoint location information
128 internal_dict: an LLDB support object not to be used"""
129 print("Hit this breakpoint!")
132As a convenience, this also works for a short Python one-liner:
134(lldb) breakpoint command add -s python 1 -o 'import time; print(time.asctime())'
136Launching '.../a.out' (x86_64)
137(lldb) Fri Sep 10 12:17:45 2010
139* thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread
143 39 -> return val + 3;
146 42 int main (int argc, char const *argv[])
148Example multiple line Python breakpoint command:
150(lldb) breakpoint command add -s p 1
151Enter your Python command(s). Type 'DONE' to end.
152def function (frame, bp_loc, internal_dict):
153 """frame: the lldb.SBFrame for the location at which you stopped
154 bp_loc: an lldb.SBBreakpointLocation for the breakpoint location information
155 internal_dict: an LLDB support object not to be used"""
157 bp_count = bp_count + 1
158 print("Hit this breakpoint " + repr(bp_count) + " times!")
162 "In this case, since there is a reference to a global variable, \
163'bp_count', you will also need to make sure 'bp_count' exists and is \
172 "Your Python code, however organized, can optionally return a value. \
173If the returned value is False, that tells LLDB not to stop at the breakpoint \
174to which the code is associated. Returning anything other than False, or even \
175returning None, or even omitting a return statement entirely, will cause \
180 "Final Note: A warning that no breakpoint command was generated when there \
181are no syntax errors may indicate that a function was declared but never called.");
197 if (output_sp && interactive) {
204 std::string &line)
override {
207 std::vector<std::reference_wrapper<BreakpointOptions>> *bp_options_vec =
208 (std::vector<std::reference_wrapper<BreakpointOptions>> *)
211 auto cmd_data = std::make_unique<BreakpointOptions::CommandData>();
212 cmd_data->user_source.SplitIntoLines(line.c_str(), line.size());
213 bp_options.SetCommandDataCallback(cmd_data);
218 std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec,
229 std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec,
230 const char *oneliner) {
232 auto cmd_data = std::make_unique<BreakpointOptions::CommandData>();
234 cmd_data->user_source.AppendString(oneliner);
237 bp_options.SetCommandDataCallback(cmd_data);
250 const int short_option =
251 g_breakpoint_command_add_options[option_idx].short_option;
253 switch (short_option) {
262 g_breakpoint_command_add_options[option_idx].enum_values,
277 bool success =
false;
282 "invalid value for stop-on-error: \"{0}\"", option_arg);
290 llvm_unreachable(
"Unimplemented option");
307 return llvm::ArrayRef(g_breakpoint_command_add_options);
328 size_t num_breakpoints = breakpoints.
GetSize();
330 if (num_breakpoints == 0) {
331 result.
AppendError(
"No breakpoints exist to have commands added");
345 command, target, result, &valid_bp_ids,
346 BreakpointName::Permissions::PermissionKinds::listPerm);
351 const size_t count = valid_bp_ids.
GetSize();
353 for (
size_t i = 0; i < count; ++i) {
391 if (!
error.Success())
409 std::vector<std::reference_wrapper<BreakpointOptions>>
426 "Enter your debugger command(s). Type 'DONE' to end.\n";
430#define LLDB_OPTIONS_breakpoint_command_delete
431#include "CommandOptions.inc"
437 "Delete the set of commands from a breakpoint.",
457 switch (short_option) {
463 llvm_unreachable(
"Unimplemented option");
474 return llvm::ArrayRef(g_breakpoint_command_delete_options);
486 size_t num_breakpoints = breakpoints.
GetSize();
488 if (num_breakpoints == 0) {
489 result.
AppendError(
"No breakpoints exist to have commands deleted");
493 if (command.
empty()) {
495 "No breakpoint specified from which to delete the commands");
501 command, target, result, &valid_bp_ids,
502 BreakpointName::Permissions::PermissionKinds::listPerm);
505 const size_t count = valid_bp_ids.
GetSize();
506 for (
size_t i = 0; i < count; ++i) {
515 bp_loc_sp->ClearCallback();
540 "List the script or set of commands to be "
541 "executed when the breakpoint is hit.",
542 nullptr, eCommandRequiresTarget) {
553 size_t num_breakpoints = breakpoints.
GetSize();
555 if (num_breakpoints == 0) {
556 result.
AppendError(
"No breakpoints exist for which to list commands");
560 if (command.
empty()) {
562 "No breakpoint specified for which to list the commands");
568 command, target, result, &valid_bp_ids,
569 BreakpointName::Permissions::PermissionKinds::listPerm);
572 const size_t count = valid_bp_ids.
GetSize();
573 for (
size_t i = 0; i < count; ++i) {
595 const Baton *baton =
nullptr;
613 "Breakpoint %s does not have an associated command.\n",
632 interpreter,
"command",
633 "Commands for adding, removing and listing "
634 "LLDB commands executed when a breakpoint is "
636 "command <sub-command> [<sub-command-options>] <breakpoint-id>") {
644 add_command_object->SetCommandName(
"breakpoint command add");
645 delete_command_object->SetCommandName(
"breakpoint command delete");
646 list_command_object->SetCommandName(
"breakpoint command list");
static llvm::raw_ostream & error(Stream &strm)
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
~CommandOptions() override=default
lldb::ScriptLanguage m_script_language
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
bool m_use_script_language
void CollectDataForBreakpointCommandCallback(std::vector< std::reference_wrapper< BreakpointOptions > > &bp_options_vec, CommandReturnObject &result)
CommandObjectBreakpointCommandAdd(CommandInterpreter &interpreter)
Options * GetOptions() override
OptionGroupPythonClassWithDict m_func_options
void SetBreakpointCommandCallback(std::vector< std::reference_wrapper< BreakpointOptions > > &bp_options_vec, const char *oneliner)
Set a one-liner as the callback for the breakpoint.
~CommandObjectBreakpointCommandAdd() override=default
OptionGroupOptions m_all_options
static const char * g_reader_instructions
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.
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override
std::vector< std::reference_wrapper< BreakpointOptions > > m_bp_options_vec
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void OptionParsingStarting(ExecutionContext *execution_context) override
~CommandOptions() override=default
~CommandObjectBreakpointCommandDelete() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectBreakpointCommandDelete(CommandInterpreter &interpreter)
Options * GetOptions() override
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectBreakpointCommandList() override=default
CommandObjectBreakpointCommandList(CommandInterpreter &interpreter)
A command line argument class.
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
BreakpointID GetBreakpointIDAtIndex(size_t index) const
lldb::break_id_t GetBreakpointID() const
lldb::break_id_t GetLocationID() const
static void GetCanonicalReference(Stream *s, lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
Takes a breakpoint ID and the breakpoint location id and returns a string containing the canonical de...
General Outline: Allows adding and removing breakpoints and find by ID and index.
size_t GetSize() const
Returns the number of elements in this breakpoint list.
"lldb/Breakpoint/BreakpointOptions.h" Class that manages the options on a breakpoint or breakpoint lo...
Baton * GetBaton()
Fetch the baton from the callback.
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
BreakpointOptions & GetOptions()
Returns the BreakpointOptions structure set at the breakpoint level.
lldb::BreakpointLocationSP FindLocationByID(lldb::break_id_t bp_loc_id)
Find a breakpoint location for a given breakpoint location ID.
void GetLLDBCommandsFromIOHandler(const char *prompt, IOHandlerDelegate &delegate, void *baton=nullptr)
~CommandObjectBreakpointCommand() override
CommandObjectBreakpointCommand(CommandInterpreter &interpreter)
static void VerifyBreakpointOrLocationIDs(Args &args, Target &target, CommandReturnObject &result, BreakpointIDList *valid_ids, BreakpointName::Permissions ::PermissionKinds purpose)
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
virtual void SetHelpLong(llvm::StringRef str)
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
Target & GetDummyTarget()
CommandInterpreter & m_interpreter
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void SetError(Status error)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
Stream & GetOutputStream()
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()
void Append(OptionGroup *group)
Append options from a OptionGroup class.
const std::string & GetName()
const StructuredData::DictionarySP GetStructuredData()
A command line option parsing protocol class.
std::vector< Option > m_getopt_table
virtual void CollectDataForBreakpointCommandCallback(std::vector< std::reference_wrapper< BreakpointOptions > > &options, CommandReturnObject &result)
Status SetBreakpointCommandCallback(std::vector< std::reference_wrapper< BreakpointOptions > > &bp_options_vec, const char *callback_text)
Set the specified text as the callback for the breakpoint.
Status SetBreakpointCommandCallbackFunction(std::vector< std::reference_wrapper< BreakpointOptions > > &bp_options_vec, const char *function_name, StructuredData::ObjectSP extra_args_sp)
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
const char * GetData() const
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.
lldb::BreakpointSP GetBreakpointByID(lldb::break_id_t break_id)
BreakpointList & GetBreakpointList(bool internal=false)
#define LLDB_INVALID_BREAK_ID
A class that represents a running process on the host machine.
ScriptLanguage
Script interpreter types.
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
@ eReturnStatusSuccessFinishResult
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)