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);
#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
static uint32_t GetEffectiveUserID();
static uint32_t GetEffectiveGroupID();
+ static FileSpec GetDefaultShell();
+
protected:
static bool ComputeSupportExeDirectory(FileSpec &file_spec);
static bool ComputeHeaderDirectory(FileSpec &file_spec);
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);
// 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"
void
SetProcessPluginName (const char *plugin);
- const char *
+ const FileSpec &
GetShell () const;
void
- SetShell (const char * path);
+ SetShell (const FileSpec &shell);
uint32_t
GetResumeCount () const
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;
// 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
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
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;
return getegid();
}
+FileSpec
+HostInfoPosix::GetDefaultShell()
+{
+ return FileSpec("/bin/sh", false);
+}
+
bool
HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec)
{
return m_program_filespec;
}
+FileSpec
+HostInfoWindows::GetDefaultShell()
+{
+ return FileSpec(::getenv("ComSpec"), false);
+}
+
bool
HostInfoWindows::ComputePythonDirectory(FileSpec &file_spec)
{
#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);
}
// 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++;
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++;
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,
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':
ProcessInfo(),
m_working_dir (),
m_plugin_name (),
- m_shell (),
m_flags (0),
m_file_actions (),
m_pty (new lldb_utility::PseudoTerminal),
ProcessInfo(),
m_working_dir(),
m_plugin_name(),
- m_shell(),
m_flags(launch_flags),
m_file_actions(),
m_pty(new lldb_utility::PseudoTerminal),
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
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;
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)
}
}
shell_arguments.AppendArgument (shell_command.GetString().c_str());
- m_executable.SetFile(shell_executable, false);
+ m_executable = m_shell;
m_arguments = shell_arguments;
return true;
}
#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"
}
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'."