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