I’m still learning the power of gdb. It’s an immensely useful tool for debugging programs (funny, that…).
Today I wanted to find out the contents of a QString. “print s”, where “s” is a QString, doesn’t do much for you, though. The data is stored as an array of ushorts inside a shared data member. But all I want is to print out the string as it would appear if I did “qDebug() << s”, for example.
Solution: head over to the kdesdk module, and into the scripts directory, where mountains of useful bits reside. The script you want is kde-devel-gdb.
Now copy this to your home directory and put the line “source ~/kde-devel-gdb” into your ~/.gdbinit file. Or, if you’re building KDE in the manner prescribed on techbase, you can just put “source /home/kde-devel/src/KDE/kdesdk/scripts/kde-devel-gdb” into your ~/.gdbinit file.
To use, check out “help user-defined”. For example, to print a QString called s, type “printq4string s”. Ta-da!
10th December 2012 at 2:41 pm |
1. Where is the kdesdk module?
2. I have the kde-devel-gdb file contents – what extension do I give it when I create the file?
3. I don’t have a.gdbinit file. If I make a gdbinit file, what do I call it? You only give what the extension should be.
Thanks in advance.
10th December 2012 at 9:21 pm |
1. The kdesdk module is where I linked to it. If you want to get a local copy of it, you need to do
svn checkout http://anonsvn.kde.org/home/kde/trunk/KDE/kdesdk
2. You don’t have to give it any extensions. Linux doesn’t care about extensions in the same way that Windows does.
3. Similarly, “gdbinit” is not the extension, “.gdbinit” is the whole filename. Just do something like
echo ‘source ~/kde-devel-gdb’ >> ~/.gdbinit