c++xcodeqtgdbqlist

Printing Qt data structures (QList, QString, etc.) in XCode 3.xx GDB


I am trying to debug some Qt containers in XCode and the results I get back from GDB are not useful:

    print l1
$1 = (QSharedPointer<QList<SNAPSHOT> > &) @0x102780650: {
  <QtSharedPointer::ExternalRefCount<QList<SNAPSHOT> >> = {
    <QtSharedPointer::Basic<QList<SNAPSHOT> >> = {
      value = 0x1161e47e0
    }, 
    members of QtSharedPointer::ExternalRefCount<QList<SNAPSHOT> >: 
    d = 0x1161ace00
  }, <No data fields>}
Current language:  auto; currently c++
(gdb) print strQuery
$2 = {
  d = 0x1161e2890

How do I get some useful out put from l1 (QList) and strQuery (QString)?
I've already tried using this .gdbinit which adds some macros like "printq4string" but those are quite painful to use as when printing out structs i need to manually run this on each member variable.


Solution

  • I read the source and came up with this suboptimal approach, I leave it to the community to improve on this:

        QString s1("This should be easy");
    
        QList<QString> s;
        s.push_back("Can you debug me?");
    
    (gdb) print/c s1.d.data[0]@30
    $2 = {84 'T', 104 'h', 105 'i', 115 's', 32 ' ', 115 's', 104 'h', 111 'o', 117 'u', 108 'l', 100 'd', 32 ' ', 98 'b', 101 'e', 32 ' ', 101 'e', 97 'a', 115 's', 121 'y', 0 '\0', 0 '\0', 0 '\0', 0 '\0', 0 '\0', 0 '\0', 0 '\0', 0 '\0', 14 '\016', 0 '\0', 0 '\0'}
    
    (gdb) print/c ((QString*)s.d.array).d.data[0]@20
    $12 = {67 'C', 97 'a', 110 'n', 32 ' ', 121 'y', 111 'o', 117 'u', 32 ' ', 100 'd', 101 'e', 98 'b', 117 'u', 103 'g', 32 ' ', 109 'm', 101 'e', 63 '?', 0 '\0', 0 '\0', 0 '\0'}