Strings in gdb


#1

Does anybody know how to print the contents of a String (wide char) using gdb?


#2

Six month after… :smiley:

Does anybody know if there’s a way to display a Juce String in the Xcode debugger ?

thanks!


#3

I’ve never found a way, (though haven’t looked very hard, TBH). It’d certainly be handy.


#4

I found this, but never tried it: http://www.skynet.ie/~caolan/TechTexts/GdbUnicodePrinting.html


#5

Not an elegant solution, but better than nothing: I simply expand the string variable to show the following:

myString
private
text

then right click on text and select View As Memory. In the memory viewer window set the Columns combo to 4 and voila, your string is readable in the text pane, vertically. I said it was not beautiful :slight_smile: but for me it alredy avoided hundreds of debug printouts.


#6

The previous post was not 100% correct, the “text” item I spoke about also contains the refCount and the allocatedNumChars integers, so you have to expand the String variable a bit more:

myString
private
text
refCount
allocatedNumChars
text

Now View As Memory on the second “text” line really gives you the content of your String.


#7

If you can tunnel down into the juce String class to see the data you want, then shouldn’t it be possible to write a custom data formatter for XCode to do the same thing, but without the hassle?

http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeUserGuide/Contents/Resources/en.lproj/06_04_db_view_info/chapter_42_section_4.html


#8

With custom data formatters in XCode you can customize how variables
will be presented in the Value and Summary columns of the variable view of the debugger.

This option is especially useful if you have complex data structures and you would like to watch the most important fields in the Summary column.
You can switch on/off Data Formatters with the menu item Debug > Variables View > Enable Data Formatters.
They are enabled by default.

In order to create a data formatter for the juce string class
you have to follow these steps:

o - Enable Data Formatters with Debug > Variables View.
o - In the editor set a breakpoint just one line after your string variable
o - Start your debugger and click continue until you reach this line.
o - Right-Click with your mouse inside the variable view of the debugger
at the line which shows information about your variable (Type,Value,Summary)
o - Inside the context-menu which opens now select the item ‘Edit summary format’

o - The summary field now is editable. Copy the following format string into the field:
{(const char *)$VAR.toUTF8()}:s

o - Press the return key. Now you should see the proper formatted value.

In the expression above we have used the string conversion method ‘toUTF8’ which is a built-in function of the juce string class. With $VAR we referenced the current variable. The :s stands for the Summary column.

Hope that helps
Best regards,
Frank


#9

Nice one Frank - thanks for the tip, that’ll come in handy.

I’m impressed that it can actually call c++ functions to format the data, I didn’t realise it was that powerful…


#10

Thanks again for that tip Frank. My Xcode stopped working with that, then finally stopped trying even. I just refreshed it from your tip, and it’s back to good. Jules - I don’t suppose this qualifies as a sticky topic? Debugging on Mac is heinous without it.

Bruce


#11

done - (hope you don’t mind Jules).


#12

Thanks, valley!


#13