Remove LLDB_DEFAULT_SHELL #define, and determine this at runtime.

Differential Revision: http://reviews.llvm.org/D5805
Reviewed by: Greg Clayton

llvm-svn: 220217
This commit is contained in:
Zachary Turner 2014-10-20 17:46:43 +00:00
parent 7550b114b1
commit 10687b0ea5
16 changed files with 64 additions and 61 deletions

View File

@ -259,7 +259,7 @@ public:
int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit 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 std::string *command_output, // Pass NULL if you don't want the command output
uint32_t timeout_sec, uint32_t timeout_sec,
const char *shell = LLDB_DEFAULT_SHELL); bool run_in_default_shell = true);
static lldb::DataBufferSP static lldb::DataBufferSP
GetAuxvData (lldb_private::Process *process); GetAuxvData (lldb_private::Process *process);

View File

@ -10,6 +10,7 @@
#ifndef lldb_Host_posix_HostInfoPosix_h_ #ifndef lldb_Host_posix_HostInfoPosix_h_
#define lldb_Host_posix_HostInfoPosix_h_ #define lldb_Host_posix_HostInfoPosix_h_
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/HostInfoBase.h" #include "lldb/Host/HostInfoBase.h"
namespace lldb_private namespace lldb_private
@ -30,6 +31,8 @@ class HostInfoPosix : public HostInfoBase
static uint32_t GetEffectiveUserID(); static uint32_t GetEffectiveUserID();
static uint32_t GetEffectiveGroupID(); static uint32_t GetEffectiveGroupID();
static FileSpec GetDefaultShell();
protected: protected:
static bool ComputeSupportExeDirectory(FileSpec &file_spec); static bool ComputeSupportExeDirectory(FileSpec &file_spec);
static bool ComputeHeaderDirectory(FileSpec &file_spec); static bool ComputeHeaderDirectory(FileSpec &file_spec);

View File

@ -33,6 +33,7 @@ class HostInfoWindows : public HostInfoBase
static bool GetOSKernelDescription(std::string &s); static bool GetOSKernelDescription(std::string &s);
static bool GetHostname(std::string &s); static bool GetHostname(std::string &s);
static FileSpec GetProgramFileSpec(); static FileSpec GetProgramFileSpec();
static FileSpec GetDefaultShell();
protected: protected:
static bool ComputePythonDirectory(FileSpec &file_spec); static bool ComputePythonDirectory(FileSpec &file_spec);

View File

@ -15,6 +15,7 @@
// LLDB Headers // LLDB Headers
#include "lldb/Core/Flags.h" #include "lldb/Core/Flags.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Host.h" #include "lldb/Host/Host.h"
#include "lldb/Target/FileAction.h" #include "lldb/Target/FileAction.h"
#include "lldb/Target/ProcessInfo.h" #include "lldb/Target/ProcessInfo.h"
@ -105,11 +106,11 @@ namespace lldb_private
void void
SetProcessPluginName (const char *plugin); SetProcessPluginName (const char *plugin);
const char * const FileSpec &
GetShell () const; GetShell () const;
void void
SetShell (const char * path); SetShell (const FileSpec &shell);
uint32_t uint32_t
GetResumeCount () const GetResumeCount () const
@ -215,7 +216,7 @@ namespace lldb_private
protected: protected:
std::string m_working_dir; std::string m_working_dir;
std::string m_plugin_name; std::string m_plugin_name;
std::string m_shell; FileSpec m_shell;
Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags
std::vector<FileAction> m_file_actions; // File actions for any other files std::vector<FileAction> m_file_actions; // File actions for any other files
std::shared_ptr<lldb_utility::PseudoTerminal> m_pty; std::shared_ptr<lldb_utility::PseudoTerminal> m_pty;

View File

@ -49,11 +49,6 @@
// LLDB defines // LLDB defines
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#define LLDB_GENERIC_ERROR UINT32_MAX #define LLDB_GENERIC_ERROR UINT32_MAX
#if defined(_WIN32)
#define LLDB_DEFAULT_SHELL "cmd.exe"
#else
#define LLDB_DEFAULT_SHELL "/bin/sh"
#endif
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Breakpoints // Breakpoints

View File

@ -236,13 +236,16 @@ SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
const char * const char *
SBLaunchInfo::GetShell () 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 void
SBLaunchInfo::SetShell (const char * path) SBLaunchInfo::SetShell (const char * path)
{ {
m_opaque_sp->SetShell (path); m_opaque_sp->SetShell (FileSpec(path, false));
} }
uint32_t uint32_t

View File

@ -550,14 +550,14 @@ Host::RunShellCommand (const char *command,
int *signo_ptr, int *signo_ptr,
std::string *command_output_ptr, std::string *command_output_ptr,
uint32_t timeout_sec, uint32_t timeout_sec,
const char *shell) bool run_in_default_shell)
{ {
Error error; Error error;
ProcessLaunchInfo launch_info; ProcessLaunchInfo launch_info;
if (shell && shell[0]) if (run_in_default_shell)
{ {
// Run the command in a shell // Run the command in a shell
launch_info.SetShell(shell); launch_info.SetShell(HostInfo::GetDefaultShell());
launch_info.GetArguments().AppendArgument(command); launch_info.GetArguments().AppendArgument(command);
const bool localhost = true; const bool localhost = true;
const bool will_debug = false; const bool will_debug = false;

View File

@ -125,6 +125,12 @@ HostInfoPosix::GetEffectiveGroupID()
return getegid(); return getegid();
} }
FileSpec
HostInfoPosix::GetDefaultShell()
{
return FileSpec("/bin/sh", false);
}
bool bool
HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec)
{ {

View File

@ -96,6 +96,12 @@ HostInfoWindows::GetProgramFileSpec()
return m_program_filespec; return m_program_filespec;
} }
FileSpec
HostInfoWindows::GetDefaultShell()
{
return FileSpec(::getenv("ComSpec"), false);
}
bool bool
HostInfoWindows::ComputePythonDirectory(FileSpec &file_spec) HostInfoWindows::ComputePythonDirectory(FileSpec &file_spec)
{ {

View File

@ -339,7 +339,11 @@ CommandInterpreter::Initialize ()
#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__) #if defined (__arm__) || defined (__arm64__) || defined (__aarch64__)
ProcessAliasOptionsArgs (cmd_obj_sp, "--", alias_arguments_vector_sp); ProcessAliasOptionsArgs (cmd_obj_sp, "--", alias_arguments_vector_sp);
#else #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 #endif
AddAlias ("r", cmd_obj_sp); AddAlias ("r", cmd_obj_sp);
AddAlias ("run", cmd_obj_sp); AddAlias ("run", cmd_obj_sp);

View File

@ -554,17 +554,18 @@ PlatformLinux::GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info)
} }
// If we're not launching a shell, we're done. // If we're not launching a shell, we're done.
const char *shell = launch_info.GetShell(); const FileSpec &shell = launch_info.GetShell();
if (shell == NULL) if (!shell)
return resume_count; 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. // We're in a shell, so for sure we have to resume past the shell exec.
++resume_count; ++resume_count;
// Figure out what shell we're planning on using. // 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) if (shell_name == NULL)
shell_name = shell; shell_name = shell_string.c_str();
else else
shell_name++; shell_name++;

View File

@ -1146,13 +1146,14 @@ PlatformDarwin::SetThreadCreationBreakpoint (Target &target)
int32_t int32_t
PlatformDarwin::GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info) PlatformDarwin::GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info)
{ {
const char *shell = launch_info.GetShell(); const FileSpec &shell = launch_info.GetShell();
if (shell == NULL) if (!shell)
return 1; 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) if (shell_name == NULL)
shell_name = shell; shell_name = shell_string.c_str();
else else
shell_name++; shell_name++;

View File

@ -1063,10 +1063,14 @@ Platform::LaunchProcess (ProcessLaunchInfo &launch_info)
const bool first_arg_is_full_shell_command = false; const bool first_arg_is_full_shell_command = false;
uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info); uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info);
if (log) 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'", log->Printf ("Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32 ", shell is '%s'",
__FUNCTION__, __FUNCTION__,
num_resumes, num_resumes,
launch_info.GetShell () ? launch_info.GetShell () : "<null>"); shell_str);
}
if (!launch_info.ConvertArgumentsForLaunchingInShell (error, if (!launch_info.ConvertArgumentsForLaunchingInShell (error,
is_localhost, is_localhost,

View File

@ -480,9 +480,9 @@ ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *op
case 'c': case 'c':
if (option_arg && option_arg[0]) if (option_arg && option_arg[0])
launch_info.SetShell (option_arg); launch_info.SetShell (FileSpec(option_arg, false));
else else
launch_info.SetShell (LLDB_DEFAULT_SHELL); launch_info.SetShell (HostInfo::GetDefaultShell());
break; break;
case 'v': case 'v':

View File

@ -25,7 +25,6 @@ ProcessLaunchInfo::ProcessLaunchInfo () :
ProcessInfo(), ProcessInfo(),
m_working_dir (), m_working_dir (),
m_plugin_name (), m_plugin_name (),
m_shell (),
m_flags (0), m_flags (0),
m_file_actions (), m_file_actions (),
m_pty (new lldb_utility::PseudoTerminal), m_pty (new lldb_utility::PseudoTerminal),
@ -42,7 +41,6 @@ ProcessLaunchInfo::ProcessLaunchInfo(const char *stdin_path, const char *stdout_
ProcessInfo(), ProcessInfo(),
m_working_dir(), m_working_dir(),
m_plugin_name(), m_plugin_name(),
m_shell(),
m_flags(launch_flags), m_flags(launch_flags),
m_file_actions(), m_file_actions(),
m_pty(new lldb_utility::PseudoTerminal), m_pty(new lldb_utility::PseudoTerminal),
@ -181,27 +179,23 @@ ProcessLaunchInfo::SetProcessPluginName (const char *plugin)
m_plugin_name.clear(); m_plugin_name.clear();
} }
const char * const FileSpec &
ProcessLaunchInfo::GetShell () const ProcessLaunchInfo::GetShell () const
{ {
if (m_shell.empty()) return m_shell;
return NULL;
return m_shell.c_str();
} }
void 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); m_flags.Set (lldb::eLaunchFlagLaunchInShell);
} }
else else
{
m_shell.clear();
m_flags.Clear (lldb::eLaunchFlagLaunchInShell); m_flags.Clear (lldb::eLaunchFlagLaunchInShell);
}
} }
void void
@ -220,7 +214,7 @@ ProcessLaunchInfo::Clear ()
ProcessInfo::Clear(); ProcessInfo::Clear();
m_working_dir.clear(); m_working_dir.clear();
m_plugin_name.clear(); m_plugin_name.clear();
m_shell.clear(); m_shell.Clear();
m_flags.Clear(); m_flags.Clear();
m_file_actions.clear(); m_file_actions.clear();
m_resume_count = 0; m_resume_count = 0;
@ -388,34 +382,17 @@ ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell (Error &error,
if (GetFlags().Test (eLaunchFlagLaunchInShell)) if (GetFlags().Test (eLaunchFlagLaunchInShell))
{ {
const char *shell_executable = GetShell(); if (m_shell)
if (shell_executable)
{ {
char shell_resolved_path[PATH_MAX]; char shell_resolved_path[PATH_MAX];
std::string shell_executable = m_shell.GetPath();
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;
}
const char **argv = GetArguments().GetConstArgumentVector (); const char **argv = GetArguments().GetConstArgumentVector ();
if (argv == NULL || argv[0] == NULL) if (argv == NULL || argv[0] == NULL)
return false; return false;
Args shell_arguments; Args shell_arguments;
std::string safe_arg; std::string safe_arg;
shell_arguments.AppendArgument (shell_executable); shell_arguments.AppendArgument (shell_executable.c_str());
shell_arguments.AppendArgument ("-c"); shell_arguments.AppendArgument ("-c");
StreamString shell_command; StreamString shell_command;
if (will_debug) if (will_debug)
@ -494,7 +471,7 @@ ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell (Error &error,
} }
} }
shell_arguments.AppendArgument (shell_command.GetString().c_str()); shell_arguments.AppendArgument (shell_command.GetString().c_str());
m_executable.SetFile(shell_executable, false); m_executable = m_shell;
m_arguments = shell_arguments; m_arguments = shell_arguments;
return true; return true;
} }

View File

@ -35,6 +35,7 @@
#include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObject.h"
#include "lldb/Expression/ClangASTSource.h" #include "lldb/Expression/ClangASTSource.h"
#include "lldb/Expression/ClangUserExpression.h" #include "lldb/Expression/ClangUserExpression.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Host.h" #include "lldb/Host/Host.h"
#include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/CommandReturnObject.h"
@ -2477,7 +2478,7 @@ Target::Launch (Listener &listener, ProcessLaunchInfo &launch_info)
} }
else if (state == eStateExited) 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 int exit_status = m_process_sp->GetExitStatus();
const char *exit_desc = m_process_sp->GetExitDescription(); 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'." #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'."