1 //===-- CommandOptionsProcessLaunch.cpp -----------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "CommandOptionsProcessLaunch.h"
11 #include "lldb/Host/FileSystem.h"
12 #include "lldb/Host/HostInfo.h"
13 #include "lldb/Host/OptionParser.h"
14 #include "lldb/Interpreter/CommandCompletions.h"
15 #include "lldb/Interpreter/CommandObject.h"
16 #include "lldb/Interpreter/CommandOptionArgumentTable.h"
17 #include "lldb/Interpreter/OptionArgParser.h"
18 #include "lldb/Target/ExecutionContext.h"
19 #include "lldb/Target/Platform.h"
20 #include "lldb/Target/Target.h"
22 #include "llvm/ADT/ArrayRef.h"
26 using namespace lldb_private
;
28 #define LLDB_OPTIONS_process_launch
29 #include "CommandOptions.inc"
31 Status
CommandOptionsProcessLaunch::SetOptionValue(
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
;
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
);
43 case 'm': // Stop at user entry point
44 target_sp
->CreateBreakpointAtUserEntry(error
);
46 case 'i': // STDIN for read only
49 if (action
.Open(STDIN_FILENO
, FileSpec(option_arg
), true, false))
50 launch_info
.AppendFileAction(action
);
54 case 'o': // Open STDOUT for write only
57 if (action
.Open(STDOUT_FILENO
, FileSpec(option_arg
), false, true))
58 launch_info
.AppendFileAction(action
);
62 case 'e': // STDERR for write only
65 if (action
.Open(STDERR_FILENO
, FileSpec(option_arg
), false, true))
66 launch_info
.AppendFileAction(action
);
70 case 'P': // Process plug-in name
71 launch_info
.SetProcessPluginName(option_arg
);
74 case 'n': // Disable STDIO
77 const FileSpec
dev_null(FileSystem::DEV_NULL
);
78 if (action
.Open(STDIN_FILENO
, dev_null
, true, false))
79 launch_info
.AppendFileAction(action
);
80 if (action
.Open(STDOUT_FILENO
, dev_null
, false, true))
81 launch_info
.AppendFileAction(action
);
82 if (action
.Open(STDERR_FILENO
, dev_null
, false, true))
83 launch_info
.AppendFileAction(action
);
88 launch_info
.SetWorkingDirectory(FileSpec(option_arg
));
91 case 't': // Open process in new terminal window
92 launch_info
.GetFlags().Set(eLaunchFlagLaunchInTTY
);
96 PlatformSP platform_sp
=
97 target_sp
? target_sp
->GetPlatform() : PlatformSP();
98 launch_info
.GetArchitecture() =
99 Platform::GetAugmentedArchSpec(platform_sp
.get(), option_arg
);
102 case 'A': // Disable ASLR.
105 const bool disable_aslr_arg
=
106 OptionArgParser::ToBoolean(option_arg
, true, &success
);
108 disable_aslr
= disable_aslr_arg
? eLazyBoolYes
: eLazyBoolNo
;
110 return Status::FromErrorStringWithFormat(
111 "Invalid boolean value for disable-aslr option: '%s'",
112 option_arg
.empty() ? "<null>" : option_arg
.str().c_str());
116 case 'X': // shell expand args.
119 const bool expand_args
=
120 OptionArgParser::ToBoolean(option_arg
, true, &success
);
122 launch_info
.SetShellExpandArguments(expand_args
);
124 return Status::FromErrorStringWithFormat(
125 "Invalid boolean value for shell-expand-args option: '%s'",
126 option_arg
.empty() ? "<null>" : option_arg
.str().c_str());
131 if (!option_arg
.empty())
132 launch_info
.SetShell(FileSpec(option_arg
));
134 launch_info
.SetShell(HostInfo::GetDefaultShell());
138 launch_info
.GetEnvironment().insert(option_arg
);
142 return Status::FromErrorStringWithFormat(
143 "unrecognized short option character '%c'", short_option
);
148 llvm::ArrayRef
<OptionDefinition
> CommandOptionsProcessLaunch::GetDefinitions() {
149 return llvm::ArrayRef(g_process_launch_options
);