Reputation: 4373
Trying to pass a large string to a shell script using a breakpoint in Xcode
let value = Array(repeating: "a", count: 1500).joined()
let string = "{\"key\": \"\(value)\"}"
Unfortunately, the string is being truncated. Is this limitation documented and can it be overcome?
Upvotes: 1
Views: 295
Reputation: 3487
It's been nearly a year since you asked this, and I'm not sure if it will solve your question, but I've recently had a similar problem so thought I'd share my solution.
I had two issues:
po foo
) to 1023 characters. I believe this is the issue to which your question relates.,
in my string as a separator for multiple arguments (e.g. passing foo
, bar
, and baz
as arguments to the script wouldn't work correctly if any of the variables contained a ,
as Xcode would try to create another argument).So, firstly, the LLDB issue...
It seems that by default LLDB has a limit on the character length that it will print to the console (or pass to a shell script via a breakpoint argument) of around 1023 characters. You can easily change this to something larger by setting another breakpoint before the breakpoint that uses your variable and running (lldb) set set target.max-string-summary-length 10000
in the console. This can be a bit annoying so I created a ~/.lldbinit
file and placed set set target.max-string-summary-length 10000
in there instead so I don't have to keep setting it in the console.
Secondly, the comma issue...
Inside the Edit breakpoint...
menu that you provided a screenshot of above there is the option to not only provide a path to a script but to also provide arguments. I can see from your question that you provided the argument @string@
. For my script, I was passing multiple arguments, which Xcode allows you to do using a comma separated list, e.g. @foo@, @bar@, @baz@
. Each of these arguments was a string.
I noticed that sometimes one or more of these strings would truncate if they contained a comma: ,
.
So the string:
{ "num_friends" : "7" }
would be passed to my script as expected. But the string:
{ "num_friends" : "7", "num_deleted_friends" : "1" }
would truncate and would be passed to my script as two separate arguments. It seems that Xcode would split any string with a ,
even when entered using @string@
.
I validated this in my script by simply using something like:
for var in "$@"
do
echo "$var"
echo "===="
done
Where $@
expands to contain each argument. From this I could see that @string@
was being correctly passed to my script but separated as multiple arguments wherever there was a ,
. So if @string@
contained a comma my script would print:
@"{ \"num_friends\" : \"7\"
====
\"num_deleted_friends\" : \"1\" }"
instead of what I expected which was:
@"{ \"num_friends\" : \"7\", \"num_deleted_friends\" : \"1\" }"
So it seems like it might be a bug in how Xcode passes strings inside @
expressions in the breakpoint editor window.
My crude solution has been to just replace any commas with another character and then replace them back again inside my script. There's probably a better way to do this but I don't require it for my needs.
Upvotes: 2