LLDB mainline
CommandOptionsProcessLaunch.cpp
Go to the documentation of this file.
1//===-- CommandOptionsProcessLaunch.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
10
12#include "lldb/Host/HostInfo.h"
20#include "lldb/Target/Target.h"
21
22#include "llvm/ADT/ArrayRef.h"
23
24using namespace llvm;
25using namespace lldb;
26using namespace lldb_private;
27
28#define LLDB_OPTIONS_process_launch
29#include "CommandOptions.inc"
30
32 uint32_t option_idx, llvm::StringRef option_arg,
33 ExecutionContext *execution_context) {
35 const int short_option = g_process_launch_options[option_idx].short_option;
36
37 switch (short_option) {
38 case 's': // Stop at program entry point
39 launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
40 break;
41
42 case 'i': // STDIN for read only
43 {
44 FileAction action;
45 if (action.Open(STDIN_FILENO, FileSpec(option_arg), true, false))
47 break;
48 }
49
50 case 'o': // Open STDOUT for write only
51 {
52 FileAction action;
53 if (action.Open(STDOUT_FILENO, FileSpec(option_arg), false, true))
55 break;
56 }
57
58 case 'e': // STDERR for write only
59 {
60 FileAction action;
61 if (action.Open(STDERR_FILENO, FileSpec(option_arg), false, true))
63 break;
64 }
65
66 case 'P': // Process plug-in name
68 break;
69
70 case 'n': // Disable STDIO
71 {
72 FileAction action;
73 const FileSpec dev_null(FileSystem::DEV_NULL);
74 if (action.Open(STDIN_FILENO, dev_null, true, false))
76 if (action.Open(STDOUT_FILENO, dev_null, false, true))
78 if (action.Open(STDERR_FILENO, dev_null, false, true))
80 break;
81 }
82
83 case 'w':
85 break;
86
87 case 't': // Open process in new terminal window
88 launch_info.GetFlags().Set(eLaunchFlagLaunchInTTY);
89 break;
90
91 case 'a': {
92 TargetSP target_sp =
93 execution_context ? execution_context->GetTargetSP() : TargetSP();
94 PlatformSP platform_sp =
95 target_sp ? target_sp->GetPlatform() : PlatformSP();
97 Platform::GetAugmentedArchSpec(platform_sp.get(), option_arg);
98 } break;
99
100 case 'A': // Disable ASLR.
101 {
102 bool success;
103 const bool disable_aslr_arg =
104 OptionArgParser::ToBoolean(option_arg, true, &success);
105 if (success)
106 disable_aslr = disable_aslr_arg ? eLazyBoolYes : eLazyBoolNo;
107 else
108 error.SetErrorStringWithFormat(
109 "Invalid boolean value for disable-aslr option: '%s'",
110 option_arg.empty() ? "<null>" : option_arg.str().c_str());
111 break;
112 }
113
114 case 'X': // shell expand args.
115 {
116 bool success;
117 const bool expand_args =
118 OptionArgParser::ToBoolean(option_arg, true, &success);
119 if (success)
121 else
122 error.SetErrorStringWithFormat(
123 "Invalid boolean value for shell-expand-args option: '%s'",
124 option_arg.empty() ? "<null>" : option_arg.str().c_str());
125 break;
126 }
127
128 case 'c':
129 if (!option_arg.empty())
130 launch_info.SetShell(FileSpec(option_arg));
131 else
132 launch_info.SetShell(HostInfo::GetDefaultShell());
133 break;
134
135 case 'E':
136 launch_info.GetEnvironment().insert(option_arg);
137 break;
138
139 default:
140 error.SetErrorStringWithFormat("unrecognized short option character '%c'",
141 short_option);
142 break;
143 }
144 return error;
145}
146
147llvm::ArrayRef<OptionDefinition> CommandOptionsProcessLaunch::GetDefinitions() {
148 return llvm::ArrayRef(g_process_launch_options);
149}
static llvm::raw_ostream & error(Stream &strm)
lldb_private::Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, lldb_private::ExecutionContext *execution_context) override
llvm::ArrayRef< lldb_private::OptionDefinition > GetDefinitions() override
std::pair< iterator, bool > insert(llvm::StringRef KeyEqValue)
Definition: Environment.h:71
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
bool Open(int fd, const FileSpec &file_spec, bool read, bool write)
Definition: FileAction.cpp:34
A file utility class.
Definition: FileSpec.h:56
static const char * DEV_NULL
Definition: FileSystem.h:30
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
Definition: Flags.h:73
static ArchSpec GetAugmentedArchSpec(Platform *platform, llvm::StringRef triple)
Augments the triple either with information from platform or the host system (if platform is null).
Definition: Platform.cpp:265
Environment & GetEnvironment()
Definition: ProcessInfo.h:87
ArchSpec & GetArchitecture()
Definition: ProcessInfo.h:61
void SetShell(const FileSpec &shell)
void SetProcessPluginName(llvm::StringRef plugin)
void AppendFileAction(const FileAction &info)
void SetWorkingDirectory(const FileSpec &working_dir)
An error handling class.
Definition: Status.h:44
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
Definition: Debugger.h:52
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)