blob: a5947b3c8ea275276d13508cef9737bd90f512be [file] [log] [blame]
Todd Fiala6d6b55d2014-06-30 00:30:53 +00001//===-- ProcessLaunchInfo.cpp -----------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eugene Zelenko9394d7722016-02-18 00:10:17 +000010#include <climits>
Todd Fiala2850b1b2014-06-30 23:51:35 +000011
Greg Clayton8012cad2014-11-17 19:39:20 +000012#include "lldb/Core/Debugger.h"
Zachary Turner190fadc2016-03-22 17:58:09 +000013#include "lldb/Host/Config.h"
Zachary Turner4eff2d32015-10-14 21:37:36 +000014#include "lldb/Host/FileSystem.h"
Zachary Turner190fadc2016-03-22 17:58:09 +000015#include "lldb/Host/HostInfo.h"
Zachary Turner696b5282014-08-14 16:01:25 +000016#include "lldb/Target/FileAction.h"
Zachary Turner190fadc2016-03-22 17:58:09 +000017#include "lldb/Target/ProcessLaunchInfo.h"
Todd Fiala6d6b55d2014-06-30 00:30:53 +000018#include "lldb/Target/Target.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000019#include "lldb/Utility/Log.h"
Zachary Turner2f3df612017-04-06 21:28:29 +000020#include "lldb/Utility/StreamString.h"
Todd Fiala6d6b55d2014-06-30 00:30:53 +000021
Zachary Turner190fadc2016-03-22 17:58:09 +000022#include "llvm/Support/ConvertUTF.h"
Pavel Labath1d5855b2017-01-23 15:56:45 +000023#include "llvm/Support/FileSystem.h"
Zachary Turner190fadc2016-03-22 17:58:09 +000024
25#if !defined(_WIN32)
26#include <limits.h>
27#endif
28
Todd Fiala6d6b55d2014-06-30 00:30:53 +000029using namespace lldb;
30using namespace lldb_private;
31
32//----------------------------------------------------------------------------
Todd Fiala6d6b55d2014-06-30 00:30:53 +000033// ProcessLaunchInfo member functions
34//----------------------------------------------------------------------------
35
Kate Stoneb9c1b512016-09-06 20:57:50 +000036ProcessLaunchInfo::ProcessLaunchInfo()
37 : ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(0),
Pavel Labath07d6f882017-12-11 10:09:14 +000038 m_file_actions(), m_pty(new PseudoTerminal), m_resume_count(0),
39 m_monitor_callback(nullptr), m_monitor_callback_baton(nullptr),
40 m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp() {}
Todd Fiala6d6b55d2014-06-30 00:30:53 +000041
Chaoren Lind3173f32015-05-29 19:52:29 +000042ProcessLaunchInfo::ProcessLaunchInfo(const FileSpec &stdin_file_spec,
43 const FileSpec &stdout_file_spec,
44 const FileSpec &stderr_file_spec,
45 const FileSpec &working_directory,
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 uint32_t launch_flags)
47 : ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(launch_flags),
Pavel Labath07d6f882017-12-11 10:09:14 +000048 m_file_actions(), m_pty(new PseudoTerminal), m_resume_count(0),
49 m_monitor_callback(nullptr), m_monitor_callback_baton(nullptr),
50 m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp() {
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 if (stdin_file_spec) {
Todd Fiala6d6b55d2014-06-30 00:30:53 +000052 FileAction file_action;
Kate Stoneb9c1b512016-09-06 20:57:50 +000053 const bool read = true;
54 const bool write = false;
55 if (file_action.Open(STDIN_FILENO, stdin_file_spec, read, write))
56 AppendFileAction(file_action);
57 }
58 if (stdout_file_spec) {
Todd Fiala6d6b55d2014-06-30 00:30:53 +000059 FileAction file_action;
Kate Stoneb9c1b512016-09-06 20:57:50 +000060 const bool read = false;
61 const bool write = true;
62 if (file_action.Open(STDOUT_FILENO, stdout_file_spec, read, write))
63 AppendFileAction(file_action);
64 }
65 if (stderr_file_spec) {
Todd Fiala6d6b55d2014-06-30 00:30:53 +000066 FileAction file_action;
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 const bool read = false;
68 const bool write = true;
69 if (file_action.Open(STDERR_FILENO, stderr_file_spec, read, write))
70 AppendFileAction(file_action);
71 }
72 if (working_directory)
73 SetWorkingDirectory(working_directory);
Todd Fiala6d6b55d2014-06-30 00:30:53 +000074}
75
Kate Stoneb9c1b512016-09-06 20:57:50 +000076bool ProcessLaunchInfo::AppendCloseFileAction(int fd) {
77 FileAction file_action;
78 if (file_action.Close(fd)) {
79 AppendFileAction(file_action);
80 return true;
81 }
82 return false;
Todd Fiala6d6b55d2014-06-30 00:30:53 +000083}
84
Kate Stoneb9c1b512016-09-06 20:57:50 +000085bool ProcessLaunchInfo::AppendDuplicateFileAction(int fd, int dup_fd) {
86 FileAction file_action;
87 if (file_action.Duplicate(fd, dup_fd)) {
88 AppendFileAction(file_action);
89 return true;
90 }
91 return false;
Todd Fiala6d6b55d2014-06-30 00:30:53 +000092}
93
Kate Stoneb9c1b512016-09-06 20:57:50 +000094bool ProcessLaunchInfo::AppendOpenFileAction(int fd, const FileSpec &file_spec,
95 bool read, bool write) {
96 FileAction file_action;
97 if (file_action.Open(fd, file_spec, read, write)) {
98 AppendFileAction(file_action);
99 return true;
100 }
101 return false;
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000102}
103
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104bool ProcessLaunchInfo::AppendSuppressFileAction(int fd, bool read,
105 bool write) {
106 FileAction file_action;
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +0000107 if (file_action.Open(fd, FileSpec(FileSystem::DEV_NULL), read, write)) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108 AppendFileAction(file_action);
109 return true;
110 }
111 return false;
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000112}
113
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114const FileAction *ProcessLaunchInfo::GetFileActionAtIndex(size_t idx) const {
115 if (idx < m_file_actions.size())
116 return &m_file_actions[idx];
117 return nullptr;
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000118}
119
Kate Stoneb9c1b512016-09-06 20:57:50 +0000120const FileAction *ProcessLaunchInfo::GetFileActionForFD(int fd) const {
121 for (size_t idx = 0, count = m_file_actions.size(); idx < count; ++idx) {
122 if (m_file_actions[idx].GetFD() == fd)
123 return &m_file_actions[idx];
124 }
125 return nullptr;
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000126}
127
Kate Stoneb9c1b512016-09-06 20:57:50 +0000128const FileSpec &ProcessLaunchInfo::GetWorkingDirectory() const {
129 return m_working_dir;
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000130}
131
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132void ProcessLaunchInfo::SetWorkingDirectory(const FileSpec &working_dir) {
133 m_working_dir = working_dir;
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000134}
135
Kate Stoneb9c1b512016-09-06 20:57:50 +0000136const char *ProcessLaunchInfo::GetProcessPluginName() const {
137 return (m_plugin_name.empty() ? nullptr : m_plugin_name.c_str());
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000138}
139
Zachary Turnerfe114832016-11-12 16:56:47 +0000140void ProcessLaunchInfo::SetProcessPluginName(llvm::StringRef plugin) {
141 m_plugin_name = plugin;
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000142}
143
Kate Stoneb9c1b512016-09-06 20:57:50 +0000144const FileSpec &ProcessLaunchInfo::GetShell() const { return m_shell; }
145
146void ProcessLaunchInfo::SetShell(const FileSpec &shell) {
147 m_shell = shell;
148 if (m_shell) {
Jonas Devlieghere2c22c802018-11-01 17:09:22 +0000149 FileSystem::Instance().ResolveExecutableLocation(m_shell);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150 m_flags.Set(lldb::eLaunchFlagLaunchInShell);
151 } else
152 m_flags.Clear(lldb::eLaunchFlagLaunchInShell);
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000153}
154
Kate Stoneb9c1b512016-09-06 20:57:50 +0000155void ProcessLaunchInfo::SetLaunchInSeparateProcessGroup(bool separate) {
156 if (separate)
157 m_flags.Set(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
158 else
159 m_flags.Clear(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
160}
161
162void ProcessLaunchInfo::SetShellExpandArguments(bool expand) {
163 if (expand)
164 m_flags.Set(lldb::eLaunchFlagShellExpandArguments);
165 else
166 m_flags.Clear(lldb::eLaunchFlagShellExpandArguments);
167}
168
169void ProcessLaunchInfo::Clear() {
170 ProcessInfo::Clear();
171 m_working_dir.Clear();
172 m_plugin_name.clear();
173 m_shell.Clear();
174 m_flags.Clear();
175 m_file_actions.clear();
176 m_resume_count = 0;
177 m_listener_sp.reset();
178 m_hijack_listener_sp.reset();
179}
180
181void ProcessLaunchInfo::SetMonitorProcessCallback(
182 const Host::MonitorChildProcessCallback &callback, bool monitor_signals) {
183 m_monitor_callback = callback;
184 m_monitor_signals = monitor_signals;
185}
186
Pavel Labath245dd2e2018-05-15 13:42:26 +0000187bool ProcessLaunchInfo::NoOpMonitorCallback(lldb::pid_t pid, bool exited, int signal, int status) {
188 Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS);
189 LLDB_LOG(log, "pid = {0}, exited = {1}, signal = {2}, status = {3}", pid,
190 exited, signal, status);
191 return true;
192}
193
Kate Stoneb9c1b512016-09-06 20:57:50 +0000194bool ProcessLaunchInfo::MonitorProcess() const {
195 if (m_monitor_callback && ProcessIDIsValid()) {
196 Host::StartMonitoringChildProcess(m_monitor_callback, GetProcessID(),
197 m_monitor_signals);
198 return true;
199 }
200 return false;
201}
202
203void ProcessLaunchInfo::SetDetachOnError(bool enable) {
204 if (enable)
205 m_flags.Set(lldb::eLaunchFlagDetachOnError);
206 else
207 m_flags.Clear(lldb::eLaunchFlagDetachOnError);
208}
209
210void ProcessLaunchInfo::FinalizeFileActions(Target *target,
211 bool default_to_use_pty) {
212 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
213
214 // If nothing for stdin or stdout or stderr was specified, then check the
Adrian Prantl05097242018-04-30 16:49:04 +0000215 // process for any default settings that were set with "settings set"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000216 if (GetFileActionForFD(STDIN_FILENO) == nullptr ||
217 GetFileActionForFD(STDOUT_FILENO) == nullptr ||
218 GetFileActionForFD(STDERR_FILENO) == nullptr) {
219 if (log)
220 log->Printf("ProcessLaunchInfo::%s at least one of stdin/stdout/stderr "
221 "was not set, evaluating default handling",
222 __FUNCTION__);
223
224 if (m_flags.Test(eLaunchFlagLaunchInTTY)) {
Adrian Prantl05097242018-04-30 16:49:04 +0000225 // Do nothing, if we are launching in a remote terminal no file actions
226 // should be done at all.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000227 return;
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000228 }
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000229
Kate Stoneb9c1b512016-09-06 20:57:50 +0000230 if (m_flags.Test(eLaunchFlagDisableSTDIO)) {
231 if (log)
232 log->Printf("ProcessLaunchInfo::%s eLaunchFlagDisableSTDIO set, adding "
233 "suppression action for stdin, stdout and stderr",
234 __FUNCTION__);
235 AppendSuppressFileAction(STDIN_FILENO, true, false);
236 AppendSuppressFileAction(STDOUT_FILENO, false, true);
237 AppendSuppressFileAction(STDERR_FILENO, false, true);
238 } else {
Adrian Prantl05097242018-04-30 16:49:04 +0000239 // Check for any values that might have gotten set with any of: (lldb)
240 // settings set target.input-path (lldb) settings set target.output-path
Kate Stoneb9c1b512016-09-06 20:57:50 +0000241 // (lldb) settings set target.error-path
242 FileSpec in_file_spec;
243 FileSpec out_file_spec;
244 FileSpec err_file_spec;
245 if (target) {
Adrian Prantl05097242018-04-30 16:49:04 +0000246 // Only override with the target settings if we don't already have an
247 // action for in, out or error
Kate Stoneb9c1b512016-09-06 20:57:50 +0000248 if (GetFileActionForFD(STDIN_FILENO) == nullptr)
249 in_file_spec = target->GetStandardInputPath();
250 if (GetFileActionForFD(STDOUT_FILENO) == nullptr)
251 out_file_spec = target->GetStandardOutputPath();
252 if (GetFileActionForFD(STDERR_FILENO) == nullptr)
253 err_file_spec = target->GetStandardErrorPath();
254 }
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000255
Kate Stoneb9c1b512016-09-06 20:57:50 +0000256 if (log)
257 log->Printf("ProcessLaunchInfo::%s target stdin='%s', target "
258 "stdout='%s', stderr='%s'",
259 __FUNCTION__,
260 in_file_spec ? in_file_spec.GetCString() : "<null>",
261 out_file_spec ? out_file_spec.GetCString() : "<null>",
262 err_file_spec ? err_file_spec.GetCString() : "<null>");
Todd Fiala75f47c32014-10-11 21:42:09 +0000263
Kate Stoneb9c1b512016-09-06 20:57:50 +0000264 if (in_file_spec) {
265 AppendOpenFileAction(STDIN_FILENO, in_file_spec, true, false);
Todd Fiala75f47c32014-10-11 21:42:09 +0000266 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000267 log->Printf(
268 "ProcessLaunchInfo::%s appended stdin open file action for %s",
269 __FUNCTION__, in_file_spec.GetCString());
270 }
Todd Fiala75f47c32014-10-11 21:42:09 +0000271
Kate Stoneb9c1b512016-09-06 20:57:50 +0000272 if (out_file_spec) {
273 AppendOpenFileAction(STDOUT_FILENO, out_file_spec, false, true);
274 if (log)
275 log->Printf(
276 "ProcessLaunchInfo::%s appended stdout open file action for %s",
277 __FUNCTION__, out_file_spec.GetCString());
278 }
Greg Claytonbf91f712015-07-10 18:04:46 +0000279
Kate Stoneb9c1b512016-09-06 20:57:50 +0000280 if (err_file_spec) {
281 AppendOpenFileAction(STDERR_FILENO, err_file_spec, false, true);
282 if (log)
283 log->Printf(
284 "ProcessLaunchInfo::%s appended stderr open file action for %s",
285 __FUNCTION__, err_file_spec.GetCString());
286 }
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000287
Kate Stoneb9c1b512016-09-06 20:57:50 +0000288 if (default_to_use_pty &&
289 (!in_file_spec || !out_file_spec || !err_file_spec)) {
290 if (log)
291 log->Printf("ProcessLaunchInfo::%s default_to_use_pty is set, and at "
292 "least one stdin/stderr/stdout is unset, so generating a "
293 "pty to use for it",
294 __FUNCTION__);
Todd Fiala75f47c32014-10-11 21:42:09 +0000295
Kate Stoneb9c1b512016-09-06 20:57:50 +0000296 int open_flags = O_RDWR | O_NOCTTY;
Hafiz Abid Qadeerf6ee79c2016-12-15 15:00:41 +0000297#if !defined(_WIN32)
Adrian Prantl05097242018-04-30 16:49:04 +0000298 // We really shouldn't be specifying platform specific flags that are
299 // intended for a system call in generic code. But this will have to
300 // do for now.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000301 open_flags |= O_CLOEXEC;
Zachary Turner362a8132015-02-04 19:11:48 +0000302#endif
Kate Stoneb9c1b512016-09-06 20:57:50 +0000303 if (m_pty->OpenFirstAvailableMaster(open_flags, nullptr, 0)) {
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +0000304 const FileSpec slave_file_spec(m_pty->GetSlaveName(nullptr, 0));
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000305
Kate Stoneb9c1b512016-09-06 20:57:50 +0000306 // Only use the slave tty if we don't have anything specified for
307 // input and don't have an action for stdin
308 if (!in_file_spec && GetFileActionForFD(STDIN_FILENO) == nullptr) {
309 AppendOpenFileAction(STDIN_FILENO, slave_file_spec, true, false);
310 }
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000311
Kate Stoneb9c1b512016-09-06 20:57:50 +0000312 // Only use the slave tty if we don't have anything specified for
313 // output and don't have an action for stdout
314 if (!out_file_spec && GetFileActionForFD(STDOUT_FILENO) == nullptr) {
315 AppendOpenFileAction(STDOUT_FILENO, slave_file_spec, false, true);
316 }
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000317
Kate Stoneb9c1b512016-09-06 20:57:50 +0000318 // Only use the slave tty if we don't have anything specified for
319 // error and don't have an action for stderr
320 if (!err_file_spec && GetFileActionForFD(STDERR_FILENO) == nullptr) {
321 AppendOpenFileAction(STDERR_FILENO, slave_file_spec, false, true);
322 }
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000323 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000324 }
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000325 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000326 }
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000327}
328
Kate Stoneb9c1b512016-09-06 20:57:50 +0000329bool ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell(
Zachary Turner97206d52017-05-12 04:51:55 +0000330 Status &error, bool localhost, bool will_debug,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000331 bool first_arg_is_full_shell_command, int32_t num_resumes) {
332 error.Clear();
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000333
Kate Stoneb9c1b512016-09-06 20:57:50 +0000334 if (GetFlags().Test(eLaunchFlagLaunchInShell)) {
335 if (m_shell) {
336 std::string shell_executable = m_shell.GetPath();
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000337
Kate Stoneb9c1b512016-09-06 20:57:50 +0000338 const char **argv = GetArguments().GetConstArgumentVector();
339 if (argv == nullptr || argv[0] == nullptr)
340 return false;
341 Args shell_arguments;
342 std::string safe_arg;
Zachary Turnerecbb0bb2016-09-19 17:54:06 +0000343 shell_arguments.AppendArgument(shell_executable);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000344 const llvm::Triple &triple = GetArchitecture().GetTriple();
345 if (triple.getOS() == llvm::Triple::Win32 &&
346 !triple.isWindowsCygwinEnvironment())
Zachary Turnerecbb0bb2016-09-19 17:54:06 +0000347 shell_arguments.AppendArgument(llvm::StringRef("/C"));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000348 else
Zachary Turnerecbb0bb2016-09-19 17:54:06 +0000349 shell_arguments.AppendArgument(llvm::StringRef("-c"));
Zachary Turner270e99a2014-12-08 21:36:42 +0000350
Kate Stoneb9c1b512016-09-06 20:57:50 +0000351 StreamString shell_command;
352 if (will_debug) {
Adrian Prantl05097242018-04-30 16:49:04 +0000353 // Add a modified PATH environment variable in case argv[0] is a
354 // relative path.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000355 const char *argv0 = argv[0];
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +0000356 FileSpec arg_spec(argv0);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000357 if (arg_spec.IsRelative()) {
Adrian Prantl05097242018-04-30 16:49:04 +0000358 // We have a relative path to our executable which may not work if we
359 // just try to run "a.out" (without it being converted to "./a.out")
Kate Stoneb9c1b512016-09-06 20:57:50 +0000360 FileSpec working_dir = GetWorkingDirectory();
361 // Be sure to put quotes around PATH's value in case any paths have
362 // spaces...
363 std::string new_path("PATH=\"");
364 const size_t empty_path_len = new_path.size();
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000365
Kate Stoneb9c1b512016-09-06 20:57:50 +0000366 if (working_dir) {
367 new_path += working_dir.GetPath();
368 } else {
Pavel Labath1d5855b2017-01-23 15:56:45 +0000369 llvm::SmallString<64> cwd;
370 if (! llvm::sys::fs::current_path(cwd))
Kate Stoneb9c1b512016-09-06 20:57:50 +0000371 new_path += cwd;
372 }
373 std::string curr_path;
374 if (HostInfo::GetEnvironmentVar("PATH", curr_path)) {
375 if (new_path.size() > empty_path_len)
376 new_path += ':';
377 new_path += curr_path;
378 }
379 new_path += "\" ";
Malcolm Parsons771ef6d2016-11-02 20:34:10 +0000380 shell_command.PutCString(new_path);
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000381 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000382
383 if (triple.getOS() != llvm::Triple::Win32 ||
384 triple.isWindowsCygwinEnvironment())
385 shell_command.PutCString("exec");
386
387 // Only Apple supports /usr/bin/arch being able to specify the
388 // architecture
389 if (GetArchitecture().IsValid() && // Valid architecture
390 GetArchitecture().GetTriple().getVendor() ==
391 llvm::Triple::Apple && // Apple only
392 GetArchitecture().GetCore() !=
393 ArchSpec::eCore_x86_64_x86_64h) // Don't do this for x86_64h
394 {
395 shell_command.Printf(" /usr/bin/arch -arch %s",
396 GetArchitecture().GetArchitectureName());
397 // Set the resume count to 2:
398 // 1 - stop in shell
399 // 2 - stop in /usr/bin/arch
400 // 3 - then we will stop in our program
401 SetResumeCount(num_resumes + 1);
402 } else {
403 // Set the resume count to 1:
404 // 1 - stop in shell
405 // 2 - then we will stop in our program
406 SetResumeCount(num_resumes);
407 }
408 }
409
410 if (first_arg_is_full_shell_command) {
Adrian Prantl05097242018-04-30 16:49:04 +0000411 // There should only be one argument that is the shell command itself
412 // to be used as is
Kate Stoneb9c1b512016-09-06 20:57:50 +0000413 if (argv[0] && !argv[1])
414 shell_command.Printf("%s", argv[0]);
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000415 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000416 return false;
417 } else {
418 for (size_t i = 0; argv[i] != nullptr; ++i) {
419 const char *arg =
420 Args::GetShellSafeArgument(m_shell, argv[i], safe_arg);
421 shell_command.Printf(" %s", arg);
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000422 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000423 }
Zachary Turnerecbb0bb2016-09-19 17:54:06 +0000424 shell_arguments.AppendArgument(shell_command.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000425 m_executable = m_shell;
426 m_arguments = shell_arguments;
427 return true;
428 } else {
429 error.SetErrorString("invalid shell path");
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000430 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000431 } else {
432 error.SetErrorString("not launching in shell");
433 }
434 return false;
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000435}
Greg Clayton8012cad2014-11-17 19:39:20 +0000436
Kate Stoneb9c1b512016-09-06 20:57:50 +0000437ListenerSP ProcessLaunchInfo::GetListenerForProcess(Debugger &debugger) {
438 if (m_listener_sp)
439 return m_listener_sp;
440 else
441 return debugger.GetListener();
Greg Clayton8012cad2014-11-17 19:39:20 +0000442}