1 //===-- CommandObjectBreakpointCommand.cpp ----------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "CommandObjectBreakpointCommand.h"
10 #include "CommandObjectBreakpoint.h"
11 #include "lldb/Breakpoint/Breakpoint.h"
12 #include "lldb/Breakpoint/BreakpointIDList.h"
13 #include "lldb/Breakpoint/BreakpointLocation.h"
14 #include "lldb/Core/IOHandler.h"
15 #include "lldb/Host/OptionParser.h"
16 #include "lldb/Interpreter/CommandInterpreter.h"
17 #include "lldb/Interpreter/CommandReturnObject.h"
18 #include "lldb/Interpreter/OptionArgParser.h"
19 #include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
20 #include "lldb/Target/Target.h"
21 
22 
23 using namespace lldb;
24 using namespace lldb_private;
25 
26 // FIXME: "script-type" needs to have its contents determined dynamically, so
27 // somebody can add a new scripting language to lldb and have it pickable here
28 // without having to change this enumeration by hand and rebuild lldb proper.
29 static constexpr OptionEnumValueElement g_script_option_enumeration[] = {
30     {
31         eScriptLanguageNone,
32         "command",
33         "Commands are in the lldb command interpreter language",
34     },
35     {
36         eScriptLanguagePython,
37         "python",
38         "Commands are in the Python language.",
39     },
40     {
41         eSortOrderByName,
42         "default-script",
43         "Commands are in the default scripting language.",
44     },
45 };
46 
47 static constexpr OptionEnumValues ScriptOptionEnum() {
48   return OptionEnumValues(g_script_option_enumeration);
49 }
50 
51 #define LLDB_OPTIONS_breakpoint_command_add
52 #include "CommandOptions.inc"
53 
54 class CommandObjectBreakpointCommandAdd : public CommandObjectParsed,
55                                           public IOHandlerDelegateMultiline {
56 public:
57   CommandObjectBreakpointCommandAdd(CommandInterpreter &interpreter)
58       : CommandObjectParsed(interpreter, "add",
59                             "Add LLDB commands to a breakpoint, to be executed "
60                             "whenever the breakpoint is hit."
61                             "  If no breakpoint is specified, adds the "
62                             "commands to the last created breakpoint.",
63                             nullptr),
64         IOHandlerDelegateMultiline("DONE",
65                                    IOHandlerDelegate::Completion::LLDBCommand),
66         m_options(), m_func_options("breakpoint command", false, 'F') {
67     SetHelpLong(
68         R"(
69 General information about entering breakpoint commands
70 ------------------------------------------------------
71 
72 )"
73         "This command will prompt for commands to be executed when the specified \
74 breakpoint is hit.  Each command is typed on its own line following the '> ' \
75 prompt until 'DONE' is entered."
76         R"(
77 
78 )"
79         "Syntactic errors may not be detected when initially entered, and many \
80 malformed commands can silently fail when executed.  If your breakpoint commands \
81 do not appear to be executing, double-check the command syntax."
82         R"(
83 
84 )"
85         "Note: You may enter any debugger command exactly as you would at the debugger \
86 prompt.  There is no limit to the number of commands supplied, but do NOT enter \
87 more than one command per line."
88         R"(
89 
90 Special information about PYTHON breakpoint commands
91 ----------------------------------------------------
92 
93 )"
94         "You may enter either one or more lines of Python, including function \
95 definitions or calls to functions that will have been imported by the time \
96 the code executes.  Single line breakpoint commands will be interpreted 'as is' \
97 when the breakpoint is hit.  Multiple lines of Python will be wrapped in a \
98 generated function, and a call to the function will be attached to the breakpoint."
99         R"(
100 
101 This auto-generated function is passed in three arguments:
102 
103     frame:  an lldb.SBFrame object for the frame which hit breakpoint.
104 
105     bp_loc: an lldb.SBBreakpointLocation object that represents the breakpoint location that was hit.
106 
107     dict:   the python session dictionary hit.
108 
109 )"
110         "When specifying a python function with the --python-function option, you need \
111 to supply the function name prepended by the module name:"
112         R"(
113 
114     --python-function myutils.breakpoint_callback
115 
116 The function itself must have the following prototype:
117 
118 def breakpoint_callback(frame, bp_loc, dict):
119   # Your code goes here
120 
121 )"
122         "The arguments are the same as the arguments passed to generated functions as \
123 described above.  Note that the global variable 'lldb.frame' will NOT be updated when \
124 this function is called, so be sure to use the 'frame' argument. The 'frame' argument \
125 can get you to the thread via frame.GetThread(), the thread can get you to the \
126 process via thread.GetProcess(), and the process can get you back to the target \
127 via process.GetTarget()."
128         R"(
129 
130 )"
131         "Important Note: As Python code gets collected into functions, access to global \
132 variables requires explicit scoping using the 'global' keyword.  Be sure to use correct \
133 Python syntax, including indentation, when entering Python breakpoint commands."
134         R"(
135 
136 Example Python one-line breakpoint command:
137 
138 (lldb) breakpoint command add -s python 1
139 Enter your Python command(s). Type 'DONE' to end.
140 > print "Hit this breakpoint!"
141 > DONE
142 
143 As a convenience, this also works for a short Python one-liner:
144 
145 (lldb) breakpoint command add -s python 1 -o 'import time; print time.asctime()'
146 (lldb) run
147 Launching '.../a.out'  (x86_64)
148 (lldb) Fri Sep 10 12:17:45 2010
149 Process 21778 Stopped
150 * thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread
151   36
152   37   	int c(int val)
153   38   	{
154   39 ->	    return val + 3;
155   40   	}
156   41
157   42   	int main (int argc, char const *argv[])
158 
159 Example multiple line Python breakpoint command:
160 
161 (lldb) breakpoint command add -s p 1
162 Enter your Python command(s). Type 'DONE' to end.
163 > global bp_count
164 > bp_count = bp_count + 1
165 > print "Hit this breakpoint " + repr(bp_count) + " times!"
166 > DONE
167 
168 Example multiple line Python breakpoint command, using function definition:
169 
170 (lldb) breakpoint command add -s python 1
171 Enter your Python command(s). Type 'DONE' to end.
172 > def breakpoint_output (bp_no):
173 >     out_string = "Hit breakpoint number " + repr (bp_no)
174 >     print out_string
175 >     return True
176 > breakpoint_output (1)
177 > DONE
178 
179 )"
180         "In this case, since there is a reference to a global variable, \
181 'bp_count', you will also need to make sure 'bp_count' exists and is \
182 initialized:"
183         R"(
184 
185 (lldb) script
186 >>> bp_count = 0
187 >>> quit()
188 
189 )"
190         "Your Python code, however organized, can optionally return a value.  \
191 If the returned value is False, that tells LLDB not to stop at the breakpoint \
192 to which the code is associated. Returning anything other than False, or even \
193 returning None, or even omitting a return statement entirely, will cause \
194 LLDB to stop."
195         R"(
196 
197 )"
198         "Final Note: A warning that no breakpoint command was generated when there \
199 are no syntax errors may indicate that a function was declared but never called.");
200 
201     m_all_options.Append(&m_options);
202     m_all_options.Append(&m_func_options, LLDB_OPT_SET_2 | LLDB_OPT_SET_3,
203                          LLDB_OPT_SET_2);
204     m_all_options.Finalize();
205 
206     CommandArgumentEntry arg;
207     CommandArgumentData bp_id_arg;
208 
209     // Define the first (and only) variant of this arg.
210     bp_id_arg.arg_type = eArgTypeBreakpointID;
211     bp_id_arg.arg_repetition = eArgRepeatOptional;
212 
213     // There is only one variant this argument could be; put it into the
214     // argument entry.
215     arg.push_back(bp_id_arg);
216 
217     // Push the data for the first argument into the m_arguments vector.
218     m_arguments.push_back(arg);
219   }
220 
221   ~CommandObjectBreakpointCommandAdd() override = default;
222 
223   Options *GetOptions() override { return &m_all_options; }
224 
225   void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
226     StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
227     if (output_sp && interactive) {
228       output_sp->PutCString(g_reader_instructions);
229       output_sp->Flush();
230     }
231   }
232 
233   void IOHandlerInputComplete(IOHandler &io_handler,
234                               std::string &line) override {
235     io_handler.SetIsDone(true);
236 
237     std::vector<BreakpointOptions *> *bp_options_vec =
238         (std::vector<BreakpointOptions *> *)io_handler.GetUserData();
239     for (BreakpointOptions *bp_options : *bp_options_vec) {
240       if (!bp_options)
241         continue;
242 
243       auto cmd_data = std::make_unique<BreakpointOptions::CommandData>();
244       cmd_data->user_source.SplitIntoLines(line.c_str(), line.size());
245       bp_options->SetCommandDataCallback(cmd_data);
246     }
247   }
248 
249   void CollectDataForBreakpointCommandCallback(
250       std::vector<BreakpointOptions *> &bp_options_vec,
251       CommandReturnObject &result) {
252     m_interpreter.GetLLDBCommandsFromIOHandler(
253         "> ",             // Prompt
254         *this,            // IOHandlerDelegate
255         true,             // Run IOHandler in async mode
256         &bp_options_vec); // Baton for the "io_handler" that will be passed back
257                           // into our IOHandlerDelegate functions
258   }
259 
260   /// Set a one-liner as the callback for the breakpoint.
261   void
262   SetBreakpointCommandCallback(std::vector<BreakpointOptions *> &bp_options_vec,
263                                const char *oneliner) {
264     for (auto bp_options : bp_options_vec) {
265       auto cmd_data = std::make_unique<BreakpointOptions::CommandData>();
266 
267       cmd_data->user_source.AppendString(oneliner);
268       cmd_data->stop_on_error = m_options.m_stop_on_error;
269 
270       bp_options->SetCommandDataCallback(cmd_data);
271     }
272   }
273 
274   class CommandOptions : public OptionGroup {
275   public:
276     CommandOptions()
277         : OptionGroup(), m_use_commands(false), m_use_script_language(false),
278           m_script_language(eScriptLanguageNone), m_use_one_liner(false),
279           m_one_liner() {}
280 
281     ~CommandOptions() override = default;
282 
283     Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
284                           ExecutionContext *execution_context) override {
285       Status error;
286       const int short_option =
287           g_breakpoint_command_add_options[option_idx].short_option;
288 
289       switch (short_option) {
290       case 'o':
291         m_use_one_liner = true;
292         m_one_liner = option_arg;
293         break;
294 
295       case 's':
296         m_script_language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
297             option_arg,
298             g_breakpoint_command_add_options[option_idx].enum_values,
299             eScriptLanguageNone, error);
300 
301         if (m_script_language == eScriptLanguagePython ||
302             m_script_language == eScriptLanguageDefault) {
303           m_use_script_language = true;
304         } else {
305           m_use_script_language = false;
306         }
307         break;
308 
309       case 'e': {
310         bool success = false;
311         m_stop_on_error =
312             OptionArgParser::ToBoolean(option_arg, false, &success);
313         if (!success)
314           error.SetErrorStringWithFormat(
315               "invalid value for stop-on-error: \"%s\"",
316               option_arg.str().c_str());
317       } break;
318 
319       case 'D':
320         m_use_dummy = true;
321         break;
322 
323       default:
324         llvm_unreachable("Unimplemented option");
325       }
326       return error;
327     }
328 
329     void OptionParsingStarting(ExecutionContext *execution_context) override {
330       m_use_commands = true;
331       m_use_script_language = false;
332       m_script_language = eScriptLanguageNone;
333 
334       m_use_one_liner = false;
335       m_stop_on_error = true;
336       m_one_liner.clear();
337       m_use_dummy = false;
338     }
339 
340     llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
341       return llvm::makeArrayRef(g_breakpoint_command_add_options);
342     }
343 
344     // Instance variables to hold the values for command options.
345 
346     bool m_use_commands;
347     bool m_use_script_language;
348     lldb::ScriptLanguage m_script_language;
349 
350     // Instance variables to hold the values for one_liner options.
351     bool m_use_one_liner;
352     std::string m_one_liner;
353     bool m_stop_on_error;
354     bool m_use_dummy;
355   };
356 
357 protected:
358   bool DoExecute(Args &command, CommandReturnObject &result) override {
359     Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
360 
361     const BreakpointList &breakpoints = target.GetBreakpointList();
362     size_t num_breakpoints = breakpoints.GetSize();
363 
364     if (num_breakpoints == 0) {
365       result.AppendError("No breakpoints exist to have commands added");
366       result.SetStatus(eReturnStatusFailed);
367       return false;
368     }
369 
370     if (!m_func_options.GetName().empty()) {
371       m_options.m_use_one_liner = false;
372       m_options.m_use_script_language = true;
373     }
374 
375     BreakpointIDList valid_bp_ids;
376     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
377         command, &target, result, &valid_bp_ids,
378         BreakpointName::Permissions::PermissionKinds::listPerm);
379 
380     m_bp_options_vec.clear();
381 
382     if (result.Succeeded()) {
383       const size_t count = valid_bp_ids.GetSize();
384 
385       for (size_t i = 0; i < count; ++i) {
386         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
387         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
388           Breakpoint *bp =
389               target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
390           BreakpointOptions *bp_options = nullptr;
391           if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID) {
392             // This breakpoint does not have an associated location.
393             bp_options = bp->GetOptions();
394           } else {
395             BreakpointLocationSP bp_loc_sp(
396                 bp->FindLocationByID(cur_bp_id.GetLocationID()));
397             // This breakpoint does have an associated location. Get its
398             // breakpoint options.
399             if (bp_loc_sp)
400               bp_options = bp_loc_sp->GetLocationOptions();
401           }
402           if (bp_options)
403             m_bp_options_vec.push_back(bp_options);
404         }
405       }
406 
407       // If we are using script language, get the script interpreter in order
408       // to set or collect command callback.  Otherwise, call the methods
409       // associated with this object.
410       if (m_options.m_use_script_language) {
411         ScriptInterpreter *script_interp = GetDebugger().GetScriptInterpreter();
412         // Special handling for one-liner specified inline.
413         if (m_options.m_use_one_liner) {
414           script_interp->SetBreakpointCommandCallback(
415               m_bp_options_vec, m_options.m_one_liner.c_str());
416         } else if (!m_func_options.GetName().empty()) {
417           Status error = script_interp->SetBreakpointCommandCallbackFunction(
418               m_bp_options_vec, m_func_options.GetName().c_str(),
419               m_func_options.GetStructuredData());
420           if (!error.Success())
421             result.SetError(error);
422         } else {
423           script_interp->CollectDataForBreakpointCommandCallback(
424               m_bp_options_vec, result);
425         }
426       } else {
427         // Special handling for one-liner specified inline.
428         if (m_options.m_use_one_liner)
429           SetBreakpointCommandCallback(m_bp_options_vec,
430                                        m_options.m_one_liner.c_str());
431         else
432           CollectDataForBreakpointCommandCallback(m_bp_options_vec, result);
433       }
434     }
435 
436     return result.Succeeded();
437   }
438 
439 private:
440   CommandOptions m_options;
441   OptionGroupPythonClassWithDict m_func_options;
442   OptionGroupOptions m_all_options;
443 
444   std::vector<BreakpointOptions *> m_bp_options_vec; // This stores the
445                                                      // breakpoint options that
446                                                      // we are currently
447   // collecting commands for.  In the CollectData... calls we need to hand this
448   // off to the IOHandler, which may run asynchronously. So we have to have
449   // some way to keep it alive, and not leak it. Making it an ivar of the
450   // command object, which never goes away achieves this.  Note that if we were
451   // able to run the same command concurrently in one interpreter we'd have to
452   // make this "per invocation".  But there are many more reasons why it is not
453   // in general safe to do that in lldb at present, so it isn't worthwhile to
454   // come up with a more complex mechanism to address this particular weakness
455   // right now.
456   static const char *g_reader_instructions;
457 };
458 
459 const char *CommandObjectBreakpointCommandAdd::g_reader_instructions =
460     "Enter your debugger command(s).  Type 'DONE' to end.\n";
461 
462 // CommandObjectBreakpointCommandDelete
463 
464 #define LLDB_OPTIONS_breakpoint_command_delete
465 #include "CommandOptions.inc"
466 
467 class CommandObjectBreakpointCommandDelete : public CommandObjectParsed {
468 public:
469   CommandObjectBreakpointCommandDelete(CommandInterpreter &interpreter)
470       : CommandObjectParsed(interpreter, "delete",
471                             "Delete the set of commands from a breakpoint.",
472                             nullptr),
473         m_options() {
474     CommandArgumentEntry arg;
475     CommandArgumentData bp_id_arg;
476 
477     // Define the first (and only) variant of this arg.
478     bp_id_arg.arg_type = eArgTypeBreakpointID;
479     bp_id_arg.arg_repetition = eArgRepeatPlain;
480 
481     // There is only one variant this argument could be; put it into the
482     // argument entry.
483     arg.push_back(bp_id_arg);
484 
485     // Push the data for the first argument into the m_arguments vector.
486     m_arguments.push_back(arg);
487   }
488 
489   ~CommandObjectBreakpointCommandDelete() override = default;
490 
491   Options *GetOptions() override { return &m_options; }
492 
493   class CommandOptions : public Options {
494   public:
495     CommandOptions() : Options(), m_use_dummy(false) {}
496 
497     ~CommandOptions() override = default;
498 
499     Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
500                           ExecutionContext *execution_context) override {
501       Status error;
502       const int short_option = m_getopt_table[option_idx].val;
503 
504       switch (short_option) {
505       case 'D':
506         m_use_dummy = true;
507         break;
508 
509       default:
510         llvm_unreachable("Unimplemented option");
511       }
512 
513       return error;
514     }
515 
516     void OptionParsingStarting(ExecutionContext *execution_context) override {
517       m_use_dummy = false;
518     }
519 
520     llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
521       return llvm::makeArrayRef(g_breakpoint_command_delete_options);
522     }
523 
524     // Instance variables to hold the values for command options.
525     bool m_use_dummy;
526   };
527 
528 protected:
529   bool DoExecute(Args &command, CommandReturnObject &result) override {
530     Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
531 
532     const BreakpointList &breakpoints = target.GetBreakpointList();
533     size_t num_breakpoints = breakpoints.GetSize();
534 
535     if (num_breakpoints == 0) {
536       result.AppendError("No breakpoints exist to have commands deleted");
537       result.SetStatus(eReturnStatusFailed);
538       return false;
539     }
540 
541     if (command.empty()) {
542       result.AppendError(
543           "No breakpoint specified from which to delete the commands");
544       result.SetStatus(eReturnStatusFailed);
545       return false;
546     }
547 
548     BreakpointIDList valid_bp_ids;
549     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
550         command, &target, result, &valid_bp_ids,
551         BreakpointName::Permissions::PermissionKinds::listPerm);
552 
553     if (result.Succeeded()) {
554       const size_t count = valid_bp_ids.GetSize();
555       for (size_t i = 0; i < count; ++i) {
556         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
557         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
558           Breakpoint *bp =
559               target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
560           if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
561             BreakpointLocationSP bp_loc_sp(
562                 bp->FindLocationByID(cur_bp_id.GetLocationID()));
563             if (bp_loc_sp)
564               bp_loc_sp->ClearCallback();
565             else {
566               result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n",
567                                            cur_bp_id.GetBreakpointID(),
568                                            cur_bp_id.GetLocationID());
569               result.SetStatus(eReturnStatusFailed);
570               return false;
571             }
572           } else {
573             bp->ClearCallback();
574           }
575         }
576       }
577     }
578     return result.Succeeded();
579   }
580 
581 private:
582   CommandOptions m_options;
583 };
584 
585 // CommandObjectBreakpointCommandList
586 
587 class CommandObjectBreakpointCommandList : public CommandObjectParsed {
588 public:
589   CommandObjectBreakpointCommandList(CommandInterpreter &interpreter)
590       : CommandObjectParsed(interpreter, "list",
591                             "List the script or set of commands to be "
592                             "executed when the breakpoint is hit.",
593                             nullptr, eCommandRequiresTarget) {
594     CommandArgumentEntry arg;
595     CommandArgumentData bp_id_arg;
596 
597     // Define the first (and only) variant of this arg.
598     bp_id_arg.arg_type = eArgTypeBreakpointID;
599     bp_id_arg.arg_repetition = eArgRepeatPlain;
600 
601     // There is only one variant this argument could be; put it into the
602     // argument entry.
603     arg.push_back(bp_id_arg);
604 
605     // Push the data for the first argument into the m_arguments vector.
606     m_arguments.push_back(arg);
607   }
608 
609   ~CommandObjectBreakpointCommandList() override = default;
610 
611 protected:
612   bool DoExecute(Args &command, CommandReturnObject &result) override {
613     Target *target = &GetSelectedTarget();
614 
615     const BreakpointList &breakpoints = target->GetBreakpointList();
616     size_t num_breakpoints = breakpoints.GetSize();
617 
618     if (num_breakpoints == 0) {
619       result.AppendError("No breakpoints exist for which to list commands");
620       result.SetStatus(eReturnStatusFailed);
621       return false;
622     }
623 
624     if (command.empty()) {
625       result.AppendError(
626           "No breakpoint specified for which to list the commands");
627       result.SetStatus(eReturnStatusFailed);
628       return false;
629     }
630 
631     BreakpointIDList valid_bp_ids;
632     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
633         command, target, result, &valid_bp_ids,
634         BreakpointName::Permissions::PermissionKinds::listPerm);
635 
636     if (result.Succeeded()) {
637       const size_t count = valid_bp_ids.GetSize();
638       for (size_t i = 0; i < count; ++i) {
639         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
640         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
641           Breakpoint *bp =
642               target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
643 
644           if (bp) {
645             BreakpointLocationSP bp_loc_sp;
646             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
647               bp_loc_sp = bp->FindLocationByID(cur_bp_id.GetLocationID());
648               if (!bp_loc_sp) {
649                 result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n",
650                                              cur_bp_id.GetBreakpointID(),
651                                              cur_bp_id.GetLocationID());
652                 result.SetStatus(eReturnStatusFailed);
653                 return false;
654               }
655             }
656 
657             StreamString id_str;
658             BreakpointID::GetCanonicalReference(&id_str,
659                                                 cur_bp_id.GetBreakpointID(),
660                                                 cur_bp_id.GetLocationID());
661             const Baton *baton = nullptr;
662             if (bp_loc_sp)
663               baton =
664                   bp_loc_sp
665                       ->GetOptionsSpecifyingKind(BreakpointOptions::eCallback)
666                       ->GetBaton();
667             else
668               baton = bp->GetOptions()->GetBaton();
669 
670             if (baton) {
671               result.GetOutputStream().Printf("Breakpoint %s:\n",
672                                               id_str.GetData());
673               baton->GetDescription(result.GetOutputStream().AsRawOstream(),
674                                     eDescriptionLevelFull,
675                                     result.GetOutputStream().GetIndentLevel() +
676                                         2);
677             } else {
678               result.AppendMessageWithFormat(
679                   "Breakpoint %s does not have an associated command.\n",
680                   id_str.GetData());
681             }
682           }
683           result.SetStatus(eReturnStatusSuccessFinishResult);
684         } else {
685           result.AppendErrorWithFormat("Invalid breakpoint ID: %u.\n",
686                                        cur_bp_id.GetBreakpointID());
687           result.SetStatus(eReturnStatusFailed);
688         }
689       }
690     }
691 
692     return result.Succeeded();
693   }
694 };
695 
696 // CommandObjectBreakpointCommand
697 
698 CommandObjectBreakpointCommand::CommandObjectBreakpointCommand(
699     CommandInterpreter &interpreter)
700     : CommandObjectMultiword(
701           interpreter, "command",
702           "Commands for adding, removing and listing "
703           "LLDB commands executed when a breakpoint is "
704           "hit.",
705           "command <sub-command> [<sub-command-options>] <breakpoint-id>") {
706   CommandObjectSP add_command_object(
707       new CommandObjectBreakpointCommandAdd(interpreter));
708   CommandObjectSP delete_command_object(
709       new CommandObjectBreakpointCommandDelete(interpreter));
710   CommandObjectSP list_command_object(
711       new CommandObjectBreakpointCommandList(interpreter));
712 
713   add_command_object->SetCommandName("breakpoint command add");
714   delete_command_object->SetCommandName("breakpoint command delete");
715   list_command_object->SetCommandName("breakpoint command list");
716 
717   LoadSubCommand("add", add_command_object);
718   LoadSubCommand("delete", delete_command_object);
719   LoadSubCommand("list", list_command_object);
720 }
721 
722 CommandObjectBreakpointCommand::~CommandObjectBreakpointCommand() = default;
723