Xcode debugger: display long strings
Solution 1
In the debugging console you can get the string value by doing something like:
(gdb) print (void)CFShow(myCFString)
or:
(gdb) po (NSString*)myCFString
Either of those will display the entire string's contents to the debugging console. It's probably the easiest way to deal with large, variable-length strings or data structures of any kind.
For more information, the print
command in the debugger basically dumps some data structure to the console. You can also call any functions or whatever, but since print doesn't have access to the function declarations, you have to make sure you provide them implicitly (as shown in the example above), or the print command will complain.
po
is a shortcut for print-object
and is the same as print except for Objective-C objects. It basically functions like this:
(gdb) print (const char *)[[theObject debugDescription] UTF8String]
This is really useful for examining things like NSData
object and NSArray
/NSDictionary
objects.
For a lot more information on debugging topics, see Technical Note TN2124 - Mac OS X Debugging Magic and (from the debugger console) you can issue the help
command as well.
Solution 2
To display really long string use method from print long string in xcode 6 debugging console
- In lldb console increase max-string-summary-length
setting set target.max-string-summary-length 10000
- Print your string with
print
orpo
commands
print my_string
Solution 3
If you are compiling c++ project in xcode just use this command
po string_name
Related videos on Youtube
mcccclean
Updated on July 09, 2022Comments
-
mcccclean almost 2 years
While debugging a program in Xcode I have several
CFStringRef
variables that point to strings with lengths around the 200 character mark.In the debugger, it only shows the value of these strings up to a certain length and then just ellipses them away. I'd really like to see the full value of the strings.
Is there some option I can configure so it doesn't terminate them at arbitrary length?
-
jamil ahmed over 13 yearsIs there really no way to make the GUI display the non-elided version of the string?
-
pkamb about 9 yearsNotably, the debugger shows the string with escape characters. When the string is printed in the console, the escape characters are not included. "\"code\"" vs. "code". This 100 character limit is very annoying as it prevents you from copying, say, a long JSON string and then immediately pasting that string (escape characters included) as a test string variable in your code.
-
-
Brian Moeskau over 13 yearsThanks. Kind of lame that this is not built into the XCode views, but at least I can see what I'm looking at now.
-
pkamb about 9 yearsViewing the string in the debugger, escape characters are included. These are not printed to the console with
po
. Do you know of any way to preserve escape characters in the string? -
pojo about 9 yearsFor me, the print variant didn't supress the string "shortening", so I still can't see the entire string.
-
Dark about 4 yearsSadly this also does not suppress the string shortening, it still truncates with an ellipsis for long strings
-
Dark about 4 yearsFor a solution to display long strings, see: stackoverflow.com/questions/31402092/…