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
11#include "CommandObjectTrace.h"
19#include "lldb/Core/Module.h"
30#include "lldb/Target/Process.h"
32#include "lldb/Target/Target.h"
33#include "lldb/Target/Thread.h"
35#include "lldb/Utility/Args.h"
37#include "lldb/Utility/State.h"
38
39#include "llvm/ADT/ScopeExit.h"
40
41#include <bitset>
42#include <optional>
43
44using namespace lldb;
45using namespace lldb_private;
46
48public:
50 const char *name, const char *help,
51 const char *syntax, uint32_t flags,
52 const char *new_process_action)
53 : CommandObjectParsed(interpreter, name, help, syntax, flags),
54 m_new_process_action(new_process_action) {}
55
57
58protected:
60 CommandReturnObject &result) {
61 state = eStateInvalid;
62 if (process) {
63 state = process->GetState();
64
65 if (process->IsAlive() && state != eStateConnected) {
66 std::string message;
67 if (process->GetState() == eStateAttaching)
68 message =
69 llvm::formatv("There is a pending attach, abort it and {0}?",
71 else if (process->GetShouldDetach())
72 message = llvm::formatv(
73 "There is a running process, detach from it and {0}?",
75 else
76 message =
77 llvm::formatv("There is a running process, kill it and {0}?",
79
80 if (!m_interpreter.Confirm(message, true)) {
82 return false;
83 } else {
84 if (process->GetShouldDetach()) {
85 bool keep_stopped = false;
86 Status detach_error(process->Detach(keep_stopped));
87 if (detach_error.Success()) {
89 process = nullptr;
90 } else {
92 "Failed to detach from process: %s\n",
93 detach_error.AsCString());
94 }
95 } else {
96 Status destroy_error(process->Destroy(false));
97 if (destroy_error.Success()) {
99 process = nullptr;
100 } else {
101 result.AppendErrorWithFormat("Failed to kill process: %s\n",
102 destroy_error.AsCString());
103 }
104 }
105 }
106 }
107 }
108 return result.Succeeded();
109 }
110
112};
113
114// CommandObjectProcessLaunch
115#pragma mark CommandObjectProcessLaunch
117public:
120 interpreter, "process launch",
121 "Launch the executable in the debugger.", nullptr,
122 eCommandRequiresTarget, "restart"),
123
124 m_class_options("scripted process", true, 'C', 'k', 'v', 0) {
129
131 }
132
133 ~CommandObjectProcessLaunch() override = default;
134
135 Options *GetOptions() override { return &m_all_options; }
136
137 std::optional<std::string> GetRepeatCommand(Args &current_command_args,
138 uint32_t index) override {
139 // No repeat for "process launch"...
140 return std::string("");
141 }
142
143protected:
144 void DoExecute(Args &launch_args, CommandReturnObject &result) override {
145 Debugger &debugger = GetDebugger();
146 Target *target = debugger.GetSelectedTarget().get();
147 // If our listener is nullptr, users aren't allows to launch
148 ModuleSP exe_module_sp = target->GetExecutableModule();
149
150 // If the target already has an executable module, then use that. If it
151 // doesn't then someone must be trying to launch using a path that will
152 // make sense to the remote stub, but doesn't exist on the local host.
153 // In that case use the ExecutableFile that was set in the target's
154 // ProcessLaunchInfo.
155 if (exe_module_sp == nullptr && !target->GetProcessLaunchInfo().GetExecutableFile()) {
156 result.AppendError("no file in target, create a debug target using the "
157 "'target create' command");
158 return;
159 }
160
161 StateType state = eStateInvalid;
162
163 if (!StopProcessIfNecessary(m_exe_ctx.GetProcessPtr(), state, result))
164 return;
165
166 // Determine whether we will disable ASLR or leave it in the default state
167 // (i.e. enabled if the platform supports it). First check if the process
168 // launch options explicitly turn on/off
169 // disabling ASLR. If so, use that setting;
170 // otherwise, use the 'settings target.disable-aslr' setting.
171 bool disable_aslr = false;
173 // The user specified an explicit setting on the process launch line.
174 // Use it.
175 disable_aslr = (m_options.disable_aslr == eLazyBoolYes);
176 } else {
177 // The user did not explicitly specify whether to disable ASLR. Fall
178 // back to the target.disable-aslr setting.
179 disable_aslr = target->GetDisableASLR();
180 }
181
182 if (!m_class_options.GetName().empty()) {
183 m_options.launch_info.SetProcessPluginName("ScriptedProcess");
184 ScriptedMetadataSP metadata_sp = std::make_shared<ScriptedMetadata>(
188 }
189
190 if (disable_aslr)
191 m_options.launch_info.GetFlags().Set(eLaunchFlagDisableASLR);
192 else
193 m_options.launch_info.GetFlags().Clear(eLaunchFlagDisableASLR);
194
195 if (target->GetInheritTCC())
196 m_options.launch_info.GetFlags().Set(eLaunchFlagInheritTCCFromParent);
197
198 if (target->GetDetachOnError())
199 m_options.launch_info.GetFlags().Set(eLaunchFlagDetachOnError);
200
201 if (target->GetDisableSTDIO())
202 m_options.launch_info.GetFlags().Set(eLaunchFlagDisableSTDIO);
203
205 if (llvm::StringRef wd = target->GetLaunchWorkingDirectory();
206 !wd.empty()) {
208 }
209 }
210
211 // Merge the launch info environment with the target environment.
212 Environment target_env = target->GetEnvironment();
213 m_options.launch_info.GetEnvironment().insert(target_env.begin(),
214 target_env.end());
215
216 llvm::StringRef target_settings_argv0 = target->GetArg0();
217
218 if (!target_settings_argv0.empty()) {
220 target_settings_argv0);
221 if (exe_module_sp)
223 exe_module_sp->GetPlatformFileSpec(), false);
224 else
226 } else {
227 if (exe_module_sp)
229 exe_module_sp->GetPlatformFileSpec(), true);
230 else
232 }
233
234 if (launch_args.GetArgumentCount() == 0) {
237 } else {
239 // Save the arguments for subsequent runs in the current target.
240 target->SetRunArguments(launch_args);
241 }
242
243 StreamString stream;
244 Status error = target->Launch(m_options.launch_info, &stream);
245
246 if (error.Success()) {
247 ProcessSP process_sp(target->GetProcessSP());
248 if (process_sp) {
249 // There is a race condition where this thread will return up the call
250 // stack to the main command handler and show an (lldb) prompt before
251 // HandlePrivateEvent (from PrivateStateThread) has a chance to call
252 // PushProcessIOHandler().
253 process_sp->SyncIOHandler(0, std::chrono::seconds(2));
254
255 // If we didn't have a local executable, then we wouldn't have had an
256 // executable module before launch.
257 if (!exe_module_sp)
258 exe_module_sp = target->GetExecutableModule();
259 if (!exe_module_sp) {
260 result.AppendWarning("Could not get executable module after launch.");
261 } else {
262
263 const char *archname =
264 exe_module_sp->GetArchitecture().GetArchitectureName();
266 "Process %" PRIu64 " launched: '%s' (%s)\n", process_sp->GetID(),
267 exe_module_sp->GetFileSpec().GetPath().c_str(), archname);
268 }
270 // This message will refer to an event that happened after the process
271 // launched.
272 llvm::StringRef data = stream.GetString();
273 if (!data.empty())
274 result.AppendMessage(data);
275 result.SetDidChangeProcessState(true);
276 } else {
277 result.AppendError(
278 "no error returned from Target::Launch, and target has no process");
279 }
280 } else {
281 result.AppendError(error.AsCString());
282 }
283 }
284
288};
289
290#define LLDB_OPTIONS_process_attach
291#include "CommandOptions.inc"
292
293#pragma mark CommandObjectProcessAttach
295public:
298 interpreter, "process attach", "Attach to a process.",
299 "process attach <cmd-options>", 0, "attach"),
300 m_class_options("scripted process", true, 'C', 'k', 'v', 0) {
305 }
306
307 ~CommandObjectProcessAttach() override = default;
308
309 Options *GetOptions() override { return &m_all_options; }
310
311protected:
312 void DoExecute(Args &command, CommandReturnObject &result) override {
313 PlatformSP platform_sp(
314 GetDebugger().GetPlatformList().GetSelectedPlatform());
315
316 Target *target = GetDebugger().GetSelectedTarget().get();
317 // N.B. The attach should be synchronous. It doesn't help much to get the
318 // prompt back between initiating the attach and the target actually
319 // stopping. So even if the interpreter is set to be asynchronous, we wait
320 // for the stop ourselves here.
321
322 StateType state = eStateInvalid;
323 Process *process = m_exe_ctx.GetProcessPtr();
324
325 if (!StopProcessIfNecessary(process, state, result))
326 return;
327
328 if (target == nullptr) {
329 // If there isn't a current target create one.
330 TargetSP new_target_sp;
332
335 nullptr, // No platform options
336 new_target_sp);
337 target = new_target_sp.get();
338 if (target == nullptr || error.Fail()) {
339 result.AppendError(error.AsCString("Error creating target"));
340 return;
341 }
342 }
343
344 if (!m_class_options.GetName().empty()) {
345 m_options.attach_info.SetProcessPluginName("ScriptedProcess");
346 ScriptedMetadataSP metadata_sp = std::make_shared<ScriptedMetadata>(
349 }
350
351 // Record the old executable module, we want to issue a warning if the
352 // process of attaching changed the current executable (like somebody said
353 // "file foo" then attached to a PID whose executable was bar.)
354
355 ModuleSP old_exec_module_sp = target->GetExecutableModule();
356 ArchSpec old_arch_spec = target->GetArchitecture();
357
358 StreamString stream;
359 ProcessSP process_sp;
360 const auto error = target->Attach(m_options.attach_info, &stream);
361 if (error.Success()) {
362 process_sp = target->GetProcessSP();
363 if (process_sp) {
364 result.AppendMessage(stream.GetString());
366 result.SetDidChangeProcessState(true);
367 } else {
368 result.AppendError(
369 "no error returned from Target::Attach, and target has no process");
370 }
371 } else {
372 result.AppendErrorWithFormat("attach failed: %s\n", error.AsCString());
373 }
374
375 if (!result.Succeeded())
376 return;
377
378 // Okay, we're done. Last step is to warn if the executable module has
379 // changed:
380 ModuleSP new_exec_module_sp(target->GetExecutableModule());
381 if (!old_exec_module_sp) {
382 // We might not have a module if we attached to a raw pid...
383 if (new_exec_module_sp) {
385 "Executable binary set to \"%s\".\n",
386 new_exec_module_sp->GetFileSpec().GetPath().c_str());
387 }
388 } else if (!new_exec_module_sp) {
389 result.AppendWarningWithFormat("No executable binary.");
390 } else if (old_exec_module_sp->GetFileSpec() !=
391 new_exec_module_sp->GetFileSpec()) {
392
394 "Executable binary changed from \"%s\" to \"%s\".\n",
395 old_exec_module_sp->GetFileSpec().GetPath().c_str(),
396 new_exec_module_sp->GetFileSpec().GetPath().c_str());
397 }
398
399 if (!old_arch_spec.IsValid()) {
401 "Architecture set to: %s.\n",
402 target->GetArchitecture().GetTriple().getTriple().c_str());
403 } else if (!old_arch_spec.IsExactMatch(target->GetArchitecture())) {
405 "Architecture changed from %s to %s.\n",
406 old_arch_spec.GetTriple().getTriple().c_str(),
407 target->GetArchitecture().GetTriple().getTriple().c_str());
408 }
409
410 // This supports the use-case scenario of immediately continuing the
411 // process once attached.
413 // We have made a process but haven't told the interpreter about it yet,
414 // so CheckRequirements will fail for "process continue". Set the override
415 // here:
416 ExecutionContext exe_ctx(process_sp);
417 m_interpreter.HandleCommand("process continue", eLazyBoolNo, exe_ctx, result);
418 }
419 }
420
424};
425
426// CommandObjectProcessContinue
427
428#define LLDB_OPTIONS_process_continue
429#include "CommandOptions.inc"
430
431#pragma mark CommandObjectProcessContinue
432
434public:
437 interpreter, "process continue",
438 "Continue execution of all threads in the current process.",
439 "process continue",
440 eCommandRequiresProcess | eCommandTryTargetAPILock |
441 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
442
443 ~CommandObjectProcessContinue() override = default;
444
445protected:
446 class CommandOptions : public Options {
447 public:
449 // Keep default values of all options in one place: OptionParsingStarting
450 // ()
451 OptionParsingStarting(nullptr);
452 }
453
454 ~CommandOptions() override = default;
455
456 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
457 ExecutionContext *exe_ctx) override {
459 const int short_option = m_getopt_table[option_idx].val;
460 switch (short_option) {
461 case 'i':
462 if (option_arg.getAsInteger(0, m_ignore))
464 "invalid value for ignore option: \"%s\", should be a number.",
465 option_arg.str().c_str());
466 break;
467 case 'b':
470 break;
471 default:
472 llvm_unreachable("Unimplemented option");
473 }
474 return error;
475 }
476
477 void OptionParsingStarting(ExecutionContext *execution_context) override {
478 m_ignore = 0;
480 m_any_bkpts_specified = false;
481 }
482
483 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
484 return llvm::ArrayRef(g_process_continue_options);
485 }
486
487 uint32_t m_ignore = 0;
490 };
491
492 void DoExecute(Args &command, CommandReturnObject &result) override {
493 Process *process = m_exe_ctx.GetProcessPtr();
494 bool synchronous_execution = m_interpreter.GetSynchronous();
495 StateType state = process->GetState();
496 if (state == eStateStopped) {
497 if (m_options.m_ignore > 0) {
498 ThreadSP sel_thread_sp(GetDefaultThread()->shared_from_this());
499 if (sel_thread_sp) {
500 StopInfoSP stop_info_sp = sel_thread_sp->GetStopInfo();
501 if (stop_info_sp &&
502 stop_info_sp->GetStopReason() == eStopReasonBreakpoint) {
503 lldb::break_id_t bp_site_id =
504 (lldb::break_id_t)stop_info_sp->GetValue();
505 BreakpointSiteSP bp_site_sp(
506 process->GetBreakpointSiteList().FindByID(bp_site_id));
507 if (bp_site_sp) {
508 const size_t num_owners = bp_site_sp->GetNumberOfConstituents();
509 for (size_t i = 0; i < num_owners; i++) {
510 Breakpoint &bp_ref =
511 bp_site_sp->GetConstituentAtIndex(i)->GetBreakpoint();
512 if (!bp_ref.IsInternal()) {
514 }
515 }
516 }
517 }
518 }
519 }
520
521 Target &target = GetTarget();
522 BreakpointIDList run_to_bkpt_ids;
523 // Don't pass an empty run_to_breakpoint list, as Verify will look for the
524 // default breakpoint.
527 m_options.m_run_to_bkpt_args, target, result, &run_to_bkpt_ids,
529 if (!result.Succeeded()) {
530 return;
531 }
532 result.Clear();
533 if (m_options.m_any_bkpts_specified && run_to_bkpt_ids.GetSize() == 0) {
534 result.AppendError("continue-to breakpoints did not specify any actual "
535 "breakpoints or locations");
536 return;
537 }
538
539 // First figure out which breakpoints & locations were specified by the
540 // user:
541 size_t num_run_to_bkpt_ids = run_to_bkpt_ids.GetSize();
542 std::vector<break_id_t> bkpts_disabled;
543 std::vector<BreakpointID> locs_disabled;
544 if (num_run_to_bkpt_ids != 0) {
545 // Go through the ID's specified, and separate the breakpoints from are
546 // the breakpoint.location specifications since the latter require
547 // special handling. We also figure out whether there's at least one
548 // specifier in the set that is enabled.
549 BreakpointList &bkpt_list = target.GetBreakpointList();
550 std::unordered_set<break_id_t> bkpts_seen;
551 std::unordered_set<break_id_t> bkpts_with_locs_seen;
552 BreakpointIDList with_locs;
553 bool any_enabled = false;
554
555 for (size_t idx = 0; idx < num_run_to_bkpt_ids; idx++) {
556 BreakpointID bkpt_id = run_to_bkpt_ids.GetBreakpointIDAtIndex(idx);
557 break_id_t bp_id = bkpt_id.GetBreakpointID();
558 break_id_t loc_id = bkpt_id.GetLocationID();
559 BreakpointSP bp_sp
560 = bkpt_list.FindBreakpointByID(bp_id);
561 // Note, VerifyBreakpointOrLocationIDs checks for existence, so we
562 // don't need to do it again here.
563 if (bp_sp->IsEnabled()) {
564 if (loc_id == LLDB_INVALID_BREAK_ID) {
565 // A breakpoint (without location) was specified. Make sure that
566 // at least one of the locations is enabled.
567 size_t num_locations = bp_sp->GetNumLocations();
568 for (size_t loc_idx = 0; loc_idx < num_locations; loc_idx++) {
570 = bp_sp->GetLocationAtIndex(loc_idx);
571 if (loc_sp->IsEnabled()) {
572 any_enabled = true;
573 break;
574 }
575 }
576 } else {
577 // A location was specified, check if it was enabled:
578 BreakpointLocationSP loc_sp = bp_sp->FindLocationByID(loc_id);
579 if (loc_sp->IsEnabled())
580 any_enabled = true;
581 }
582
583 // Then sort the bp & bp.loc entries for later use:
584 if (bkpt_id.GetLocationID() == LLDB_INVALID_BREAK_ID)
585 bkpts_seen.insert(bkpt_id.GetBreakpointID());
586 else {
587 bkpts_with_locs_seen.insert(bkpt_id.GetBreakpointID());
588 with_locs.AddBreakpointID(bkpt_id);
589 }
590 }
591 }
592 // Do all the error checking here so once we start disabling we don't
593 // have to back out half-way through.
594
595 // Make sure at least one of the specified breakpoints is enabled.
596 if (!any_enabled) {
597 result.AppendError("at least one of the continue-to breakpoints must "
598 "be enabled.");
599 return;
600 }
601
602 // Also, if you specify BOTH a breakpoint and one of it's locations,
603 // we flag that as an error, since it won't do what you expect, the
604 // breakpoint directive will mean "run to all locations", which is not
605 // what the location directive means...
606 for (break_id_t bp_id : bkpts_with_locs_seen) {
607 if (bkpts_seen.count(bp_id)) {
608 result.AppendErrorWithFormatv("can't specify both a breakpoint and "
609 "one of its locations: {0}", bp_id);
610 }
611 }
612
613 // Now go through the breakpoints in the target, disabling all the ones
614 // that the user didn't mention:
615 for (BreakpointSP bp_sp : bkpt_list.Breakpoints()) {
616 break_id_t bp_id = bp_sp->GetID();
617 // Handle the case where no locations were specified. Note we don't
618 // have to worry about the case where a breakpoint and one of its
619 // locations are both in the lists, we've already disallowed that.
620 if (!bkpts_with_locs_seen.count(bp_id)) {
621 if (!bkpts_seen.count(bp_id) && bp_sp->IsEnabled()) {
622 bkpts_disabled.push_back(bp_id);
623 bp_sp->SetEnabled(false);
624 }
625 continue;
626 }
627 // Next, handle the case where a location was specified:
628 // Run through all the locations of this breakpoint and disable
629 // the ones that aren't on our "with locations" BreakpointID list:
630 size_t num_locations = bp_sp->GetNumLocations();
631 BreakpointID tmp_id(bp_id, LLDB_INVALID_BREAK_ID);
632 for (size_t loc_idx = 0; loc_idx < num_locations; loc_idx++) {
633 BreakpointLocationSP loc_sp = bp_sp->GetLocationAtIndex(loc_idx);
634 tmp_id.SetBreakpointLocationID(loc_idx);
635 if (!with_locs.Contains(tmp_id) && loc_sp->IsEnabled()) {
636 locs_disabled.push_back(tmp_id);
637 loc_sp->SetEnabled(false);
638 }
639 }
640 }
641 }
642
643 { // Scope for thread list mutex:
644 std::lock_guard<std::recursive_mutex> guard(
645 process->GetThreadList().GetMutex());
646 const uint32_t num_threads = process->GetThreadList().GetSize();
647
648 // Set the actions that the threads should each take when resuming
649 for (uint32_t idx = 0; idx < num_threads; ++idx) {
650 const bool override_suspend = false;
651 process->GetThreadList().GetThreadAtIndex(idx)->SetResumeState(
652 eStateRunning, override_suspend);
653 }
654 }
655
656 const uint32_t iohandler_id = process->GetIOHandlerID();
657
658 StreamString stream;
660 // For now we can only do -b with synchronous:
661 bool old_sync = GetDebugger().GetAsyncExecution();
662
663 if (run_to_bkpt_ids.GetSize() != 0) {
665 synchronous_execution = true;
666 }
667 if (synchronous_execution)
668 error = process->ResumeSynchronous(&stream);
669 else
670 error = process->Resume();
671
672 if (run_to_bkpt_ids.GetSize() != 0) {
673 GetDebugger().SetAsyncExecution(old_sync);
674 }
675
676 // Now re-enable the breakpoints we disabled:
677 BreakpointList &bkpt_list = target.GetBreakpointList();
678 for (break_id_t bp_id : bkpts_disabled) {
679 BreakpointSP bp_sp = bkpt_list.FindBreakpointByID(bp_id);
680 if (bp_sp)
681 bp_sp->SetEnabled(true);
682 }
683 for (const BreakpointID &bkpt_id : locs_disabled) {
684 BreakpointSP bp_sp
685 = bkpt_list.FindBreakpointByID(bkpt_id.GetBreakpointID());
686 if (bp_sp) {
688 = bp_sp->FindLocationByID(bkpt_id.GetLocationID());
689 if (loc_sp)
690 loc_sp->SetEnabled(true);
691 }
692 }
693
694 if (error.Success()) {
695 // There is a race condition where this thread will return up the call
696 // stack to the main command handler and show an (lldb) prompt before
697 // HandlePrivateEvent (from PrivateStateThread) has a chance to call
698 // PushProcessIOHandler().
699 process->SyncIOHandler(iohandler_id, std::chrono::seconds(2));
700
701 result.AppendMessageWithFormat("Process %" PRIu64 " resuming\n",
702 process->GetID());
703 if (synchronous_execution) {
704 // If any state changed events had anything to say, add that to the
705 // result
706 result.AppendMessage(stream.GetString());
707
708 result.SetDidChangeProcessState(true);
710 } else {
712 }
713 } else {
714 result.AppendErrorWithFormat("Failed to resume process: %s.\n",
715 error.AsCString());
716 }
717 } else {
719 "Process cannot be continued from its current state (%s).\n",
720 StateAsCString(state));
721 }
722 }
723
724 Options *GetOptions() override { return &m_options; }
725
727};
728
729// CommandObjectProcessDetach
730#define LLDB_OPTIONS_process_detach
731#include "CommandOptions.inc"
732
733#pragma mark CommandObjectProcessDetach
734
736public:
737 class CommandOptions : public Options {
738 public:
740
741 ~CommandOptions() override = default;
742
743 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
744 ExecutionContext *execution_context) override {
746 const int short_option = m_getopt_table[option_idx].val;
747
748 switch (short_option) {
749 case 's':
750 bool tmp_result;
751 bool success;
752 tmp_result = OptionArgParser::ToBoolean(option_arg, false, &success);
753 if (!success)
755 "invalid boolean option: \"%s\"", option_arg.str().c_str());
756 else {
757 if (tmp_result)
759 else
761 }
762 break;
763 default:
764 llvm_unreachable("Unimplemented option");
765 }
766 return error;
767 }
768
769 void OptionParsingStarting(ExecutionContext *execution_context) override {
771 }
772
773 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
774 return llvm::ArrayRef(g_process_detach_options);
775 }
776
777 // Instance variables to hold the values for command options.
779 };
780
782 : CommandObjectParsed(interpreter, "process detach",
783 "Detach from the current target process.",
784 "process detach",
785 eCommandRequiresProcess | eCommandTryTargetAPILock |
786 eCommandProcessMustBeLaunched) {}
787
788 ~CommandObjectProcessDetach() override = default;
789
790 Options *GetOptions() override { return &m_options; }
791
792protected:
793 void DoExecute(Args &command, CommandReturnObject &result) override {
794 Process *process = m_exe_ctx.GetProcessPtr();
795 // FIXME: This will be a Command Option:
796 bool keep_stopped;
798 // Check the process default:
799 keep_stopped = process->GetDetachKeepsStopped();
801 keep_stopped = true;
802 else
803 keep_stopped = false;
804
805 Status error(process->Detach(keep_stopped));
806 if (error.Success()) {
808 } else {
809 result.AppendErrorWithFormat("Detach failed: %s\n", error.AsCString());
810 }
811 }
812
814};
815
816// CommandObjectProcessConnect
817#define LLDB_OPTIONS_process_connect
818#include "CommandOptions.inc"
819
820#pragma mark CommandObjectProcessConnect
821
823public:
824 class CommandOptions : public Options {
825 public:
827 // Keep default values of all options in one place: OptionParsingStarting
828 // ()
829 OptionParsingStarting(nullptr);
830 }
831
832 ~CommandOptions() override = default;
833
834 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
835 ExecutionContext *execution_context) override {
837 const int short_option = m_getopt_table[option_idx].val;
838
839 switch (short_option) {
840 case 'p':
841 plugin_name.assign(std::string(option_arg));
842 break;
843
844 default:
845 llvm_unreachable("Unimplemented option");
846 }
847 return error;
848 }
849
850 void OptionParsingStarting(ExecutionContext *execution_context) override {
851 plugin_name.clear();
852 }
853
854 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
855 return llvm::ArrayRef(g_process_connect_options);
856 }
857
858 // Instance variables to hold the values for command options.
859
860 std::string plugin_name;
861 };
862
864 : CommandObjectParsed(interpreter, "process connect",
865 "Connect to a remote debug service.",
866 "process connect <remote-url>", 0) {
868 }
869
870 ~CommandObjectProcessConnect() override = default;
871
872 Options *GetOptions() override { return &m_options; }
873
874protected:
875 void DoExecute(Args &command, CommandReturnObject &result) override {
876 if (command.GetArgumentCount() != 1) {
878 "'%s' takes exactly one argument:\nUsage: %s\n", m_cmd_name.c_str(),
879 m_cmd_syntax.c_str());
880 return;
881 }
882
883 Process *process = m_exe_ctx.GetProcessPtr();
884 if (process && process->IsAlive()) {
886 "Process %" PRIu64
887 " is currently being debugged, kill the process before connecting.\n",
888 process->GetID());
889 return;
890 }
891
892 const char *plugin_name = nullptr;
893 if (!m_options.plugin_name.empty())
894 plugin_name = m_options.plugin_name.c_str();
895
897 Debugger &debugger = GetDebugger();
898 PlatformSP platform_sp = m_interpreter.GetPlatform(true);
899 ProcessSP process_sp =
900 debugger.GetAsyncExecution()
901 ? platform_sp->ConnectProcess(
902 command.GetArgumentAtIndex(0), plugin_name, debugger,
903 debugger.GetSelectedTarget().get(), error)
904 : platform_sp->ConnectProcessSynchronous(
905 command.GetArgumentAtIndex(0), plugin_name, debugger,
906 result.GetOutputStream(), debugger.GetSelectedTarget().get(),
907 error);
908 if (error.Fail() || process_sp == nullptr) {
909 result.AppendError(error.AsCString("Error connecting to the process"));
910 }
911 }
912
914};
915
916// CommandObjectProcessPlugin
917#pragma mark CommandObjectProcessPlugin
918
920public:
923 interpreter, "process plugin",
924 "Send a custom command to the current target process plug-in.",
925 "process plugin <args>", 0) {}
926
927 ~CommandObjectProcessPlugin() override = default;
928
931 if (process)
932 return process->GetPluginCommandObject();
933 return nullptr;
934 }
935};
936
937// CommandObjectProcessLoad
938#define LLDB_OPTIONS_process_load
939#include "CommandOptions.inc"
940
941#pragma mark CommandObjectProcessLoad
942
944public:
945 class CommandOptions : public Options {
946 public:
948 // Keep default values of all options in one place: OptionParsingStarting
949 // ()
950 OptionParsingStarting(nullptr);
951 }
952
953 ~CommandOptions() override = default;
954
955 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
956 ExecutionContext *execution_context) override {
958 const int short_option = m_getopt_table[option_idx].val;
959 ArchSpec arch =
960 execution_context->GetProcessPtr()->GetSystemArchitecture();
961 switch (short_option) {
962 case 'i':
963 do_install = true;
964 if (!option_arg.empty())
965 install_path.SetFile(option_arg, arch.GetTriple());
966 break;
967 default:
968 llvm_unreachable("Unimplemented option");
969 }
970 return error;
971 }
972
973 void OptionParsingStarting(ExecutionContext *execution_context) override {
974 do_install = false;
976 }
977
978 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
979 return llvm::ArrayRef(g_process_load_options);
980 }
981
982 // Instance variables to hold the values for command options.
985 };
986
988 : CommandObjectParsed(interpreter, "process load",
989 "Load a shared library into the current process.",
990 "process load <filename> [<filename> ...]",
991 eCommandRequiresProcess | eCommandTryTargetAPILock |
992 eCommandProcessMustBeLaunched |
993 eCommandProcessMustBePaused) {
995 }
996
997 ~CommandObjectProcessLoad() override = default;
998
999 void
1001 OptionElementVector &opt_element_vector) override {
1003 return;
1004 CommandObject::HandleArgumentCompletion(request, opt_element_vector);
1005 }
1006
1007 Options *GetOptions() override { return &m_options; }
1008
1009protected:
1010 void DoExecute(Args &command, CommandReturnObject &result) override {
1011 Process *process = m_exe_ctx.GetProcessPtr();
1012
1013 for (auto &entry : command.entries()) {
1014 Status error;
1015 PlatformSP platform = process->GetTarget().GetPlatform();
1016 llvm::StringRef image_path = entry.ref();
1017 uint32_t image_token = LLDB_INVALID_IMAGE_TOKEN;
1018
1019 if (!m_options.do_install) {
1020 FileSpec image_spec(image_path);
1021 platform->ResolveRemotePath(image_spec, image_spec);
1022 image_token =
1023 platform->LoadImage(process, FileSpec(), image_spec, error);
1024 } else if (m_options.install_path) {
1025 FileSpec image_spec(image_path);
1026 FileSystem::Instance().Resolve(image_spec);
1027 platform->ResolveRemotePath(m_options.install_path,
1029 image_token = platform->LoadImage(process, image_spec,
1031 } else {
1032 FileSpec image_spec(image_path);
1033 FileSystem::Instance().Resolve(image_spec);
1034 image_token =
1035 platform->LoadImage(process, image_spec, FileSpec(), error);
1036 }
1037
1038 if (image_token != LLDB_INVALID_IMAGE_TOKEN) {
1040 "Loading \"%s\"...ok\nImage %u loaded.\n", image_path.str().c_str(),
1041 image_token);
1043 } else {
1044 result.AppendErrorWithFormat("failed to load '%s': %s",
1045 image_path.str().c_str(),
1046 error.AsCString());
1047 }
1048 }
1049 }
1050
1052};
1053
1054// CommandObjectProcessUnload
1055#pragma mark CommandObjectProcessUnload
1056
1058public:
1061 interpreter, "process unload",
1062 "Unload a shared library from the current process using the index "
1063 "returned by a previous call to \"process load\".",
1064 "process unload <index>",
1065 eCommandRequiresProcess | eCommandTryTargetAPILock |
1066 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
1068 }
1069
1070 ~CommandObjectProcessUnload() override = default;
1071
1072 void
1074 OptionElementVector &opt_element_vector) override {
1075
1076 if (request.GetCursorIndex() || !m_exe_ctx.HasProcessScope())
1077 return;
1078
1079 Process *process = m_exe_ctx.GetProcessPtr();
1080
1081 const std::vector<lldb::addr_t> &tokens = process->GetImageTokens();
1082 const size_t token_num = tokens.size();
1083 for (size_t i = 0; i < token_num; ++i) {
1084 if (tokens[i] == LLDB_INVALID_IMAGE_TOKEN)
1085 continue;
1086 request.TryCompleteCurrentArg(std::to_string(i));
1087 }
1088 }
1089
1090protected:
1091 void DoExecute(Args &command, CommandReturnObject &result) override {
1092 Process *process = m_exe_ctx.GetProcessPtr();
1093
1094 for (auto &entry : command.entries()) {
1095 uint32_t image_token;
1096 if (entry.ref().getAsInteger(0, image_token)) {
1097 result.AppendErrorWithFormat("invalid image index argument '%s'",
1098 entry.ref().str().c_str());
1099 break;
1100 } else {
1101 Status error(process->GetTarget().GetPlatform()->UnloadImage(
1102 process, image_token));
1103 if (error.Success()) {
1105 "Unloading shared library with index %u...ok\n", image_token);
1107 } else {
1108 result.AppendErrorWithFormat("failed to unload image: %s",
1109 error.AsCString());
1110 break;
1111 }
1112 }
1113 }
1114 }
1115};
1116
1117// CommandObjectProcessSignal
1118#pragma mark CommandObjectProcessSignal
1119
1121public:
1124 interpreter, "process signal",
1125 "Send a UNIX signal to the current target process.", nullptr,
1126 eCommandRequiresProcess | eCommandTryTargetAPILock) {
1128 }
1129
1130 ~CommandObjectProcessSignal() override = default;
1131
1132 void
1134 OptionElementVector &opt_element_vector) override {
1135 if (!m_exe_ctx.HasProcessScope() || request.GetCursorIndex() != 0)
1136 return;
1137
1139 int signo = signals->GetFirstSignalNumber();
1140 while (signo != LLDB_INVALID_SIGNAL_NUMBER) {
1141 request.TryCompleteCurrentArg(signals->GetSignalAsStringRef(signo));
1142 signo = signals->GetNextSignalNumber(signo);
1143 }
1144 }
1145
1146protected:
1147 void DoExecute(Args &command, CommandReturnObject &result) override {
1148 Process *process = m_exe_ctx.GetProcessPtr();
1149
1150 if (command.GetArgumentCount() == 1) {
1151 int signo = LLDB_INVALID_SIGNAL_NUMBER;
1152
1153 const char *signal_name = command.GetArgumentAtIndex(0);
1154 if (::isxdigit(signal_name[0])) {
1155 if (!llvm::to_integer(signal_name, signo))
1157 } else
1158 signo = process->GetUnixSignals()->GetSignalNumberFromName(signal_name);
1159
1160 if (signo == LLDB_INVALID_SIGNAL_NUMBER) {
1161 result.AppendErrorWithFormat("Invalid signal argument '%s'.\n",
1162 command.GetArgumentAtIndex(0));
1163 } else {
1164 Status error(process->Signal(signo));
1165 if (error.Success()) {
1167 } else {
1168 result.AppendErrorWithFormat("Failed to send signal %i: %s\n", signo,
1169 error.AsCString());
1170 }
1171 }
1172 } else {
1173 result.AppendErrorWithFormat(
1174 "'%s' takes exactly one signal number argument:\nUsage: %s\n",
1175 m_cmd_name.c_str(), m_cmd_syntax.c_str());
1176 }
1177 }
1178};
1179
1180// CommandObjectProcessInterrupt
1181#pragma mark CommandObjectProcessInterrupt
1182
1184public:
1186 : CommandObjectParsed(interpreter, "process interrupt",
1187 "Interrupt the current target process.",
1188 "process interrupt",
1189 eCommandRequiresProcess | eCommandTryTargetAPILock |
1190 eCommandProcessMustBeLaunched) {}
1191
1193
1194protected:
1195 void DoExecute(Args &command, CommandReturnObject &result) override {
1196 Process *process = m_exe_ctx.GetProcessPtr();
1197 if (process == nullptr) {
1198 result.AppendError("no process to halt");
1199 return;
1200 }
1201
1202 bool clear_thread_plans = true;
1203 Status error(process->Halt(clear_thread_plans));
1204 if (error.Success()) {
1206 } else {
1207 result.AppendErrorWithFormat("Failed to halt process: %s\n",
1208 error.AsCString());
1209 }
1210 }
1211};
1212
1213// CommandObjectProcessKill
1214#pragma mark CommandObjectProcessKill
1215
1217public:
1219 : CommandObjectParsed(interpreter, "process kill",
1220 "Terminate the current target process.",
1221 "process kill",
1222 eCommandRequiresProcess | eCommandTryTargetAPILock |
1223 eCommandProcessMustBeLaunched) {}
1224
1225 ~CommandObjectProcessKill() override = default;
1226
1227protected:
1228 void DoExecute(Args &command, CommandReturnObject &result) override {
1229 Process *process = m_exe_ctx.GetProcessPtr();
1230 if (process == nullptr) {
1231 result.AppendError("no process to kill");
1232 return;
1233 }
1234
1235 Status error(process->Destroy(true));
1236 if (error.Success()) {
1238 } else {
1239 result.AppendErrorWithFormat("Failed to kill process: %s\n",
1240 error.AsCString());
1241 }
1242 }
1243};
1244
1245#define LLDB_OPTIONS_process_save_core
1246#include "CommandOptions.inc"
1247
1249public:
1252 interpreter, "process save-core",
1253 "Save the current process as a core file using an "
1254 "appropriate file type.",
1255 "process save-core [-s corefile-style -p plugin-name] FILE",
1256 eCommandRequiresProcess | eCommandTryTargetAPILock |
1257 eCommandProcessMustBeLaunched) {
1259 }
1260
1261 ~CommandObjectProcessSaveCore() override = default;
1262
1263 Options *GetOptions() override { return &m_options; }
1264
1265 class CommandOptions : public Options {
1266 public:
1267 CommandOptions() = default;
1268
1269 ~CommandOptions() override = default;
1270
1271 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1272 return llvm::ArrayRef(g_process_save_core_options);
1273 }
1274
1275 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1276 ExecutionContext *execution_context) override {
1277 const int short_option = m_getopt_table[option_idx].val;
1278 Status error;
1279
1280 switch (short_option) {
1281 case 'p':
1282 error = m_core_dump_options.SetPluginName(option_arg.data());
1283 break;
1284 case 's':
1287 option_arg, GetDefinitions()[option_idx].enum_values,
1289 break;
1290 default:
1291 llvm_unreachable("Unimplemented option");
1292 }
1293
1294 return {};
1295 }
1296
1297 void OptionParsingStarting(ExecutionContext *execution_context) override {
1299 }
1300
1301 // Instance variables to hold the values for command options.
1303 };
1304
1305protected:
1306 void DoExecute(Args &command, CommandReturnObject &result) override {
1307 ProcessSP process_sp = m_exe_ctx.GetProcessSP();
1308 if (process_sp) {
1309 if (command.GetArgumentCount() == 1) {
1310 FileSpec output_file(command.GetArgumentAtIndex(0));
1311 FileSystem::Instance().Resolve(output_file);
1312 auto &core_dump_options = m_options.m_core_dump_options;
1313 core_dump_options.SetOutputFile(output_file);
1314 Status error = PluginManager::SaveCore(process_sp, core_dump_options);
1315 if (error.Success()) {
1316 if (core_dump_options.GetStyle() ==
1317 SaveCoreStyle::eSaveCoreDirtyOnly ||
1318 core_dump_options.GetStyle() ==
1319 SaveCoreStyle::eSaveCoreStackOnly) {
1321 "\nModified-memory or stack-memory only corefile "
1322 "created. This corefile may \n"
1323 "not show library/framework/app binaries "
1324 "on a different system, or when \n"
1325 "those binaries have "
1326 "been updated/modified. Copies are not included\n"
1327 "in this corefile. Use --style full to include all "
1328 "process memory.\n");
1329 }
1331 } else {
1332 result.AppendErrorWithFormat(
1333 "Failed to save core file for process: %s\n", error.AsCString());
1334 }
1335 } else {
1336 result.AppendErrorWithFormat("'%s' takes one arguments:\nUsage: %s\n",
1337 m_cmd_name.c_str(), m_cmd_syntax.c_str());
1338 }
1339 } else {
1340 result.AppendError("invalid process");
1341 }
1342 }
1343
1345};
1346
1347// CommandObjectProcessStatus
1348#pragma mark CommandObjectProcessStatus
1349#define LLDB_OPTIONS_process_status
1350#include "CommandOptions.inc"
1351
1353public:
1356 interpreter, "process status",
1357 "Show status and stop location for the current target process.",
1358 "process status",
1359 eCommandRequiresProcess | eCommandTryTargetAPILock) {}
1360
1361 ~CommandObjectProcessStatus() override = default;
1362
1363 Options *GetOptions() override { return &m_options; }
1364
1365 class CommandOptions : public Options {
1366 public:
1367 CommandOptions() = default;
1368
1369 ~CommandOptions() override = default;
1370
1371 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1372 ExecutionContext *execution_context) override {
1373 const int short_option = m_getopt_table[option_idx].val;
1374
1375 switch (short_option) {
1376 case 'v':
1377 m_verbose = true;
1378 break;
1379 default:
1380 llvm_unreachable("Unimplemented option");
1381 }
1382
1383 return {};
1384 }
1385
1386 void OptionParsingStarting(ExecutionContext *execution_context) override {
1387 m_verbose = false;
1388 }
1389
1390 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1391 return llvm::ArrayRef(g_process_status_options);
1392 }
1393
1394 // Instance variables to hold the values for command options.
1395 bool m_verbose = false;
1396 };
1397
1398protected:
1399 void DoExecute(Args &command, CommandReturnObject &result) override {
1400 Stream &strm = result.GetOutputStream();
1402
1403 // No need to check "process" for validity as eCommandRequiresProcess
1404 // ensures it is valid
1405 Process *process = m_exe_ctx.GetProcessPtr();
1406 const bool only_threads_with_stop_reason = true;
1407 const uint32_t start_frame = 0;
1408 const uint32_t num_frames = 1;
1409 const uint32_t num_frames_with_source = 1;
1410 const bool stop_format = true;
1411 process->GetStatus(strm);
1412 process->GetThreadStatus(strm, only_threads_with_stop_reason, start_frame,
1413 num_frames, num_frames_with_source, stop_format);
1414
1415 if (m_options.m_verbose) {
1416 addr_t code_mask = process->GetCodeAddressMask();
1417 addr_t data_mask = process->GetDataAddressMask();
1418 if (code_mask != LLDB_INVALID_ADDRESS_MASK) {
1419 int bits = std::bitset<64>(~code_mask).count();
1421 "Addressable code address mask: 0x%" PRIx64 "\n", code_mask);
1423 "Addressable data address mask: 0x%" PRIx64 "\n", data_mask);
1425 "Number of bits used in addressing (code): %d\n", bits);
1426 }
1427
1428 PlatformSP platform_sp = process->GetTarget().GetPlatform();
1429 if (!platform_sp) {
1430 result.AppendError("Couldn't retrieve the target's platform");
1431 return;
1432 }
1433
1434 auto expected_crash_info =
1435 platform_sp->FetchExtendedCrashInformation(*process);
1436
1437 if (!expected_crash_info) {
1438 result.AppendError(llvm::toString(expected_crash_info.takeError()));
1439 return;
1440 }
1441
1442 StructuredData::DictionarySP crash_info_sp = *expected_crash_info;
1443
1444 if (crash_info_sp) {
1445 strm.EOL();
1446 strm.PutCString("Extended Crash Information:\n");
1447 crash_info_sp->GetDescription(strm);
1448 }
1449 }
1450 }
1451
1452private:
1454};
1455
1456// CommandObjectProcessHandle
1457#define LLDB_OPTIONS_process_handle
1458#include "CommandOptions.inc"
1459
1460#pragma mark CommandObjectProcessHandle
1461
1463public:
1464 class CommandOptions : public Options {
1465 public:
1467
1468 ~CommandOptions() override = default;
1469
1470 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1471 ExecutionContext *execution_context) override {
1472 Status error;
1473 const int short_option = m_getopt_table[option_idx].val;
1474
1475 switch (short_option) {
1476 case 'c':
1477 do_clear = true;
1478 break;
1479 case 'd':
1480 dummy = true;
1481 break;
1482 case 's':
1483 stop = std::string(option_arg);
1484 break;
1485 case 'n':
1486 notify = std::string(option_arg);
1487 break;
1488 case 'p':
1489 pass = std::string(option_arg);
1490 break;
1491 case 't':
1492 only_target_values = true;
1493 break;
1494 default:
1495 llvm_unreachable("Unimplemented option");
1496 }
1497 return error;
1498 }
1499
1500 void OptionParsingStarting(ExecutionContext *execution_context) override {
1501 stop.clear();
1502 notify.clear();
1503 pass.clear();
1504 only_target_values = false;
1505 do_clear = false;
1506 dummy = false;
1507 }
1508
1509 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1510 return llvm::ArrayRef(g_process_handle_options);
1511 }
1512
1513 // Instance variables to hold the values for command options.
1514
1515 std::string stop;
1516 std::string notify;
1517 std::string pass;
1519 bool do_clear = false;
1520 bool dummy = false;
1521 };
1522
1524 : CommandObjectParsed(interpreter, "process handle",
1525 "Manage LLDB handling of OS signals for the "
1526 "current target process. Defaults to showing "
1527 "current policy.",
1528 nullptr) {
1529 SetHelpLong("\nIf no signals are specified but one or more actions are, "
1530 "and there is a live process, update them all. If no action "
1531 "is specified, list the current values.\n"
1532 "If you specify actions with no target (e.g. in an init file) "
1533 "or in a target with no process "
1534 "the values will get copied into subsequent targets, but "
1535 "lldb won't be able to spell-check the options since it can't "
1536 "know which signal set will later be in force."
1537 "\nYou can see the signal modifications held by the target"
1538 "by passing the -t option."
1539 "\nYou can also clear the target modification for a signal"
1540 "by passing the -c option");
1542 }
1543
1544 ~CommandObjectProcessHandle() override = default;
1545
1546 Options *GetOptions() override { return &m_options; }
1547
1549 str.Printf("NAME PASS STOP NOTIFY\n");
1550 str.Printf("=========== ===== ===== ======\n");
1551 }
1552
1553 void PrintSignal(Stream &str, int32_t signo, llvm::StringRef sig_name,
1554 const UnixSignalsSP &signals_sp) {
1555 bool stop;
1556 bool suppress;
1557 bool notify;
1558
1559 str.Format("{0, -11} ", sig_name);
1560 if (signals_sp->GetSignalInfo(signo, suppress, stop, notify)) {
1561 bool pass = !suppress;
1562 str.Printf("%s %s %s", (pass ? "true " : "false"),
1563 (stop ? "true " : "false"), (notify ? "true " : "false"));
1564 }
1565 str.Printf("\n");
1566 }
1567
1568 void PrintSignalInformation(Stream &str, Args &signal_args,
1569 int num_valid_signals,
1570 const UnixSignalsSP &signals_sp) {
1571 PrintSignalHeader(str);
1572
1573 if (num_valid_signals > 0) {
1574 size_t num_args = signal_args.GetArgumentCount();
1575 for (size_t i = 0; i < num_args; ++i) {
1576 int32_t signo = signals_sp->GetSignalNumberFromName(
1577 signal_args.GetArgumentAtIndex(i));
1578 if (signo != LLDB_INVALID_SIGNAL_NUMBER)
1579 PrintSignal(str, signo, signal_args.GetArgumentAtIndex(i),
1580 signals_sp);
1581 }
1582 } else // Print info for ALL signals
1583 {
1584 int32_t signo = signals_sp->GetFirstSignalNumber();
1585 while (signo != LLDB_INVALID_SIGNAL_NUMBER) {
1586 PrintSignal(str, signo, signals_sp->GetSignalAsStringRef(signo),
1587 signals_sp);
1588 signo = signals_sp->GetNextSignalNumber(signo);
1589 }
1590 }
1591 }
1592
1593protected:
1594 void DoExecute(Args &signal_args, CommandReturnObject &result) override {
1595 Target &target = GetTarget();
1596
1597 // Any signals that are being set should be added to the Target's
1598 // DummySignals so they will get applied on rerun, etc.
1599 // If we have a process, however, we can do a more accurate job of vetting
1600 // the user's options.
1601 ProcessSP process_sp = target.GetProcessSP();
1602
1603 std::optional<bool> stop_action = {};
1604 std::optional<bool> pass_action = {};
1605 std::optional<bool> notify_action = {};
1606
1607 if (!m_options.stop.empty()) {
1608 bool success = false;
1609 bool value = OptionArgParser::ToBoolean(m_options.stop, false, &success);
1610 if (!success) {
1611 result.AppendError(
1612 "Invalid argument for command option --stop; must be "
1613 "true or false.\n");
1614 return;
1615 }
1616
1617 stop_action = value;
1618 }
1619
1620 if (!m_options.pass.empty()) {
1621 bool success = false;
1622 bool value = OptionArgParser::ToBoolean(m_options.pass, false, &success);
1623 if (!success) {
1624 result.AppendError(
1625 "Invalid argument for command option --pass; must be "
1626 "true or false.\n");
1627 return;
1628 }
1629 pass_action = value;
1630 }
1631
1632 if (!m_options.notify.empty()) {
1633 bool success = false;
1634 bool value =
1636 if (!success) {
1637 result.AppendError("Invalid argument for command option --notify; must "
1638 "be true or false.\n");
1639 return;
1640 }
1641 notify_action = value;
1642 }
1643
1644 if (!m_options.notify.empty() && !notify_action.has_value()) {
1645 }
1646
1647 bool no_actions = (!stop_action.has_value() && !pass_action.has_value() &&
1648 !notify_action.has_value());
1649 if (m_options.only_target_values && !no_actions) {
1650 result.AppendError("-t is for reporting, not setting, target values.");
1651 return;
1652 }
1653
1654 size_t num_args = signal_args.GetArgumentCount();
1655 UnixSignalsSP signals_sp;
1656 if (process_sp)
1657 signals_sp = process_sp->GetUnixSignals();
1658
1659 int num_signals_set = 0;
1660
1661 // If we were just asked to print the target values, do that here and
1662 // return:
1664 target.PrintDummySignals(result.GetOutputStream(), signal_args);
1666 return;
1667 }
1668
1669 // This handles clearing values:
1670 if (m_options.do_clear) {
1671 target.ClearDummySignals(signal_args);
1672 if (m_options.dummy)
1673 GetDummyTarget().ClearDummySignals(signal_args);
1675 return;
1676 }
1677
1678 // This rest handles setting values:
1679 if (num_args > 0) {
1680 for (const auto &arg : signal_args) {
1681 // Do the process first. If we have a process we can catch
1682 // invalid signal names, which we do here.
1683 if (signals_sp) {
1684 int32_t signo = signals_sp->GetSignalNumberFromName(arg.c_str());
1685 if (signo != LLDB_INVALID_SIGNAL_NUMBER) {
1686 if (stop_action.has_value())
1687 signals_sp->SetShouldStop(signo, *stop_action);
1688 if (pass_action.has_value()) {
1689 bool suppress = !*pass_action;
1690 signals_sp->SetShouldSuppress(signo, suppress);
1691 }
1692 if (notify_action.has_value())
1693 signals_sp->SetShouldNotify(signo, *notify_action);
1694 ++num_signals_set;
1695 } else {
1696 result.AppendErrorWithFormat("Invalid signal name '%s'\n",
1697 arg.c_str());
1698 continue;
1699 }
1700 } else {
1701 // If there's no process we can't check, so we just set them all.
1702 // But since the map signal name -> signal number across all platforms
1703 // is not 1-1, we can't sensibly set signal actions by number before
1704 // we have a process. Check that here:
1705 int32_t signo;
1706 if (llvm::to_integer(arg.c_str(), signo)) {
1707 result.AppendErrorWithFormat("Can't set signal handling by signal "
1708 "number with no process");
1709 return;
1710 }
1711 num_signals_set = num_args;
1712 }
1713 auto set_lazy_bool = [](std::optional<bool> action) -> LazyBool {
1714 if (!action.has_value())
1715 return eLazyBoolCalculate;
1716 return (*action) ? eLazyBoolYes : eLazyBoolNo;
1717 };
1718
1719 // If there were no actions, we're just listing, don't add the dummy:
1720 if (!no_actions)
1721 target.AddDummySignal(arg.ref(), set_lazy_bool(pass_action),
1722 set_lazy_bool(notify_action),
1723 set_lazy_bool(stop_action));
1724 }
1725 } else {
1726 // No signal specified, if any command options were specified, update ALL
1727 // signals. But we can't do this without a process since we don't know
1728 // all the possible signals that might be valid for this target.
1729 if ((notify_action.has_value() || stop_action.has_value() ||
1730 pass_action.has_value()) &&
1731 process_sp) {
1733 "Do you really want to update all the signals?", false)) {
1734 int32_t signo = signals_sp->GetFirstSignalNumber();
1735 while (signo != LLDB_INVALID_SIGNAL_NUMBER) {
1736 if (notify_action.has_value())
1737 signals_sp->SetShouldNotify(signo, *notify_action);
1738 if (stop_action.has_value())
1739 signals_sp->SetShouldStop(signo, *stop_action);
1740 if (pass_action.has_value()) {
1741 bool suppress = !*pass_action;
1742 signals_sp->SetShouldSuppress(signo, suppress);
1743 }
1744 signo = signals_sp->GetNextSignalNumber(signo);
1745 }
1746 }
1747 }
1748 }
1749
1750 if (signals_sp)
1751 PrintSignalInformation(result.GetOutputStream(), signal_args,
1752 num_signals_set, signals_sp);
1753 else
1754 target.PrintDummySignals(result.GetOutputStream(),
1755 signal_args);
1756
1757 if (num_signals_set > 0)
1759 else
1761 }
1762
1764};
1765
1766// Next are the subcommands of CommandObjectMultiwordProcessTrace
1767
1768// CommandObjectProcessTraceStart
1770public:
1773 /*live_debug_session_only*/ true, interpreter,
1774 "process trace start",
1775 "Start tracing this process with the corresponding trace "
1776 "plug-in.",
1777 "process trace start [<trace-options>]") {}
1778
1779protected:
1782 }
1783};
1784
1785// CommandObjectProcessTraceStop
1787public:
1789 : CommandObjectParsed(interpreter, "process trace stop",
1790 "Stop tracing this process. This does not affect "
1791 "traces started with the "
1792 "\"thread trace start\" command.",
1793 "process trace stop",
1794 eCommandRequiresProcess | eCommandTryTargetAPILock |
1795 eCommandProcessMustBeLaunched |
1796 eCommandProcessMustBePaused |
1797 eCommandProcessMustBeTraced) {}
1798
1800
1801 void DoExecute(Args &command, CommandReturnObject &result) override {
1802 ProcessSP process_sp = m_exe_ctx.GetProcessSP();
1803
1804 TraceSP trace_sp = process_sp->GetTarget().GetTrace();
1805
1806 if (llvm::Error err = trace_sp->Stop())
1807 result.AppendError(toString(std::move(err)));
1808 else
1810 }
1811};
1812
1813// CommandObjectMultiwordProcessTrace
1815public:
1818 interpreter, "trace", "Commands for tracing the current process.",
1819 "process trace <subcommand> [<subcommand objects>]") {
1821 interpreter)));
1823 new CommandObjectProcessTraceStop(interpreter)));
1824 }
1825
1827};
1828
1829// CommandObjectMultiwordProcess
1830
1832 CommandInterpreter &interpreter)
1834 interpreter, "process",
1835 "Commands for interacting with processes on the current platform.",
1836 "process <subcommand> [<subcommand-options>]") {
1837 LoadSubCommand("attach",
1839 LoadSubCommand("launch",
1842 interpreter)));
1843 LoadSubCommand("connect",
1845 LoadSubCommand("detach",
1847 LoadSubCommand("load",
1848 CommandObjectSP(new CommandObjectProcessLoad(interpreter)));
1849 LoadSubCommand("unload",
1851 LoadSubCommand("signal",
1853 LoadSubCommand("handle",
1855 LoadSubCommand("status",
1858 interpreter)));
1859 LoadSubCommand("kill",
1860 CommandObjectSP(new CommandObjectProcessKill(interpreter)));
1861 LoadSubCommand("plugin",
1864 interpreter)));
1866 "trace",
1868}
1869
static llvm::raw_ostream & error(Stream &strm)
~CommandObjectMultiwordProcessTrace() override=default
CommandObjectMultiwordProcessTrace(CommandInterpreter &interpreter)
CommandOptionsProcessAttach m_options
~CommandObjectProcessAttach() override=default
OptionGroupPythonClassWithDict m_class_options
CommandObjectProcessAttach(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
~CommandObjectProcessConnect() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectProcessConnect(CommandInterpreter &interpreter)
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *exe_ctx) override
Set the value of an option.
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void OptionParsingStarting(ExecutionContext *execution_context) override
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectProcessContinue(CommandInterpreter &interpreter)
~CommandObjectProcessContinue() override=default
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectProcessDetach(CommandInterpreter &interpreter)
~CommandObjectProcessDetach() override=default
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
CommandObjectProcessHandle(CommandInterpreter &interpreter)
~CommandObjectProcessHandle() override=default
void DoExecute(Args &signal_args, CommandReturnObject &result) override
void PrintSignalInformation(Stream &str, Args &signal_args, int num_valid_signals, const UnixSignalsSP &signals_sp)
void PrintSignal(Stream &str, int32_t signo, llvm::StringRef sig_name, const UnixSignalsSP &signals_sp)
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectProcessInterrupt(CommandInterpreter &interpreter)
~CommandObjectProcessInterrupt() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectProcessKill() override=default
CommandObjectProcessKill(CommandInterpreter &interpreter)
bool StopProcessIfNecessary(Process *process, StateType &state, CommandReturnObject &result)
CommandObjectProcessLaunchOrAttach(CommandInterpreter &interpreter, const char *name, const char *help, const char *syntax, uint32_t flags, const char *new_process_action)
~CommandObjectProcessLaunchOrAttach() override=default
void DoExecute(Args &launch_args, CommandReturnObject &result) override
OptionGroupPythonClassWithDict m_class_options
std::optional< std::string > GetRepeatCommand(Args &current_command_args, uint32_t index) override
Get the command that appropriate for a "repeat" of the current command.
~CommandObjectProcessLaunch() override=default
CommandOptionsProcessLaunch m_options
CommandObjectProcessLaunch(CommandInterpreter &interpreter)
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
~CommandObjectProcessLoad() override=default
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectProcessLoad(CommandInterpreter &interpreter)
~CommandObjectProcessPlugin() override=default
CommandObjectProcessPlugin(CommandInterpreter &interpreter)
CommandObject * GetProxyCommandObject() override
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
~CommandObjectProcessSaveCore() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectProcessSaveCore(CommandInterpreter &interpreter)
CommandObjectProcessSignal(CommandInterpreter &interpreter)
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
~CommandObjectProcessSignal() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
CommandObjectProcessStatus(CommandInterpreter &interpreter)
~CommandObjectProcessStatus() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectProcessTraceStart(CommandInterpreter &interpreter)
lldb::CommandObjectSP GetDelegateCommand(Trace &trace) override
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectProcessTraceStop(CommandInterpreter &interpreter)
~CommandObjectProcessTraceStop() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectProcessUnload(CommandInterpreter &interpreter)
~CommandObjectProcessUnload() override=default
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
An architecture specification class.
Definition: ArchSpec.h:31
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:359
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:461
bool IsExactMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, ExactMatch).
Definition: ArchSpec.h:508
A command line argument class.
Definition: Args.h:33
void AppendArguments(const Args &rhs)
Definition: Args.cpp:307
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition: Args.h:120
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
Definition: Args.cpp:332
llvm::ArrayRef< ArgEntry > entries() const
Definition: Args.h:132
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
Definition: Args.cpp:273
void Clear()
Clear the arguments.
Definition: Args.cpp:388
bool Contains(BreakpointID bp_id) const
bool AddBreakpointID(BreakpointID bp_id)
BreakpointID GetBreakpointIDAtIndex(size_t index) const
void SetBreakpointLocationID(lldb::break_id_t loc_id)
Definition: BreakpointID.h:44
lldb::break_id_t GetBreakpointID() const
Definition: BreakpointID.h:33
lldb::break_id_t GetLocationID() const
Definition: BreakpointID.h:35
General Outline: Allows adding and removing breakpoints and find by ID and index.
BreakpointIterable Breakpoints()
lldb::BreakpointSP FindBreakpointByID(lldb::break_id_t breakID) const
Returns a shared pointer to the breakpoint with id breakID.
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition: Breakpoint.h:81
void SetIgnoreCount(uint32_t count)
Set the breakpoint to ignore the next count breakpoint hits.
Definition: Breakpoint.cpp:302
bool IsInternal() const
Tell whether this breakpoint is an "internal" breakpoint.
Definition: Breakpoint.cpp:250
bool Confirm(llvm::StringRef message, bool default_answer)
bool HandleCommand(const char *command_line, LazyBool add_to_history, const ExecutionContext &override_context, CommandReturnObject &result)
ExecutionContext GetExecutionContext() const
lldb::PlatformSP GetPlatform(bool prefer_target_platform)
static void VerifyBreakpointOrLocationIDs(Args &args, Target &target, CommandReturnObject &result, BreakpointIDList *valid_ids, BreakpointName::Permissions ::PermissionKinds purpose)
CommandObjectMultiwordProcess(CommandInterpreter &interpreter)
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
This class works by delegating the logic to the actual trace plug-in that can support the current pro...
virtual void SetHelpLong(llvm::StringRef str)
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
ExecutionContext m_exe_ctx
CommandInterpreter & m_interpreter
virtual void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector)
The default version handles argument definitions that have only one argument type,...
void AppendErrorWithFormatv(const char *format, Args &&... args)
void AppendMessage(llvm::StringRef in_string)
void void AppendError(llvm::StringRef in_string)
void AppendWarningWithFormat(const char *format,...) __attribute__((format(printf
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
void void AppendWarning(llvm::StringRef in_string)
"lldb/Utility/ArgCompletionRequest.h"
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
A class to manage flag bits.
Definition: Debugger.h:80
lldb::TargetSP GetSelectedTarget()
Definition: Debugger.h:185
void SetAsyncExecution(bool async)
Definition: Debugger.cpp:1018
TargetList & GetTargetList()
Get accessor for the target list.
Definition: Debugger.h:198
std::pair< iterator, bool > insert(llvm::StringRef KeyEqValue)
Definition: Environment.h:71
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool HasProcessScope() const
Returns true the ExecutionContext object contains a valid target and process.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
Process * GetProcessPtr() const
Returns a pointer to the process object.
A file utility class.
Definition: FileSpec.h:56
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition: FileSpec.cpp:174
void Clear()
Clears the object state.
Definition: FileSpec.cpp:259
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
static FileSystem & Instance()
ValueType Clear(ValueType mask=~static_cast< ValueType >(0))
Clear one or more flags.
Definition: Flags.h:61
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
Definition: Flags.h:73
void Append(OptionGroup *group)
Append options from a OptionGroup class.
Definition: Options.cpp:788
const StructuredData::DictionarySP GetStructuredData()
A command line option parsing protocol class.
Definition: Options.h:58
std::vector< Option > m_getopt_table
Definition: Options.h:198
static Status SaveCore(const lldb::ProcessSP &process_sp, lldb_private::SaveCoreOptions &core_options)
void SetProcessPluginName(llvm::StringRef plugin)
Definition: Process.h:162
bool GetContinueOnceAttached() const
Definition: Process.h:150
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
Definition: ProcessInfo.cpp:65
void SetScriptedMetadata(lldb::ScriptedMetadataSP metadata_sp)
Definition: ProcessInfo.h:97
FileSpec & GetExecutableFile()
Definition: ProcessInfo.h:43
Environment & GetEnvironment()
Definition: ProcessInfo.h:88
void SetProcessPluginName(llvm::StringRef plugin)
void SetWorkingDirectory(const FileSpec &working_dir)
const FileSpec & GetWorkingDirectory() const
bool GetDetachKeepsStopped() const
Definition: Process.cpp:292
A plug-in interface definition class for debugging a process.
Definition: Process.h:343
StopPointSiteList< lldb_private::BreakpointSite > & GetBreakpointSiteList()
Definition: Process.cpp:1583
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
Definition: Process.h:542
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:3510
ThreadList & GetThreadList()
Definition: Process.h:2182
Status Resume()
Resumes all of a process's threads as configured using the Thread run control functions.
Definition: Process.cpp:1355
Status ResumeSynchronous(Stream *stream)
Resume a process, and wait for it to stop.
Definition: Process.cpp:1372
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:5767
Status Detach(bool keep_stopped)
Detaches from a running or stopped process.
Definition: Process.cpp:3458
Status Signal(int signal)
Sends a process a UNIX signal signal.
Definition: Process.cpp:3591
lldb::StateType GetState()
Get accessor for the current process state.
Definition: Process.cpp:1308
void GetStatus(Stream &ostrm)
Definition: Process.cpp:5747
uint32_t GetIOHandlerID() const
Definition: Process.h:2244
bool GetShouldDetach() const
Definition: Process.h:766
const std::vector< lldb::addr_t > & GetImageTokens()
Get the image vector for the current process.
Definition: Process.h:774
virtual bool IsAlive()
Check if a process is still alive.
Definition: Process.cpp:1100
virtual ArchSpec GetSystemArchitecture()
Get the system architecture for this process.
Definition: Process.h:732
virtual CommandObject * GetPluginCommandObject()
Return a multi-word command object that can be used to expose plug-in specific commands.
Definition: Process.h:591
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:636
lldb::addr_t GetDataAddressMask()
Definition: Process.cpp:5879
const lldb::UnixSignalsSP & GetUnixSignals()
Definition: Process.cpp:3606
lldb::addr_t GetCodeAddressMask()
Get the current address mask in the Process.
Definition: Process.cpp:5872
Status Halt(bool clear_thread_plans=false, bool use_run_lock=true)
Halts a running process.
Definition: Process.cpp:3303
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1246
lldb_private::Status SetPluginName(const char *name)
void SetStyle(lldb::SaveCoreStyle style)
void SetOutputFile(lldb_private::FileSpec file)
An error handling class.
Definition: Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition: Status.cpp:106
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:195
bool Success() const
Test for success condition.
Definition: Status.cpp:304
StopPointSiteSP FindByID(typename StopPointSite::SiteID site_id)
Returns a shared pointer to the site with id site_id.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
void Format(const char *format, Args &&... args)
Definition: Stream.h:353
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:155
std::shared_ptr< Dictionary > DictionarySP
Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path, llvm::StringRef triple_str, LoadDependentFiles get_dependent_modules, const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp)
Create a new Target.
Definition: TargetList.cpp:45
llvm::StringRef GetLaunchWorkingDirectory() const
Definition: Target.cpp:4491
llvm::StringRef GetArg0() const
Definition: Target.cpp:4538
void SetRunArguments(const Args &args)
Definition: Target.cpp:4555
const ProcessLaunchInfo & GetProcessLaunchInfo() const
Definition: Target.cpp:4967
Environment GetEnvironment() const
Definition: Target.cpp:4589
void SetProcessLaunchInfo(const ProcessLaunchInfo &launch_info)
Definition: Target.cpp:4971
void ClearDummySignals(Args &signal_names)
Clear the dummy signals in signal_names from the target, or all signals if signal_names is empty.
Definition: Target.cpp:3757
BreakpointList & GetBreakpointList(bool internal=false)
Definition: Target.cpp:391
const lldb::ProcessSP & GetProcessSP() const
Definition: Target.cpp:297
Status Launch(ProcessLaunchInfo &launch_info, Stream *stream)
Definition: Target.cpp:3323
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition: Target.cpp:1504
lldb::PlatformSP GetPlatform()
Definition: Target.h:1463
const ArchSpec & GetArchitecture() const
Definition: Target.h:1039
void AddDummySignal(llvm::StringRef name, LazyBool pass, LazyBool print, LazyBool stop)
Add a signal to the Target's list of stored signals/actions.
Definition: Target.cpp:3688
void PrintDummySignals(Stream &strm, Args &signals)
Print all the signals set in this target.
Definition: Target.cpp:3782
Status Attach(ProcessAttachInfo &attach_info, Stream *stream)
Definition: Target.cpp:3522
uint32_t GetSize(bool can_update=true)
Definition: ThreadList.cpp:82
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
Definition: ThreadList.cpp:90
std::recursive_mutex & GetMutex() const override
Definition: ThreadList.cpp:787
A plug-in interface definition class for trace information.
Definition: Trace.h:48
virtual lldb::CommandObjectSP GetProcessTraceStartCommand(CommandInterpreter &interpreter)=0
Get the command handle for the "process trace start" command.
#define LLDB_OPT_SET_1
Definition: lldb-defines.h:111
#define LLDB_OPT_SET_2
Definition: lldb-defines.h:112
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
#define LLDB_INVALID_ADDRESS_MASK
Address Mask Bits not used for addressing are set to 1 in the mask; all mask bits set is an invalid v...
Definition: lldb-defines.h:133
#define LLDB_INVALID_SIGNAL_NUMBER
Definition: lldb-defines.h:92
#define LLDB_OPT_SET_ALL
Definition: lldb-defines.h:110
#define LLDB_INVALID_IMAGE_TOKEN
Definition: lldb-defines.h:85
A class that represents a running process on the host machine.
std::vector< OptionArgElement > OptionElementVector
Definition: Options.h:43
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
const char * toString(AppleArm64ExceptionClass EC)
static uint32_t bits(const uint32_t val, const uint32_t msbit, const uint32_t lsbit)
Definition: ARMUtils.h:265
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Trace > TraceSP
Definition: lldb-forward.h:458
std::shared_ptr< lldb_private::BreakpointSite > BreakpointSiteSP
Definition: lldb-forward.h:323
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
Definition: lldb-forward.h:324
@ eSaveCoreUnspecified
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:450
std::shared_ptr< lldb_private::ScriptedMetadata > ScriptedMetadataSP
Definition: lldb-forward.h:407
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
Definition: lldb-forward.h:333
std::shared_ptr< lldb_private::UnixSignals > UnixSignalsSP
Definition: lldb-forward.h:480
std::shared_ptr< lldb_private::Platform > PlatformSP
Definition: lldb-forward.h:388
StateType
Process and Thread States.
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eStateRunning
Process or thread is running and can't be examined.
@ eStateAttaching
Process is currently trying to attach.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
Definition: lldb-forward.h:321
int32_t break_id_t
Definition: lldb-types.h:86
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:389
@ eReturnStatusFailed
@ eReturnStatusSuccessContinuingNoResult
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
@ eArgTypeConnectURL
@ eArgTypeUnsignedInteger
@ eArgTypeUnixSignal
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
Definition: lldb-forward.h:431
uint64_t addr_t
Definition: lldb-types.h:80
@ eStopReasonBreakpoint
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:448
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373
static int64_t ToOptionEnum(llvm::StringRef s, const OptionEnumValues &enum_values, int32_t fail_value, Status &error)
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)