Index: lldb/trunk/include/lldb/Host/Host.h =================================================================== --- lldb/trunk/include/lldb/Host/Host.h +++ lldb/trunk/include/lldb/Host/Host.h @@ -259,7 +259,7 @@ 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); Index: lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h =================================================================== --- lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h +++ lldb/trunk/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 @@ static uint32_t GetEffectiveUserID(); static uint32_t GetEffectiveGroupID(); + static FileSpec GetDefaultShell(); + protected: static bool ComputeSupportExeDirectory(FileSpec &file_spec); static bool ComputeHeaderDirectory(FileSpec &file_spec); Index: lldb/trunk/include/lldb/Host/windows/HostInfoWindows.h =================================================================== --- lldb/trunk/include/lldb/Host/windows/HostInfoWindows.h +++ lldb/trunk/include/lldb/Host/windows/HostInfoWindows.h @@ -33,6 +33,7 @@ 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); Index: lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h =================================================================== --- lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h +++ lldb/trunk/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 @@ 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 @@ 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 m_file_actions; // File actions for any other files std::shared_ptr m_pty; Index: lldb/trunk/include/lldb/lldb-defines.h =================================================================== --- lldb/trunk/include/lldb/lldb-defines.h +++ lldb/trunk/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 Index: lldb/trunk/source/API/SBTarget.cpp =================================================================== --- lldb/trunk/source/API/SBTarget.cpp +++ lldb/trunk/source/API/SBTarget.cpp @@ -236,13 +236,16 @@ 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 Index: lldb/trunk/source/Host/common/Host.cpp =================================================================== --- lldb/trunk/source/Host/common/Host.cpp +++ lldb/trunk/source/Host/common/Host.cpp @@ -550,14 +550,14 @@ 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; Index: lldb/trunk/source/Host/posix/HostInfoPosix.cpp =================================================================== --- lldb/trunk/source/Host/posix/HostInfoPosix.cpp +++ lldb/trunk/source/Host/posix/HostInfoPosix.cpp @@ -125,6 +125,12 @@ return getegid(); } +FileSpec +HostInfoPosix::GetDefaultShell() +{ + return FileSpec("/bin/sh", false); +} + bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) { Index: lldb/trunk/source/Host/windows/HostInfoWindows.cpp =================================================================== --- lldb/trunk/source/Host/windows/HostInfoWindows.cpp +++ lldb/trunk/source/Host/windows/HostInfoWindows.cpp @@ -96,6 +96,12 @@ return m_program_filespec; } +FileSpec +HostInfoWindows::GetDefaultShell() +{ + return FileSpec(::getenv("ComSpec"), false); +} + bool HostInfoWindows::ComputePythonDirectory(FileSpec &file_spec) { Index: lldb/trunk/source/Interpreter/CommandInterpreter.cpp =================================================================== --- lldb/trunk/source/Interpreter/CommandInterpreter.cpp +++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp @@ -339,7 +339,11 @@ #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); Index: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp +++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp @@ -554,17 +554,18 @@ } // 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++; Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1146,13 +1146,14 @@ 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++; Index: lldb/trunk/source/Target/Platform.cpp =================================================================== --- lldb/trunk/source/Target/Platform.cpp +++ lldb/trunk/source/Target/Platform.cpp @@ -1063,10 +1063,14 @@ 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() : ""; log->Printf ("Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32 ", shell is '%s'", __FUNCTION__, num_resumes, - launch_info.GetShell () ? launch_info.GetShell () : ""); + shell_str); + } if (!launch_info.ConvertArgumentsForLaunchingInShell (error, is_localhost, Index: lldb/trunk/source/Target/Process.cpp =================================================================== --- lldb/trunk/source/Target/Process.cpp +++ lldb/trunk/source/Target/Process.cpp @@ -480,9 +480,9 @@ 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': Index: lldb/trunk/source/Target/ProcessLaunchInfo.cpp =================================================================== --- lldb/trunk/source/Target/ProcessLaunchInfo.cpp +++ lldb/trunk/source/Target/ProcessLaunchInfo.cpp @@ -25,7 +25,6 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ } } shell_arguments.AppendArgument (shell_command.GetString().c_str()); - m_executable.SetFile(shell_executable, false); + m_executable = m_shell; m_arguments = shell_arguments; return true; } Index: lldb/trunk/source/Target/Target.cpp =================================================================== --- lldb/trunk/source/Target/Target.cpp +++ lldb/trunk/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 @@ } 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'."