[Lldb-commits] [lldb] acc56e5 - [lldb] Expand $ when using tcsh

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 13 13:01:15 PDT 2022


Author: Jonas Devlieghere
Date: 2022-04-13T13:01:09-07:00
New Revision: acc56e55feee61fc0038bc132a94e54ce56ced98

URL: https://github.com/llvm/llvm-project/commit/acc56e55feee61fc0038bc132a94e54ce56ced98
DIFF: https://github.com/llvm/llvm-project/commit/acc56e55feee61fc0038bc132a94e54ce56ced98.diff

LOG: [lldb] Expand $ when using tcsh

Unlike for any of the other shells, we were escaping $ when using tcsh.
There's nothing special about $ in tcsh and this prevents you from
expanding shell variables, one of the main reasons this functionality
exists in the first place.

Differential revision: https://reviews.llvm.org/D123690

Added: 
    lldb/test/Shell/Process/Inputs/echo.c
    lldb/test/Shell/Process/TestShell.test

Modified: 
    lldb/source/Utility/Args.cpp
    lldb/unittests/Utility/ArgsTest.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Utility/Args.cpp b/lldb/source/Utility/Args.cpp
index 8b20ee3f05ee9..3978f94226530 100644
--- a/lldb/source/Utility/Args.cpp
+++ b/lldb/source/Utility/Args.cpp
@@ -385,7 +385,7 @@ std::string Args::GetShellSafeArgument(const FileSpec &shell,
   };
 
   static ShellDescriptor g_Shells[] = {{ConstString("bash"), " '\"<>()&;"},
-                                       {ConstString("tcsh"), " '\"<>()&$;"},
+                                       {ConstString("tcsh"), " '\"<>()&;"},
                                        {ConstString("zsh"), " '\"<>()&;\\|"},
                                        {ConstString("sh"), " '\"<>()&;"}};
 

diff  --git a/lldb/test/Shell/Process/Inputs/echo.c b/lldb/test/Shell/Process/Inputs/echo.c
new file mode 100644
index 0000000000000..dc8db7368f5d0
--- /dev/null
+++ b/lldb/test/Shell/Process/Inputs/echo.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(int argc, char **argv) {
+  for (int i = 0; i < argc; ++i)
+    printf("%s\n", argv[i]);
+}

diff  --git a/lldb/test/Shell/Process/TestShell.test b/lldb/test/Shell/Process/TestShell.test
new file mode 100644
index 0000000000000..b08d8611d41f5
--- /dev/null
+++ b/lldb/test/Shell/Process/TestShell.test
@@ -0,0 +1,8 @@
+REQUIRES: shell, system-darwin
+RUN: %clang_host %p/Inputs/echo.c -o %t.out
+
+RUN: not %lldb %t.out -b -o 'process launch --shell=tcsh -- $NO_SUCH_SHELL_VARIABLE' 2>&1 | FileCheck --check-prefix=FAILURE %s
+RUN: %lldb %t.out -b -o 'process launch --shell=tcsh -- $HOME' 2>&1 | FileCheck --check-prefix=SUCCESS %s
+
+FAILURE: exited with status 1
+SUCCESS: exited with status = 0

diff  --git a/lldb/unittests/Utility/ArgsTest.cpp b/lldb/unittests/Utility/ArgsTest.cpp
index dc306b209a24d..755a110aa555f 100644
--- a/lldb/unittests/Utility/ArgsTest.cpp
+++ b/lldb/unittests/Utility/ArgsTest.cpp
@@ -336,8 +336,8 @@ TEST(ArgsTest, GetShellSafeArgument) {
 
   // Test escaping tcsh special characters.
   FileSpec tcsh("/bin/tcsh", FileSpec::Style::posix);
-  EXPECT_EQ(Args::GetShellSafeArgument(tcsh, R"( '"<>()&$;)"),
-            R"(\ \'\"\<\>\(\)\&\$\;)");
+  EXPECT_EQ(Args::GetShellSafeArgument(tcsh, R"( '"<>()&;)"),
+            R"(\ \'\"\<\>\(\)\&\;)");
   // Normal characters and globbing expressions that shouldn't be escaped.
   EXPECT_EQ(Args::GetShellSafeArgument(tcsh, "aA1*"), "aA1*");
 


        


More information about the lldb-commits mailing list