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 TargetSP target_sp =
38 execution_context ? execution_context->GetTargetSP() : TargetSP();
39 switch (short_option) {
40 case 's': // Stop at program entry point
41 launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
42 break;
43 case 'm': // Stop at user entry point
44 target_sp->CreateBreakpointAtUserEntry(error);
45 break;
46 case 'i': // STDIN for read only
47 {
48 FileAction action;
49 if (action.Open(STDIN_FILENO, FileSpec(option_arg), true, false))
51 break;
52 }
53
54 case 'o': // Open STDOUT for write only
55 {
56 FileAction action;
57 if (action.Open(STDOUT_FILENO, FileSpec(option_arg), false, true))
59 break;
60 }
61
62 case 'e': // STDERR for write only
63 {
64 FileAction action;
65 if (action.Open(STDERR_FILENO, FileSpec(option_arg), false, true))
67 break;
68 }
69
70 case 'P': // Process plug-in name
72 break;
73
74 case 'n': // Disable STDIO
75 {
76 FileAction action;
77 const FileSpec dev_null(FileSystem::DEV_NULL);
78 if (action.Open(STDIN_FILENO, dev_null, true, false))
80 if (action.Open(STDOUT_FILENO, dev_null, false, true))
82 if (action.Open(STDERR_FILENO, dev_null, false, true))
84 break;
85 }
86
87 case 'w':
89 break;
90
91 case 't': // Open process in new terminal window
92 launch_info.GetFlags().Set(eLaunchFlagLaunchInTTY);
93 break;
94
95 case 'a': {
96 PlatformSP platform_sp =
97 target_sp ? target_sp->GetPlatform() : PlatformSP();
99 Platform::GetAugmentedArchSpec(platform_sp.get(), option_arg);
100 } break;
101
102 case 'A': // Disable ASLR.
103 {
104 bool success;
105 const bool disable_aslr_arg =
106 OptionArgParser::ToBoolean(option_arg, true, &success);
107 if (success)
108 disable_aslr = disable_aslr_arg ? eLazyBoolYes : eLazyBoolNo;
109 else
110 error.SetErrorStringWithFormat(
111 "Invalid boolean value for disable-aslr option: '%s'",
112 option_arg.empty() ? "<null>" : option_arg.str().c_str());
113 break;
114 }
115
116 case 'X': // shell expand args.
117 {
118 bool success;
119 const bool expand_args =
120 OptionArgParser::ToBoolean(option_arg, true, &success);
121 if (success)
123 else
124 error.SetErrorStringWithFormat(
125 "Invalid boolean value for shell-expand-args option: '%s'",
126 option_arg.empty() ? "<null>" : option_arg.str().c_str());
127 break;
128 }
129
130 case 'c':
131 if (!option_arg.empty())
132 launch_info.SetShell(FileSpec(option_arg));
133 else
134 launch_info.SetShell(HostInfo::GetDefaultShell());
135 break;
136
137 case 'E':
138 launch_info.GetEnvironment().insert(option_arg);
139 break;
140
141 default:
142 error.SetErrorStringWithFormat("unrecognized short option character '%c'",
143 short_option);
144 break;
145 }
146 return error;
147}
148
149llvm::ArrayRef<OptionDefinition> CommandOptionsProcessLaunch::GetDefinitions() {
150 return llvm::ArrayRef(g_process_launch_options);
151}
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:32
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:227
Environment & GetEnvironment()
Definition: ProcessInfo.h:88
ArchSpec & GetArchitecture()
Definition: ProcessInfo.h:62
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: SBAddress.h:15
std::shared_ptr< lldb_private::Platform > PlatformSP
Definition: lldb-forward.h:386
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:444
Definition: Debugger.h:54
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)