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