32

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?

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
mcccclean
  • 7,721
  • 10
  • 32
  • 36
  • 1
    Is there really no way to make the GUI display the non-elided version of the string? – i_am_jorf Dec 15 '10 at 19:31
  • Notably, 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. – pkamb Jan 30 '15 at 06:32

3 Answers3

36

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.

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
Jason Coco
  • 77,985
  • 20
  • 184
  • 180
  • Thanks. Kind of lame that this is not built into the XCode views, but at least I can see what I'm looking at now. – Brian Moeskau Sep 24 '10 at 18:32
  • Viewing 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? – pkamb Jan 30 '15 at 06:33
  • 2
    For me, the print variant didn't supress the string "shortening", so I still can't see the entire string. – pojo Mar 12 '15 at 13:22
  • 1
    For a solution to display long strings, see: https://stackoverflow.com/questions/31402092/print-long-string-in-xcode-6-debugging-console – Dark Mar 16 '20 at 13:24
8

To display really long string use method from print long string in xcode 6 debugging console

  1. In lldb console increase max-string-summary-length
setting set target.max-string-summary-length 10000
  1. Print your string with print or po commands
print my_string
Alexander Ushakov
  • 5,139
  • 3
  • 27
  • 50
1

If you are compiling c++ project in xcode just use this command

po string_name

Muhammad Shauket
  • 2,643
  • 19
  • 40
  • 1
    Sadly this also does not suppress the string shortening, it still truncates with an ellipsis for long strings – Dark Mar 16 '20 at 13:23