1 //===-- CommandObjectProcess.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 #include "CommandObjectProcess.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Interpreter/Args.h" 17 #include "lldb/Interpreter/Options.h" 18 #include "lldb/Core/State.h" 19 #include "lldb/Interpreter/CommandInterpreter.h" 20 #include "lldb/Interpreter/CommandReturnObject.h" 21 #include "./CommandObjectThread.h" 22 #include "lldb/Target/Process.h" 23 #include "lldb/Target/Target.h" 24 #include "lldb/Target/Thread.h" 25 26 using namespace lldb; 27 using namespace lldb_private; 28 29 //------------------------------------------------------------------------- 30 // CommandObjectProcessLaunch 31 //------------------------------------------------------------------------- 32 #pragma mark CommandObjectProjectLaunch 33 class CommandObjectProcessLaunch : public CommandObject 34 { 35 public: 36 37 class CommandOptions : public Options 38 { 39 public: 40 41 CommandOptions () : 42 Options() 43 { 44 // Keep default values of all options in one place: ResetOptionValues () 45 ResetOptionValues (); 46 } 47 48 ~CommandOptions () 49 { 50 } 51 52 Error 53 SetOptionValue (int option_idx, const char *option_arg) 54 { 55 Error error; 56 char short_option = (char) m_getopt_table[option_idx].val; 57 58 switch (short_option) 59 { 60 case 's': stop_at_entry = true; break; 61 case 'e': stderr_path = option_arg; break; 62 case 'i': stdin_path = option_arg; break; 63 case 'o': stdout_path = option_arg; break; 64 case 'p': plugin_name = option_arg; break; 65 case 'n': no_stdio = true; break; 66 case 't': 67 if (option_arg && option_arg[0]) 68 tty_name.assign (option_arg); 69 in_new_tty = true; 70 break; 71 default: 72 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); 73 break; 74 75 } 76 return error; 77 } 78 79 void 80 ResetOptionValues () 81 { 82 Options::ResetOptionValues(); 83 stop_at_entry = false; 84 in_new_tty = false; 85 tty_name.clear(); 86 stdin_path.clear(); 87 stdout_path.clear(); 88 stderr_path.clear(); 89 plugin_name.clear(); 90 no_stdio = false; 91 } 92 93 const lldb::OptionDefinition* 94 GetDefinitions () 95 { 96 return g_option_table; 97 } 98 99 // Options table: Required for subclasses of Options. 100 101 static lldb::OptionDefinition g_option_table[]; 102 103 // Instance variables to hold the values for command options. 104 105 bool stop_at_entry; 106 bool in_new_tty; 107 bool no_stdio; 108 std::string tty_name; 109 std::string stderr_path; 110 std::string stdin_path; 111 std::string stdout_path; 112 std::string plugin_name; 113 114 }; 115 116 CommandObjectProcessLaunch (CommandInterpreter &interpreter) : 117 CommandObject (interpreter, 118 "process launch", 119 "Launch the executable in the debugger.", 120 NULL) 121 { 122 CommandArgumentEntry arg; 123 CommandArgumentData run_args_arg; 124 125 // Define the first (and only) variant of this arg. 126 run_args_arg.arg_type = eArgTypeRunArgs; 127 run_args_arg.arg_repetition = eArgRepeatOptional; 128 129 // There is only one variant this argument could be; put it into the argument entry. 130 arg.push_back (run_args_arg); 131 132 // Push the data for the first argument into the m_arguments vector. 133 m_arguments.push_back (arg); 134 } 135 136 137 ~CommandObjectProcessLaunch () 138 { 139 } 140 141 Options * 142 GetOptions () 143 { 144 return &m_options; 145 } 146 147 bool 148 Execute (Args& launch_args, CommandReturnObject &result) 149 { 150 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 151 152 if (target == NULL) 153 { 154 result.AppendError ("invalid target, set executable file using 'file' command"); 155 result.SetStatus (eReturnStatusFailed); 156 return false; 157 } 158 159 // If our listener is NULL, users aren't allows to launch 160 char filename[PATH_MAX]; 161 const Module *exe_module = target->GetExecutableModule().get(); 162 exe_module->GetFileSpec().GetPath(filename, sizeof(filename)); 163 164 Process *process = m_interpreter.GetDebugger().GetExecutionContext().process; 165 if (process && process->IsAlive()) 166 { 167 if (!m_interpreter.Confirm ("There is a running process, kill it and restart?", true)) 168 { 169 result.AppendErrorWithFormat ("Process %u is currently being debugged, restart cancelled.\n", 170 process->GetID()); 171 result.SetStatus (eReturnStatusFailed); 172 return false; 173 } 174 else 175 { 176 Error error (process->Destroy()); 177 if (error.Success()) 178 { 179 result.SetStatus (eReturnStatusSuccessFinishResult); 180 } 181 else 182 { 183 result.AppendErrorWithFormat ("Failed to kill process: %s\n", error.AsCString()); 184 result.SetStatus (eReturnStatusFailed); 185 } 186 } 187 } 188 189 const char *plugin_name; 190 if (!m_options.plugin_name.empty()) 191 plugin_name = m_options.plugin_name.c_str(); 192 else 193 plugin_name = NULL; 194 195 process = target->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name).get(); 196 197 if (process == NULL) 198 { 199 result.AppendErrorWithFormat ("Failed to find a process plugin for executable.\n"); 200 result.SetStatus (eReturnStatusFailed); 201 return false; 202 } 203 204 // If no launch args were given on the command line, then use any that 205 // might have been set using the "run-args" set variable. 206 if (launch_args.GetArgumentCount() == 0) 207 { 208 if (process->GetRunArguments().GetArgumentCount() > 0) 209 launch_args = process->GetRunArguments(); 210 } 211 212 if (m_options.in_new_tty) 213 { 214 char exec_file_path[PATH_MAX]; 215 if (exe_module->GetFileSpec().GetPath(exec_file_path, sizeof(exec_file_path))) 216 { 217 launch_args.InsertArgumentAtIndex(0, exec_file_path); 218 } 219 else 220 { 221 result.AppendError("invalid executable"); 222 result.SetStatus (eReturnStatusFailed); 223 return false; 224 } 225 } 226 227 Args environment; 228 229 process->GetEnvironmentAsArgs (environment); 230 231 uint32_t launch_flags = eLaunchFlagNone; 232 233 if (process->GetDisableASLR()) 234 launch_flags |= eLaunchFlagDisableASLR; 235 236 if (m_options.no_stdio) 237 launch_flags |= eLaunchFlagDisableSTDIO; 238 else if (!m_options.in_new_tty 239 && m_options.stdin_path.empty() 240 && m_options.stdout_path.empty() 241 && m_options.stderr_path.empty()) 242 { 243 // Only use the settings value if the user hasn't specified any options that would override it. 244 if (process->GetDisableSTDIO()) 245 launch_flags |= eLaunchFlagDisableSTDIO; 246 } 247 248 const char **inferior_argv = launch_args.GetArgumentCount() ? launch_args.GetConstArgumentVector() : NULL; 249 const char **inferior_envp = environment.GetArgumentCount() ? environment.GetConstArgumentVector() : NULL; 250 251 Error error; 252 253 if (m_options.in_new_tty) 254 { 255 256 lldb::pid_t pid = Host::LaunchInNewTerminal (m_options.tty_name.c_str(), 257 inferior_argv, 258 inferior_envp, 259 &exe_module->GetArchitecture(), 260 true, 261 process->GetDisableASLR()); 262 263 if (pid != LLDB_INVALID_PROCESS_ID) 264 error = process->Attach (pid); 265 } 266 else 267 { 268 const char * stdin_path = NULL; 269 const char * stdout_path = NULL; 270 const char * stderr_path = NULL; 271 272 // Were any standard input/output/error paths given on the command line? 273 if (m_options.stdin_path.empty() && 274 m_options.stdout_path.empty() && 275 m_options.stderr_path.empty()) 276 { 277 // No standard file handles were given on the command line, check 278 // with the process object in case they were give using "set settings" 279 stdin_path = process->GetStandardInputPath(); 280 stdout_path = process->GetStandardOutputPath(); 281 stderr_path = process->GetStandardErrorPath(); 282 } 283 else 284 { 285 stdin_path = m_options.stdin_path.empty() ? NULL : m_options.stdin_path.c_str(); 286 stdout_path = m_options.stdout_path.empty() ? NULL : m_options.stdout_path.c_str(); 287 stderr_path = m_options.stderr_path.empty() ? NULL : m_options.stderr_path.c_str(); 288 } 289 290 if (stdin_path == NULL) 291 stdin_path = "/dev/null"; 292 if (stdout_path == NULL) 293 stdout_path = "/dev/null"; 294 if (stderr_path == NULL) 295 stderr_path = "/dev/null"; 296 297 error = process->Launch (inferior_argv, 298 inferior_envp, 299 launch_flags, 300 stdin_path, 301 stdout_path, 302 stderr_path); 303 } 304 305 if (error.Success()) 306 { 307 const char *archname = exe_module->GetArchitecture().AsCString(); 308 309 result.AppendMessageWithFormat ("Process %i launched: '%s' (%s)\n", process->GetID(), filename, archname); 310 result.SetDidChangeProcessState (true); 311 if (m_options.stop_at_entry == false) 312 { 313 result.SetStatus (eReturnStatusSuccessContinuingNoResult); 314 StateType state = process->WaitForProcessToStop (NULL); 315 316 if (state == eStateStopped) 317 { 318 error = process->Resume(); 319 if (error.Success()) 320 { 321 bool synchronous_execution = m_interpreter.GetSynchronous (); 322 if (synchronous_execution) 323 { 324 state = process->WaitForProcessToStop (NULL); 325 result.SetDidChangeProcessState (true); 326 result.SetStatus (eReturnStatusSuccessFinishResult); 327 } 328 else 329 { 330 result.SetStatus (eReturnStatusSuccessContinuingNoResult); 331 } 332 } 333 } 334 } 335 } 336 337 return result.Succeeded(); 338 } 339 340 virtual const char *GetRepeatCommand (Args ¤t_command_args, uint32_t index) 341 { 342 // No repeat for "process launch"... 343 return ""; 344 } 345 346 protected: 347 348 CommandOptions m_options; 349 }; 350 351 352 #define SET1 LLDB_OPT_SET_1 353 #define SET2 LLDB_OPT_SET_2 354 #define SET3 LLDB_OPT_SET_3 355 356 lldb::OptionDefinition 357 CommandObjectProcessLaunch::CommandOptions::g_option_table[] = 358 { 359 { SET1 | SET2 | SET3, false, "stop-at-entry", 's', no_argument, NULL, 0, eArgTypeNone, "Stop at the entry point of the program when launching a process."}, 360 { SET1 , false, "stdin", 'i', required_argument, NULL, 0, eArgTypePath, "Redirect stdin for the process to <path>."}, 361 { SET1 , false, "stdout", 'o', required_argument, NULL, 0, eArgTypePath, "Redirect stdout for the process to <path>."}, 362 { SET1 , false, "stderr", 'e', required_argument, NULL, 0, eArgTypePath, "Redirect stderr for the process to <path>."}, 363 { SET1 | SET2 | SET3, false, "plugin", 'p', required_argument, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, 364 { SET2 , false, "tty", 't', optional_argument, NULL, 0, eArgTypePath, "Start the process in a terminal. If <path> is specified, look for a terminal whose name contains <path>, else start the process in a new terminal."}, 365 { SET3, false, "no-stdio", 'n', no_argument, NULL, 0, eArgTypeNone, "Do not set up for terminal I/O to go to running process."}, 366 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 367 }; 368 369 #undef SET1 370 #undef SET2 371 #undef SET3 372 373 //------------------------------------------------------------------------- 374 // CommandObjectProcessAttach 375 //------------------------------------------------------------------------- 376 #pragma mark CommandObjectProcessAttach 377 class CommandObjectProcessAttach : public CommandObject 378 { 379 public: 380 381 class CommandOptions : public Options 382 { 383 public: 384 385 CommandOptions () : 386 Options() 387 { 388 // Keep default values of all options in one place: ResetOptionValues () 389 ResetOptionValues (); 390 } 391 392 ~CommandOptions () 393 { 394 } 395 396 Error 397 SetOptionValue (int option_idx, const char *option_arg) 398 { 399 Error error; 400 char short_option = (char) m_getopt_table[option_idx].val; 401 bool success = false; 402 switch (short_option) 403 { 404 case 'p': 405 pid = Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success); 406 if (!success || pid == LLDB_INVALID_PROCESS_ID) 407 { 408 error.SetErrorStringWithFormat("Invalid process ID '%s'.\n", option_arg); 409 } 410 break; 411 412 case 'P': 413 plugin_name = option_arg; 414 break; 415 416 case 'n': 417 name.assign(option_arg); 418 break; 419 420 case 'w': 421 waitfor = true; 422 break; 423 424 default: 425 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); 426 break; 427 } 428 return error; 429 } 430 431 void 432 ResetOptionValues () 433 { 434 Options::ResetOptionValues(); 435 pid = LLDB_INVALID_PROCESS_ID; 436 name.clear(); 437 waitfor = false; 438 } 439 440 const lldb::OptionDefinition* 441 GetDefinitions () 442 { 443 return g_option_table; 444 } 445 446 virtual bool 447 HandleOptionArgumentCompletion (CommandInterpreter &interpeter, 448 Args &input, 449 int cursor_index, 450 int char_pos, 451 OptionElementVector &opt_element_vector, 452 int opt_element_index, 453 int match_start_point, 454 int max_return_elements, 455 bool &word_complete, 456 StringList &matches) 457 { 458 int opt_arg_pos = opt_element_vector[opt_element_index].opt_arg_pos; 459 int opt_defs_index = opt_element_vector[opt_element_index].opt_defs_index; 460 461 // We are only completing the name option for now... 462 463 const lldb::OptionDefinition *opt_defs = GetDefinitions(); 464 if (opt_defs[opt_defs_index].short_option == 'n') 465 { 466 // Are we in the name? 467 468 // Look to see if there is a -P argument provided, and if so use that plugin, otherwise 469 // use the default plugin. 470 Process *process = interpeter.GetDebugger().GetExecutionContext().process; 471 bool need_to_delete_process = false; 472 473 const char *partial_name = NULL; 474 partial_name = input.GetArgumentAtIndex(opt_arg_pos); 475 476 if (process && process->IsAlive()) 477 return true; 478 479 Target *target = interpeter.GetDebugger().GetSelectedTarget().get(); 480 if (target == NULL) 481 { 482 // No target has been set yet, for now do host completion. Otherwise I don't know how we would 483 // figure out what the right target to use is... 484 std::vector<lldb::pid_t> pids; 485 Host::ListProcessesMatchingName (partial_name, matches, pids); 486 return true; 487 } 488 if (!process) 489 { 490 process = target->CreateProcess (interpeter.GetDebugger().GetListener(), partial_name).get(); 491 need_to_delete_process = true; 492 } 493 494 if (process) 495 { 496 matches.Clear(); 497 std::vector<lldb::pid_t> pids; 498 process->ListProcessesMatchingName (NULL, matches, pids); 499 if (need_to_delete_process) 500 target->DeleteCurrentProcess(); 501 return true; 502 } 503 } 504 505 return false; 506 } 507 508 // Options table: Required for subclasses of Options. 509 510 static lldb::OptionDefinition g_option_table[]; 511 512 // Instance variables to hold the values for command options. 513 514 lldb::pid_t pid; 515 std::string plugin_name; 516 std::string name; 517 bool waitfor; 518 }; 519 520 CommandObjectProcessAttach (CommandInterpreter &interpreter) : 521 CommandObject (interpreter, 522 "process attach", 523 "Attach to a process.", 524 "process attach <cmd-options>") 525 { 526 } 527 528 ~CommandObjectProcessAttach () 529 { 530 } 531 532 bool 533 Execute (Args& command, 534 CommandReturnObject &result) 535 { 536 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 537 538 Process *process = m_interpreter.GetDebugger().GetExecutionContext().process; 539 if (process) 540 { 541 if (process->IsAlive()) 542 { 543 result.AppendErrorWithFormat ("Process %u is currently being debugged, kill the process before attaching.\n", 544 process->GetID()); 545 result.SetStatus (eReturnStatusFailed); 546 return false; 547 } 548 } 549 550 if (target == NULL) 551 { 552 // If there isn't a current target create one. 553 TargetSP new_target_sp; 554 FileSpec emptyFileSpec; 555 ArchSpec emptyArchSpec; 556 Error error; 557 558 error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(), 559 emptyFileSpec, 560 emptyArchSpec, 561 NULL, 562 false, 563 new_target_sp); 564 target = new_target_sp.get(); 565 if (target == NULL || error.Fail()) 566 { 567 result.AppendError(error.AsCString("Error creating empty target")); 568 return false; 569 } 570 m_interpreter.GetDebugger().GetTargetList().SetSelectedTarget(target); 571 } 572 573 // Record the old executable module, we want to issue a warning if the process of attaching changed the 574 // current executable (like somebody said "file foo" then attached to a PID whose executable was bar.) 575 576 ModuleSP old_exec_module_sp = target->GetExecutableModule(); 577 ArchSpec old_arch_spec = target->GetArchitecture(); 578 579 if (command.GetArgumentCount()) 580 { 581 result.AppendErrorWithFormat("Invalid arguments for '%s'.\nUsage: \n", m_cmd_name.c_str(), m_cmd_syntax.c_str()); 582 result.SetStatus (eReturnStatusFailed); 583 } 584 else 585 { 586 const char *plugin_name = NULL; 587 588 if (!m_options.plugin_name.empty()) 589 plugin_name = m_options.plugin_name.c_str(); 590 591 process = target->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name).get(); 592 593 if (process) 594 { 595 Error error; 596 int attach_pid = m_options.pid; 597 598 const char *wait_name = NULL; 599 600 if (m_options.name.empty()) 601 { 602 if (old_exec_module_sp) 603 { 604 wait_name = old_exec_module_sp->GetFileSpec().GetFilename().AsCString(); 605 } 606 } 607 else 608 { 609 wait_name = m_options.name.c_str(); 610 } 611 612 // If we are waiting for a process with this name to show up, do that first. 613 if (m_options.waitfor) 614 { 615 616 if (wait_name == NULL) 617 { 618 result.AppendError("Invalid arguments: must have a file loaded or supply a process name with the waitfor option.\n"); 619 result.SetStatus (eReturnStatusFailed); 620 return false; 621 } 622 623 m_interpreter.GetDebugger().GetOutputStream().Printf("Waiting to attach to a process named \"%s\".\n", wait_name); 624 error = process->Attach (wait_name, m_options.waitfor); 625 if (error.Success()) 626 { 627 result.SetStatus (eReturnStatusSuccessContinuingNoResult); 628 } 629 else 630 { 631 result.AppendErrorWithFormat ("Waiting for a process to launch named '%s': %s\n", 632 wait_name, 633 error.AsCString()); 634 result.SetStatus (eReturnStatusFailed); 635 return false; 636 } 637 } 638 else 639 { 640 // If the process was specified by name look it up, so we can warn if there are multiple 641 // processes with this pid. 642 643 if (attach_pid == LLDB_INVALID_PROCESS_ID && wait_name != NULL) 644 { 645 std::vector<lldb::pid_t> pids; 646 StringList matches; 647 648 process->ListProcessesMatchingName(wait_name, matches, pids); 649 if (matches.GetSize() > 1) 650 { 651 result.AppendErrorWithFormat("More than one process named %s\n", wait_name); 652 result.SetStatus (eReturnStatusFailed); 653 return false; 654 } 655 else if (matches.GetSize() == 0) 656 { 657 result.AppendErrorWithFormat("Could not find a process named %s\n", wait_name); 658 result.SetStatus (eReturnStatusFailed); 659 return false; 660 } 661 else 662 { 663 attach_pid = pids[0]; 664 } 665 666 } 667 668 if (attach_pid != LLDB_INVALID_PROCESS_ID) 669 { 670 error = process->Attach (attach_pid); 671 if (error.Success()) 672 { 673 result.SetStatus (eReturnStatusSuccessContinuingNoResult); 674 } 675 else 676 { 677 result.AppendErrorWithFormat ("Attaching to process %i failed: %s.\n", 678 attach_pid, 679 error.AsCString()); 680 result.SetStatus (eReturnStatusFailed); 681 } 682 } 683 else 684 { 685 result.AppendErrorWithFormat ("No PID specified for attach\n", 686 attach_pid, 687 error.AsCString()); 688 result.SetStatus (eReturnStatusFailed); 689 690 } 691 } 692 } 693 } 694 695 if (result.Succeeded()) 696 { 697 // Okay, we're done. Last step is to warn if the executable module has changed: 698 if (!old_exec_module_sp) 699 { 700 char new_path[PATH_MAX + 1]; 701 target->GetExecutableModule()->GetFileSpec().GetPath(new_path, PATH_MAX); 702 703 result.AppendMessageWithFormat("Executable module set to \"%s\".\n", 704 new_path); 705 } 706 else if (old_exec_module_sp->GetFileSpec() != target->GetExecutableModule()->GetFileSpec()) 707 { 708 char old_path[PATH_MAX + 1]; 709 char new_path[PATH_MAX + 1]; 710 711 old_exec_module_sp->GetFileSpec().GetPath(old_path, PATH_MAX); 712 target->GetExecutableModule()->GetFileSpec().GetPath (new_path, PATH_MAX); 713 714 result.AppendWarningWithFormat("Executable module changed from \"%s\" to \"%s\".\n", 715 old_path, new_path); 716 } 717 718 if (!old_arch_spec.IsValid()) 719 { 720 result.AppendMessageWithFormat ("Architecture set to: %s.\n", target->GetArchitecture().AsCString()); 721 } 722 else if (old_arch_spec != target->GetArchitecture()) 723 { 724 result.AppendWarningWithFormat("Architecture changed from %s to %s.\n", 725 old_arch_spec.AsCString(), target->GetArchitecture().AsCString()); 726 } 727 } 728 return result.Succeeded(); 729 } 730 731 Options * 732 GetOptions () 733 { 734 return &m_options; 735 } 736 737 protected: 738 739 CommandOptions m_options; 740 }; 741 742 743 lldb::OptionDefinition 744 CommandObjectProcessAttach::CommandOptions::g_option_table[] = 745 { 746 { LLDB_OPT_SET_ALL, false, "plugin", 'P', required_argument, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, 747 { LLDB_OPT_SET_1, false, "pid", 'p', required_argument, NULL, 0, eArgTypePid, "The process ID of an existing process to attach to."}, 748 { LLDB_OPT_SET_2, false, "name", 'n', required_argument, NULL, 0, eArgTypeProcessName, "The name of the process to attach to."}, 749 { LLDB_OPT_SET_2, false, "waitfor",'w', no_argument, NULL, 0, eArgTypeNone, "Wait for the the process with <process-name> to launch."}, 750 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 751 }; 752 753 //------------------------------------------------------------------------- 754 // CommandObjectProcessContinue 755 //------------------------------------------------------------------------- 756 #pragma mark CommandObjectProcessContinue 757 758 class CommandObjectProcessContinue : public CommandObject 759 { 760 public: 761 762 CommandObjectProcessContinue (CommandInterpreter &interpreter) : 763 CommandObject (interpreter, 764 "process continue", 765 "Continue execution of all threads in the current process.", 766 "process continue", 767 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) 768 { 769 } 770 771 772 ~CommandObjectProcessContinue () 773 { 774 } 775 776 bool 777 Execute (Args& command, 778 CommandReturnObject &result) 779 { 780 Process *process = m_interpreter.GetDebugger().GetExecutionContext().process; 781 bool synchronous_execution = m_interpreter.GetSynchronous (); 782 783 if (process == NULL) 784 { 785 result.AppendError ("no process to continue"); 786 result.SetStatus (eReturnStatusFailed); 787 return false; 788 } 789 790 StateType state = process->GetState(); 791 if (state == eStateStopped) 792 { 793 if (command.GetArgumentCount() != 0) 794 { 795 result.AppendErrorWithFormat ("The '%s' command does not take any arguments.\n", m_cmd_name.c_str()); 796 result.SetStatus (eReturnStatusFailed); 797 return false; 798 } 799 800 const uint32_t num_threads = process->GetThreadList().GetSize(); 801 802 // Set the actions that the threads should each take when resuming 803 for (uint32_t idx=0; idx<num_threads; ++idx) 804 { 805 process->GetThreadList().GetThreadAtIndex(idx)->SetResumeState (eStateRunning); 806 } 807 808 Error error(process->Resume()); 809 if (error.Success()) 810 { 811 result.AppendMessageWithFormat ("Process %i resuming\n", process->GetID()); 812 if (synchronous_execution) 813 { 814 state = process->WaitForProcessToStop (NULL); 815 816 result.SetDidChangeProcessState (true); 817 result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state)); 818 result.SetStatus (eReturnStatusSuccessFinishNoResult); 819 } 820 else 821 { 822 result.SetStatus (eReturnStatusSuccessContinuingNoResult); 823 } 824 } 825 else 826 { 827 result.AppendErrorWithFormat("Failed to resume process: %s.\n", error.AsCString()); 828 result.SetStatus (eReturnStatusFailed); 829 } 830 } 831 else 832 { 833 result.AppendErrorWithFormat ("Process cannot be continued from its current state (%s).\n", 834 StateAsCString(state)); 835 result.SetStatus (eReturnStatusFailed); 836 } 837 return result.Succeeded(); 838 } 839 }; 840 841 //------------------------------------------------------------------------- 842 // CommandObjectProcessDetach 843 //------------------------------------------------------------------------- 844 #pragma mark CommandObjectProcessDetach 845 846 class CommandObjectProcessDetach : public CommandObject 847 { 848 public: 849 850 CommandObjectProcessDetach (CommandInterpreter &interpreter) : 851 CommandObject (interpreter, 852 "process detach", 853 "Detach from the current process being debugged.", 854 "process detach", 855 eFlagProcessMustBeLaunched) 856 { 857 } 858 859 ~CommandObjectProcessDetach () 860 { 861 } 862 863 bool 864 Execute (Args& command, 865 CommandReturnObject &result) 866 { 867 Process *process = m_interpreter.GetDebugger().GetExecutionContext().process; 868 if (process == NULL) 869 { 870 result.AppendError ("must have a valid process in order to detach"); 871 result.SetStatus (eReturnStatusFailed); 872 return false; 873 } 874 875 result.AppendMessageWithFormat ("Detaching from process %i\n", process->GetID()); 876 Error error (process->Detach()); 877 if (error.Success()) 878 { 879 result.SetStatus (eReturnStatusSuccessFinishResult); 880 } 881 else 882 { 883 result.AppendErrorWithFormat ("Detach failed: %s\n", error.AsCString()); 884 result.SetStatus (eReturnStatusFailed); 885 return false; 886 } 887 return result.Succeeded(); 888 } 889 }; 890 891 //------------------------------------------------------------------------- 892 // CommandObjectProcessLoad 893 //------------------------------------------------------------------------- 894 #pragma mark CommandObjectProcessLoad 895 896 class CommandObjectProcessLoad : public CommandObject 897 { 898 public: 899 900 CommandObjectProcessLoad (CommandInterpreter &interpreter) : 901 CommandObject (interpreter, 902 "process load", 903 "Load a shared library into the current process.", 904 "process load <filename> [<filename> ...]", 905 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) 906 { 907 } 908 909 ~CommandObjectProcessLoad () 910 { 911 } 912 913 bool 914 Execute (Args& command, 915 CommandReturnObject &result) 916 { 917 Process *process = m_interpreter.GetDebugger().GetExecutionContext().process; 918 if (process == NULL) 919 { 920 result.AppendError ("must have a valid process in order to load a shared library"); 921 result.SetStatus (eReturnStatusFailed); 922 return false; 923 } 924 925 const uint32_t argc = command.GetArgumentCount(); 926 927 for (uint32_t i=0; i<argc; ++i) 928 { 929 Error error; 930 const char *image_path = command.GetArgumentAtIndex(i); 931 FileSpec image_spec (image_path, false); 932 uint32_t image_token = process->LoadImage(image_spec, error); 933 if (image_token != LLDB_INVALID_IMAGE_TOKEN) 934 { 935 result.AppendMessageWithFormat ("Loading \"%s\"...ok\nImage %u loaded.\n", image_path, image_token); 936 result.SetStatus (eReturnStatusSuccessFinishResult); 937 } 938 else 939 { 940 result.AppendErrorWithFormat ("failed to load '%s': %s", image_path, error.AsCString()); 941 result.SetStatus (eReturnStatusFailed); 942 } 943 } 944 return result.Succeeded(); 945 } 946 }; 947 948 949 //------------------------------------------------------------------------- 950 // CommandObjectProcessUnload 951 //------------------------------------------------------------------------- 952 #pragma mark CommandObjectProcessUnload 953 954 class CommandObjectProcessUnload : public CommandObject 955 { 956 public: 957 958 CommandObjectProcessUnload (CommandInterpreter &interpreter) : 959 CommandObject (interpreter, 960 "process unload", 961 "Unload a shared library from the current process using the index returned by a previous call to \"process load\".", 962 "process unload <index>", 963 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) 964 { 965 } 966 967 ~CommandObjectProcessUnload () 968 { 969 } 970 971 bool 972 Execute (Args& command, 973 CommandReturnObject &result) 974 { 975 Process *process = m_interpreter.GetDebugger().GetExecutionContext().process; 976 if (process == NULL) 977 { 978 result.AppendError ("must have a valid process in order to load a shared library"); 979 result.SetStatus (eReturnStatusFailed); 980 return false; 981 } 982 983 const uint32_t argc = command.GetArgumentCount(); 984 985 for (uint32_t i=0; i<argc; ++i) 986 { 987 const char *image_token_cstr = command.GetArgumentAtIndex(i); 988 uint32_t image_token = Args::StringToUInt32(image_token_cstr, LLDB_INVALID_IMAGE_TOKEN, 0); 989 if (image_token == LLDB_INVALID_IMAGE_TOKEN) 990 { 991 result.AppendErrorWithFormat ("invalid image index argument '%s'", image_token_cstr); 992 result.SetStatus (eReturnStatusFailed); 993 break; 994 } 995 else 996 { 997 Error error (process->UnloadImage(image_token)); 998 if (error.Success()) 999 { 1000 result.AppendMessageWithFormat ("Unloading shared library with index %u...ok\n", image_token); 1001 result.SetStatus (eReturnStatusSuccessFinishResult); 1002 } 1003 else 1004 { 1005 result.AppendErrorWithFormat ("failed to unload image: %s", error.AsCString()); 1006 result.SetStatus (eReturnStatusFailed); 1007 break; 1008 } 1009 } 1010 } 1011 return result.Succeeded(); 1012 } 1013 }; 1014 1015 //------------------------------------------------------------------------- 1016 // CommandObjectProcessSignal 1017 //------------------------------------------------------------------------- 1018 #pragma mark CommandObjectProcessSignal 1019 1020 class CommandObjectProcessSignal : public CommandObject 1021 { 1022 public: 1023 1024 CommandObjectProcessSignal (CommandInterpreter &interpreter) : 1025 CommandObject (interpreter, 1026 "process signal", 1027 "Send a UNIX signal to the current process being debugged.", 1028 NULL) 1029 { 1030 CommandArgumentEntry arg; 1031 CommandArgumentData signal_arg; 1032 1033 // Define the first (and only) variant of this arg. 1034 signal_arg.arg_type = eArgTypeUnixSignal; 1035 signal_arg.arg_repetition = eArgRepeatPlain; 1036 1037 // There is only one variant this argument could be; put it into the argument entry. 1038 arg.push_back (signal_arg); 1039 1040 // Push the data for the first argument into the m_arguments vector. 1041 m_arguments.push_back (arg); 1042 } 1043 1044 ~CommandObjectProcessSignal () 1045 { 1046 } 1047 1048 bool 1049 Execute (Args& command, 1050 CommandReturnObject &result) 1051 { 1052 Process *process = m_interpreter.GetDebugger().GetExecutionContext().process; 1053 if (process == NULL) 1054 { 1055 result.AppendError ("no process to signal"); 1056 result.SetStatus (eReturnStatusFailed); 1057 return false; 1058 } 1059 1060 if (command.GetArgumentCount() == 1) 1061 { 1062 int signo = LLDB_INVALID_SIGNAL_NUMBER; 1063 1064 const char *signal_name = command.GetArgumentAtIndex(0); 1065 if (::isxdigit (signal_name[0])) 1066 signo = Args::StringToSInt32(signal_name, LLDB_INVALID_SIGNAL_NUMBER, 0); 1067 else 1068 signo = process->GetUnixSignals().GetSignalNumberFromName (signal_name); 1069 1070 if (signo == LLDB_INVALID_SIGNAL_NUMBER) 1071 { 1072 result.AppendErrorWithFormat ("Invalid signal argument '%s'.\n", command.GetArgumentAtIndex(0)); 1073 result.SetStatus (eReturnStatusFailed); 1074 } 1075 else 1076 { 1077 Error error (process->Signal (signo)); 1078 if (error.Success()) 1079 { 1080 result.SetStatus (eReturnStatusSuccessFinishResult); 1081 } 1082 else 1083 { 1084 result.AppendErrorWithFormat ("Failed to send signal %i: %s\n", signo, error.AsCString()); 1085 result.SetStatus (eReturnStatusFailed); 1086 } 1087 } 1088 } 1089 else 1090 { 1091 result.AppendErrorWithFormat("'%s' takes exactly one signal number argument:\nUsage: \n", m_cmd_name.c_str(), 1092 m_cmd_syntax.c_str()); 1093 result.SetStatus (eReturnStatusFailed); 1094 } 1095 return result.Succeeded(); 1096 } 1097 }; 1098 1099 1100 //------------------------------------------------------------------------- 1101 // CommandObjectProcessInterrupt 1102 //------------------------------------------------------------------------- 1103 #pragma mark CommandObjectProcessInterrupt 1104 1105 class CommandObjectProcessInterrupt : public CommandObject 1106 { 1107 public: 1108 1109 1110 CommandObjectProcessInterrupt (CommandInterpreter &interpreter) : 1111 CommandObject (interpreter, 1112 "process interrupt", 1113 "Interrupt the current process being debugged.", 1114 "process interrupt", 1115 eFlagProcessMustBeLaunched) 1116 { 1117 } 1118 1119 ~CommandObjectProcessInterrupt () 1120 { 1121 } 1122 1123 bool 1124 Execute (Args& command, 1125 CommandReturnObject &result) 1126 { 1127 Process *process = m_interpreter.GetDebugger().GetExecutionContext().process; 1128 if (process == NULL) 1129 { 1130 result.AppendError ("no process to halt"); 1131 result.SetStatus (eReturnStatusFailed); 1132 return false; 1133 } 1134 1135 if (command.GetArgumentCount() == 0) 1136 { 1137 Error error(process->Halt ()); 1138 if (error.Success()) 1139 { 1140 result.SetStatus (eReturnStatusSuccessFinishResult); 1141 1142 // Maybe we should add a "SuspendThreadPlans so we 1143 // can halt, and keep in place all the current thread plans. 1144 process->GetThreadList().DiscardThreadPlans(); 1145 } 1146 else 1147 { 1148 result.AppendErrorWithFormat ("Failed to halt process: %s\n", error.AsCString()); 1149 result.SetStatus (eReturnStatusFailed); 1150 } 1151 } 1152 else 1153 { 1154 result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: \n", 1155 m_cmd_name.c_str(), 1156 m_cmd_syntax.c_str()); 1157 result.SetStatus (eReturnStatusFailed); 1158 } 1159 return result.Succeeded(); 1160 } 1161 }; 1162 1163 //------------------------------------------------------------------------- 1164 // CommandObjectProcessKill 1165 //------------------------------------------------------------------------- 1166 #pragma mark CommandObjectProcessKill 1167 1168 class CommandObjectProcessKill : public CommandObject 1169 { 1170 public: 1171 1172 CommandObjectProcessKill (CommandInterpreter &interpreter) : 1173 CommandObject (interpreter, 1174 "process kill", 1175 "Terminate the current process being debugged.", 1176 "process kill", 1177 eFlagProcessMustBeLaunched) 1178 { 1179 } 1180 1181 ~CommandObjectProcessKill () 1182 { 1183 } 1184 1185 bool 1186 Execute (Args& command, 1187 CommandReturnObject &result) 1188 { 1189 Process *process = m_interpreter.GetDebugger().GetExecutionContext().process; 1190 if (process == NULL) 1191 { 1192 result.AppendError ("no process to kill"); 1193 result.SetStatus (eReturnStatusFailed); 1194 return false; 1195 } 1196 1197 if (command.GetArgumentCount() == 0) 1198 { 1199 Error error (process->Destroy()); 1200 if (error.Success()) 1201 { 1202 result.SetStatus (eReturnStatusSuccessFinishResult); 1203 } 1204 else 1205 { 1206 result.AppendErrorWithFormat ("Failed to kill process: %s\n", error.AsCString()); 1207 result.SetStatus (eReturnStatusFailed); 1208 } 1209 } 1210 else 1211 { 1212 result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: \n", 1213 m_cmd_name.c_str(), 1214 m_cmd_syntax.c_str()); 1215 result.SetStatus (eReturnStatusFailed); 1216 } 1217 return result.Succeeded(); 1218 } 1219 }; 1220 1221 //------------------------------------------------------------------------- 1222 // CommandObjectProcessStatus 1223 //------------------------------------------------------------------------- 1224 #pragma mark CommandObjectProcessStatus 1225 1226 class CommandObjectProcessStatus : public CommandObject 1227 { 1228 public: 1229 CommandObjectProcessStatus (CommandInterpreter &interpreter) : 1230 CommandObject (interpreter, 1231 "process status", 1232 "Show the current status and location of executing process.", 1233 "process status", 1234 0) 1235 { 1236 } 1237 1238 ~CommandObjectProcessStatus() 1239 { 1240 } 1241 1242 1243 bool 1244 Execute 1245 ( 1246 Args& command, 1247 CommandReturnObject &result 1248 ) 1249 { 1250 StreamString &output_stream = result.GetOutputStream(); 1251 result.SetStatus (eReturnStatusSuccessFinishNoResult); 1252 ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext()); 1253 if (exe_ctx.process) 1254 { 1255 const StateType state = exe_ctx.process->GetState(); 1256 if (StateIsStoppedState(state)) 1257 { 1258 if (state == eStateExited) 1259 { 1260 int exit_status = exe_ctx.process->GetExitStatus(); 1261 const char *exit_description = exe_ctx.process->GetExitDescription(); 1262 output_stream.Printf ("Process %d exited with status = %i (0x%8.8x) %s\n", 1263 exe_ctx.process->GetID(), 1264 exit_status, 1265 exit_status, 1266 exit_description ? exit_description : ""); 1267 } 1268 else 1269 { 1270 output_stream.Printf ("Process %d %s\n", exe_ctx.process->GetID(), StateAsCString (state)); 1271 if (exe_ctx.thread == NULL) 1272 exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get(); 1273 if (exe_ctx.thread != NULL) 1274 { 1275 DisplayThreadsInfo (m_interpreter, &exe_ctx, result, true, true); 1276 } 1277 else 1278 { 1279 result.AppendError ("No valid thread found in current process."); 1280 result.SetStatus (eReturnStatusFailed); 1281 } 1282 } 1283 } 1284 else 1285 { 1286 output_stream.Printf ("Process %d is running.\n", 1287 exe_ctx.process->GetID()); 1288 } 1289 } 1290 else 1291 { 1292 result.AppendError ("No current location or status available."); 1293 result.SetStatus (eReturnStatusFailed); 1294 } 1295 return result.Succeeded(); 1296 } 1297 }; 1298 1299 //------------------------------------------------------------------------- 1300 // CommandObjectProcessHandle 1301 //------------------------------------------------------------------------- 1302 #pragma mark CommandObjectProcessHandle 1303 1304 class CommandObjectProcessHandle : public CommandObject 1305 { 1306 public: 1307 1308 class CommandOptions : public Options 1309 { 1310 public: 1311 1312 CommandOptions () : 1313 Options () 1314 { 1315 ResetOptionValues (); 1316 } 1317 1318 ~CommandOptions () 1319 { 1320 } 1321 1322 Error 1323 SetOptionValue (int option_idx, const char *option_arg) 1324 { 1325 Error error; 1326 char short_option = (char) m_getopt_table[option_idx].val; 1327 1328 switch (short_option) 1329 { 1330 case 's': 1331 stop = option_arg; 1332 break; 1333 case 'n': 1334 notify = option_arg; 1335 break; 1336 case 'p': 1337 pass = option_arg; 1338 break; 1339 default: 1340 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); 1341 break; 1342 } 1343 return error; 1344 } 1345 1346 void 1347 ResetOptionValues () 1348 { 1349 Options::ResetOptionValues(); 1350 stop.clear(); 1351 notify.clear(); 1352 pass.clear(); 1353 } 1354 1355 const lldb::OptionDefinition* 1356 GetDefinitions () 1357 { 1358 return g_option_table; 1359 } 1360 1361 // Options table: Required for subclasses of Options. 1362 1363 static lldb::OptionDefinition g_option_table[]; 1364 1365 // Instance variables to hold the values for command options. 1366 1367 std::string stop; 1368 std::string notify; 1369 std::string pass; 1370 }; 1371 1372 1373 CommandObjectProcessHandle (CommandInterpreter &interpreter) : 1374 CommandObject (interpreter, 1375 "process handle", 1376 "Show or update what the process and debugger should do with various signals received from the OS.", 1377 NULL) 1378 { 1379 SetHelpLong ("If no signals are specified, update them all. If no update option is specified, list the current values.\n"); 1380 CommandArgumentEntry arg; 1381 CommandArgumentData signal_arg; 1382 1383 signal_arg.arg_type = eArgTypeUnixSignal; 1384 signal_arg.arg_repetition = eArgRepeatStar; 1385 1386 arg.push_back (signal_arg); 1387 1388 m_arguments.push_back (arg); 1389 } 1390 1391 ~CommandObjectProcessHandle () 1392 { 1393 } 1394 1395 Options * 1396 GetOptions () 1397 { 1398 return &m_options; 1399 } 1400 1401 bool 1402 VerifyCommandOptionValue (const std::string &option, int &real_value) 1403 { 1404 bool okay = true; 1405 1406 bool success = false; 1407 bool tmp_value = Args::StringToBoolean (option.c_str(), false, &success); 1408 1409 if (success && tmp_value) 1410 real_value = 1; 1411 else if (success && !tmp_value) 1412 real_value = 0; 1413 else 1414 { 1415 // If the value isn't 'true' or 'false', it had better be 0 or 1. 1416 real_value = Args::StringToUInt32 (option.c_str(), 3); 1417 if (real_value != 0 && real_value != 1) 1418 okay = false; 1419 } 1420 1421 return okay; 1422 } 1423 1424 void 1425 PrintSignalHeader (Stream &str) 1426 { 1427 str.Printf ("NAME PASS STOP NOTIFY\n"); 1428 str.Printf ("========== ===== ===== ======\n"); 1429 } 1430 1431 void 1432 PrintSignal (Stream &str, int32_t signo, const char *sig_name, UnixSignals &signals) 1433 { 1434 bool stop; 1435 bool suppress; 1436 bool notify; 1437 1438 str.Printf ("%-10s ", sig_name); 1439 if (signals.GetSignalInfo (signo, suppress, stop, notify)) 1440 { 1441 bool pass = !suppress; 1442 str.Printf ("%s %s %s", 1443 (pass ? "true " : "false"), 1444 (stop ? "true " : "false"), 1445 (notify ? "true " : "false")); 1446 } 1447 str.Printf ("\n"); 1448 } 1449 1450 void 1451 PrintSignalInformation (Stream &str, Args &signal_args, int num_valid_signals, UnixSignals &signals) 1452 { 1453 PrintSignalHeader (str); 1454 1455 if (num_valid_signals > 0) 1456 { 1457 size_t num_args = signal_args.GetArgumentCount(); 1458 for (size_t i = 0; i < num_args; ++i) 1459 { 1460 int32_t signo = signals.GetSignalNumberFromName (signal_args.GetArgumentAtIndex (i)); 1461 if (signo != LLDB_INVALID_SIGNAL_NUMBER) 1462 PrintSignal (str, signo, signal_args.GetArgumentAtIndex (i), signals); 1463 } 1464 } 1465 else // Print info for ALL signals 1466 { 1467 int32_t signo = signals.GetFirstSignalNumber(); 1468 while (signo != LLDB_INVALID_SIGNAL_NUMBER) 1469 { 1470 PrintSignal (str, signo, signals.GetSignalAsCString (signo), signals); 1471 signo = signals.GetNextSignalNumber (signo); 1472 } 1473 } 1474 } 1475 1476 bool 1477 Execute (Args &signal_args, CommandReturnObject &result) 1478 { 1479 TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget(); 1480 1481 if (!target_sp) 1482 { 1483 result.AppendError ("No current target;" 1484 " cannot handle signals until you have a valid target and process.\n"); 1485 result.SetStatus (eReturnStatusFailed); 1486 return false; 1487 } 1488 1489 ProcessSP process_sp = target_sp->GetProcessSP(); 1490 1491 if (!process_sp) 1492 { 1493 result.AppendError ("No current process; cannot handle signals until you have a valid process.\n"); 1494 result.SetStatus (eReturnStatusFailed); 1495 return false; 1496 } 1497 1498 int stop_action = -1; // -1 means leave the current setting alone 1499 int pass_action = -1; // -1 means leave the current setting alone 1500 int notify_action = -1; // -1 means leave the current setting alone 1501 1502 if (! m_options.stop.empty() 1503 && ! VerifyCommandOptionValue (m_options.stop, stop_action)) 1504 { 1505 result.AppendError ("Invalid argument for command option --stop; must be true or false.\n"); 1506 result.SetStatus (eReturnStatusFailed); 1507 return false; 1508 } 1509 1510 if (! m_options.notify.empty() 1511 && ! VerifyCommandOptionValue (m_options.notify, notify_action)) 1512 { 1513 result.AppendError ("Invalid argument for command option --notify; must be true or false.\n"); 1514 result.SetStatus (eReturnStatusFailed); 1515 return false; 1516 } 1517 1518 if (! m_options.pass.empty() 1519 && ! VerifyCommandOptionValue (m_options.pass, pass_action)) 1520 { 1521 result.AppendError ("Invalid argument for command option --pass; must be true or false.\n"); 1522 result.SetStatus (eReturnStatusFailed); 1523 return false; 1524 } 1525 1526 size_t num_args = signal_args.GetArgumentCount(); 1527 UnixSignals &signals = process_sp->GetUnixSignals(); 1528 int num_signals_set = 0; 1529 1530 if (num_args > 0) 1531 { 1532 for (size_t i = 0; i < num_args; ++i) 1533 { 1534 int32_t signo = signals.GetSignalNumberFromName (signal_args.GetArgumentAtIndex (i)); 1535 if (signo != LLDB_INVALID_SIGNAL_NUMBER) 1536 { 1537 // Casting the actions as bools here should be okay, because VerifyCommandOptionValue guarantees 1538 // the value is either 0 or 1. 1539 if (stop_action != -1) 1540 signals.SetShouldStop (signo, (bool) stop_action); 1541 if (pass_action != -1) 1542 { 1543 bool suppress = ! ((bool) pass_action); 1544 signals.SetShouldSuppress (signo, suppress); 1545 } 1546 if (notify_action != -1) 1547 signals.SetShouldNotify (signo, (bool) notify_action); 1548 ++num_signals_set; 1549 } 1550 else 1551 { 1552 result.AppendErrorWithFormat ("Invalid signal name '%s'\n", signal_args.GetArgumentAtIndex (i)); 1553 } 1554 } 1555 } 1556 else 1557 { 1558 // No signal specified, if any command options were specified, update ALL signals. 1559 if ((notify_action != -1) || (stop_action != -1) || (pass_action != -1)) 1560 { 1561 if (m_interpreter.Confirm ("Do you really want to update all the signals?", false)) 1562 { 1563 int32_t signo = signals.GetFirstSignalNumber(); 1564 while (signo != LLDB_INVALID_SIGNAL_NUMBER) 1565 { 1566 if (notify_action != -1) 1567 signals.SetShouldNotify (signo, (bool) notify_action); 1568 if (stop_action != -1) 1569 signals.SetShouldStop (signo, (bool) stop_action); 1570 if (pass_action != -1) 1571 { 1572 bool suppress = ! ((bool) pass_action); 1573 signals.SetShouldSuppress (signo, suppress); 1574 } 1575 signo = signals.GetNextSignalNumber (signo); 1576 } 1577 } 1578 } 1579 } 1580 1581 PrintSignalInformation (result.GetOutputStream(), signal_args, num_signals_set, signals); 1582 1583 if (num_signals_set > 0) 1584 result.SetStatus (eReturnStatusSuccessFinishNoResult); 1585 else 1586 result.SetStatus (eReturnStatusFailed); 1587 1588 return result.Succeeded(); 1589 } 1590 1591 protected: 1592 1593 CommandOptions m_options; 1594 }; 1595 1596 lldb::OptionDefinition 1597 CommandObjectProcessHandle::CommandOptions::g_option_table[] = 1598 { 1599 { LLDB_OPT_SET_1, false, "stop", 's', required_argument, NULL, 0, eArgTypeBoolean, "Whether or not the process should be stopped if the signal is received." }, 1600 { LLDB_OPT_SET_1, false, "notify", 'n', required_argument, NULL, 0, eArgTypeBoolean, "Whether or not the debugger should notify the user if the signal is received." }, 1601 { LLDB_OPT_SET_1, false, "pass", 'p', required_argument, NULL, 0, eArgTypeBoolean, "Whether or not the signal should be passed to the process." }, 1602 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 1603 }; 1604 1605 //------------------------------------------------------------------------- 1606 // CommandObjectMultiwordProcess 1607 //------------------------------------------------------------------------- 1608 1609 CommandObjectMultiwordProcess::CommandObjectMultiwordProcess (CommandInterpreter &interpreter) : 1610 CommandObjectMultiword (interpreter, 1611 "process", 1612 "A set of commands for operating on a process.", 1613 "process <subcommand> [<subcommand-options>]") 1614 { 1615 LoadSubCommand ("attach", CommandObjectSP (new CommandObjectProcessAttach (interpreter))); 1616 LoadSubCommand ("launch", CommandObjectSP (new CommandObjectProcessLaunch (interpreter))); 1617 LoadSubCommand ("continue", CommandObjectSP (new CommandObjectProcessContinue (interpreter))); 1618 LoadSubCommand ("detach", CommandObjectSP (new CommandObjectProcessDetach (interpreter))); 1619 LoadSubCommand ("load", CommandObjectSP (new CommandObjectProcessLoad (interpreter))); 1620 LoadSubCommand ("unload", CommandObjectSP (new CommandObjectProcessUnload (interpreter))); 1621 LoadSubCommand ("signal", CommandObjectSP (new CommandObjectProcessSignal (interpreter))); 1622 LoadSubCommand ("handle", CommandObjectSP (new CommandObjectProcessHandle (interpreter))); 1623 LoadSubCommand ("status", CommandObjectSP (new CommandObjectProcessStatus (interpreter))); 1624 LoadSubCommand ("interrupt", CommandObjectSP (new CommandObjectProcessInterrupt (interpreter))); 1625 LoadSubCommand ("kill", CommandObjectSP (new CommandObjectProcessKill (interpreter))); 1626 } 1627 1628 CommandObjectMultiwordProcess::~CommandObjectMultiwordProcess () 1629 { 1630 } 1631 1632