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

via lldb-commits lldb-commits at lists.llvm.org
Sat Oct 12 11:28:03 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Keith Smiley (keith)

<details>
<summary>Changes</summary>

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.


---
Full diff: https://github.com/llvm/llvm-project/pull/112107.diff


2 Files Affected:

- (modified) lldb/source/Utility/Args.cpp (+1-1) 
- (modified) lldb/unittests/Utility/ArgsTest.cpp (+2-2) 


``````````diff
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*");
 

``````````

</details>


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


More information about the lldb-commits mailing list