[Lldb-commits] [lldb] r220217 - Remove LLDB_DEFAULT_SHELL #define, and determine this at runtime.
Zachary Turner
zturner at google.com
Mon Oct 20 10:46:44 PDT 2014
Author: zturner
Date: Mon Oct 20 12:46:43 2014
New Revision: 220217
URL: http://llvm.org/viewvc/llvm-project?rev=220217&view=rev
Log:
Remove LLDB_DEFAULT_SHELL #define, and determine this at runtime.
Differential Revision: http://reviews.llvm.org/D5805
Reviewed by: Greg Clayton
Modified:
lldb/trunk/include/lldb/Host/Host.h
lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h
lldb/trunk/include/lldb/Host/windows/HostInfoWindows.h
lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h
lldb/trunk/include/lldb/lldb-defines.h
lldb/trunk/source/API/SBTarget.cpp
lldb/trunk/source/Host/common/Host.cpp
lldb/trunk/source/Host/posix/HostInfoPosix.cpp
lldb/trunk/source/Host/windows/HostInfoWindows.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/trunk/source/Target/Platform.cpp
lldb/trunk/source/Target/Process.cpp
lldb/trunk/source/Target/ProcessLaunchInfo.cpp
lldb/trunk/source/Target/Target.cpp
Modified: lldb/trunk/include/lldb/Host/Host.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Host.h (original)
+++ lldb/trunk/include/lldb/Host/Host.h Mon Oct 20 12:46:43 2014
@@ -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);
Modified: lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h (original)
+++ lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h Mon Oct 20 12:46:43 2014
@@ -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 HostInfoBas
static uint32_t GetEffectiveUserID();
static uint32_t GetEffectiveGroupID();
+ static FileSpec GetDefaultShell();
+
protected:
static bool ComputeSupportExeDirectory(FileSpec &file_spec);
static bool ComputeHeaderDirectory(FileSpec &file_spec);
Modified: lldb/trunk/include/lldb/Host/windows/HostInfoWindows.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/windows/HostInfoWindows.h?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/windows/HostInfoWindows.h (original)
+++ lldb/trunk/include/lldb/Host/windows/HostInfoWindows.h Mon Oct 20 12:46:43 2014
@@ -33,6 +33,7 @@ class HostInfoWindows : public HostInfoB
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);
Modified: lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h (original)
+++ lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h Mon Oct 20 12:46:43 2014
@@ -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;
Modified: lldb/trunk/include/lldb/lldb-defines.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-defines.h?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-defines.h (original)
+++ lldb/trunk/include/lldb/lldb-defines.h Mon Oct 20 12:46:43 2014
@@ -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
Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Mon Oct 20 12:46:43 2014
@@ -236,13 +236,16 @@ SBLaunchInfo::SetProcessPluginName (cons
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
Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Mon Oct 20 12:46:43 2014
@@ -550,14 +550,14 @@ Host::RunShellCommand (const char *comma
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;
Modified: lldb/trunk/source/Host/posix/HostInfoPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/HostInfoPosix.cpp?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/HostInfoPosix.cpp (original)
+++ lldb/trunk/source/Host/posix/HostInfoPosix.cpp Mon Oct 20 12:46:43 2014
@@ -125,6 +125,12 @@ HostInfoPosix::GetEffectiveGroupID()
return getegid();
}
+FileSpec
+HostInfoPosix::GetDefaultShell()
+{
+ return FileSpec("/bin/sh", false);
+}
+
bool
HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec)
{
Modified: lldb/trunk/source/Host/windows/HostInfoWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/HostInfoWindows.cpp?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/HostInfoWindows.cpp (original)
+++ lldb/trunk/source/Host/windows/HostInfoWindows.cpp Mon Oct 20 12:46:43 2014
@@ -96,6 +96,12 @@ HostInfoWindows::GetProgramFileSpec()
return m_program_filespec;
}
+FileSpec
+HostInfoWindows::GetDefaultShell()
+{
+ return FileSpec(::getenv("ComSpec"), false);
+}
+
bool
HostInfoWindows::ComputePythonDirectory(FileSpec &file_spec)
{
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Mon Oct 20 12:46:43 2014
@@ -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);
Modified: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp Mon Oct 20 12:46:43 2014
@@ -554,17 +554,18 @@ PlatformLinux::GetResumeCountForLaunchIn
}
// 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++;
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Mon Oct 20 12:46:43 2014
@@ -1146,13 +1146,14 @@ PlatformDarwin::SetThreadCreationBreakpo
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++;
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Mon Oct 20 12:46:43 2014
@@ -1063,10 +1063,14 @@ Platform::LaunchProcess (ProcessLaunchIn
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,
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Mon Oct 20 12:46:43 2014
@@ -480,9 +480,9 @@ ProcessLaunchCommandOptions::SetOptionVa
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':
Modified: lldb/trunk/source/Target/ProcessLaunchInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ProcessLaunchInfo.cpp?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/source/Target/ProcessLaunchInfo.cpp (original)
+++ lldb/trunk/source/Target/ProcessLaunchInfo.cpp Mon Oct 20 12:46:43 2014
@@ -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(con
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
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::ConvertArgumentsForLa
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::ConvertArgumentsForLa
}
}
shell_arguments.AppendArgument (shell_command.GetString().c_str());
- m_executable.SetFile(shell_executable, false);
+ m_executable = m_shell;
m_arguments = shell_arguments;
return true;
}
Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=220217&r1=220216&r2=220217&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Mon Oct 20 12:46:43 2014
@@ -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, Proc
}
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'."
More information about the lldb-commits
mailing list