[Lldb-commits] [lldb] [lldb] Escape ? for zsh (PR #112107)

Keith Smiley via lldb-commits lldb-commits at lists.llvm.org
Sat Oct 12 11:27:32 PDT 2024


https://github.com/keith created https://github.com/llvm/llvm-project/pull/112107

Previously on macOS with lldb-argdumper if you ran:

```
lldb -o r -- /tmp/foo "some arg?"
```

It would fail with this error:

```
error: shell expansion failed (reason: lldb-argdumper exited with error 1). consider launching with 'process launch'.
```

stderr is silenced here but the underlying error if you print it for
debugging is:

```
zsh: no matches found: ?
```

This change escapes the `?` so this argument works as expected.


>From 2cd6a6726373e8b499aba4e41dafad5780f2134f Mon Sep 17 00:00:00 2001
From: Keith Smiley <keithbsmiley at gmail.com>
Date: Sat, 12 Oct 2024 11:25:16 -0700
Subject: [PATCH] [lldb] Escape ? for zsh

Previously on macOS with lldb-argdumper if you ran:

```
lldb -o r -- /tmp/foo "some arg?"
```

It would fail with this error:

```
error: shell expansion failed (reason: lldb-argdumper exited with error 1). consider launching with 'process launch'.
```

stderr is silenced here but the underlying error if you print it for
debugging is:

```
zsh: no matches found: ?
```

This change escapes the `?` so this argument works as expected.
---
 lldb/source/Utility/Args.cpp        | 2 +-
 lldb/unittests/Utility/ArgsTest.cpp | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lldb/source/Utility/Args.cpp b/lldb/source/Utility/Args.cpp
index 8ba40bae4d67e5..92a7ef03273fbc 100644
--- a/lldb/source/Utility/Args.cpp
+++ b/lldb/source/Utility/Args.cpp
@@ -401,7 +401,7 @@ std::string Args::GetShellSafeArgument(const FileSpec &shell,
   static ShellDescriptor g_Shells[] = {{"bash", " '\"<>()&;"},
                                        {"fish", " '\"<>()&\\|;"},
                                        {"tcsh", " '\"<>()&;"},
-                                       {"zsh", " '\"<>()&;\\|"},
+                                       {"zsh", " '\"<>()&;\\|?"},
                                        {"sh", " '\"<>()&;"}};
 
   // safe minimal set
diff --git a/lldb/unittests/Utility/ArgsTest.cpp b/lldb/unittests/Utility/ArgsTest.cpp
index 8d2b625f524d67..34d6b4dd7c95a0 100644
--- a/lldb/unittests/Utility/ArgsTest.cpp
+++ b/lldb/unittests/Utility/ArgsTest.cpp
@@ -292,8 +292,8 @@ TEST(ArgsTest, GetShellSafeArgument) {
   EXPECT_EQ(Args::GetShellSafeArgument(bash, "a\"b"), "a\\\"b");
 
   FileSpec zsh("/bin/zsh", FileSpec::Style::posix);
-  EXPECT_EQ(Args::GetShellSafeArgument(zsh, R"('";()<>&|\)"),
-            R"(\'\"\;\(\)\<\>\&\|\\)");
+  EXPECT_EQ(Args::GetShellSafeArgument(zsh, R"('"?;()<>&|\)"),
+            R"(\'\"\?\;\(\)\<\>\&\|\\)");
   // Normal characters and expressions that shouldn't be escaped.
   EXPECT_EQ(Args::GetShellSafeArgument(zsh, "aA$1*"), "aA$1*");
 



More information about the lldb-commits mailing list