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