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