-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[lldb] Escape ? for zsh #112107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[lldb] Escape ? for zsh #112107
Conversation
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.
|
@llvm/pr-subscribers-lldb Author: Keith Smiley (keith) ChangesPreviously on macOS with lldb-argdumper if you ran: It would fail with this error: stderr is silenced here but the underlying error if you print it for This change escapes the Full diff: https://github.com/llvm/llvm-project/pull/112107.diff 2 Files Affected:
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*");
|
|
So... |
|
hmm good point. I wonder if the fix here should be around surfacing the error to users then, so they know they have to escape it depending on their use case |
in the example shown, |
|
Oh yea great point. I guess another way to put that is if I copy the exact same invocation and run it directly it works, so that differing is unexpected. |
|
I agree (and I don't think this is going to be very contentious) that we should not expand args from the lldb command line (precisely for the reason you mention). The trickiness comes from how this expansion is performed. The command line args are first copied into the I would (probably?) be fine with that interpretation, but I suspect others will have different opinions. If we want command line args to not get expanded, but keep expanding the example above, then we may need to come up with a different way to pass cmdline args. |
Previously on macOS with lldb-argdumper if you ran:
It would fail with this error:
stderr is silenced here but the underlying error if you print it for
debugging is:
This change escapes the
?so this argument works as expected.