summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Host/Host.h2
-rw-r--r--lldb/include/lldb/Host/posix/HostInfoPosix.h3
-rw-r--r--lldb/include/lldb/Host/windows/HostInfoWindows.h1
-rw-r--r--lldb/include/lldb/Target/ProcessLaunchInfo.h7
-rw-r--r--lldb/include/lldb/lldb-defines.h5
-rw-r--r--lldb/source/API/SBTarget.cpp7
-rw-r--r--lldb/source/Host/common/Host.cpp6
-rw-r--r--lldb/source/Host/posix/HostInfoPosix.cpp6
-rw-r--r--lldb/source/Host/windows/HostInfoWindows.cpp6
-rw-r--r--lldb/source/Interpreter/CommandInterpreter.cpp6
-rw-r--r--lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp9
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp9
-rw-r--r--lldb/source/Target/Platform.cpp6
-rw-r--r--lldb/source/Target/Process.cpp4
-rw-r--r--lldb/source/Target/ProcessLaunchInfo.cpp45
-rw-r--r--lldb/source/Target/Target.cpp3
16 files changed, 64 insertions, 61 deletions
diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h
index 6479f1048b8..94f0c680a63 100644
--- a/lldb/include/lldb/Host/Host.h
+++ b/lldb/include/lldb/Host/Host.h
@@ -259,7 +259,7 @@ public:
int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
std::string *command_output, // Pass NULL if you don't want the command output
uint32_t timeout_sec,
- const char *shell = LLDB_DEFAULT_SHELL);
+ bool run_in_default_shell = true);
static lldb::DataBufferSP
GetAuxvData (lldb_private::Process *process);
diff --git a/lldb/include/lldb/Host/posix/HostInfoPosix.h b/lldb/include/lldb/Host/posix/HostInfoPosix.h
index 6e0dcbe4802..9524a2a2481 100644
--- a/lldb/include/lldb/Host/posix/HostInfoPosix.h
+++ b/lldb/include/lldb/Host/posix/HostInfoPosix.h
@@ -10,6 +10,7 @@
#ifndef lldb_Host_posix_HostInfoPosix_h_
#define lldb_Host_posix_HostInfoPosix_h_
+#include "lldb/Host/FileSpec.h"
#include "lldb/Host/HostInfoBase.h"
namespace lldb_private
@@ -30,6 +31,8 @@ class HostInfoPosix : public HostInfoBase
static uint32_t GetEffectiveUserID();
static uint32_t GetEffectiveGroupID();
+ static FileSpec GetDefaultShell();
+
protected:
static bool ComputeSupportExeDirectory(FileSpec &file_spec);
static bool ComputeHeaderDirectory(FileSpec &file_spec);
diff --git a/lldb/include/lldb/Host/windows/HostInfoWindows.h b/lldb/include/lldb/Host/windows/HostInfoWindows.h
index 7077a5173d7..022e15533d3 100644
--- a/lldb/include/lldb/Host/windows/HostInfoWindows.h
+++ b/lldb/include/lldb/Host/windows/HostInfoWindows.h
@@ -33,6 +33,7 @@ class HostInfoWindows : public HostInfoBase
static bool GetOSKernelDescription(std::string &s);
static bool GetHostname(std::string &s);
static FileSpec GetProgramFileSpec();
+ static FileSpec GetDefaultShell();
protected:
static bool ComputePythonDirectory(FileSpec &file_spec);
diff --git a/lldb/include/lldb/Target/ProcessLaunchInfo.h b/lldb/include/lldb/Target/ProcessLaunchInfo.h
index 37752c34418..94e4eb05fdf 100644
--- a/lldb/include/lldb/Target/ProcessLaunchInfo.h
+++ b/lldb/include/lldb/Target/ProcessLaunchInfo.h
@@ -15,6 +15,7 @@
// LLDB Headers
#include "lldb/Core/Flags.h"
+#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Host.h"
#include "lldb/Target/FileAction.h"
#include "lldb/Target/ProcessInfo.h"
@@ -105,11 +106,11 @@ namespace lldb_private
void
SetProcessPluginName (const char *plugin);
- const char *
+ const FileSpec &
GetShell () const;
void
- SetShell (const char * path);
+ SetShell (const FileSpec &shell);
uint32_t
GetResumeCount () const
@@ -215,7 +216,7 @@ namespace lldb_private
protected:
std::string m_working_dir;
std::string m_plugin_name;
- std::string m_shell;
+ FileSpec m_shell;
Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags
std::vector<FileAction> m_file_actions; // File actions for any other files
std::shared_ptr<lldb_utility::PseudoTerminal> m_pty;
diff --git a/lldb/include/lldb/lldb-defines.h b/lldb/include/lldb/lldb-defines.h
index a6caf4228da..add182c13ec 100644
--- a/lldb/include/lldb/lldb-defines.h
+++ b/lldb/include/lldb/lldb-defines.h
@@ -49,11 +49,6 @@
// LLDB defines
//----------------------------------------------------------------------
#define LLDB_GENERIC_ERROR UINT32_MAX
-#if defined(_WIN32)
-#define LLDB_DEFAULT_SHELL "cmd.exe"
-#else
-#define LLDB_DEFAULT_SHELL "/bin/sh"
-#endif
//----------------------------------------------------------------------
// Breakpoints
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index e26692d9d8c..4080bd54d8d 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -236,13 +236,16 @@ SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
const char *
SBLaunchInfo::GetShell ()
{
- return m_opaque_sp->GetShell();
+ // Constify this string so that it is saved in the string pool. Otherwise
+ // it would be freed when this function goes out of scope.
+ ConstString shell(m_opaque_sp->GetShell().GetPath().c_str());
+ return shell.AsCString();
}
void
SBLaunchInfo::SetShell (const char * path)
{
- m_opaque_sp->SetShell (path);
+ m_opaque_sp->SetShell (FileSpec(path, false));
}
uint32_t
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index 87676613809..33729abb2c6 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -550,14 +550,14 @@ Host::RunShellCommand (const char *command,
int *signo_ptr,
std::string *command_output_ptr,
uint32_t timeout_sec,
- const char *shell)
+ bool run_in_default_shell)
{
Error error;
ProcessLaunchInfo launch_info;
- if (shell && shell[0])
+ if (run_in_default_shell)
{
// Run the command in a shell
- launch_info.SetShell(shell);
+ launch_info.SetShell(HostInfo::GetDefaultShell());
launch_info.GetArguments().AppendArgument(command);
const bool localhost = true;
const bool will_debug = false;
diff --git a/lldb/source/Host/posix/HostInfoPosix.cpp b/lldb/source/Host/posix/HostInfoPosix.cpp
index 849171370cb..018d423ee9d 100644
--- a/lldb/source/Host/posix/HostInfoPosix.cpp
+++ b/lldb/source/Host/posix/HostInfoPosix.cpp
@@ -125,6 +125,12 @@ HostInfoPosix::GetEffectiveGroupID()
return getegid();
}
+FileSpec
+HostInfoPosix::GetDefaultShell()
+{
+ return FileSpec("/bin/sh", false);
+}
+
bool
HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec)
{
diff --git a/lldb/source/Host/windows/HostInfoWindows.cpp b/lldb/source/Host/windows/HostInfoWindows.cpp
index 8b2a6600e41..c0366dd47bc 100644
--- a/lldb/source/Host/windows/HostInfoWindows.cpp
+++ b/lldb/source/Host/windows/HostInfoWindows.cpp
@@ -96,6 +96,12 @@ HostInfoWindows::GetProgramFileSpec()
return m_program_filespec;
}
+FileSpec
+HostInfoWindows::GetDefaultShell()
+{
+ return FileSpec(::getenv("ComSpec"), false);
+}
+
bool
HostInfoWindows::ComputePythonDirectory(FileSpec &file_spec)
{
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index b281bf1954c..9097ab007e6 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -339,7 +339,11 @@ CommandInterpreter::Initialize ()
#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__)
ProcessAliasOptionsArgs (cmd_obj_sp, "--", alias_arguments_vector_sp);
#else
- ProcessAliasOptionsArgs (cmd_obj_sp, "--shell=" LLDB_DEFAULT_SHELL " --", alias_arguments_vector_sp);
+ std::string shell_option;
+ shell_option.append("--shell=");
+ shell_option.append(HostInfo::GetDefaultShell().GetPath());
+ shell_option.append(" --");
+ ProcessAliasOptionsArgs (cmd_obj_sp, shell_option.c_str(), alias_arguments_vector_sp);
#endif
AddAlias ("r", cmd_obj_sp);
AddAlias ("run", cmd_obj_sp);
diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
index 94767903264..d158e27bb5e 100644
--- a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -554,17 +554,18 @@ PlatformLinux::GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info)
}
// If we're not launching a shell, we're done.
- const char *shell = launch_info.GetShell();
- if (shell == NULL)
+ const FileSpec &shell = launch_info.GetShell();
+ if (!shell)
return resume_count;
+ std::string shell_string = shell.GetPath();
// We're in a shell, so for sure we have to resume past the shell exec.
++resume_count;
// Figure out what shell we're planning on using.
- const char *shell_name = strrchr (shell, '/');
+ const char *shell_name = strrchr (shell_string.c_str(), '/');
if (shell_name == NULL)
- shell_name = shell;
+ shell_name = shell_string.c_str();
else
shell_name++;
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 5ab953c9c39..55356674eb6 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1146,13 +1146,14 @@ PlatformDarwin::SetThreadCreationBreakpoint (Target &target)
int32_t
PlatformDarwin::GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info)
{
- const char *shell = launch_info.GetShell();
- if (shell == NULL)
+ const FileSpec &shell = launch_info.GetShell();
+ if (!shell)
return 1;
- const char *shell_name = strrchr (shell, '/');
+ std::string shell_string = shell.GetPath();
+ const char *shell_name = strrchr (shell_string.c_str(), '/');
if (shell_name == NULL)
- shell_name = shell;
+ shell_name = shell_string.c_str();
else
shell_name++;
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index edad0024ed3..9ab338d69d9 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -1063,10 +1063,14 @@ Platform::LaunchProcess (ProcessLaunchInfo &launch_info)
const bool first_arg_is_full_shell_command = false;
uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info);
if (log)
+ {
+ const FileSpec &shell = launch_info.GetShell();
+ const char *shell_str = (shell) ? shell.GetPath().c_str() : "<null>";
log->Printf ("Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32 ", shell is '%s'",
__FUNCTION__,
num_resumes,
- launch_info.GetShell () ? launch_info.GetShell () : "<null>");
+ shell_str);
+ }
if (!launch_info.ConvertArgumentsForLaunchingInShell (error,
is_localhost,
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 037ad681762..9c209738301 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -480,9 +480,9 @@ ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *op
case 'c':
if (option_arg && option_arg[0])
- launch_info.SetShell (option_arg);
+ launch_info.SetShell (FileSpec(option_arg, false));
else
- launch_info.SetShell (LLDB_DEFAULT_SHELL);
+ launch_info.SetShell (HostInfo::GetDefaultShell());
break;
case 'v':
diff --git a/lldb/source/Target/ProcessLaunchInfo.cpp b/lldb/source/Target/ProcessLaunchInfo.cpp
index 5b6d1a8ddc4..f44cf41bd3d 100644
--- a/lldb/source/Target/ProcessLaunchInfo.cpp
+++ b/lldb/source/Target/ProcessLaunchInfo.cpp
@@ -25,7 +25,6 @@ ProcessLaunchInfo::ProcessLaunchInfo () :
ProcessInfo(),
m_working_dir (),
m_plugin_name (),
- m_shell (),
m_flags (0),
m_file_actions (),
m_pty (new lldb_utility::PseudoTerminal),
@@ -42,7 +41,6 @@ ProcessLaunchInfo::ProcessLaunchInfo(const char *stdin_path, const char *stdout_
ProcessInfo(),
m_working_dir(),
m_plugin_name(),
- m_shell(),
m_flags(launch_flags),
m_file_actions(),
m_pty(new lldb_utility::PseudoTerminal),
@@ -181,27 +179,23 @@ ProcessLaunchInfo::SetProcessPluginName (const char *plugin)
m_plugin_name.clear();
}
-const char *
+const FileSpec &
ProcessLaunchInfo::GetShell () const
{
- if (m_shell.empty())
- return NULL;
- return m_shell.c_str();
+ return m_shell;
}
void
-ProcessLaunchInfo::SetShell (const char * path)
+ProcessLaunchInfo::SetShell (const FileSpec &shell)
{
- if (path && path[0])
+ m_shell = shell;
+ if (m_shell)
{
- m_shell.assign (path);
+ m_shell.ResolveExecutableLocation();
m_flags.Set (lldb::eLaunchFlagLaunchInShell);
}
else
- {
- m_shell.clear();
m_flags.Clear (lldb::eLaunchFlagLaunchInShell);
- }
}
void
@@ -220,7 +214,7 @@ ProcessLaunchInfo::Clear ()
ProcessInfo::Clear();
m_working_dir.clear();
m_plugin_name.clear();
- m_shell.clear();
+ m_shell.Clear();
m_flags.Clear();
m_file_actions.clear();
m_resume_count = 0;
@@ -388,34 +382,17 @@ ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell (Error &error,
if (GetFlags().Test (eLaunchFlagLaunchInShell))
{
- const char *shell_executable = GetShell();
- if (shell_executable)
+ if (m_shell)
{
char shell_resolved_path[PATH_MAX];
-
- if (localhost)
- {
- FileSpec shell_filespec (shell_executable, true);
-
- if (!shell_filespec.Exists())
- {
- // Resolve the path in case we just got "bash", "sh" or "tcsh"
- if (!shell_filespec.ResolveExecutableLocation ())
- {
- error.SetErrorStringWithFormat("invalid shell path '%s'", shell_executable);
- return false;
- }
- }
- shell_filespec.GetPath (shell_resolved_path, sizeof(shell_resolved_path));
- shell_executable = shell_resolved_path;
- }
+ std::string shell_executable = m_shell.GetPath();
const char **argv = GetArguments().GetConstArgumentVector ();
if (argv == NULL || argv[0] == NULL)
return false;
Args shell_arguments;
std::string safe_arg;
- shell_arguments.AppendArgument (shell_executable);
+ shell_arguments.AppendArgument (shell_executable.c_str());
shell_arguments.AppendArgument ("-c");
StreamString shell_command;
if (will_debug)
@@ -494,7 +471,7 @@ ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell (Error &error,
}
}
shell_arguments.AppendArgument (shell_command.GetString().c_str());
- m_executable.SetFile(shell_executable, false);
+ m_executable = m_shell;
m_arguments = shell_arguments;
return true;
}
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index d30f91d1566..093e6f2d45a 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -35,6 +35,7 @@
#include "lldb/Core/ValueObject.h"
#include "lldb/Expression/ClangASTSource.h"
#include "lldb/Expression/ClangUserExpression.h"
+#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Host.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
@@ -2477,7 +2478,7 @@ Target::Launch (Listener &listener, ProcessLaunchInfo &launch_info)
}
else if (state == eStateExited)
{
- bool with_shell = launch_info.GetShell();
+ bool with_shell = !!launch_info.GetShell();
const int exit_status = m_process_sp->GetExitStatus();
const char *exit_desc = m_process_sp->GetExitDescription();
#define LAUNCH_SHELL_MESSAGE "\n'r' and 'run' are aliases that default to launching through a shell.\nTry launching without going through a shell by using 'process launch'."
OpenPOWER on IntegriCloud