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