This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix escaping when launching in terminal with AppleScript
ClosedPublic

Authored by JDevlieghere on Apr 27 2022, 3:54 PM.

Details

Summary

Fix escaping when launching in terminal with AppleScript. The invocation we're building up is wrapped in single quotes when passed to bash and wrapped in double quotes for AppleScript.

Here's an example invocation with the new escaping:

tell application "Terminal"
   activate
        do script "/bin/bash -c 'arch -arch arm64 '/Users/jonas/llvm/build-ra/bin/darwin-debug' --unix-socket=/tmp/dL2jSh --arch=arm64 --working-dir \"/private/tmp/with spaces\" --disable-aslr --env=\"OS_ACTIVITY_DT_MODE=enable\" --  \"/Users/jonas/llvm/build-ra/bin/lldb-instr\" \"foo bar\" \"baz quux\" ; echo Process exited with status $?';exit"
end tell

Previously we were using unescaped single quotes which resulted in the whole bash invocation being passed in pieces. That works most of the time but breaks when you have a space in your current working directory for example.

rdar://91870763

Diff Detail

Event Timeline

JDevlieghere created this revision.Apr 27 2022, 3:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 3:54 PM
JDevlieghere edited the summary of this revision. (Show Details)Apr 27 2022, 3:57 PM
aprantl added inline comments.Apr 27 2022, 3:58 PM
lldb/source/Host/macosx/objcxx/Host.mm
222

Should we use raw C++ string literals for this?
https://en.cppreference.com/w/cpp/language/string_literal

267

Is this leftover debugging code?

I have some trivial suggestions inside, but otherwise, thanks!

JDevlieghere marked an inline comment as done.Apr 27 2022, 4:19 PM
JDevlieghere added inline comments.
lldb/source/Host/macosx/objcxx/Host.mm
267

Yup, I added that to generate the invocation I put in the summary and forgot to take it out again.

JDevlieghere marked 2 inline comments as done.

Address Adrian's code review feedback.

aprantl accepted this revision.Apr 27 2022, 4:36 PM
This revision is now accepted and ready to land.Apr 27 2022, 4:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 4:45 PM