[Lldb-commits] [PATCH] D68316: [Host] Return the user's shell from GetDefaultShell
Jonas Devlieghere via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 1 20:08:12 PDT 2019
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, jingham, friss.
LLDB handles shell expansion by running lldb-argdumper under a shell. Currently, this is always `/bin/sh` on POSIX. This potentially leads to different behavior between lldb and the user's current shell. Here's an example of different expansions between shells:
$ /bin/bash -c 'echo -config={Options:[{key:foo_key,value:foo_value}]}'
-config={Options:[key:foo_key]} -config={Options:[value:foo_value]}
$ /bin/zsh -c 'echo -config={Options:[{key:foo_key,value:foo_value}]}'
zsh:1: no matches found: -config={Options:[key:foo_key]}
$ /bin/sh -c 'echo -config={Options:[{key:foo_key,value:foo_value}]}'
-config={Options:[key:foo_key]} -config={Options:[value:foo_value]}
$ /usr/local/bin/fish -c 'echo -config={Options:[{key:foo_key,value:foo_value}]}'
-config=Options:[key:foo_key] -config=Options:[value:foo_value]
To reduce surprises, this patch returns the user's current shell. It first looks at the `SHELL` environment variable. If that isn't set, it'll ask for the user's default shell. Only if that fails, we'll fallback to `/bin/sh`, which should always be available.
https://reviews.llvm.org/D68316
Files:
lldb/lit/Host/Inputs/simple.c
lldb/lit/Host/TestCustomShell.test
lldb/source/Host/posix/HostInfoPosix.cpp
Index: lldb/source/Host/posix/HostInfoPosix.cpp
===================================================================
--- lldb/source/Host/posix/HostInfoPosix.cpp
+++ lldb/source/Host/posix/HostInfoPosix.cpp
@@ -113,7 +113,13 @@
uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); }
-FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh"); }
+FileSpec HostInfoPosix::GetDefaultShell() {
+ if (const char *v = ::getenv("SHELL"))
+ return FileSpec(v);
+ if (const char *v = ::getpwuid(::geteuid())->pw_shell)
+ return FileSpec(v);
+ return FileSpec("/bin/sh");
+}
bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
return ComputePathRelativeToLibrary(file_spec, "/bin");
Index: lldb/lit/Host/TestCustomShell.test
===================================================================
--- /dev/null
+++ lldb/lit/Host/TestCustomShell.test
@@ -0,0 +1,5 @@
+# UNSUPPORTED: system-windows
+
+# RUN: %clang %S/Inputs/simple.c -g -o %t.out
+# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
+# CHECK: error: shell expansion failed
Index: lldb/lit/Host/Inputs/simple.c
===================================================================
--- /dev/null
+++ lldb/lit/Host/Inputs/simple.c
@@ -0,0 +1 @@
+int main(int argc, char const *argv[]) { return 0; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68316.222745.patch
Type: text/x-patch
Size: 1321 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191002/c1318130/attachment.bin>
More information about the lldb-commits
mailing list