1 //===-- CommandObjectWatchpointCommand.cpp ----------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // C Includes 11 // C++ Includes 12 #include <vector> 13 14 // Other libraries and framework includes 15 // Project includes 16 #include "CommandObjectWatchpoint.h" 17 #include "CommandObjectWatchpointCommand.h" 18 #include "lldb/Breakpoint/StoppointCallbackContext.h" 19 #include "lldb/Breakpoint/Watchpoint.h" 20 #include "lldb/Core/IOHandler.h" 21 #include "lldb/Core/State.h" 22 #include "lldb/Interpreter/CommandInterpreter.h" 23 #include "lldb/Interpreter/CommandReturnObject.h" 24 #include "lldb/Target/Target.h" 25 #include "lldb/Target/Thread.h" 26 27 using namespace lldb; 28 using namespace lldb_private; 29 30 //------------------------------------------------------------------------- 31 // CommandObjectWatchpointCommandAdd 32 //------------------------------------------------------------------------- 33 34 class CommandObjectWatchpointCommandAdd : public CommandObjectParsed, 35 public IOHandlerDelegateMultiline { 36 public: 37 CommandObjectWatchpointCommandAdd(CommandInterpreter &interpreter) 38 : CommandObjectParsed(interpreter, "add", 39 "Add a set of LLDB commands to a watchpoint, to be " 40 "executed whenever the watchpoint is hit.", 41 nullptr), 42 IOHandlerDelegateMultiline("DONE", 43 IOHandlerDelegate::Completion::LLDBCommand), 44 m_options() { 45 SetHelpLong( 46 R"( 47 General information about entering watchpoint commands 48 ------------------------------------------------------ 49 50 )" 51 "This command will prompt for commands to be executed when the specified \ 52 watchpoint is hit. Each command is typed on its own line following the '> ' \ 53 prompt until 'DONE' is entered." 54 R"( 55 56 )" 57 "Syntactic errors may not be detected when initially entered, and many \ 58 malformed commands can silently fail when executed. If your watchpoint commands \ 59 do not appear to be executing, double-check the command syntax." 60 R"( 61 62 )" 63 "Note: You may enter any debugger command exactly as you would at the debugger \ 64 prompt. There is no limit to the number of commands supplied, but do NOT enter \ 65 more than one command per line." 66 R"( 67 68 Special information about PYTHON watchpoint commands 69 ---------------------------------------------------- 70 71 )" 72 "You may enter either one or more lines of Python, including function \ 73 definitions or calls to functions that will have been imported by the time \ 74 the code executes. Single line watchpoint commands will be interpreted 'as is' \ 75 when the watchpoint is hit. Multiple lines of Python will be wrapped in a \ 76 generated function, and a call to the function will be attached to the watchpoint." 77 R"( 78 79 This auto-generated function is passed in three arguments: 80 81 frame: an lldb.SBFrame object for the frame which hit the watchpoint. 82 83 wp: the watchpoint that was hit. 84 85 )" 86 "When specifying a python function with the --python-function option, you need \ 87 to supply the function name prepended by the module name:" 88 R"( 89 90 --python-function myutils.watchpoint_callback 91 92 The function itself must have the following prototype: 93 94 def watchpoint_callback(frame, wp): 95 # Your code goes here 96 97 )" 98 "The arguments are the same as the arguments passed to generated functions as \ 99 described above. Note that the global variable 'lldb.frame' will NOT be updated when \ 100 this function is called, so be sure to use the 'frame' argument. The 'frame' argument \ 101 can get you to the thread via frame.GetThread(), the thread can get you to the \ 102 process via thread.GetProcess(), and the process can get you back to the target \ 103 via process.GetTarget()." 104 R"( 105 106 )" 107 "Important Note: As Python code gets collected into functions, access to global \ 108 variables requires explicit scoping using the 'global' keyword. Be sure to use correct \ 109 Python syntax, including indentation, when entering Python watchpoint commands." 110 R"( 111 112 Example Python one-line watchpoint command: 113 114 (lldb) watchpoint command add -s python 1 115 Enter your Python command(s). Type 'DONE' to end. 116 > print "Hit this watchpoint!" 117 > DONE 118 119 As a convenience, this also works for a short Python one-liner: 120 121 (lldb) watchpoint command add -s python 1 -o 'import time; print time.asctime()' 122 (lldb) run 123 Launching '.../a.out' (x86_64) 124 (lldb) Fri Sep 10 12:17:45 2010 125 Process 21778 Stopped 126 * thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = watchpoint 1.1, queue = com.apple.main-thread 127 36 128 37 int c(int val) 129 38 { 130 39 -> return val + 3; 131 40 } 132 41 133 42 int main (int argc, char const *argv[]) 134 135 Example multiple line Python watchpoint command, using function definition: 136 137 (lldb) watchpoint command add -s python 1 138 Enter your Python command(s). Type 'DONE' to end. 139 > def watchpoint_output (wp_no): 140 > out_string = "Hit watchpoint number " + repr (wp_no) 141 > print out_string 142 > return True 143 > watchpoint_output (1) 144 > DONE 145 146 Example multiple line Python watchpoint command, using 'loose' Python: 147 148 (lldb) watchpoint command add -s p 1 149 Enter your Python command(s). Type 'DONE' to end. 150 > global wp_count 151 > wp_count = wp_count + 1 152 > print "Hit this watchpoint " + repr(wp_count) + " times!" 153 > DONE 154 155 )" 156 "In this case, since there is a reference to a global variable, \ 157 'wp_count', you will also need to make sure 'wp_count' exists and is \ 158 initialized:" 159 R"( 160 161 (lldb) script 162 >>> wp_count = 0 163 >>> quit() 164 165 )" 166 "Final Note: A warning that no watchpoint command was generated when there \ 167 are no syntax errors may indicate that a function was declared but never called."); 168 169 CommandArgumentEntry arg; 170 CommandArgumentData wp_id_arg; 171 172 // Define the first (and only) variant of this arg. 173 wp_id_arg.arg_type = eArgTypeWatchpointID; 174 wp_id_arg.arg_repetition = eArgRepeatPlain; 175 176 // There is only one variant this argument could be; put it into the 177 // argument entry. 178 arg.push_back(wp_id_arg); 179 180 // Push the data for the first argument into the m_arguments vector. 181 m_arguments.push_back(arg); 182 } 183 184 ~CommandObjectWatchpointCommandAdd() override = default; 185 186 Options *GetOptions() override { return &m_options; } 187 188 void IOHandlerActivated(IOHandler &io_handler) override { 189 StreamFileSP output_sp(io_handler.GetOutputStreamFile()); 190 if (output_sp) { 191 output_sp->PutCString( 192 "Enter your debugger command(s). Type 'DONE' to end.\n"); 193 output_sp->Flush(); 194 } 195 } 196 197 void IOHandlerInputComplete(IOHandler &io_handler, 198 std::string &line) override { 199 io_handler.SetIsDone(true); 200 201 // The WatchpointOptions object is owned by the watchpoint or watchpoint 202 // location 203 WatchpointOptions *wp_options = 204 (WatchpointOptions *)io_handler.GetUserData(); 205 if (wp_options) { 206 std::unique_ptr<WatchpointOptions::CommandData> data_ap( 207 new WatchpointOptions::CommandData()); 208 if (data_ap) { 209 data_ap->user_source.SplitIntoLines(line); 210 auto baton_sp = std::make_shared<WatchpointOptions::CommandBaton>( 211 std::move(data_ap)); 212 wp_options->SetCallback(WatchpointOptionsCallbackFunction, baton_sp); 213 } 214 } 215 } 216 217 void CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options, 218 CommandReturnObject &result) { 219 m_interpreter.GetLLDBCommandsFromIOHandler( 220 "> ", // Prompt 221 *this, // IOHandlerDelegate 222 true, // Run IOHandler in async mode 223 wp_options); // Baton for the "io_handler" that will be passed back into 224 // our IOHandlerDelegate functions 225 } 226 227 /// Set a one-liner as the callback for the watchpoint. 228 void SetWatchpointCommandCallback(WatchpointOptions *wp_options, 229 const char *oneliner) { 230 std::unique_ptr<WatchpointOptions::CommandData> data_ap( 231 new WatchpointOptions::CommandData()); 232 233 // It's necessary to set both user_source and script_source to the oneliner. 234 // The former is used to generate callback description (as in watchpoint 235 // command list) 236 // while the latter is used for Python to interpret during the actual 237 // callback. 238 data_ap->user_source.AppendString(oneliner); 239 data_ap->script_source.assign(oneliner); 240 data_ap->stop_on_error = m_options.m_stop_on_error; 241 242 auto baton_sp = 243 std::make_shared<WatchpointOptions::CommandBaton>(std::move(data_ap)); 244 wp_options->SetCallback(WatchpointOptionsCallbackFunction, baton_sp); 245 } 246 247 static bool 248 WatchpointOptionsCallbackFunction(void *baton, 249 StoppointCallbackContext *context, 250 lldb::user_id_t watch_id) { 251 bool ret_value = true; 252 if (baton == nullptr) 253 return true; 254 255 WatchpointOptions::CommandData *data = 256 (WatchpointOptions::CommandData *)baton; 257 StringList &commands = data->user_source; 258 259 if (commands.GetSize() > 0) { 260 ExecutionContext exe_ctx(context->exe_ctx_ref); 261 Target *target = exe_ctx.GetTargetPtr(); 262 if (target) { 263 CommandReturnObject result; 264 Debugger &debugger = target->GetDebugger(); 265 // Rig up the results secondary output stream to the debugger's, so the 266 // output will come out synchronously 267 // if the debugger is set up that way. 268 269 StreamSP output_stream(debugger.GetAsyncOutputStream()); 270 StreamSP error_stream(debugger.GetAsyncErrorStream()); 271 result.SetImmediateOutputStream(output_stream); 272 result.SetImmediateErrorStream(error_stream); 273 274 CommandInterpreterRunOptions options; 275 options.SetStopOnContinue(true); 276 options.SetStopOnError(data->stop_on_error); 277 options.SetEchoCommands(false); 278 options.SetPrintResults(true); 279 options.SetAddToHistory(false); 280 281 debugger.GetCommandInterpreter().HandleCommands(commands, &exe_ctx, 282 options, result); 283 result.GetImmediateOutputStream()->Flush(); 284 result.GetImmediateErrorStream()->Flush(); 285 } 286 } 287 return ret_value; 288 } 289 290 class CommandOptions : public Options { 291 public: 292 CommandOptions() 293 : Options(), m_use_commands(false), m_use_script_language(false), 294 m_script_language(eScriptLanguageNone), m_use_one_liner(false), 295 m_one_liner(), m_function_name() {} 296 297 ~CommandOptions() override = default; 298 299 Error SetOptionValue(uint32_t option_idx, const char *option_arg, 300 ExecutionContext *execution_context) override { 301 Error error; 302 const int short_option = m_getopt_table[option_idx].val; 303 304 switch (short_option) { 305 case 'o': 306 m_use_one_liner = true; 307 m_one_liner = option_arg; 308 break; 309 310 case 's': 311 m_script_language = (lldb::ScriptLanguage)Args::StringToOptionEnum( 312 option_arg, g_option_table[option_idx].enum_values, 313 eScriptLanguageNone, error); 314 315 m_use_script_language = (m_script_language == eScriptLanguagePython || 316 m_script_language == eScriptLanguageDefault); 317 break; 318 319 case 'e': { 320 bool success = false; 321 m_stop_on_error = Args::StringToBoolean(option_arg, false, &success); 322 if (!success) 323 error.SetErrorStringWithFormat( 324 "invalid value for stop-on-error: \"%s\"", option_arg); 325 } break; 326 327 case 'F': 328 m_use_one_liner = false; 329 m_use_script_language = true; 330 m_function_name.assign(option_arg); 331 break; 332 333 default: 334 break; 335 } 336 return error; 337 } 338 339 void OptionParsingStarting(ExecutionContext *execution_context) override { 340 m_use_commands = true; 341 m_use_script_language = false; 342 m_script_language = eScriptLanguageNone; 343 344 m_use_one_liner = false; 345 m_stop_on_error = true; 346 m_one_liner.clear(); 347 m_function_name.clear(); 348 } 349 350 const OptionDefinition *GetDefinitions() override { return g_option_table; } 351 352 // Options table: Required for subclasses of Options. 353 354 static OptionDefinition g_option_table[]; 355 356 // Instance variables to hold the values for command options. 357 358 bool m_use_commands; 359 bool m_use_script_language; 360 lldb::ScriptLanguage m_script_language; 361 362 // Instance variables to hold the values for one_liner options. 363 bool m_use_one_liner; 364 std::string m_one_liner; 365 bool m_stop_on_error; 366 std::string m_function_name; 367 }; 368 369 protected: 370 bool DoExecute(Args &command, CommandReturnObject &result) override { 371 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 372 373 if (target == nullptr) { 374 result.AppendError("There is not a current executable; there are no " 375 "watchpoints to which to add commands"); 376 result.SetStatus(eReturnStatusFailed); 377 return false; 378 } 379 380 const WatchpointList &watchpoints = target->GetWatchpointList(); 381 size_t num_watchpoints = watchpoints.GetSize(); 382 383 if (num_watchpoints == 0) { 384 result.AppendError("No watchpoints exist to have commands added"); 385 result.SetStatus(eReturnStatusFailed); 386 return false; 387 } 388 389 if (!m_options.m_use_script_language && 390 !m_options.m_function_name.empty()) { 391 result.AppendError("need to enable scripting to have a function run as a " 392 "watchpoint command"); 393 result.SetStatus(eReturnStatusFailed); 394 return false; 395 } 396 397 std::vector<uint32_t> valid_wp_ids; 398 if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, 399 valid_wp_ids)) { 400 result.AppendError("Invalid watchpoints specification."); 401 result.SetStatus(eReturnStatusFailed); 402 return false; 403 } 404 405 result.SetStatus(eReturnStatusSuccessFinishNoResult); 406 const size_t count = valid_wp_ids.size(); 407 for (size_t i = 0; i < count; ++i) { 408 uint32_t cur_wp_id = valid_wp_ids.at(i); 409 if (cur_wp_id != LLDB_INVALID_WATCH_ID) { 410 Watchpoint *wp = target->GetWatchpointList().FindByID(cur_wp_id).get(); 411 // Sanity check wp first. 412 if (wp == nullptr) 413 continue; 414 415 WatchpointOptions *wp_options = wp->GetOptions(); 416 // Skip this watchpoint if wp_options is not good. 417 if (wp_options == nullptr) 418 continue; 419 420 // If we are using script language, get the script interpreter 421 // in order to set or collect command callback. Otherwise, call 422 // the methods associated with this object. 423 if (m_options.m_use_script_language) { 424 // Special handling for one-liner specified inline. 425 if (m_options.m_use_one_liner) { 426 m_interpreter.GetScriptInterpreter()->SetWatchpointCommandCallback( 427 wp_options, m_options.m_one_liner.c_str()); 428 } 429 // Special handling for using a Python function by name 430 // instead of extending the watchpoint callback data structures, we 431 // just automatize 432 // what the user would do manually: make their watchpoint command be a 433 // function call 434 else if (!m_options.m_function_name.empty()) { 435 std::string oneliner(m_options.m_function_name); 436 oneliner += "(frame, wp, internal_dict)"; 437 m_interpreter.GetScriptInterpreter()->SetWatchpointCommandCallback( 438 wp_options, oneliner.c_str()); 439 } else { 440 m_interpreter.GetScriptInterpreter() 441 ->CollectDataForWatchpointCommandCallback(wp_options, result); 442 } 443 } else { 444 // Special handling for one-liner specified inline. 445 if (m_options.m_use_one_liner) 446 SetWatchpointCommandCallback(wp_options, 447 m_options.m_one_liner.c_str()); 448 else 449 CollectDataForWatchpointCommandCallback(wp_options, result); 450 } 451 } 452 } 453 454 return result.Succeeded(); 455 } 456 457 private: 458 CommandOptions m_options; 459 }; 460 461 // FIXME: "script-type" needs to have its contents determined dynamically, so 462 // somebody can add a new scripting 463 // language to lldb and have it pickable here without having to change this 464 // enumeration by hand and rebuild lldb proper. 465 466 static OptionEnumValueElement g_script_option_enumeration[4] = { 467 {eScriptLanguageNone, "command", 468 "Commands are in the lldb command interpreter language"}, 469 {eScriptLanguagePython, "python", "Commands are in the Python language."}, 470 {eSortOrderByName, "default-script", 471 "Commands are in the default scripting language."}, 472 {0, nullptr, nullptr}}; 473 474 OptionDefinition 475 CommandObjectWatchpointCommandAdd::CommandOptions::g_option_table[] = { 476 // clang-format off 477 {LLDB_OPT_SET_1, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOneLiner, "Specify a one-line watchpoint command inline. Be sure to surround it with quotes."}, 478 {LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Specify whether watchpoint command execution should terminate on error."}, 479 {LLDB_OPT_SET_ALL, false, "script-type", 's', OptionParser::eRequiredArgument, nullptr, g_script_option_enumeration, 0, eArgTypeNone, "Specify the language for the commands - if none is specified, the lldb command interpreter will be used."}, 480 {LLDB_OPT_SET_2, false, "python-function", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Give the name of a Python function to run as command for this watchpoint. Be sure to give a module name if appropriate."}, 481 {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } 482 // clang-format on 483 }; 484 485 //------------------------------------------------------------------------- 486 // CommandObjectWatchpointCommandDelete 487 //------------------------------------------------------------------------- 488 489 class CommandObjectWatchpointCommandDelete : public CommandObjectParsed { 490 public: 491 CommandObjectWatchpointCommandDelete(CommandInterpreter &interpreter) 492 : CommandObjectParsed(interpreter, "delete", 493 "Delete the set of commands from a watchpoint.", 494 nullptr) { 495 CommandArgumentEntry arg; 496 CommandArgumentData wp_id_arg; 497 498 // Define the first (and only) variant of this arg. 499 wp_id_arg.arg_type = eArgTypeWatchpointID; 500 wp_id_arg.arg_repetition = eArgRepeatPlain; 501 502 // There is only one variant this argument could be; put it into the 503 // argument entry. 504 arg.push_back(wp_id_arg); 505 506 // Push the data for the first argument into the m_arguments vector. 507 m_arguments.push_back(arg); 508 } 509 510 ~CommandObjectWatchpointCommandDelete() override = default; 511 512 protected: 513 bool DoExecute(Args &command, CommandReturnObject &result) override { 514 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 515 516 if (target == nullptr) { 517 result.AppendError("There is not a current executable; there are no " 518 "watchpoints from which to delete commands"); 519 result.SetStatus(eReturnStatusFailed); 520 return false; 521 } 522 523 const WatchpointList &watchpoints = target->GetWatchpointList(); 524 size_t num_watchpoints = watchpoints.GetSize(); 525 526 if (num_watchpoints == 0) { 527 result.AppendError("No watchpoints exist to have commands deleted"); 528 result.SetStatus(eReturnStatusFailed); 529 return false; 530 } 531 532 if (command.GetArgumentCount() == 0) { 533 result.AppendError( 534 "No watchpoint specified from which to delete the commands"); 535 result.SetStatus(eReturnStatusFailed); 536 return false; 537 } 538 539 std::vector<uint32_t> valid_wp_ids; 540 if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, 541 valid_wp_ids)) { 542 result.AppendError("Invalid watchpoints specification."); 543 result.SetStatus(eReturnStatusFailed); 544 return false; 545 } 546 547 result.SetStatus(eReturnStatusSuccessFinishNoResult); 548 const size_t count = valid_wp_ids.size(); 549 for (size_t i = 0; i < count; ++i) { 550 uint32_t cur_wp_id = valid_wp_ids.at(i); 551 if (cur_wp_id != LLDB_INVALID_WATCH_ID) { 552 Watchpoint *wp = target->GetWatchpointList().FindByID(cur_wp_id).get(); 553 if (wp) 554 wp->ClearCallback(); 555 } else { 556 result.AppendErrorWithFormat("Invalid watchpoint ID: %u.\n", cur_wp_id); 557 result.SetStatus(eReturnStatusFailed); 558 return false; 559 } 560 } 561 return result.Succeeded(); 562 } 563 }; 564 565 //------------------------------------------------------------------------- 566 // CommandObjectWatchpointCommandList 567 //------------------------------------------------------------------------- 568 569 class CommandObjectWatchpointCommandList : public CommandObjectParsed { 570 public: 571 CommandObjectWatchpointCommandList(CommandInterpreter &interpreter) 572 : CommandObjectParsed(interpreter, "list", "List the script or set of " 573 "commands to be executed when " 574 "the watchpoint is hit.", 575 nullptr) { 576 CommandArgumentEntry arg; 577 CommandArgumentData wp_id_arg; 578 579 // Define the first (and only) variant of this arg. 580 wp_id_arg.arg_type = eArgTypeWatchpointID; 581 wp_id_arg.arg_repetition = eArgRepeatPlain; 582 583 // There is only one variant this argument could be; put it into the 584 // argument entry. 585 arg.push_back(wp_id_arg); 586 587 // Push the data for the first argument into the m_arguments vector. 588 m_arguments.push_back(arg); 589 } 590 591 ~CommandObjectWatchpointCommandList() override = default; 592 593 protected: 594 bool DoExecute(Args &command, CommandReturnObject &result) override { 595 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 596 597 if (target == nullptr) { 598 result.AppendError("There is not a current executable; there are no " 599 "watchpoints for which to list commands"); 600 result.SetStatus(eReturnStatusFailed); 601 return false; 602 } 603 604 const WatchpointList &watchpoints = target->GetWatchpointList(); 605 size_t num_watchpoints = watchpoints.GetSize(); 606 607 if (num_watchpoints == 0) { 608 result.AppendError("No watchpoints exist for which to list commands"); 609 result.SetStatus(eReturnStatusFailed); 610 return false; 611 } 612 613 if (command.GetArgumentCount() == 0) { 614 result.AppendError( 615 "No watchpoint specified for which to list the commands"); 616 result.SetStatus(eReturnStatusFailed); 617 return false; 618 } 619 620 std::vector<uint32_t> valid_wp_ids; 621 if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, 622 valid_wp_ids)) { 623 result.AppendError("Invalid watchpoints specification."); 624 result.SetStatus(eReturnStatusFailed); 625 return false; 626 } 627 628 result.SetStatus(eReturnStatusSuccessFinishNoResult); 629 const size_t count = valid_wp_ids.size(); 630 for (size_t i = 0; i < count; ++i) { 631 uint32_t cur_wp_id = valid_wp_ids.at(i); 632 if (cur_wp_id != LLDB_INVALID_WATCH_ID) { 633 Watchpoint *wp = target->GetWatchpointList().FindByID(cur_wp_id).get(); 634 635 if (wp) { 636 const WatchpointOptions *wp_options = wp->GetOptions(); 637 if (wp_options) { 638 // Get the callback baton associated with the current watchpoint. 639 const Baton *baton = wp_options->GetBaton(); 640 if (baton) { 641 result.GetOutputStream().Printf("Watchpoint %u:\n", cur_wp_id); 642 result.GetOutputStream().IndentMore(); 643 baton->GetDescription(&result.GetOutputStream(), 644 eDescriptionLevelFull); 645 result.GetOutputStream().IndentLess(); 646 } else { 647 result.AppendMessageWithFormat( 648 "Watchpoint %u does not have an associated command.\n", 649 cur_wp_id); 650 } 651 } 652 result.SetStatus(eReturnStatusSuccessFinishResult); 653 } else { 654 result.AppendErrorWithFormat("Invalid watchpoint ID: %u.\n", 655 cur_wp_id); 656 result.SetStatus(eReturnStatusFailed); 657 } 658 } 659 } 660 661 return result.Succeeded(); 662 } 663 }; 664 665 //------------------------------------------------------------------------- 666 // CommandObjectWatchpointCommand 667 //------------------------------------------------------------------------- 668 669 CommandObjectWatchpointCommand::CommandObjectWatchpointCommand( 670 CommandInterpreter &interpreter) 671 : CommandObjectMultiword( 672 interpreter, "command", 673 "Commands for adding, removing and examining LLDB commands " 674 "executed when the watchpoint is hit (watchpoint 'commmands').", 675 "command <sub-command> [<sub-command-options>] <watchpoint-id>") { 676 CommandObjectSP add_command_object( 677 new CommandObjectWatchpointCommandAdd(interpreter)); 678 CommandObjectSP delete_command_object( 679 new CommandObjectWatchpointCommandDelete(interpreter)); 680 CommandObjectSP list_command_object( 681 new CommandObjectWatchpointCommandList(interpreter)); 682 683 add_command_object->SetCommandName("watchpoint command add"); 684 delete_command_object->SetCommandName("watchpoint command delete"); 685 list_command_object->SetCommandName("watchpoint command list"); 686 687 LoadSubCommand("add", add_command_object); 688 LoadSubCommand("delete", delete_command_object); 689 LoadSubCommand("list", list_command_object); 690 } 691 692 CommandObjectWatchpointCommand::~CommandObjectWatchpointCommand() = default; 693