LLDB  mainline
CommandObjectProcess.cpp
Go to the documentation of this file.
1 //===-- CommandObjectProcess.cpp ------------------------------------------===//
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 "CommandObjectProcess.h"
10 #include "CommandObjectTrace.h"
15 #include "lldb/Core/Module.h"
17 #include "lldb/Host/OptionParser.h"
23 #include "lldb/Target/Platform.h"
24 #include "lldb/Target/Process.h"
25 #include "lldb/Target/StopInfo.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Target/Thread.h"
29 #include "lldb/Utility/Args.h"
30 #include "lldb/Utility/State.h"
31 
32 using namespace lldb;
33 using namespace lldb_private;
34 
36 public:
38  const char *name, const char *help,
39  const char *syntax, uint32_t flags,
40  const char *new_process_action)
41  : CommandObjectParsed(interpreter, name, help, syntax, flags),
42  m_new_process_action(new_process_action) {}
43 
44  ~CommandObjectProcessLaunchOrAttach() override = default;
45 
46 protected:
47  bool StopProcessIfNecessary(Process *process, StateType &state,
48  CommandReturnObject &result) {
49  state = eStateInvalid;
50  if (process) {
51  state = process->GetState();
52 
53  if (process->IsAlive() && state != eStateConnected) {
55  if (process->GetState() == eStateAttaching)
56  message =
57  llvm::formatv("There is a pending attach, abort it and {0}?",
58  m_new_process_action);
59  else if (process->GetShouldDetach())
60  message = llvm::formatv(
61  "There is a running process, detach from it and {0}?",
62  m_new_process_action);
63  else
64  message =
65  llvm::formatv("There is a running process, kill it and {0}?",
66  m_new_process_action);
67 
68  if (!m_interpreter.Confirm(message, true)) {
70  return false;
71  } else {
72  if (process->GetShouldDetach()) {
73  bool keep_stopped = false;
74  Status detach_error(process->Detach(keep_stopped));
75  if (detach_error.Success()) {
77  process = nullptr;
78  } else {
79  result.AppendErrorWithFormat(
80  "Failed to detach from process: %s\n",
81  detach_error.AsCString());
83  }
84  } else {
85  Status destroy_error(process->Destroy(false));
86  if (destroy_error.Success()) {
88  process = nullptr;
89  } else {
90  result.AppendErrorWithFormat("Failed to kill process: %s\n",
91  destroy_error.AsCString());
93  }
94  }
95  }
96  }
97  }
98  return result.Succeeded();
99  }
100 
102 };
103 
104 // CommandObjectProcessLaunch
105 #pragma mark CommandObjectProcessLaunch
107 public:
110  interpreter, "process launch",
111  "Launch the executable in the debugger.", nullptr,
112  eCommandRequiresTarget, "restart"),
113  m_options(),
114  m_class_options("scripted process", true, 'C', 'k', 'v', 0),
115  m_all_options() {
116  m_all_options.Append(&m_options);
117  m_all_options.Append(&m_class_options, LLDB_OPT_SET_1 | LLDB_OPT_SET_2,
119  m_all_options.Finalize();
120 
122  CommandArgumentData run_args_arg;
123 
124  // Define the first (and only) variant of this arg.
125  run_args_arg.arg_type = eArgTypeRunArgs;
126  run_args_arg.arg_repetition = eArgRepeatOptional;
127 
128  // There is only one variant this argument could be; put it into the
129  // 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  ~CommandObjectProcessLaunch() override = default;
137 
138  void
140  OptionElementVector &opt_element_vector) override {
141 
142  CommandCompletions::InvokeCommonCompletionCallbacks(
143  GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
144  request, nullptr);
145  }
146 
147  Options *GetOptions() override { return &m_all_options; }
148 
149  const char *GetRepeatCommand(Args &current_command_args,
150  uint32_t index) override {
151  // No repeat for "process launch"...
152  return "";
153  }
154 
155 protected:
156  bool DoExecute(Args &launch_args, CommandReturnObject &result) override {
157  Debugger &debugger = GetDebugger();
158  Target *target = debugger.GetSelectedTarget().get();
159  // If our listener is nullptr, users aren't allows to launch
160  ModuleSP exe_module_sp = target->GetExecutableModule();
161 
162  if (exe_module_sp == nullptr) {
163  result.AppendError("no file in target, create a debug target using the "
164  "'target create' command");
166  return false;
167  }
168 
169  StateType state = eStateInvalid;
170 
171  if (!StopProcessIfNecessary(m_exe_ctx.GetProcessPtr(), state, result))
172  return false;
173 
174  llvm::StringRef target_settings_argv0 = target->GetArg0();
175 
176  // Determine whether we will disable ASLR or leave it in the default state
177  // (i.e. enabled if the platform supports it). First check if the process
178  // launch options explicitly turn on/off
179  // disabling ASLR. If so, use that setting;
180  // otherwise, use the 'settings target.disable-aslr' setting.
181  bool disable_aslr = false;
182  if (m_options.disable_aslr != eLazyBoolCalculate) {
183  // The user specified an explicit setting on the process launch line.
184  // Use it.
185  disable_aslr = (m_options.disable_aslr == eLazyBoolYes);
186  } else {
187  // The user did not explicitly specify whether to disable ASLR. Fall
188  // back to the target.disable-aslr setting.
189  disable_aslr = target->GetDisableASLR();
190  }
191 
192  if (!m_class_options.GetName().empty()) {
193  m_options.launch_info.SetProcessPluginName("ScriptedProcess");
194  m_options.launch_info.SetScriptedProcessClassName(
195  m_class_options.GetName());
196  m_options.launch_info.SetScriptedProcessDictionarySP(
197  m_class_options.GetStructuredData());
198  target->SetProcessLaunchInfo(m_options.launch_info);
199  }
200 
201  if (disable_aslr)
202  m_options.launch_info.GetFlags().Set(eLaunchFlagDisableASLR);
203  else
204  m_options.launch_info.GetFlags().Clear(eLaunchFlagDisableASLR);
205 
206  if (target->GetInheritTCC())
207  m_options.launch_info.GetFlags().Set(eLaunchFlagInheritTCCFromParent);
208 
209  if (target->GetDetachOnError())
210  m_options.launch_info.GetFlags().Set(eLaunchFlagDetachOnError);
211 
212  if (target->GetDisableSTDIO())
213  m_options.launch_info.GetFlags().Set(eLaunchFlagDisableSTDIO);
214 
215  // Merge the launch info environment with the target environment.
216  Environment target_env = target->GetEnvironment();
217  m_options.launch_info.GetEnvironment().insert(target_env.begin(),
218  target_env.end());
219 
220  if (!target_settings_argv0.empty()) {
221  m_options.launch_info.GetArguments().AppendArgument(
222  target_settings_argv0);
223  m_options.launch_info.SetExecutableFile(
224  exe_module_sp->GetPlatformFileSpec(), false);
225  } else {
226  m_options.launch_info.SetExecutableFile(
227  exe_module_sp->GetPlatformFileSpec(), true);
228  }
229 
230  if (launch_args.GetArgumentCount() == 0) {
231  m_options.launch_info.GetArguments().AppendArguments(
232  target->GetProcessLaunchInfo().GetArguments());
233  } else {
234  m_options.launch_info.GetArguments().AppendArguments(launch_args);
235  // Save the arguments for subsequent runs in the current target.
236  target->SetRunArguments(launch_args);
237  }
238 
239  StreamString stream;
240  Status error = target->Launch(m_options.launch_info, &stream);
241 
242  if (error.Success()) {
243  ProcessSP process_sp(target->GetProcessSP());
244  if (process_sp) {
245  // There is a race condition where this thread will return up the call
246  // stack to the main command handler and show an (lldb) prompt before
247  // HandlePrivateEvent (from PrivateStateThread) has a chance to call
248  // PushProcessIOHandler().
249  process_sp->SyncIOHandler(0, std::chrono::seconds(2));
250 
251  llvm::StringRef data = stream.GetString();
252  if (!data.empty())
253  result.AppendMessage(data);
254  const char *archname =
255  exe_module_sp->GetArchitecture().GetArchitectureName();
257  "Process %" PRIu64 " launched: '%s' (%s)\n", process_sp->GetID(),
258  exe_module_sp->GetFileSpec().GetPath().c_str(), archname);
260  result.SetDidChangeProcessState(true);
261  } else {
262  result.AppendError(
263  "no error returned from Target::Launch, and target has no process");
265  }
266  } else {
267  result.AppendError(error.AsCString());
269  }
270  return result.Succeeded();
271  }
272 
276 };
277 
278 #define LLDB_OPTIONS_process_attach
279 #include "CommandOptions.inc"
280 
281 #pragma mark CommandObjectProcessAttach
283 public:
284  class CommandOptions : public Options {
285  public:
287  // Keep default values of all options in one place: OptionParsingStarting
288  // ()
289  OptionParsingStarting(nullptr);
290  }
291 
292  ~CommandOptions() override = default;
293 
294  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
295  ExecutionContext *execution_context) override {
296  Status error;
297  const int short_option = m_getopt_table[option_idx].val;
298  switch (short_option) {
299  case 'c':
300  attach_info.SetContinueOnceAttached(true);
301  break;
302 
303  case 'p': {
304  lldb::pid_t pid;
305  if (option_arg.getAsInteger(0, pid)) {
306  error.SetErrorStringWithFormat("invalid process ID '%s'",
307  option_arg.str().c_str());
308  } else {
309  attach_info.SetProcessID(pid);
310  }
311  } break;
312 
313  case 'P':
314  attach_info.SetProcessPluginName(option_arg);
315  break;
316 
317  case 'n':
318  attach_info.GetExecutableFile().SetFile(option_arg,
319  FileSpec::Style::native);
320  break;
321 
322  case 'w':
323  attach_info.SetWaitForLaunch(true);
324  break;
325 
326  case 'i':
327  attach_info.SetIgnoreExisting(false);
328  break;
329 
330  default:
331  llvm_unreachable("Unimplemented option");
332  }
333  return error;
334  }
335 
336  void OptionParsingStarting(ExecutionContext *execution_context) override {
337  attach_info.Clear();
338  }
339 
340  llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
341  return llvm::makeArrayRef(g_process_attach_options);
342  }
343 
345  };
346 
349  interpreter, "process attach", "Attach to a process.",
350  "process attach <cmd-options>", 0, "attach"),
351  m_options() {}
352 
353  ~CommandObjectProcessAttach() override = default;
354 
355  Options *GetOptions() override { return &m_options; }
356 
357 protected:
358  bool DoExecute(Args &command, CommandReturnObject &result) override {
359  PlatformSP platform_sp(
360  GetDebugger().GetPlatformList().GetSelectedPlatform());
361 
362  Target *target = GetDebugger().GetSelectedTarget().get();
363  // N.B. The attach should be synchronous. It doesn't help much to get the
364  // prompt back between initiating the attach and the target actually
365  // stopping. So even if the interpreter is set to be asynchronous, we wait
366  // for the stop ourselves here.
367 
368  StateType state = eStateInvalid;
369  Process *process = m_exe_ctx.GetProcessPtr();
370 
371  if (!StopProcessIfNecessary(process, state, result))
372  return false;
373 
374  if (target == nullptr) {
375  // If there isn't a current target create one.
376  TargetSP new_target_sp;
377  Status error;
378 
379  error = GetDebugger().GetTargetList().CreateTarget(
380  GetDebugger(), "", "", eLoadDependentsNo,
381  nullptr, // No platform options
382  new_target_sp);
383  target = new_target_sp.get();
384  if (target == nullptr || error.Fail()) {
385  result.AppendError(error.AsCString("Error creating target"));
386  return false;
387  }
388  }
389 
390  // Record the old executable module, we want to issue a warning if the
391  // process of attaching changed the current executable (like somebody said
392  // "file foo" then attached to a PID whose executable was bar.)
393 
394  ModuleSP old_exec_module_sp = target->GetExecutableModule();
395  ArchSpec old_arch_spec = target->GetArchitecture();
396 
397  if (command.GetArgumentCount()) {
398  result.AppendErrorWithFormat("Invalid arguments for '%s'.\nUsage: %s\n",
399  m_cmd_name.c_str(), m_cmd_syntax.c_str());
401  return false;
402  }
403 
404  StreamString stream;
405  const auto error = target->Attach(m_options.attach_info, &stream);
406  if (error.Success()) {
407  ProcessSP process_sp(target->GetProcessSP());
408  if (process_sp) {
409  result.AppendMessage(stream.GetString());
411  result.SetDidChangeProcessState(true);
412  } else {
413  result.AppendError(
414  "no error returned from Target::Attach, and target has no process");
416  }
417  } else {
418  result.AppendErrorWithFormat("attach failed: %s\n", error.AsCString());
420  }
421 
422  if (!result.Succeeded())
423  return false;
424 
425  // Okay, we're done. Last step is to warn if the executable module has
426  // changed:
427  char new_path[PATH_MAX];
428  ModuleSP new_exec_module_sp(target->GetExecutableModule());
429  if (!old_exec_module_sp) {
430  // We might not have a module if we attached to a raw pid...
431  if (new_exec_module_sp) {
432  new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
433  result.AppendMessageWithFormat("Executable module set to \"%s\".\n",
434  new_path);
435  }
436  } else if (old_exec_module_sp->GetFileSpec() !=
437  new_exec_module_sp->GetFileSpec()) {
438  char old_path[PATH_MAX];
439 
440  old_exec_module_sp->GetFileSpec().GetPath(old_path, PATH_MAX);
441  new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
442 
444  "Executable module changed from \"%s\" to \"%s\".\n", old_path,
445  new_path);
446  }
447 
448  if (!old_arch_spec.IsValid()) {
450  "Architecture set to: %s.\n",
451  target->GetArchitecture().GetTriple().getTriple().c_str());
452  } else if (!old_arch_spec.IsExactMatch(target->GetArchitecture())) {
454  "Architecture changed from %s to %s.\n",
455  old_arch_spec.GetTriple().getTriple().c_str(),
456  target->GetArchitecture().GetTriple().getTriple().c_str());
457  }
458 
459  // This supports the use-case scenario of immediately continuing the
460  // process once attached.
461  if (m_options.attach_info.GetContinueOnceAttached())
462  m_interpreter.HandleCommand("process continue", eLazyBoolNo, result);
463 
464  return result.Succeeded();
465  }
466 
468 };
469 
470 // CommandObjectProcessContinue
471 
472 #define LLDB_OPTIONS_process_continue
473 #include "CommandOptions.inc"
474 
475 #pragma mark CommandObjectProcessContinue
476 
478 public:
481  interpreter, "process continue",
482  "Continue execution of all threads in the current process.",
483  "process continue",
484  eCommandRequiresProcess | eCommandTryTargetAPILock |
485  eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
486  m_options() {}
487 
488  ~CommandObjectProcessContinue() override = default;
489 
490 protected:
491  class CommandOptions : public Options {
492  public:
494  // Keep default values of all options in one place: OptionParsingStarting
495  // ()
496  OptionParsingStarting(nullptr);
497  }
498 
499  ~CommandOptions() override = default;
500 
501  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
502  ExecutionContext *execution_context) override {
503  Status error;
504  const int short_option = m_getopt_table[option_idx].val;
505  switch (short_option) {
506  case 'i':
507  if (option_arg.getAsInteger(0, m_ignore))
508  error.SetErrorStringWithFormat(
509  "invalid value for ignore option: \"%s\", should be a number.",
510  option_arg.str().c_str());
511  break;
512 
513  default:
514  llvm_unreachable("Unimplemented option");
515  }
516  return error;
517  }
518 
519  void OptionParsingStarting(ExecutionContext *execution_context) override {
520  m_ignore = 0;
521  }
522 
523  llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
524  return llvm::makeArrayRef(g_process_continue_options);
525  }
526 
528  };
529 
530  bool DoExecute(Args &command, CommandReturnObject &result) override {
531  Process *process = m_exe_ctx.GetProcessPtr();
532  bool synchronous_execution = m_interpreter.GetSynchronous();
533  StateType state = process->GetState();
534  if (state == eStateStopped) {
535  if (command.GetArgumentCount() != 0) {
536  result.AppendErrorWithFormat(
537  "The '%s' command does not take any arguments.\n",
538  m_cmd_name.c_str());
540  return false;
541  }
542 
543  if (m_options.m_ignore > 0) {
544  ThreadSP sel_thread_sp(GetDefaultThread()->shared_from_this());
545  if (sel_thread_sp) {
546  StopInfoSP stop_info_sp = sel_thread_sp->GetStopInfo();
547  if (stop_info_sp &&
548  stop_info_sp->GetStopReason() == eStopReasonBreakpoint) {
549  lldb::break_id_t bp_site_id =
550  (lldb::break_id_t)stop_info_sp->GetValue();
551  BreakpointSiteSP bp_site_sp(
552  process->GetBreakpointSiteList().FindByID(bp_site_id));
553  if (bp_site_sp) {
554  const size_t num_owners = bp_site_sp->GetNumberOfOwners();
555  for (size_t i = 0; i < num_owners; i++) {
556  Breakpoint &bp_ref =
557  bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
558  if (!bp_ref.IsInternal()) {
559  bp_ref.SetIgnoreCount(m_options.m_ignore);
560  }
561  }
562  }
563  }
564  }
565  }
566 
567  { // Scope for thread list mutex:
568  std::lock_guard<std::recursive_mutex> guard(
569  process->GetThreadList().GetMutex());
570  const uint32_t num_threads = process->GetThreadList().GetSize();
571 
572  // Set the actions that the threads should each take when resuming
573  for (uint32_t idx = 0; idx < num_threads; ++idx) {
574  const bool override_suspend = false;
575  process->GetThreadList().GetThreadAtIndex(idx)->SetResumeState(
576  eStateRunning, override_suspend);
577  }
578  }
579 
580  const uint32_t iohandler_id = process->GetIOHandlerID();
581 
582  StreamString stream;
583  Status error;
584  if (synchronous_execution)
585  error = process->ResumeSynchronous(&stream);
586  else
587  error = process->Resume();
588 
589  if (error.Success()) {
590  // There is a race condition where this thread will return up the call
591  // stack to the main command handler and show an (lldb) prompt before
592  // HandlePrivateEvent (from PrivateStateThread) has a chance to call
593  // PushProcessIOHandler().
594  process->SyncIOHandler(iohandler_id, std::chrono::seconds(2));
595 
596  result.AppendMessageWithFormat("Process %" PRIu64 " resuming\n",
597  process->GetID());
598  if (synchronous_execution) {
599  // If any state changed events had anything to say, add that to the
600  // result
601  result.AppendMessage(stream.GetString());
602 
603  result.SetDidChangeProcessState(true);
605  } else {
607  }
608  } else {
609  result.AppendErrorWithFormat("Failed to resume process: %s.\n",
610  error.AsCString());
612  }
613  } else {
614  result.AppendErrorWithFormat(
615  "Process cannot be continued from its current state (%s).\n",
616  StateAsCString(state));
618  }
619  return result.Succeeded();
620  }
621 
622  Options *GetOptions() override { return &m_options; }
623 
625 };
626 
627 // CommandObjectProcessDetach
628 #define LLDB_OPTIONS_process_detach
629 #include "CommandOptions.inc"
630 
631 #pragma mark CommandObjectProcessDetach
632 
634 public:
635  class CommandOptions : public Options {
636  public:
637  CommandOptions() : Options() { OptionParsingStarting(nullptr); }
638 
639  ~CommandOptions() override = default;
640 
641  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
642  ExecutionContext *execution_context) override {
643  Status error;
644  const int short_option = m_getopt_table[option_idx].val;
645 
646  switch (short_option) {
647  case 's':
648  bool tmp_result;
649  bool success;
650  tmp_result = OptionArgParser::ToBoolean(option_arg, false, &success);
651  if (!success)
652  error.SetErrorStringWithFormat("invalid boolean option: \"%s\"",
653  option_arg.str().c_str());
654  else {
655  if (tmp_result)
656  m_keep_stopped = eLazyBoolYes;
657  else
658  m_keep_stopped = eLazyBoolNo;
659  }
660  break;
661  default:
662  llvm_unreachable("Unimplemented option");
663  }
664  return error;
665  }
666 
667  void OptionParsingStarting(ExecutionContext *execution_context) override {
668  m_keep_stopped = eLazyBoolCalculate;
669  }
670 
671  llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
672  return llvm::makeArrayRef(g_process_detach_options);
673  }
674 
675  // Instance variables to hold the values for command options.
677  };
678 
680  : CommandObjectParsed(interpreter, "process detach",
681  "Detach from the current target process.",
682  "process detach",
683  eCommandRequiresProcess | eCommandTryTargetAPILock |
684  eCommandProcessMustBeLaunched),
685  m_options() {}
686 
687  ~CommandObjectProcessDetach() override = default;
688 
689  Options *GetOptions() override { return &m_options; }
690 
691 protected:
692  bool DoExecute(Args &command, CommandReturnObject &result) override {
693  Process *process = m_exe_ctx.GetProcessPtr();
694  // FIXME: This will be a Command Option:
695  bool keep_stopped;
696  if (m_options.m_keep_stopped == eLazyBoolCalculate) {
697  // Check the process default:
698  keep_stopped = process->GetDetachKeepsStopped();
699  } else if (m_options.m_keep_stopped == eLazyBoolYes)
700  keep_stopped = true;
701  else
702  keep_stopped = false;
703 
704  Status error(process->Detach(keep_stopped));
705  if (error.Success()) {
707  } else {
708  result.AppendErrorWithFormat("Detach failed: %s\n", error.AsCString());
710  return false;
711  }
712  return result.Succeeded();
713  }
714 
716 };
717 
718 // CommandObjectProcessConnect
719 #define LLDB_OPTIONS_process_connect
720 #include "CommandOptions.inc"
721 
722 #pragma mark CommandObjectProcessConnect
723 
725 public:
726  class CommandOptions : public Options {
727  public:
729  // Keep default values of all options in one place: OptionParsingStarting
730  // ()
731  OptionParsingStarting(nullptr);
732  }
733 
734  ~CommandOptions() override = default;
735 
736  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
737  ExecutionContext *execution_context) override {
738  Status error;
739  const int short_option = m_getopt_table[option_idx].val;
740 
741  switch (short_option) {
742  case 'p':
743  plugin_name.assign(std::string(option_arg));
744  break;
745 
746  default:
747  llvm_unreachable("Unimplemented option");
748  }
749  return error;
750  }
751 
752  void OptionParsingStarting(ExecutionContext *execution_context) override {
753  plugin_name.clear();
754  }
755 
756  llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
757  return llvm::makeArrayRef(g_process_connect_options);
758  }
759 
760  // Instance variables to hold the values for command options.
761 
763  };
764 
766  : CommandObjectParsed(interpreter, "process connect",
767  "Connect to a remote debug service.",
768  "process connect <remote-url>", 0),
769  m_options() {}
770 
771  ~CommandObjectProcessConnect() override = default;
772 
773  Options *GetOptions() override { return &m_options; }
774 
775 protected:
776  bool DoExecute(Args &command, CommandReturnObject &result) override {
777  if (command.GetArgumentCount() != 1) {
778  result.AppendErrorWithFormat(
779  "'%s' takes exactly one argument:\nUsage: %s\n", m_cmd_name.c_str(),
780  m_cmd_syntax.c_str());
782  return false;
783  }
784 
785  Process *process = m_exe_ctx.GetProcessPtr();
786  if (process && process->IsAlive()) {
787  result.AppendErrorWithFormat(
788  "Process %" PRIu64
789  " is currently being debugged, kill the process before connecting.\n",
790  process->GetID());
792  return false;
793  }
794 
795  const char *plugin_name = nullptr;
796  if (!m_options.plugin_name.empty())
797  plugin_name = m_options.plugin_name.c_str();
798 
799  Status error;
800  Debugger &debugger = GetDebugger();
801  PlatformSP platform_sp = m_interpreter.GetPlatform(true);
802  ProcessSP process_sp =
803  debugger.GetAsyncExecution()
804  ? platform_sp->ConnectProcess(
805  command.GetArgumentAtIndex(0), plugin_name, debugger,
806  debugger.GetSelectedTarget().get(), error)
807  : platform_sp->ConnectProcessSynchronous(
808  command.GetArgumentAtIndex(0), plugin_name, debugger,
809  result.GetOutputStream(), debugger.GetSelectedTarget().get(),
810  error);
811  if (error.Fail() || process_sp == nullptr) {
812  result.AppendError(error.AsCString("Error connecting to the process"));
814  return false;
815  }
816  return true;
817  }
818 
820 };
821 
822 // CommandObjectProcessPlugin
823 #pragma mark CommandObjectProcessPlugin
824 
826 public:
829  interpreter, "process plugin",
830  "Send a custom command to the current target process plug-in.",
831  "process plugin <args>", 0) {}
832 
833  ~CommandObjectProcessPlugin() override = default;
834 
836  Process *process = m_interpreter.GetExecutionContext().GetProcessPtr();
837  if (process)
838  return process->GetPluginCommandObject();
839  return nullptr;
840  }
841 };
842 
843 // CommandObjectProcessLoad
844 #define LLDB_OPTIONS_process_load
845 #include "CommandOptions.inc"
846 
847 #pragma mark CommandObjectProcessLoad
848 
850 public:
851  class CommandOptions : public Options {
852  public:
854  // Keep default values of all options in one place: OptionParsingStarting
855  // ()
856  OptionParsingStarting(nullptr);
857  }
858 
859  ~CommandOptions() override = default;
860 
861  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
862  ExecutionContext *execution_context) override {
863  Status error;
864  const int short_option = m_getopt_table[option_idx].val;
865  switch (short_option) {
866  case 'i':
867  do_install = true;
868  if (!option_arg.empty())
869  install_path.SetFile(option_arg, FileSpec::Style::native);
870  break;
871  default:
872  llvm_unreachable("Unimplemented option");
873  }
874  return error;
875  }
876 
877  void OptionParsingStarting(ExecutionContext *execution_context) override {
878  do_install = false;
879  install_path.Clear();
880  }
881 
882  llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
883  return llvm::makeArrayRef(g_process_load_options);
884  }
885 
886  // Instance variables to hold the values for command options.
889  };
890 
892  : CommandObjectParsed(interpreter, "process load",
893  "Load a shared library into the current process.",
894  "process load <filename> [<filename> ...]",
895  eCommandRequiresProcess | eCommandTryTargetAPILock |
896  eCommandProcessMustBeLaunched |
897  eCommandProcessMustBePaused),
898  m_options() {}
899 
900  ~CommandObjectProcessLoad() override = default;
901 
902  void
904  OptionElementVector &opt_element_vector) override {
905  if (!m_exe_ctx.HasProcessScope())
906  return;
907 
908  CommandCompletions::InvokeCommonCompletionCallbacks(
909  GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
910  request, nullptr);
911  }
912 
913  Options *GetOptions() override { return &m_options; }
914 
915 protected:
916  bool DoExecute(Args &command, CommandReturnObject &result) override {
917  Process *process = m_exe_ctx.GetProcessPtr();
918 
919  for (auto &entry : command.entries()) {
920  Status error;
921  PlatformSP platform = process->GetTarget().GetPlatform();
922  llvm::StringRef image_path = entry.ref();
923  uint32_t image_token = LLDB_INVALID_IMAGE_TOKEN;
924 
925  if (!m_options.do_install) {
926  FileSpec image_spec(image_path);
927  platform->ResolveRemotePath(image_spec, image_spec);
928  image_token =
929  platform->LoadImage(process, FileSpec(), image_spec, error);
930  } else if (m_options.install_path) {
931  FileSpec image_spec(image_path);
932  FileSystem::Instance().Resolve(image_spec);
933  platform->ResolveRemotePath(m_options.install_path,
934  m_options.install_path);
935  image_token = platform->LoadImage(process, image_spec,
936  m_options.install_path, error);
937  } else {
938  FileSpec image_spec(image_path);
939  FileSystem::Instance().Resolve(image_spec);
940  image_token =
941  platform->LoadImage(process, image_spec, FileSpec(), error);
942  }
943 
944  if (image_token != LLDB_INVALID_IMAGE_TOKEN) {
946  "Loading \"%s\"...ok\nImage %u loaded.\n", image_path.str().c_str(),
947  image_token);
949  } else {
950  result.AppendErrorWithFormat("failed to load '%s': %s",
951  image_path.str().c_str(),
952  error.AsCString());
954  }
955  }
956  return result.Succeeded();
957  }
958 
960 };
961 
962 // CommandObjectProcessUnload
963 #pragma mark CommandObjectProcessUnload
964 
966 public:
969  interpreter, "process unload",
970  "Unload a shared library from the current process using the index "
971  "returned by a previous call to \"process load\".",
972  "process unload <index>",
973  eCommandRequiresProcess | eCommandTryTargetAPILock |
974  eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
975 
976  ~CommandObjectProcessUnload() override = default;
977 
978  void
980  OptionElementVector &opt_element_vector) override {
981 
982  if (request.GetCursorIndex() || !m_exe_ctx.HasProcessScope())
983  return;
984 
985  Process *process = m_exe_ctx.GetProcessPtr();
986 
987  const std::vector<lldb::addr_t> &tokens = process->GetImageTokens();
988  const size_t token_num = tokens.size();
989  for (size_t i = 0; i < token_num; ++i) {
990  if (tokens[i] == LLDB_INVALID_IMAGE_TOKEN)
991  continue;
992  request.TryCompleteCurrentArg(std::to_string(i));
993  }
994  }
995 
996 protected:
997  bool DoExecute(Args &command, CommandReturnObject &result) override {
998  Process *process = m_exe_ctx.GetProcessPtr();
999 
1000  for (auto &entry : command.entries()) {
1001  uint32_t image_token;
1002  if (entry.ref().getAsInteger(0, image_token)) {
1003  result.AppendErrorWithFormat("invalid image index argument '%s'",
1004  entry.ref().str().c_str());
1006  break;
1007  } else {
1008  Status error(process->GetTarget().GetPlatform()->UnloadImage(
1009  process, image_token));
1010  if (error.Success()) {
1011  result.AppendMessageWithFormat(
1012  "Unloading shared library with index %u...ok\n", image_token);
1014  } else {
1015  result.AppendErrorWithFormat("failed to unload image: %s",
1016  error.AsCString());
1018  break;
1019  }
1020  }
1021  }
1022  return result.Succeeded();
1023  }
1024 };
1025 
1026 // CommandObjectProcessSignal
1027 #pragma mark CommandObjectProcessSignal
1028 
1030 public:
1033  interpreter, "process signal",
1034  "Send a UNIX signal to the current target process.", nullptr,
1035  eCommandRequiresProcess | eCommandTryTargetAPILock) {
1037  CommandArgumentData signal_arg;
1038 
1039  // Define the first (and only) variant of this arg.
1040  signal_arg.arg_type = eArgTypeUnixSignal;
1041  signal_arg.arg_repetition = eArgRepeatPlain;
1042 
1043  // There is only one variant this argument could be; put it into the
1044  // argument entry.
1045  arg.push_back(signal_arg);
1046 
1047  // Push the data for the first argument into the m_arguments vector.
1048  m_arguments.push_back(arg);
1049  }
1050 
1051  ~CommandObjectProcessSignal() override = default;
1052 
1053  void
1055  OptionElementVector &opt_element_vector) override {
1056  if (!m_exe_ctx.HasProcessScope() || request.GetCursorIndex() != 0)
1057  return;
1058 
1059  UnixSignalsSP signals = m_exe_ctx.GetProcessPtr()->GetUnixSignals();
1060  int signo = signals->GetFirstSignalNumber();
1061  while (signo != LLDB_INVALID_SIGNAL_NUMBER) {
1062  request.AddCompletion(signals->GetSignalAsCString(signo), "");
1063  signo = signals->GetNextSignalNumber(signo);
1064  }
1065  }
1066 
1067 protected:
1068  bool DoExecute(Args &command, CommandReturnObject &result) override {
1069  Process *process = m_exe_ctx.GetProcessPtr();
1070 
1071  if (command.GetArgumentCount() == 1) {
1072  int signo = LLDB_INVALID_SIGNAL_NUMBER;
1073 
1074  const char *signal_name = command.GetArgumentAtIndex(0);
1075  if (::isxdigit(signal_name[0])) {
1076  if (!llvm::to_integer(signal_name, signo))
1078  } else
1079  signo = process->GetUnixSignals()->GetSignalNumberFromName(signal_name);
1080 
1081  if (signo == LLDB_INVALID_SIGNAL_NUMBER) {
1082  result.AppendErrorWithFormat("Invalid signal argument '%s'.\n",
1083  command.GetArgumentAtIndex(0));
1085  } else {
1086  Status error(process->Signal(signo));
1087  if (error.Success()) {
1089  } else {
1090  result.AppendErrorWithFormat("Failed to send signal %i: %s\n", signo,
1091  error.AsCString());
1093  }
1094  }
1095  } else {
1096  result.AppendErrorWithFormat(
1097  "'%s' takes exactly one signal number argument:\nUsage: %s\n",
1098  m_cmd_name.c_str(), m_cmd_syntax.c_str());
1100  }
1101  return result.Succeeded();
1102  }
1103 };
1104 
1105 // CommandObjectProcessInterrupt
1106 #pragma mark CommandObjectProcessInterrupt
1107 
1109 public:
1111  : CommandObjectParsed(interpreter, "process interrupt",
1112  "Interrupt the current target process.",
1113  "process interrupt",
1114  eCommandRequiresProcess | eCommandTryTargetAPILock |
1115  eCommandProcessMustBeLaunched) {}
1116 
1117  ~CommandObjectProcessInterrupt() override = default;
1118 
1119 protected:
1120  bool DoExecute(Args &command, CommandReturnObject &result) override {
1121  Process *process = m_exe_ctx.GetProcessPtr();
1122  if (process == nullptr) {
1123  result.AppendError("no process to halt");
1125  return false;
1126  }
1127 
1128  if (command.GetArgumentCount() == 0) {
1129  bool clear_thread_plans = true;
1130  Status error(process->Halt(clear_thread_plans));
1131  if (error.Success()) {
1133  } else {
1134  result.AppendErrorWithFormat("Failed to halt process: %s\n",
1135  error.AsCString());
1137  }
1138  } else {
1139  result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n",
1140  m_cmd_name.c_str(), m_cmd_syntax.c_str());
1142  }
1143  return result.Succeeded();
1144  }
1145 };
1146 
1147 // CommandObjectProcessKill
1148 #pragma mark CommandObjectProcessKill
1149 
1151 public:
1153  : CommandObjectParsed(interpreter, "process kill",
1154  "Terminate the current target process.",
1155  "process kill",
1156  eCommandRequiresProcess | eCommandTryTargetAPILock |
1157  eCommandProcessMustBeLaunched) {}
1158 
1159  ~CommandObjectProcessKill() override = default;
1160 
1161 protected:
1162  bool DoExecute(Args &command, CommandReturnObject &result) override {
1163  Process *process = m_exe_ctx.GetProcessPtr();
1164  if (process == nullptr) {
1165  result.AppendError("no process to kill");
1167  return false;
1168  }
1169 
1170  if (command.GetArgumentCount() == 0) {
1171  Status error(process->Destroy(true));
1172  if (error.Success()) {
1174  } else {
1175  result.AppendErrorWithFormat("Failed to kill process: %s\n",
1176  error.AsCString());
1178  }
1179  } else {
1180  result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n",
1181  m_cmd_name.c_str(), m_cmd_syntax.c_str());
1183  }
1184  return result.Succeeded();
1185  }
1186 };
1187 
1188 // CommandObjectProcessSaveCore
1189 #pragma mark CommandObjectProcessSaveCore
1190 
1192 public:
1194  : CommandObjectParsed(interpreter, "process save-core",
1195  "Save the current process as a core file using an "
1196  "appropriate file type.",
1197  "process save-core FILE",
1198  eCommandRequiresProcess | eCommandTryTargetAPILock |
1199  eCommandProcessMustBeLaunched) {}
1200 
1201  ~CommandObjectProcessSaveCore() override = default;
1202 
1203 protected:
1204  bool DoExecute(Args &command, CommandReturnObject &result) override {
1205  ProcessSP process_sp = m_exe_ctx.GetProcessSP();
1206  if (process_sp) {
1207  if (command.GetArgumentCount() == 1) {
1208  FileSpec output_file(command.GetArgumentAtIndex(0));
1209  Status error = PluginManager::SaveCore(process_sp, output_file);
1210  if (error.Success()) {
1212  } else {
1213  result.AppendErrorWithFormat(
1214  "Failed to save core file for process: %s\n", error.AsCString());
1216  }
1217  } else {
1218  result.AppendErrorWithFormat("'%s' takes one arguments:\nUsage: %s\n",
1219  m_cmd_name.c_str(), m_cmd_syntax.c_str());
1221  }
1222  } else {
1223  result.AppendError("invalid process");
1225  return false;
1226  }
1227 
1228  return result.Succeeded();
1229  }
1230 };
1231 
1232 // CommandObjectProcessStatus
1233 #pragma mark CommandObjectProcessStatus
1234 #define LLDB_OPTIONS_process_status
1235 #include "CommandOptions.inc"
1236 
1238 public:
1241  interpreter, "process status",
1242  "Show status and stop location for the current target process.",
1243  "process status",
1244  eCommandRequiresProcess | eCommandTryTargetAPILock),
1245  m_options() {}
1246 
1247  ~CommandObjectProcessStatus() override = default;
1248 
1249  Options *GetOptions() override { return &m_options; }
1250 
1251  class CommandOptions : public Options {
1252  public:
1253  CommandOptions() : Options(), m_verbose(false) {}
1254 
1255  ~CommandOptions() override = default;
1256 
1257  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1258  ExecutionContext *execution_context) override {
1259  const int short_option = m_getopt_table[option_idx].val;
1260 
1261  switch (short_option) {
1262  case 'v':
1263  m_verbose = true;
1264  break;
1265  default:
1266  llvm_unreachable("Unimplemented option");
1267  }
1268 
1269  return {};
1270  }
1271 
1272  void OptionParsingStarting(ExecutionContext *execution_context) override {
1273  m_verbose = false;
1274  }
1275 
1276  llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1277  return llvm::makeArrayRef(g_process_status_options);
1278  }
1279 
1280  // Instance variables to hold the values for command options.
1282  };
1283 
1284 protected:
1285  bool DoExecute(Args &command, CommandReturnObject &result) override {
1286  Stream &strm = result.GetOutputStream();
1288 
1289  if (command.GetArgumentCount()) {
1290  result.AppendError("'process status' takes no arguments");
1292  return result.Succeeded();
1293  }
1294 
1295  // No need to check "process" for validity as eCommandRequiresProcess
1296  // ensures it is valid
1297  Process *process = m_exe_ctx.GetProcessPtr();
1298  const bool only_threads_with_stop_reason = true;
1299  const uint32_t start_frame = 0;
1300  const uint32_t num_frames = 1;
1301  const uint32_t num_frames_with_source = 1;
1302  const bool stop_format = true;
1303  process->GetStatus(strm);
1304  process->GetThreadStatus(strm, only_threads_with_stop_reason, start_frame,
1305  num_frames, num_frames_with_source, stop_format);
1306 
1307  if (m_options.m_verbose) {
1308  PlatformSP platform_sp = process->GetTarget().GetPlatform();
1309  if (!platform_sp) {
1310  result.AppendError("Couldn'retrieve the target's platform");
1312  return result.Succeeded();
1313  }
1314 
1315  auto expected_crash_info =
1316  platform_sp->FetchExtendedCrashInformation(*process);
1317 
1318  if (!expected_crash_info) {
1319  result.AppendError(llvm::toString(expected_crash_info.takeError()));
1321  return result.Succeeded();
1322  }
1323 
1324  StructuredData::DictionarySP crash_info_sp = *expected_crash_info;
1325 
1326  if (crash_info_sp) {
1327  strm.PutCString("Extended Crash Information:\n");
1328  crash_info_sp->Dump(strm);
1329  }
1330  }
1331 
1332  return result.Succeeded();
1333  }
1334 
1335 private:
1337 };
1338 
1339 // CommandObjectProcessHandle
1340 #define LLDB_OPTIONS_process_handle
1341 #include "CommandOptions.inc"
1342 
1343 #pragma mark CommandObjectProcessHandle
1344 
1346 public:
1347  class CommandOptions : public Options {
1348  public:
1349  CommandOptions() : Options() { OptionParsingStarting(nullptr); }
1350 
1351  ~CommandOptions() override = default;
1352 
1353  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1354  ExecutionContext *execution_context) override {
1355  Status error;
1356  const int short_option = m_getopt_table[option_idx].val;
1357 
1358  switch (short_option) {
1359  case 's':
1360  stop = std::string(option_arg);
1361  break;
1362  case 'n':
1363  notify = std::string(option_arg);
1364  break;
1365  case 'p':
1366  pass = std::string(option_arg);
1367  break;
1368  default:
1369  llvm_unreachable("Unimplemented option");
1370  }
1371  return error;
1372  }
1373 
1374  void OptionParsingStarting(ExecutionContext *execution_context) override {
1375  stop.clear();
1376  notify.clear();
1377  pass.clear();
1378  }
1379 
1380  llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1381  return llvm::makeArrayRef(g_process_handle_options);
1382  }
1383 
1384  // Instance variables to hold the values for command options.
1385 
1389  };
1390 
1392  : CommandObjectParsed(interpreter, "process handle",
1393  "Manage LLDB handling of OS signals for the "
1394  "current target process. Defaults to showing "
1395  "current policy.",
1396  nullptr, eCommandRequiresTarget),
1397  m_options() {
1398  SetHelpLong("\nIf no signals are specified, update them all. If no update "
1399  "option is specified, list the current values.");
1401  CommandArgumentData signal_arg;
1402 
1403  signal_arg.arg_type = eArgTypeUnixSignal;
1404  signal_arg.arg_repetition = eArgRepeatStar;
1405 
1406  arg.push_back(signal_arg);
1407 
1408  m_arguments.push_back(arg);
1409  }
1410 
1411  ~CommandObjectProcessHandle() override = default;
1412 
1413  Options *GetOptions() override { return &m_options; }
1414 
1415  bool VerifyCommandOptionValue(const std::string &option, int &real_value) {
1416  bool okay = true;
1417  bool success = false;
1418  bool tmp_value = OptionArgParser::ToBoolean(option, false, &success);
1419 
1420  if (success && tmp_value)
1421  real_value = 1;
1422  else if (success && !tmp_value)
1423  real_value = 0;
1424  else {
1425  // If the value isn't 'true' or 'false', it had better be 0 or 1.
1426  if (!llvm::to_integer(option, real_value))
1427  real_value = 3;
1428  if (real_value != 0 && real_value != 1)
1429  okay = false;
1430  }
1431 
1432  return okay;
1433  }
1434 
1436  str.Printf("NAME PASS STOP NOTIFY\n");
1437  str.Printf("=========== ===== ===== ======\n");
1438  }
1439 
1440  void PrintSignal(Stream &str, int32_t signo, const char *sig_name,
1441  const UnixSignalsSP &signals_sp) {
1442  bool stop;
1443  bool suppress;
1444  bool notify;
1445 
1446  str.Printf("%-11s ", sig_name);
1447  if (signals_sp->GetSignalInfo(signo, suppress, stop, notify)) {
1448  bool pass = !suppress;
1449  str.Printf("%s %s %s", (pass ? "true " : "false"),
1450  (stop ? "true " : "false"), (notify ? "true " : "false"));
1451  }
1452  str.Printf("\n");
1453  }
1454 
1455  void PrintSignalInformation(Stream &str, Args &signal_args,
1456  int num_valid_signals,
1457  const UnixSignalsSP &signals_sp) {
1458  PrintSignalHeader(str);
1459 
1460  if (num_valid_signals > 0) {
1461  size_t num_args = signal_args.GetArgumentCount();
1462  for (size_t i = 0; i < num_args; ++i) {
1463  int32_t signo = signals_sp->GetSignalNumberFromName(
1464  signal_args.GetArgumentAtIndex(i));
1465  if (signo != LLDB_INVALID_SIGNAL_NUMBER)
1466  PrintSignal(str, signo, signal_args.GetArgumentAtIndex(i),
1467  signals_sp);
1468  }
1469  } else // Print info for ALL signals
1470  {
1471  int32_t signo = signals_sp->GetFirstSignalNumber();
1472  while (signo != LLDB_INVALID_SIGNAL_NUMBER) {
1473  PrintSignal(str, signo, signals_sp->GetSignalAsCString(signo),
1474  signals_sp);
1475  signo = signals_sp->GetNextSignalNumber(signo);
1476  }
1477  }
1478  }
1479 
1480 protected:
1481  bool DoExecute(Args &signal_args, CommandReturnObject &result) override {
1482  Target *target_sp = &GetSelectedTarget();
1483 
1484  ProcessSP process_sp = target_sp->GetProcessSP();
1485 
1486  if (!process_sp) {
1487  result.AppendError("No current process; cannot handle signals until you "
1488  "have a valid process.\n");
1490  return false;
1491  }
1492 
1493  int stop_action = -1; // -1 means leave the current setting alone
1494  int pass_action = -1; // -1 means leave the current setting alone
1495  int notify_action = -1; // -1 means leave the current setting alone
1496 
1497  if (!m_options.stop.empty() &&
1498  !VerifyCommandOptionValue(m_options.stop, stop_action)) {
1499  result.AppendError("Invalid argument for command option --stop; must be "
1500  "true or false.\n");
1502  return false;
1503  }
1504 
1505  if (!m_options.notify.empty() &&
1506  !VerifyCommandOptionValue(m_options.notify, notify_action)) {
1507  result.AppendError("Invalid argument for command option --notify; must "
1508  "be true or false.\n");
1510  return false;
1511  }
1512 
1513  if (!m_options.pass.empty() &&
1514  !VerifyCommandOptionValue(m_options.pass, pass_action)) {
1515  result.AppendError("Invalid argument for command option --pass; must be "
1516  "true or false.\n");
1518  return false;
1519  }
1520 
1521  size_t num_args = signal_args.GetArgumentCount();
1522  UnixSignalsSP signals_sp = process_sp->GetUnixSignals();
1523  int num_signals_set = 0;
1524 
1525  if (num_args > 0) {
1526  for (const auto &arg : signal_args) {
1527  int32_t signo = signals_sp->GetSignalNumberFromName(arg.c_str());
1528  if (signo != LLDB_INVALID_SIGNAL_NUMBER) {
1529  // Casting the actions as bools here should be okay, because
1530  // VerifyCommandOptionValue guarantees the value is either 0 or 1.
1531  if (stop_action != -1)
1532  signals_sp->SetShouldStop(signo, stop_action);
1533  if (pass_action != -1) {
1534  bool suppress = !pass_action;
1535  signals_sp->SetShouldSuppress(signo, suppress);
1536  }
1537  if (notify_action != -1)
1538  signals_sp->SetShouldNotify(signo, notify_action);
1539  ++num_signals_set;
1540  } else {
1541  result.AppendErrorWithFormat("Invalid signal name '%s'\n",
1542  arg.c_str());
1543  }
1544  }
1545  } else {
1546  // No signal specified, if any command options were specified, update ALL
1547  // signals.
1548  if ((notify_action != -1) || (stop_action != -1) || (pass_action != -1)) {
1549  if (m_interpreter.Confirm(
1550  "Do you really want to update all the signals?", false)) {
1551  int32_t signo = signals_sp->GetFirstSignalNumber();
1552  while (signo != LLDB_INVALID_SIGNAL_NUMBER) {
1553  if (notify_action != -1)
1554  signals_sp->SetShouldNotify(signo, notify_action);
1555  if (stop_action != -1)
1556  signals_sp->SetShouldStop(signo, stop_action);
1557  if (pass_action != -1) {
1558  bool suppress = !pass_action;
1559  signals_sp->SetShouldSuppress(signo, suppress);
1560  }
1561  signo = signals_sp->GetNextSignalNumber(signo);
1562  }
1563  }
1564  }
1565  }
1566 
1567  PrintSignalInformation(result.GetOutputStream(), signal_args,
1568  num_signals_set, signals_sp);
1569 
1570  if (num_signals_set > 0)
1572  else
1574 
1575  return result.Succeeded();
1576  }
1577 
1579 };
1580 
1581 // Next are the subcommands of CommandObjectMultiwordProcessTrace
1582 
1583 // CommandObjectProcessTraceStart
1585 public:
1588  /*live_debug_session_only*/ true, interpreter,
1589  "process trace start",
1590  "Start tracing this process with the corresponding trace "
1591  "plug-in.",
1592  "process trace start [<trace-options>]") {}
1593 
1594 protected:
1595  lldb::CommandObjectSP GetDelegateCommand(Trace &trace) override {
1596  return trace.GetProcessTraceStartCommand(m_interpreter);
1597  }
1598 };
1599 
1600 // CommandObjectProcessTraceStop
1602 public:
1604  : CommandObjectParsed(interpreter, "process trace stop",
1605  "Stop tracing this process. This does not affect "
1606  "traces started with the "
1607  "\"thread trace start\" command.",
1608  "process trace stop",
1609  eCommandRequiresProcess | eCommandTryTargetAPILock |
1610  eCommandProcessMustBeLaunched |
1611  eCommandProcessMustBePaused |
1612  eCommandProcessMustBeTraced) {}
1613 
1614  ~CommandObjectProcessTraceStop() override = default;
1615 
1616  bool DoExecute(Args &command, CommandReturnObject &result) override {
1617  ProcessSP process_sp = m_exe_ctx.GetProcessSP();
1618 
1619  TraceSP trace_sp = process_sp->GetTarget().GetTrace();
1620 
1621  if (llvm::Error err = trace_sp->StopProcess())
1622  result.SetError(toString(std::move(err)));
1623  else
1625 
1626  return result.Succeeded();
1627  }
1628 };
1629 
1630 // CommandObjectMultiwordProcessTrace
1632 public:
1635  interpreter, "trace", "Commands for tracing the current process.",
1636  "process trace <subcommand> [<subcommand objects>]") {
1637  LoadSubCommand("start", CommandObjectSP(new CommandObjectProcessTraceStart(
1638  interpreter)));
1639  LoadSubCommand("stop", CommandObjectSP(
1640  new CommandObjectProcessTraceStop(interpreter)));
1641  }
1642 
1643  ~CommandObjectMultiwordProcessTrace() override = default;
1644 };
1645 
1646 // CommandObjectMultiwordProcess
1647 
1648 CommandObjectMultiwordProcess::CommandObjectMultiwordProcess(
1649  CommandInterpreter &interpreter)
1651  interpreter, "process",
1652  "Commands for interacting with processes on the current platform.",
1653  "process <subcommand> [<subcommand-options>]") {
1654  LoadSubCommand("attach",
1655  CommandObjectSP(new CommandObjectProcessAttach(interpreter)));
1656  LoadSubCommand("launch",
1657  CommandObjectSP(new CommandObjectProcessLaunch(interpreter)));
1658  LoadSubCommand("continue", CommandObjectSP(new CommandObjectProcessContinue(
1659  interpreter)));
1660  LoadSubCommand("connect",
1661  CommandObjectSP(new CommandObjectProcessConnect(interpreter)));
1662  LoadSubCommand("detach",
1663  CommandObjectSP(new CommandObjectProcessDetach(interpreter)));
1664  LoadSubCommand("load",
1665  CommandObjectSP(new CommandObjectProcessLoad(interpreter)));
1666  LoadSubCommand("unload",
1667  CommandObjectSP(new CommandObjectProcessUnload(interpreter)));
1668  LoadSubCommand("signal",
1669  CommandObjectSP(new CommandObjectProcessSignal(interpreter)));
1670  LoadSubCommand("handle",
1671  CommandObjectSP(new CommandObjectProcessHandle(interpreter)));
1672  LoadSubCommand("status",
1673  CommandObjectSP(new CommandObjectProcessStatus(interpreter)));
1674  LoadSubCommand("interrupt", CommandObjectSP(new CommandObjectProcessInterrupt(
1675  interpreter)));
1676  LoadSubCommand("kill",
1677  CommandObjectSP(new CommandObjectProcessKill(interpreter)));
1678  LoadSubCommand("plugin",
1679  CommandObjectSP(new CommandObjectProcessPlugin(interpreter)));
1680  LoadSubCommand("save-core", CommandObjectSP(new CommandObjectProcessSaveCore(
1681  interpreter)));
1683  "trace",
1684  CommandObjectSP(new CommandObjectMultiwordProcessTrace(interpreter)));
1685 }
1686 
lldb_private::eArgRepeatOptional
@ eArgRepeatOptional
Definition: lldb-private-enumerations.h:96
lldb_private::ProcessInfo::GetArguments
Args & GetArguments()
Definition: ProcessInfo.h:75
lldb_private::CommandObjectParsed
Definition: CommandObject.h:378
lldb_private::OptionGroupPythonClassWithDict
Definition: OptionGroupPythonClassWithDict.h:25
CommandObjectProcessUnload
Definition: CommandObjectProcess.cpp:965
lldb_private::ExecutionContext
Definition: ExecutionContext.h:291
CommandObjectProcessLaunch::m_options
CommandOptionsProcessLaunch m_options
Definition: CommandObjectProcess.cpp:273
CommandObjectProcessDetach::CommandOptions::CommandOptions
CommandOptions()
Definition: CommandObjectProcess.cpp:637
lldb_private::Process::GetShouldDetach
bool GetShouldDetach() const
Definition: Process.h:727
lldb_private::Process::GetThreadStatus
size_t GetThreadStatus(Stream &ostrm, bool only_threads_with_stop_reason, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source, bool stop_format)
Definition: Process.cpp:5466
CommandObjectProcessLaunch::HandleArgumentCompletion
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
Definition: CommandObjectProcess.cpp:139
lldb_private::ArchSpec
Definition: ArchSpec.h:33
CommandObjectProcessKill::CommandObjectProcessKill
CommandObjectProcessKill(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:1152
CommandObjectProcessContinue::CommandOptions::SetOptionValue
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
Definition: CommandObjectProcess.cpp:501
lldb_private::Process::GetStatus
void GetStatus(Stream &ostrm)
Definition: Process.cpp:5446
CommandObjectProcessLaunchOrAttach::m_new_process_action
std::string m_new_process_action
Definition: CommandObjectProcess.cpp:101
lldb_private::TargetProperties::GetInheritTCC
bool GetInheritTCC() const
Definition: Target.cpp:3886
CommandObjectProcessDetach::CommandOptions::m_keep_stopped
LazyBool m_keep_stopped
Definition: CommandObjectProcess.cpp:676
CommandObjectProcessLaunch::CommandObjectProcessLaunch
CommandObjectProcessLaunch(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:108
lldb_private::eArgRepeatPlain
@ eArgRepeatPlain
Definition: lldb-private-enumerations.h:95
lldb_private::CommandReturnObject::SetError
void SetError(const Status &error, const char *fallback_error_cstr=nullptr)
Definition: CommandReturnObject.cpp:106
CommandObjectProcessAttach
Definition: CommandObjectProcess.cpp:282
CommandObjectProcessConnect::CommandObjectProcessConnect
CommandObjectProcessConnect(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:765
CommandObjectProcessSaveCore::CommandObjectProcessSaveCore
CommandObjectProcessSaveCore(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:1193
CommandObjectProcessDetach::CommandOptions::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: CommandObjectProcess.cpp:671
CommandObjectProcessStatus::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:1285
CommandObjectProcessKill
Definition: CommandObjectProcess.cpp:1150
CommandObjectProcessDetach::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:692
lldb_private::CompletionRequest::TryCompleteCurrentArg
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
Definition: CompletionRequest.h:180
lldb::eStateAttaching
@ eStateAttaching
Process is currently trying to attach.
Definition: lldb-enumerations.h:78
lldb_private::eLazyBoolYes
@ eLazyBoolYes
Definition: lldb-private-enumerations.h:115
CommandObjectProcessAttach::CommandOptions::SetOptionValue
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
Definition: CommandObjectProcess.cpp:294
CommandObjectProcessLoad
Definition: CommandObjectProcess.cpp:849
CommandObjectProcessInterrupt
Definition: CommandObjectProcess.cpp:1108
lldb_private::Process
Definition: Process.h:343
lldb_private::Target::GetExecutableModule
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition: Target.cpp:1353
lldb_private::OptionGroupOptions
Definition: Options.h:255
lldb_private::Process::GetBreakpointSiteList
BreakpointSiteList & GetBreakpointSiteList()
Definition: Process.cpp:1532
Module.h
lldb_private::Process::GetThreadList
ThreadList & GetThreadList()
Definition: Process.h:2047
BreakpointLocation.h
lldb_private::CommandObject::CommandArgumentData
Definition: CommandObject.h:89
lldb_private::Process::GetTarget
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1196
lldb_private::StateAsCString
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
CommandObjectProcessHandle::CommandOptions::CommandOptions
CommandOptions()
Definition: CommandObjectProcess.cpp:1349
CommandObjectProcessTraceStart
Definition: CommandObjectProcess.cpp:1584
lldb_private::Trace::GetProcessTraceStartCommand
virtual lldb::CommandObjectSP GetProcessTraceStartCommand(CommandInterpreter &interpreter)=0
Get the command handle for the "process trace start" command.
CommandObjectProcessContinue
Definition: CommandObjectProcess.cpp:477
CommandObjectProcessHandle::VerifyCommandOptionValue
bool VerifyCommandOptionValue(const std::string &option, int &real_value)
Definition: CommandObjectProcess.cpp:1415
CommandObjectProcessHandle::PrintSignalHeader
void PrintSignalHeader(Stream &str)
Definition: CommandObjectProcess.cpp:1435
OptionArgParser.h
CommandObjectProcessConnect::CommandOptions::CommandOptions
CommandOptions()
Definition: CommandObjectProcess.cpp:728
lldb::eArgTypeRunArgs
@ eArgTypeRunArgs
Definition: lldb-enumerations.h:570
lldb_private::CommandObject::CommandArgumentData::arg_repetition
ArgumentRepetitionType arg_repetition
Definition: CommandObject.h:92
lldb_private::Process::IsAlive
virtual bool IsAlive()
Check if a process is still alive.
Definition: Process.cpp:1063
lldb_private::ProcessProperties::GetDetachKeepsStopped
bool GetDetachKeepsStopped() const
Definition: Process.cpp:263
lldb_private::Stream
Definition: Stream.h:28
CommandObjectProcessContinue::GetOptions
Options * GetOptions() override
Definition: CommandObjectProcess.cpp:622
lldb_private::Args
Definition: Args.h:33
lldb_private::Process::Halt
Status Halt(bool clear_thread_plans=false, bool use_run_lock=true)
Halts a running process.
Definition: Process.cpp:3059
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:444
lldb_private::LazyBool
LazyBool
Definition: lldb-private-enumerations.h:115
CommandObjectProcessTraceStart::CommandObjectProcessTraceStart
CommandObjectProcessTraceStart(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:1586
CommandReturnObject.h
CommandObjectProcessLoad::CommandOptions::CommandOptions
CommandOptions()
Definition: CommandObjectProcess.cpp:853
CommandObjectProcessAttach::CommandObjectProcessAttach
CommandObjectProcessAttach(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:347
lldb_private::Target
Definition: Target.h:447
CommandObjectProcessDetach::CommandOptions::SetOptionValue
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
Definition: CommandObjectProcess.cpp:641
CommandObjectProcessLoad::m_options
CommandOptions m_options
Definition: CommandObjectProcess.cpp:959
lldb_private::CommandObjectTraceProxy
This class works by delegating the logic to the actual trace plug-in that can support the current pro...
Definition: CommandObjectTrace.h:25
CommandObjectProcessContinue::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:530
CommandObjectProcessConnect
Definition: CommandObjectProcess.cpp:724
CommandObjectProcessAttach::CommandOptions
Definition: CommandObjectProcess.cpp:284
CommandObjectTrace.h
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
CommandObjectProcessAttach::CommandOptions::attach_info
ProcessAttachInfo attach_info
Definition: CommandObjectProcess.cpp:344
lldb_private::Process::GetState
lldb::StateType GetState()
Get accessor for the current process state.
Definition: Process.cpp:1273
CommandObjectProcessHandle::PrintSignalInformation
void PrintSignalInformation(Stream &str, Args &signal_args, int num_valid_signals, const UnixSignalsSP &signals_sp)
Definition: CommandObjectProcess.cpp:1455
CommandObjectProcessConnect::GetOptions
Options * GetOptions() override
Definition: CommandObjectProcess.cpp:773
lldb_private::Process::GetIOHandlerID
uint32_t GetIOHandlerID() const
Definition: Process.h:2099
Process.h
CommandObjectProcessInterrupt::CommandObjectProcessInterrupt
CommandObjectProcessInterrupt(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:1110
CommandObjectProcessInterrupt::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:1120
CommandObjectProcessHandle
Definition: CommandObjectProcess.cpp:1345
CommandObjectProcessDetach::CommandObjectProcessDetach
CommandObjectProcessDetach(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:679
lldb::eReturnStatusSuccessFinishNoResult
@ eReturnStatusSuccessFinishNoResult
Definition: lldb-enumerations.h:260
lldb_private::Environment::insert
std::pair< iterator, bool > insert(llvm::StringRef KeyEqValue)
Definition: Environment.h:71
lldb_private::Process::Signal
Status Signal(int signal)
Sends a process a UNIX signal signal.
Definition: Process.cpp:3283
lldb_private::TargetProperties::GetDisableSTDIO
bool GetDisableSTDIO() const
Definition: Target.cpp:3908
lldb::eStateStopped
@ eStateStopped
Process or thread is stopped and can be examined.
Definition: lldb-enumerations.h:84
Target.h
CommandObjectProcessLoad::CommandOptions::install_path
FileSpec install_path
Definition: CommandObjectProcess.cpp:888
CommandObjectProcessUnload::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:997
lldb_private::Target::GetPlatform
lldb::PlatformSP GetPlatform()
Definition: Target.h:1331
lldb_private::Trace
Definition: Trace.h:44
CommandObjectProcessLaunch::GetOptions
Options * GetOptions() override
Definition: CommandObjectProcess.cpp:147
Platform.h
lldb_private::FileSpec
Definition: FileSpec.h:56
CommandObjectProcessContinue::CommandOptions::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: CommandObjectProcess.cpp:523
lldb_private::CommandObjectMultiword
Definition: CommandObjectMultiword.h:19
CommandObjectProcessAttach::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:358
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
Options.h
LLDB_INVALID_SIGNAL_NUMBER
#define LLDB_INVALID_SIGNAL_NUMBER
Definition: lldb-defines.h:95
lldb_private::Status::Success
bool Success() const
Test for success condition.
Definition: Status.cpp:288
lldb_private::TargetProperties::GetArg0
llvm::StringRef GetArg0() const
Definition: Target.cpp:3936
CommandObjectProcessConnect::CommandOptions
Definition: CommandObjectProcess.cpp:726
CommandObjectProcessContinue::CommandOptions
Definition: CommandObjectProcess.cpp:491
CommandObjectProcessStatus::CommandOptions
Definition: CommandObjectProcess.cpp:1251
CommandObjectProcessLaunchOrAttach::CommandObjectProcessLaunchOrAttach
CommandObjectProcessLaunchOrAttach(CommandInterpreter &interpreter, const char *name, const char *help, const char *syntax, uint32_t flags, const char *new_process_action)
Definition: CommandObjectProcess.cpp:37
CommandObjectProcessHandle::CommandObjectProcessHandle
CommandObjectProcessHandle(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:1391
lldb_private::Options
Definition: Options.h:57
CommandObjectProcessLaunch::GetRepeatCommand
const char * GetRepeatCommand(Args &current_command_args, uint32_t index) override
Get the command that appropriate for a "repeat" of the current command.
Definition: CommandObjectProcess.cpp:149
CommandObjectProcessLoad::GetOptions
Options * GetOptions() override
Definition: CommandObjectProcess.cpp:913
lldb_private::breakpad::toString
llvm::StringRef toString(Record::Kind K)
Definition: BreakpadRecords.cpp:483
lldb_private::TargetProperties::GetDetachOnError
bool GetDetachOnError() const
Definition: Target.cpp:3897
Args.h
lldb_private::eLoadDependentsNo
@ eLoadDependentsNo
Definition: Target.h:65
CommandObjectProcessDetach
Definition: CommandObjectProcess.cpp:633
lldb_private::TargetProperties::SetRunArguments
void SetRunArguments(const Args &args)
Definition: Target.cpp:3953
OptionGroupPythonClassWithDict.h
CommandObjectProcessTraceStop::CommandObjectProcessTraceStop
CommandObjectProcessTraceStop(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:1603
UnixSignals.h
lldb_private::CommandObjectMultiword::LoadSubCommand
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
Definition: CommandObjectMultiword.cpp:68
CommandObjectProcessLoad::CommandOptions::do_install
bool do_install
Definition: CommandObjectProcess.cpp:887
lldb_private::Breakpoint::IsInternal
bool IsInternal() const
Tell whether this breakpoint is an "internal" breakpoint.
Definition: Breakpoint.cpp:259
CommandObjectProcessStatus::CommandOptions::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: CommandObjectProcess.cpp:1272
LLDB_OPT_SET_1
#define LLDB_OPT_SET_1
Definition: lldb-defines.h:112
lldb_private::CommandReturnObject::SetStatus
void SetStatus(lldb::ReturnStatus status)
Definition: CommandReturnObject.cpp:131
lldb::eStateConnected
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
Definition: lldb-enumerations.h:76
CommandObjectProcessStatus::CommandOptions::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: CommandObjectProcess.cpp:1276
CommandObjectProcessSignal::HandleArgumentCompletion
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
Definition: CommandObjectProcess.cpp:1054
CommandObjectProcessLaunch::m_all_options
OptionGroupOptions m_all_options
Definition: CommandObjectProcess.cpp:275
lldb_private::Breakpoint::SetIgnoreCount
void SetIgnoreCount(uint32_t count)
Set the breakpoint to ignore the next count breakpoint hits.
Definition: Breakpoint.cpp:311
CommandObjectProcessSignal
Definition: CommandObjectProcess.cpp:1029
lldb_private::CommandReturnObject::GetOutputStream
Stream & GetOutputStream()
Definition: CommandReturnObject.h:45
CommandObjectProcessConnect::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:776
LLDB_OPT_SET_ALL
#define LLDB_OPT_SET_ALL
Definition: lldb-defines.h:111
lldb::break_id_t
int32_t break_id_t
Definition: lldb-types.h:88
CommandObjectProcessHandle::CommandOptions::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: CommandObjectProcess.cpp:1374
CommandObjectProcessStatus::CommandOptions::SetOptionValue
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
Definition: CommandObjectProcess.cpp:1257
lldb_private::Process::Destroy
Status Destroy(bool force_kill)
Kills the process and shuts down all threads that were spawned to track and monitor the process.
Definition: Process.cpp:3205
lldb_private::StreamString
Definition: StreamString.h:23
CommandObjectProcessLaunch
Definition: CommandObjectProcess.cpp:106
CommandObjectProcessStatus::GetOptions
Options * GetOptions() override
Definition: CommandObjectProcess.cpp:1249
lldb_private::Args::entries
llvm::ArrayRef< ArgEntry > entries() const
Definition: Args.h:130
CommandObjectProcessConnect::CommandOptions::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: CommandObjectProcess.cpp:752
lldb_private::ThreadList::GetMutex
std::recursive_mutex & GetMutex() const override
Definition: ThreadList.cpp:748
CommandObjectProcessContinue::CommandObjectProcessContinue
CommandObjectProcessContinue(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:479
lldb_private::BreakpointSiteList::FindByID
lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID)
Returns a shared pointer to the breakpoint site with id breakID.
Definition: BreakpointSiteList.cpp:111
CommandObjectProcessSignal::CommandObjectProcessSignal
CommandObjectProcessSignal(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:1031
CommandObjectProcessStatus::m_options
CommandOptions m_options
Definition: CommandObjectProcess.cpp:1336
CommandObjectProcessConnect::CommandOptions::SetOptionValue
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
Definition: CommandObjectProcess.cpp:736
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:221
lldb_private::eArgRepeatStar
@ eArgRepeatStar
Definition: lldb-private-enumerations.h:98
CommandObjectProcessAttach::GetOptions
Options * GetOptions() override
Definition: CommandObjectProcess.cpp:355
lldb_private::StructuredData::DictionarySP
std::shared_ptr< Dictionary > DictionarySP
Definition: StructuredData.h:67
lldb::eReturnStatusFailed
@ eReturnStatusFailed
Definition: lldb-enumerations.h:265
CommandObjectProcessLoad::HandleArgumentCompletion
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
Definition: CommandObjectProcess.cpp:903
lldb_private::Debugger
Definition: Debugger.h:70
lldb_private::Process::ResumeSynchronous
Status ResumeSynchronous(Stream *stream)
Definition: Process.cpp:1327
CommandObjectProcessPlugin::GetProxyCommandObject
CommandObject * GetProxyCommandObject() override
Definition: CommandObjectProcess.cpp:835
CommandOptionsProcessLaunch.h
CommandObjectProcessDetach::GetOptions
Options * GetOptions() override
Definition: CommandObjectProcess.cpp:689
lldb::eArgTypeUnixSignal
@ eArgTypeUnixSignal
Definition: lldb-enumerations.h:591
CommandObjectProcessSaveCore::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:1204
lldb_private::CommandObject::CommandArgumentData::arg_type
lldb::CommandArgumentType arg_type
Definition: CommandObject.h:91
lldb_private::OptionElementVector
std::vector< OptionArgElement > OptionElementVector
Definition: Options.h:42
CommandObjectProcessSaveCore
Definition: CommandObjectProcess.cpp:1191
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
lldb_private::ThreadList::GetThreadAtIndex
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
Definition: ThreadList.cpp:90
lldb_private::ArchSpec::IsValid
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:342
CommandObjectProcessTraceStop::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:1616
CommandObjectProcessConnect::CommandOptions::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: CommandObjectProcess.cpp:756
lldb::eReturnStatusSuccessContinuingNoResult
@ eReturnStatusSuccessContinuingNoResult
Definition: lldb-enumerations.h:262
CommandObjectProcessUnload::HandleArgumentCompletion
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
Definition: CommandObjectProcess.cpp:979
Thread.h
lldb_private::Process::GetUnixSignals
const lldb::UnixSignalsSP & GetUnixSignals()
Definition: Process.cpp:3298
lldb_private::TargetProperties::SetProcessLaunchInfo
void SetProcessLaunchInfo(const ProcessLaunchInfo &launch_info)
Definition: Target.cpp:4270
CommandObjectProcessHandle::DoExecute
bool DoExecute(Args &signal_args, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:1481
CommandObjectProcessLoad::CommandOptions::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: CommandObjectProcess.cpp:882
CommandObjectProcessStatus
Definition: CommandObjectProcess.cpp:1237
CommandObjectProcessUnload::CommandObjectProcessUnload
CommandObjectProcessUnload(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:967
CommandObjectProcessLoad::CommandOptions::SetOptionValue
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
Definition: CommandObjectProcess.cpp:861
CommandObjectProcessLaunch::m_class_options
OptionGroupPythonClassWithDict m_class_options
Definition: CommandObjectProcess.cpp:274
CommandObjectProcessHandle::CommandOptions::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: CommandObjectProcess.cpp:1380
lldb_private::ProcessAttachInfo
Definition: Process.h:113
CommandObjectProcessConnect::CommandOptions::plugin_name
std::string plugin_name
Definition: CommandObjectProcess.cpp:762
CommandObjectProcessAttach::CommandOptions::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: CommandObjectProcess.cpp:340
CommandObjectProcessAttach::CommandOptions::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: CommandObjectProcess.cpp:336
lldb_private::TargetProperties::GetProcessLaunchInfo
const ProcessLaunchInfo & GetProcessLaunchInfo() const
Definition: Target.cpp:4266
lldb_private::CommandObject
Definition: CommandObject.h:67
CommandObjectProcessPlugin
Definition: CommandObjectProcess.cpp:825
lldb_private::Target::Attach
Status Attach(ProcessAttachInfo &attach_info, Stream *stream)
Definition: Target.cpp:3125
CommandObjectProcessHandle::CommandOptions::stop
std::string stop
Definition: CommandObjectProcess.cpp:1386
CommandObjectProcessDetach::m_options
CommandOptions m_options
Definition: CommandObjectProcess.cpp:715
lldb_private::Target::GetProcessSP
const lldb::ProcessSP & GetProcessSP() const
Definition: Target.cpp:212
lldb_private::Target::Launch
Status Launch(ProcessLaunchInfo &launch_info, Stream *stream)
Definition: Target.cpp:2925
lldb_private::Target::GetArchitecture
const ArchSpec & GetArchitecture() const
Definition: Target.h:963
CommandObjectProcessPlugin::CommandObjectProcessPlugin
CommandObjectProcessPlugin(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:827
lldb_private::CommandObjectProxy
Definition: CommandObjectMultiword.h:73
lldb_private::Status
Definition: Status.h:44
lldb_private::TargetProperties::GetEnvironment
Environment GetEnvironment() const
Definition: Target.cpp:3988
lldb_private::Args::GetArgumentAtIndex
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
Definition: Args.cpp:259
lldb_private::CommandReturnObject
Definition: CommandReturnObject.h:25
CommandObjectProcessHandle::GetOptions
Options * GetOptions() override
Definition: CommandObjectProcess.cpp:1413
message
message(FATAL_ERROR "invalid libipt include path provided") endif() include_directories($
Definition: Plugins/Trace/intel-pt/CMakeLists.txt:6
uint32_t
lldb_private::eLazyBoolNo
@ eLazyBoolNo
Definition: lldb-private-enumerations.h:115
LLDB_INVALID_IMAGE_TOKEN
#define LLDB_INVALID_IMAGE_TOKEN
Definition: lldb-defines.h:88
CommandObjectProcessDetach::CommandOptions::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: CommandObjectProcess.cpp:667
lldb::eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishResult
Definition: lldb-enumerations.h:261
CommandObjectProcessAttach::CommandOptions::CommandOptions
CommandOptions()
Definition: CommandObjectProcess.cpp:286
CommandObjectProcessLoad::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:916
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
CommandObjectProcessHandle::m_options
CommandOptions m_options
Definition: CommandObjectProcess.cpp:1578
lldb_private::CommandReturnObject::AppendMessageWithFormat
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
Definition: CommandReturnObject.cpp:64
CommandObjectProcessHandle::CommandOptions
Definition: CommandObjectProcess.cpp:1347
CommandObjectProcessContinue::m_options
CommandOptions m_options
Definition: CommandObjectProcess.cpp:624
lldb_private::ThreadList::GetSize
uint32_t GetSize(bool can_update=true)
Definition: ThreadList.cpp:82
CommandObjectProcessLoad::CommandObjectProcessLoad
CommandObjectProcessLoad(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:891
lldb_private::Process::Detach
Status Detach(bool keep_stopped)
Detaches from a running or stopped process.
Definition: Process.cpp:3153
lldb_private::Environment
Definition: Environment.h:18
lldb_private::CommandReturnObject::AppendWarningWithFormat
void AppendWarningWithFormat(const char *format,...) __attribute__((format(printf
Definition: CommandReturnObject.cpp:76
CommandObjectProcessTraceStart::GetDelegateCommand
lldb::CommandObjectSP GetDelegateCommand(Trace &trace) override
Definition: CommandObjectProcess.cpp:1595
StopInfo.h
lldb::eStopReasonBreakpoint
@ eStopReasonBreakpoint
Definition: lldb-enumerations.h:243
lldb_private::CommandReturnObject::Succeeded
bool Succeeded()
Definition: CommandReturnObject.cpp:135
PluginManager.h
lldb_private::CommandReturnObject::SetDidChangeProcessState
void SetDidChangeProcessState(bool b)
Definition: CommandReturnObject.cpp:161
CommandObjectProcessHandle::CommandOptions::pass
std::string pass
Definition: CommandObjectProcess.cpp:1388
CommandObjectProcessAttach::m_options
CommandOptions m_options
Definition: CommandObjectProcess.cpp:467
CommandObjectProcessTraceStop
Definition: CommandObjectProcess.cpp:1601
CommandObjectProcessLaunchOrAttach
Definition: CommandObjectProcess.cpp:35
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::Process::GetID
lldb::pid_t GetID() const
Sets the stored pid.
Definition: Process.h:544
CommandObjectProcessStatus::CommandOptions::m_verbose
bool m_verbose
Definition: CommandObjectProcess.cpp:1281
CommandObjectMultiwordProcessTrace::CommandObjectMultiwordProcessTrace
CommandObjectMultiwordProcessTrace(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:1633
CommandObjectProcessContinue::CommandOptions::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: CommandObjectProcess.cpp:519
lldb_private::CommandReturnObject::AppendErrorWithFormat
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
Definition: CommandReturnObject.cpp:48
OptionParser.h
lldb_private::CompletionRequest::GetCursorIndex
size_t GetCursorIndex() const
Definition: CompletionRequest.h:156
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Debugger::GetSelectedTarget
lldb::TargetSP GetSelectedTarget()
Definition: Debugger.h:210
CommandObjectProcess.h
lldb_private::eLazyBoolCalculate
@ eLazyBoolCalculate
Definition: lldb-private-enumerations.h:115
lldb_private::Process::GetImageTokens
const std::vector< lldb::addr_t > & GetImageTokens()
Get the image vector for the current process.
Definition: Process.h:735
lldb_private::Debugger::GetAsyncExecution
bool GetAsyncExecution()
Definition: Debugger.cpp:794
CommandObjectProcessLoad::CommandOptions
Definition: CommandObjectProcess.cpp:851
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:29
Breakpoint.h
CommandObjectProcessKill::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:1162
CommandObjectProcessHandle::CommandOptions::SetOptionValue
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
Definition: CommandObjectProcess.cpp:1353
CommandObjectProcessLaunchOrAttach::StopProcessIfNecessary
bool StopProcessIfNecessary(Process *process, StateType &state, CommandReturnObject &result)
Definition: CommandObjectProcess.cpp:47
lldb_private::CompletionRequest::AddCompletion
void AddCompletion(llvm::StringRef completion, llvm::StringRef description="", CompletionMode mode=CompletionMode::Normal)
Adds a possible completion string.
Definition: CompletionRequest.h:167
CommandObjectProcessDetach::CommandOptions
Definition: CommandObjectProcess.cpp:635
lldb::eStateInvalid
@ eStateInvalid
Definition: lldb-enumerations.h:74
CommandInterpreter.h
lldb_private::Process::Resume
Status Resume()
Resumes all of a process's threads as configured using the Thread run control functions.
Definition: Process.cpp:1308
State.h
BreakpointSite.h
lldb_private::CommandObjectMultiwordProcess::~CommandObjectMultiwordProcess
~CommandObjectMultiwordProcess() override
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
CommandObjectProcessContinue::CommandOptions::m_ignore
uint32_t m_ignore
Definition: CommandObjectProcess.cpp:527
lldb_private::TargetProperties::GetDisableASLR
bool GetDisableASLR() const
Definition: Target.cpp:3875
CommandObjectProcessContinue::CommandOptions::CommandOptions
CommandOptions()
Definition: CommandObjectProcess.cpp:493
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
CommandObjectProcessStatus::CommandOptions::CommandOptions
CommandOptions()
Definition: CommandObjectProcess.cpp:1253
CommandObjectMultiwordProcessTrace
Definition: CommandObjectProcess.cpp:1631
lldb_private::CommandObject::CommandArgumentEntry
std::vector< CommandArgumentData > CommandArgumentEntry
Definition: CommandObject.h:105
PATH_MAX
#define PATH_MAX
Definition: windows/PosixApi.h:25
lldb_private::CommandReturnObject::AppendError
void void AppendError(llvm::StringRef in_string)
Definition: CommandReturnObject.cpp:100
lldb_private::Process::GetPluginCommandObject
virtual CommandObject * GetPluginCommandObject()
Return a multi-word command object that can be used to expose plug-in specific commands.
Definition: Process.h:589
lldb_private::Args::GetArgumentCount
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition: Args.h:118
CommandObjectProcessLoad::CommandOptions::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: CommandObjectProcess.cpp:877
lldb_private::CommandOptionsProcessLaunch
Definition: CommandOptionsProcessLaunch.h:19
LLDB_OPT_SET_2
#define LLDB_OPT_SET_2
Definition: lldb-defines.h:113
CommandObjectProcessHandle::PrintSignal
void PrintSignal(Stream &str, int32_t signo, const char *sig_name, const UnixSignalsSP &signals_sp)
Definition: CommandObjectProcess.cpp:1440
lldb
Definition: SBAddress.h:15
CommandObjectProcessStatus::CommandObjectProcessStatus
CommandObjectProcessStatus(CommandInterpreter &interpreter)
Definition: CommandObjectProcess.cpp:1239
lldb_private::Process::SyncIOHandler
void SyncIOHandler(uint32_t iohandler_id, const Timeout< std::micro > &timeout)
Waits for the process state to be running within a given msec timeout.
Definition: Process.cpp:620
lldb::eStateRunning
@ eStateRunning
Process or thread is running and can't be examined.
Definition: lldb-enumerations.h:85
CommandObjectProcessLaunch::DoExecute
bool DoExecute(Args &launch_args, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:156
lldb_private::CommandReturnObject::AppendMessage
void AppendMessage(llvm::StringRef in_string)
Definition: CommandReturnObject.cpp:88
CommandObjectProcessSignal::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectProcess.cpp:1068
GetPlatformList
static std::vector< PlatformSP > & GetPlatformList()
Definition: Platform.cpp:137
lldb_private::Breakpoint
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition: Breakpoint.h:79
lldb_private::ArchSpec::IsExactMatch
bool IsExactMatch(const ArchSpec &rhs) const
Compare an ArchSpec to another ArchSpec, requiring an exact cpu type match between them.
Definition: ArchSpec.cpp:930
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
CommandObjectProcessHandle::CommandOptions::notify
std::string notify
Definition: CommandObjectProcess.cpp:1387
lldb_private::Status::AsCString
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:131
CommandObjectProcessConnect::m_options
CommandOptions m_options
Definition: CommandObjectProcess.cpp:819