PDA

View Full Version : Xcode Qt4 Custom Data Formatters (for viewing in the debugger)



jkyle
14th May 2010, 01:21
Hey Everyone,

Xcode makes a very nice IDE for Qt for those of use doing our work on a mac. And though Creator is also shaping up to be a very nice IDE, it's one more tool to learn.

It was irking me to no end that viewing the values of various QObjects wasn't possible in the Debugger. So I set out on a mission.

The result of the mission is plugin bundle I wrote that does just that. The supported data types are limited as I just got started, but it covers:

QString (displays the string)
QModelIndex (displays something like row: 1, col: 5)
QVariant (displays the toString() for it)
QFile (displays the assigned file path)


And I'm working on a QAbstractItemModel (I figure I'll show the metaobject's className property).

Works with both pointers and instances of those data types "out the box".

Anyway, during my searching I saw this come up quite a few times with no good solution for it, so here's my work:

http://github.com/jameskyle/Qt4DataFormatter

abey
14th May 2010, 13:40
Great initiative! I was precisely look for a solution for this issue.

I could compile the bundle (in 32bit) and install it, but couldn't see any change in Xcode. I figured it might be a 64bit vs. 32 bit thing and restarted Xcode in 32bit mode, but it didn't change anything. Is there anything else that must be done/enabled/whatnot?

Thanks
Antoine

abey
14th May 2010, 13:44
Actually, never mind my question above. It's actually working!

What wasn't working is for references (QString&). Is there any way this could be done?

jkyle
14th May 2010, 16:12
I could compile the bundle (in 32bit) and install it, but couldn't see any change in Xcode. I figured it might be a 64bit vs. 32 bit thing and restarted Xcode in 32bit mode, but it didn't change anything. Is there anything else that must be done/enabled/whatnot?


Yeah, make sure it's the proper arch. The bundle is loaded when you open the xcode debugger. So if you tail -f /var/log/system.log before opening the debugger you should see any error output that could cause failure to load.

Also, you can verify the bundle was properly loaded by opening

Run=>Show=>Shared Libraries

If the bundle was loaded (after opening the debugger), you'll see a line similar to (you can filter by name)


Qt4DataFormatter 0x00000001002 All Default

I need to build a universal binary of qt4 so I can build a universal of this bundle.

abey
14th May 2010, 16:18
Thanks for the info. Any idea on how to make it work with QString references?

jkyle
14th May 2010, 16:20
Actually, never mind my question above. It's actually working!

What wasn't working is for references (QString&). Is there any way this could be done?

Sure. The displays are all simple functions that take a pointer as an argument and then return a char* of the summary string. If you double click on the summary, you'll see something like:


// Summary String for QString *
{(char *)printQString($VAR, (int) $ID)}:s

$VAR is the raw variable that's appearing (in this case a pointer) and $ID is some generated instance id. The rest is basically just a function call and I cast the output for good measure.

So, for a QString &, you could double click the Summary string and put something like:


// Summary String for QString &
{(char *)printQString(&$VAR, (int) $ID)}:s

I'm not 100% on this one, I'll test it the next time I run across a reference, but you get the idea. When you make changes like this, it saves them in ~/Library/Application\ Support/Developer/Shared/Xcode/CustomDataViews/CustomDataViews.plist

If you find a matching print method, you can add it to the bundle itself too and share. The bundle has a CustomDataViews.plist in it's bundle package that's referred to.

abey
14th May 2010, 16:24
Awesome, it works! Thanks a bunch!

jkyle
17th May 2010, 18:52
I've added summaries for QDomNodes and QDomElements. They are now available in master.

They'll show up like this in the summary field of the debugger:


"tagName: some_tname, text: contents of tag"

andrey_s
29th December 2011, 22:45
Does anybody know will it work with xcode4? I get compilation error, it can find this file:
#include "/Developer/Applications/Xcode.app/Contents/PlugIns/GDBMIDebugging.xcplugin/Contents/Headers/DataFormatterPlugin.h"

dgermann
22nd April 2013, 12:21
Hello

Thank you for this formatter, it is very useful indeed.

However, I am having some troubles using it. Though it works in principle, the xCode debugger does not always display the contents of a variable. Sometimes, "out of scope" is displayed although the variable should be known, or the format string itself is displayed instead its evaluation. Also, sometimes the summary is not updated until one or two additional code lines are executed.

Originally, code optimizations were activated. Deactivating them did help but not entirely remove the above symptoms. Are there other build settings interfering with the formatter? Is there a way to enforce an update of the summary of a variable or is there any other way to avoid the described problems?

I am using xCode 3.2.6 64-bit (for compatibility reasons, so an update to xCode 4 won't be an option)

Thanks a lot.