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