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