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