gdbmacros.py 64 KB
Newer Older
hjk's avatar
hjk committed
1
2
3
4
5
6
7
8
9

#Note: Keep name-type-value-numchild-extra order

#######################################################################
#
# Dumper Implementations
#
#######################################################################

10
def qdump__QByteArray(d, item):
11
12
    d.putByteArrayValue(item.value)

hjk's avatar
hjk committed
13
14
    d_ptr = item.value['d'].dereference()
    size = d_ptr['size']
15
    d.putNumChild(size)
hjk's avatar
hjk committed
16
17

    if d.isExpanded(item):
18
19
20
        n = qmin(size, 1000)
        innerType = gdb.lookup_type("char")
        data = d_ptr['data']
21
        d.beginChildren(n, innerType)
hjk's avatar
hjk committed
22
23
24
25
26
27
28
29
30
        p = gdb.Value(data.cast(innerType.pointer()))
        for i in xrange(0, n):
            d.putItem(Item(p.dereference(), item.iname, i, None))
            p += 1
        if n < size:
            d.putEllipsis()
        d.endChildren()


31
def qdump__QChar(d, item):
hjk's avatar
hjk committed
32
    ucs = int(item.value["ucs"])
33
    c = select(curses.ascii.isprint(ucs), ucs, '?')
34
    d.putValue("'%c' (%d)" % (c, ucs))
hjk's avatar
hjk committed
35
36
37
    d.putNumChild(0)


38
def qdump__QAbstractItem(d, item):
hjk's avatar
hjk committed
39
40
41
42
43
44
45
46
47
48
    r = item.value["r"]
    c = item.value["c"]
    p = item.value["p"]
    m = item.value["m"]
    rowCount = call(m, "rowCount(mi)")
    if rowCount < 0:
        return
    columnCount = call(m, "columnCount(mi)")
    if columnCount < 0:
        return
49
50
    d.putStringValue(call(m, "data(mi, Qt::DisplayRole).toString()"))
    d.putNumChild(rowCount * columnCount)
hjk's avatar
hjk committed
51
52
53
54
55
56
    if d.isExpanded(item):
        innerType = gdb.lookup_type(d.ns + "QAbstractItem")
        d.beginChildren()
        for row in xrange(0, rowCount):
            for column in xrange(0, columnCount):
                child = call(m, "index(row, column, mi)")
57
                d.putName("[%s,%s]" % (row, column))
hjk's avatar
hjk committed
58
59
                rr = call(m, "rowCount(child)")
                cc = call(m, "columnCount(child)")
60
                d.putNumChild(rr * cc)
hjk's avatar
hjk committed
61
                d.putField("value",
62
                    call(m, "data(child, Qt::DisplayRole).toString())"), 6)
hjk's avatar
hjk committed
63
64
                d.endHash()
        #d.beginHash()
65
66
67
        #d.putName("DisplayRole")
        #d.putNumChild(0)
        #d.putValue(m->data(mi, Qt::DisplayRole).toString(), 2)
hjk's avatar
hjk committed
68
69
70
71
72
        #d.putField("type", ns + "QString")
        #d.endHash()
        d.endChildren()


73
def qdump__QAbstractItemModel(d, item):
hjk's avatar
hjk committed
74
75
76
77
78
79
80
    rowCount = call(item.value, "rowCount()")
    if rowCount < 0:
        return
    columnCount = call(item.valuem, "columnCount()")
    if columnCount < 0:
        return

81
82
    d.putValue("(%s,%s)" % (rowCount, columnCount))
    d.putNumChild(1)
hjk's avatar
hjk committed
83
    if d.isExpanded(item):
84
        d.beginChildren(1)
hjk's avatar
hjk committed
85
        d.beginHash()
86
87
88
89
        d.putNumChild(1)
        d.putName(d.ns + "QObject")
        d.putValue(call(item.value, "objectName()"), 2)
        d.putType(d.ns + "QObject")
hjk's avatar
hjk committed
90
91
92
93
94
95
        d.putField("displayedtype", call(item, "m.metaObject()->className()"))
        d.endHash()
        for row in xrange(0, rowCount):
            for column in xrange(0, columnCount):
                mi = call(m, "index(%s,%s)" % (row, column))
                d.beginHash()
96
97
98
99
100
                d.putName("[%s,%s]" % (row, column))
                d.putValue("m.data(mi, Qt::DisplayRole).toString()", 6)
                #d.putNumChild((m.hasChildren(mi) ? 1 : 0)
                d.putNumChild(1) #m.rowCount(mi) * m.columnCount(mi))
                d.putType(d.ns + "QAbstractItem")
hjk's avatar
hjk committed
101
102
103
104
                d.endHash()
        d.endChildren()


105
def qdump__QDateTime(d, item):
106
107
    d.putStringValue(call(item.value, "toString(%sQt::TextDate)" % d.ns))
    d.putNumChild(3)
hjk's avatar
hjk committed
108
    if d.isExpanded(item):
109
        d.beginChildren(8)
hjk's avatar
hjk committed
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
        d.putCallItem("isNull", item, "isNull()")
        d.putCallItem("toTime_t", item, "toTime_t()")
        d.putCallItem("toString",
            item, "toString(%sQt::TextDate)" % d.ns)
        d.putCallItem("(ISO)",
            item, "toString(%sQt::ISODate)" % d.ns)
        d.putCallItem("(SystemLocale)",
            item, "toString(%sQt::SystemLocaleDate)" % d.ns)
        d.putCallItem("(Locale)",
            item, "toString(%sQt::LocaleDate)" % d.ns)
        d.putCallItem("toUTC",
            item, "toTimeSpec(%sQt::UTC)" % d.ns)
        d.putCallItem("toLocalTime",
            item, "toTimeSpec(%sQt::LocalTime)" % d.ns)
        d.endChildren()


127
def qdump__QDir(d, item):
128
129
    d.putStringValue(call(item.value, "path()"))
    d.putNumChild(2)
hjk's avatar
hjk committed
130
    if d.isExpanded(item):
131
        d.beginChildren(2)
hjk's avatar
hjk committed
132
133
134
135
136
        d.putCallItem("absolutePath", item, "absolutePath()")
        d.putCallItem("canonicalPath", item, "canonicalPath()")
        d.endChildren()


137
def qdump__QFile(d, item):
138
139
    d.putStringValue(call(item.value, "fileName()"))
    d.putNumChild(2)
hjk's avatar
hjk committed
140
    if d.isExpanded(item):
141
        d.beginChildren(2)
hjk's avatar
hjk committed
142
143
144
145
146
        d.putCallItem("fileName", item, "fileName()")
        d.putCallItem("exists", item, "exists()")
        d.endChildren()


147
def qdump__QFileInfo(d, item):
148
149
    d.putStringValue(call(item.value, "filePath()"))
    d.putNumChild(3)
hjk's avatar
hjk committed
150
    if d.isExpanded(item):
151
        d.beginChildren(10, gdb.lookup_type(d.ns + "QString"))
hjk's avatar
hjk committed
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
        d.putCallItem("absolutePath", item, "absolutePath()")
        d.putCallItem("absoluteFilePath", item, "absoluteFilePath()")
        d.putCallItem("canonicalPath", item, "canonicalPath()")
        d.putCallItem("canonicalFilePath", item, "canonicalFilePath()")
        d.putCallItem("completeBaseName", item, "completeBaseName()")
        d.putCallItem("completeSuffix", item, "completeSuffix()")
        d.putCallItem("baseName", item, "baseName()")
        if False:
            #ifdef Q_OS_MACX
            d.putCallItem("isBundle", item, "isBundle()")
            d.putCallItem("bundleName", item, "bundleName()")
        d.putCallItem("fileName", item, "fileName()")
        d.putCallItem("filePath", item, "filePath()")
        # Crashes gdb (archer-tromey-python, at dad6b53fe)
        #d.putCallItem("group", item, "group()")
        #d.putCallItem("owner", item, "owner()")
        d.putCallItem("path", item, "path()")

        d.putCallItem("groupid", item, "groupId()")
        d.putCallItem("ownerid", item, "ownerId()")

        #QFile::Permissions permissions () const
        perms = call(item.value, "permissions()")
        d.beginHash()
176
177
178
179
        d.putName("permissions")
        d.putValue(" ")
        d.putType(d.ns + "QFile::Permissions")
        d.putNumChild(10)
hjk's avatar
hjk committed
180
        if d.isExpandedIName(item.iname + ".permissions"):
181
            d.beginChildren(10)
hjk's avatar
hjk committed
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
            d.putBoolItem("ReadOwner",  perms & 0x4000)
            d.putBoolItem("WriteOwner", perms & 0x2000)
            d.putBoolItem("ExeOwner",   perms & 0x1000)
            d.putBoolItem("ReadUser",   perms & 0x0400)
            d.putBoolItem("WriteUser",  perms & 0x0200)
            d.putBoolItem("ExeUser",    perms & 0x0100)
            d.putBoolItem("ReadGroup",  perms & 0x0040)
            d.putBoolItem("WriteGroup", perms & 0x0020)
            d.putBoolItem("ExeGroup",   perms & 0x0010)
            d.putBoolItem("ReadOther",  perms & 0x0004)
            d.putBoolItem("WriteOther", perms & 0x0002)
            d.putBoolItem("ExeOther",   perms & 0x0001)
            d.endChildren()
        d.endHash()

        #QDir absoluteDir () const
        #QDir dir () const
        d.putCallItem("caching", item, "caching()")
        d.putCallItem("exists", item, "exists()")
        d.putCallItem("isAbsolute", item, "isAbsolute()")
        d.putCallItem("isDir", item, "isDir()")
        d.putCallItem("isExecutable", item, "isExecutable()")
        d.putCallItem("isFile", item, "isFile()")
        d.putCallItem("isHidden", item, "isHidden()")
        d.putCallItem("isReadable", item, "isReadable()")
        d.putCallItem("isRelative", item, "isRelative()")
        d.putCallItem("isRoot", item, "isRoot()")
        d.putCallItem("isSymLink", item, "isSymLink()")
        d.putCallItem("isWritable", item, "isWritable()")
        d.putCallItem("created", item, "created()")
        d.putCallItem("lastModified", item, "lastModified()")
        d.putCallItem("lastRead", item, "lastRead()")
        d.endChildren()


217
def qdump__QFlags(d, item):
hjk's avatar
hjk committed
218
219
220
221
    #warn("QFLAGS: %s" % item.value) 
    i = item.value["i"]
    enumType = item.value.type.template_argument(0)
    #warn("QFLAGS: %s" % item.value["i"].cast(enumType)) 
222
    d.putValue("%s (%s)" % (i.cast(enumType), i))
hjk's avatar
hjk committed
223
224
225
    d.putNumChild(0)


226
def qdump__QHash(d, item):
hjk's avatar
hjk committed
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268

    def hashDataFirstNode(value):
        value = value.cast(hashDataType)
        bucket = value["buckets"]
        e = value.cast(hashNodeType)
        for n in xrange(value["numBuckets"] - 1, -1, -1):
            n = n - 1
            if n < 0:
                break
            if bucket.dereference() != e:
                return bucket.dereference()
            bucket = bucket + 1
        return e;

    def hashDataNextNode(node):
        next = node["next"]
        if next["next"]:
            return next
        d = node.cast(hashDataType.pointer()).dereference()
        numBuckets = d["numBuckets"]
        start = (node["h"] % numBuckets) + 1
        bucket = d["buckets"] + start
        for n in xrange(0, numBuckets - start):
            if bucket.dereference() != next:
                return bucket.dereference()
            bucket += 1
        return node

    keyType = item.value.type.template_argument(0)
    valueType = item.value.type.template_argument(1)

    d_ptr = item.value["d"]
    e_ptr = item.value["e"]
    n = d_ptr["size"]

    hashDataType = d_ptr.type
    hashNodeType = e_ptr.type

    check(0 <= n and n <= 100 * 1000 * 1000)
    check(d_ptr["ref"]["_q_value"] > 0)

    d.putItemCount(n)
269
    d.putNumChild(n)
hjk's avatar
hjk committed
270
271
272
273
274
275
276
277
278
    if d.isExpanded(item):
        if n > 1000:
            n = 1000

        isSimpleKey = isSimpleType(keyType)
        isSimpleValue = isSimpleType(valueType)
        node = hashDataFirstNode(item.value)

        innerType = e_ptr.dereference().type
279
280
        inner = select(isSimpleKey and isSimpleValue, valueType, innerType)
        d.beginChildren(n, inner)
hjk's avatar
hjk committed
281
282
283
284
285
286
        for i in xrange(0, n):
            it = node.dereference().cast(innerType)
            d.beginHash()
            key = it["key"]
            value = it["value"]
            if isSimpleKey and isSimpleValue:
287
                d.putName(key)
hjk's avatar
hjk committed
288
289
290
291
292
293
294
295
296
                d.putItemHelper(Item(value, item.iname, i, None))
                d.putType(valueType)
            else:
                d.putItemHelper(Item(it, item.iname, i, None))
            d.endHash()
            node = hashDataNextNode(node)
        d.endChildren()


297
def qdump__QHashNode(d, item):
hjk's avatar
hjk committed
298
299
300
301
302
303
    keyType = item.value.type.template_argument(0)
    valueType = item.value.type.template_argument(1)
    key = item.value["key"]
    value = item.value["value"]

    if isSimpleType(valueType):
304
        d.safePutItemHelper(Item(value))
hjk's avatar
hjk committed
305
    else:
306
        d.putValue(" ")
hjk's avatar
hjk committed
307

308
    d.putNumChild(2)
hjk's avatar
hjk committed
309
310
311
    if d.isExpanded(item):
        d.beginChildren()
        d.beginHash()
312
        d.putName("key")
hjk's avatar
hjk committed
313
314
315
        d.putItemHelper(Item(key, None, None, None))
        d.endHash()
        d.beginHash()
316
        d.putName("value")
hjk's avatar
hjk committed
317
318
319
320
321
        d.putItemHelper(Item(value, None, None, None))
        d.endHash()
        d.endChildren()


322
def qdump__QList(d, item):
hjk's avatar
hjk committed
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
    d_ptr = item.value["d"]
    begin = d_ptr["begin"]
    end = d_ptr["end"]
    array = d_ptr["array"]
    check(begin >= 0 and end >= 0 and end <= 1000 * 1000 * 1000)
    n = end - begin
    check(n >= 0)
    #if n > 0:
    #    checkAccess(&list.front())
    #    checkAccess(&list.back())

    check(d_ptr["ref"]["_q_value"] > 0)

    # Additional checks on pointer arrays.
    innerType = item.value.type.template_argument(0)
    innerTypeIsPointer = innerType.code == gdb.TYPE_CODE_PTR \
        and str(innerType.target().unqualified()) != "char"
    if innerTypeIsPointer:
        p = gdb.Value(array).cast(innerType.pointer()) + begin
342
        checkPointerRange(p, qmin(n, 100))
hjk's avatar
hjk committed
343
344

    d.putItemCount(n)
345
    d.putNumChild(n)
hjk's avatar
hjk committed
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
    if d.isExpanded(item):
        # about 0.5s / 1000 items
        if n > 2000:
            n = 2000

        innerSize = innerType.sizeof
        # The exact condition here is:
        #  QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic
        # but this data is available neither in the compiled binary nor
        # in the frontend.
        # So as first approximation only do the 'isLarge' check:
        isInternal = innerSize <= d_ptr.type.sizeof and d.isMovableType(innerType)
        #warn("INTERNAL: %d" % int(isInternal))

        p = gdb.Value(array).cast(innerType.pointer()) + begin
361
362
363
364
365
        if innerTypeIsPointer:
            inner = innerType.target()
        else:
            inner = innerType
        d.beginChildren(n, inner)
hjk's avatar
hjk committed
366
        for i in xrange(0, n):
367
368
            if isInternal:
                d.putItem(Item(p.dereference(), item.iname, i, None))
hjk's avatar
hjk committed
369
            else:
370
371
                pp = p.cast(innerType.pointer().pointer()).dereference()
                d.putItem(Item(pp.dereference(), item.iname, i, None))
hjk's avatar
hjk committed
372
373
374
375
376
377
378
            p += 1

        if n < end - begin:
            d.putEllipsis()
        d.endChildren()


379
def qdump__QImage(d, item):
hjk's avatar
hjk committed
380
381
382
383
    painters = item.value["painters"]
    check(0 <= painters and painters < 1000)
    d_ptr = item.value["d"]
    if isNull(d_ptr):
384
        d.putValue("(null)")
hjk's avatar
hjk committed
385
386
    else:
        check(d_ptr["ref"]["_q_value"] > 0)
387
388
        d.putValue("(%dx%d)" % (d_ptr["width"], d_ptr["height"]))
    d.putNumChild(0)
hjk's avatar
hjk committed
389
390
391
392
393
394
395
396
397
398
399
400
401
402
    #d.putNumChild(1)
    if d.isExpanded(item):
        d.beginChildren()
        d.beginHash()
        d.putName("data")
        d.putType(" ");
        d.putNumChild(0)
        bits = d_ptr["data"]
        nbytes = d_ptr["nbytes"]
        d.putValue("size: %s bytes" % nbytes);
        d.putField("valuetooltipencoded", "6")
        d.putField("valuetooltip", encodeCharArray(bits, nbytes))
        d.endHash()
        d.endChildren()
hjk's avatar
hjk committed
403
404


405
def qdump__QLinkedList(d, item):
hjk's avatar
hjk committed
406
407
408
409
410
411
412
413
    d_ptr = item.value["d"]
    e_ptr = item.value["e"]
    nn = d_ptr["size"]
    n = nn
    check(0 <= n and n <= 100*1000*1000)
    check(d_ptr["ref"]["_q_value"] > 0)

    d.putItemCount(n)
414
    d.putNumChild(n)
hjk's avatar
hjk committed
415
416
417
418
419

    if d.isExpanded(item):
        innerType = item.value.type.template_argument(0)
        if n > 1000:
            n = 1000
420
        d.beginChildren(n, innerType)
hjk's avatar
hjk committed
421
422
        p = e_ptr["n"]
        for i in xrange(0, n):
423
            d.safePutItem(Item(p["t"], None, None, None))
hjk's avatar
hjk committed
424
425
426
427
428
429
            p = p["n"]
        if n < nn:
            d.putEllipsis()
        d.endChildren()


430
def qdump__QLocale(d, item):
431
432
    d.putStringValue(call(item.value, "name()"))
    d.putNumChild(8)
hjk's avatar
hjk committed
433
    if d.isExpanded(item):
434
        d.beginChildren(1, gdb.lookup_type(d.ns + "QChar"), 0)
hjk's avatar
hjk committed
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
        d.putCallItem("country", item, "country()")
        d.putCallItem("language", item, "language()")
        d.putCallItem("measurementSystem", item, "measurementSystem()")
        d.putCallItem("numberOptions", item, "numberOptions()")
        d.putCallItem("timeFormat_(short)", item,
            "timeFormat(" + d.ns + "QLocale::ShortFormat)")
        d.putCallItem("timeFormat_(long)", item,
            "timeFormat(" + d.ns + "QLocale::LongFormat)")
        d.putCallItem("decimalPoint", item, "decimalPoint()")
        d.putCallItem("exponential", item, "exponential()")
        d.putCallItem("percent", item, "percent()")
        d.putCallItem("zeroDigit", item, "zeroDigit()")
        d.putCallItem("groupSeparator", item, "groupSeparator()")
        d.putCallItem("negativeSign", item, "negativeSign()")
        d.endChildren()


452
def qdump__QMapNode(d, item):
453
454
    d.putValue(" ")
    d.putNumChild(2)
hjk's avatar
hjk committed
455
    if d.isExpanded(item):
456
        d.beginChildren(2)
hjk's avatar
hjk committed
457
        d.beginHash()
458
        d.putName("key")
hjk's avatar
hjk committed
459
460
461
        d.putItemHelper(Item(item.value["key"], item.iname, "name", None))
        d.endHash()
        d.beginHash()
462
        d.putName("value")
hjk's avatar
hjk committed
463
464
465
466
467
        d.putItemHelper(Item(item.value["value"], item.iname, "value", None))
        d.endHash()
        d.endChildren()


468
def qdump__QMap(d, item):
hjk's avatar
hjk committed
469
470
471
472
473
474
475
    d_ptr = item.value["d"].dereference()
    e_ptr = item.value["e"].dereference()
    n = d_ptr["size"]
    check(0 <= n and n <= 100*1000*1000)
    check(d_ptr["ref"]["_q_value"] > 0)

    d.putItemCount(n)
476
    d.putNumChild(n)
hjk's avatar
hjk committed
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
    if d.isExpanded(item):
        if n > 1000:
            n = 1000

        keyType = item.value.type.template_argument(0)
        valueType = item.value.type.template_argument(1)

        isSimpleKey = isSimpleType(keyType)
        isSimpleValue = isSimpleType(valueType)

        it = e_ptr["forward"].dereference()

        # QMapPayloadNode is QMapNode except for the 'forward' member, so
        # its size is most likely the offset of the 'forward' member therein.
        # Or possibly 2 * sizeof(void *)
        nodeType = gdb.lookup_type(d.ns + "QMapNode<%s, %s>" % (keyType, valueType))
        payloadSize = nodeType.sizeof - 2 * gdb.lookup_type("void").pointer().sizeof
        charPtr = gdb.lookup_type("char").pointer()

496
        innerType = select(isSimpleKey and isSimpleValue, valueType, nodeType)
hjk's avatar
hjk committed
497

498
        d.beginChildren(n, innerType)
hjk's avatar
hjk committed
499
500
501
502
503
504
505
506
507
508
509
        for i in xrange(0, n):
            itd = it.dereference()
            base = it.cast(charPtr) - payloadSize
            node = base.cast(nodeType.pointer()).dereference()
            d.beginHash()

            key = node["key"]
            value = node["value"]
            #if isSimpleType(item.value.type): # or isStringType(d, item.value.type):
            if isSimpleKey and isSimpleValue:
                #d.putType(valueType)
510
                d.putName(key)
hjk's avatar
hjk committed
511
512
513
514
515
516
517
518
                d.putItemHelper(Item(value, item.iname, i, None))
            else:
                d.putItemHelper(Item(node, item.iname, i, None))
            d.endHash()
            it = it.dereference()["forward"].dereference()
        d.endChildren()


519
520
def qdump__MultiMap(d, item):
    qdump__Map(d, item)
hjk's avatar
hjk committed
521
522


523
def qdump__QModelIndex(d, item):
hjk's avatar
hjk committed
524
525
526
527
528
    r = item.value["r"]
    c = item.value["c"]
    p = item.value["p"]
    m = item.value["m"]
    if r >= 0 and c >= 0 and not isNull(m):
529
530
        d.putValue("(%s, %s)" % (r, c))
        d.putNumChild(5)
hjk's avatar
hjk committed
531
532
533
534
535
536
        if d.isExpanded(item):
            d.beginChildren()
            d.putIntItem("row", r)
            d.putIntItem("column", c)
            d.putCallItem("parent", item, "parent()")
            d.beginHash()
537
538
539
540
            d.putName("model")
            d.putValue(m)
            d.putType(d.ns + "QAbstractItemModel*")
            d.putNumChild(1)
hjk's avatar
hjk committed
541
542
543
544
            d.endHash()

            d.endChildren()
    else:
545
546
        d.putValue("(invalid)")
        d.putNumChild(0)
hjk's avatar
hjk committed
547
548
549
550
551
552
553
554
555
556
557
558
559


def extractCString(table, offset):
    result = ""
    while True:
        d = table[offset]
        if d == 0:
            break
        result += "%c" % d
        offset += 1
    return result


560
def qdump__QObject(d, item):
hjk's avatar
hjk committed
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
    #warn("OBJECT: %s " % item.value)
    staticMetaObject = item.value["staticMetaObject"]
    #warn("SMO: %s " % staticMetaObject)
    privateType = gdb.lookup_type(d.ns + "QObjectPrivate")
    d_ptr = item.value["d_ptr"]["d"].dereference().cast(privateType)
    #warn("D_PTR: %s " % d_ptr)
    objectName = d_ptr["objectName"]
    #warn("OBJECTNAME: %s " % objectName)
    #warn("D_PTR: %s " % d_ptr.dereference())
    mo = d_ptr["metaObject"]
    type = d.stripNamespaceFromType(item.value.type)
    if isNull(mo):
        mo = staticMetaObject
    #warn("MO: %s " % mo)
    #warn("MO.D: %s " % mo["d"])
    metaData = mo["d"]["data"]
    metaStringData = mo["d"]["stringdata"]
    #warn("METADATA: %s " % metaData)
    #warn("STRINGDATA: %s " % metaStringData)
    #warn("TYPE: %s " % item.value.type)
581
582
    #d.putValue("")
    d.putStringValue(objectName)
hjk's avatar
hjk committed
583
584
585
586
587
588
589
590
591
592
593
594
595
596
    #QSignalMapper::staticMetaObject
    #check(d_ptr["ref"]["_q_value"] > 0)
    d.putNumChild(4)
    if d.isExpanded(item):
        d.beginChildren()

        # parent and children
        d.putItem(Item(d_ptr["parent"], item.iname, "parent", "parent"))
        d.putItem(Item(d_ptr["children"], item.iname, "children", "children"))

        # properties
        d.beginHash()
        propertyCount = metaData[6]
        propertyData = metaData[7]
597
        d.putName("properties")
hjk's avatar
hjk committed
598
        d.putItemCount(propertyCount)
599
600
        d.putType(" ")
        d.putNumChild(propertyCount)
hjk's avatar
hjk committed
601
602
603
604
605
606
607
        if d.isExpandedIName(item.iname + ".properties"):
            d.beginChildren()
            for property in xrange(0, propertyCount):
                d.beginHash()
                offset = propertyData + 3 * property
                propertyName = extractCString(metaStringData, metaData[offset])
                propertyType = extractCString(metaStringData, metaData[offset + 1])
608
                d.putName(propertyName)
hjk's avatar
hjk committed
609
610
611
612
613
614
615
616
617
618
619
620
621
                #flags = metaData[offset + 2]
                #warn("FLAGS: %s " % flags)
                warn("PROPERTY TYPE: %s " % propertyType)
                # #exp = '((\'%sQObject\'*)%s)->property("%s")' \
                #     % (d.ns, item.value.address, propertyName)
                #exp = '"((\'%sQObject\'*)%s)"' % (d.ns, item.value.address,)
                #warn("EXPRESSION:  %s" % exp)
                #value = gdb.parse_and_eval(exp)
                value = call(item.value, 'property("%s")' % propertyName)
                warn("VALUE:  %s" % value)
                warn("TYPE:  %s" % value.type)
                if True and propertyType == "QString":
                    # FIXME: re-use parts of QVariant dumper
622
                    #d.putType(d.ns + "QString")
hjk's avatar
hjk committed
623
624
625
626
                    data = value["d"]["data"]["ptr"]
                    innerType = gdb.lookup_type(d.ns + "QString")
                    d.putItemHelper(
                        Item(data.cast(innerType), item.iname, property, None))
627
                    #d.putNumChild(0)
hjk's avatar
hjk committed
628
629
630
631
632
633
634
635
636
637
                else:
                    iname = "%s.properties.%s" % (item.iname, propertyName)
                    d.putItemHelper(Item(value, iname, propertyName))
                d.endHash()
            d.endChildren()
        d.endHash()

        # connections
        d.beginHash()
        connectionCount = 0
638
        d.putName("connections")
hjk's avatar
hjk committed
639
        d.putItemCount(connectionCount)
640
641
        d.putType(" ")
        d.putNumChild(connectionCount)
hjk's avatar
hjk committed
642
643
644
645
646
647
648
649
650
651
652
653
        if connectionCount:
            d.putField("childtype", "")
            d.putField("childnumchild", "0")

        if d.isExpandedIName(item.iname + ".connections"):
            d.beginChildren()

            connectionLists = d_ptr["connectionLists"]
            warn("CONNECTIONLISTS: %s " % connectionLists)

            for connection in xrange(0, connectionCount):
                d.beginHash()
654
655
                d.putName("connection %d" % connection)
                d.putValue("")
hjk's avatar
hjk committed
656
657
658
659
660
661
662
                d.endHash()
            d.endChildren()
        d.endHash()

        # signals
        signalCount = metaData[13]
        d.beginHash()
663
        d.putName("signals")
hjk's avatar
hjk committed
664
        d.putItemCount(signalCount)
665
666
        d.putType(" ")
        d.putNumChild(signalCount)
hjk's avatar
hjk committed
667
668
669
670
671
672
673
674
675
        if signalCount:
            # FIXME: empty type does not work for childtype
            #d.putField("childtype", ".")
            d.putField("childnumchild", "0")
        if d.isExpandedIName(item.iname + ".signals"):
            d.beginChildren()
            for signal in xrange(0, signalCount):
                d.beginHash()
                offset = metaData[14 + 5 * signal]
676
677
678
                d.putName("signal %d" % signal)
                d.putType(" ")
                d.putValue(extractCString(metaStringData, offset))
hjk's avatar
hjk committed
679
680
681
682
683
684
685
                d.endHash()
            d.endChildren()
        d.endHash()

        # slots
        d.beginHash()
        slotCount = metaData[4] - signalCount
686
        d.putName("slots")
hjk's avatar
hjk committed
687
        d.putItemCount(slotCount)
688
689
        d.putType(" ")
        d.putNumChild(slotCount)
hjk's avatar
hjk committed
690
691
692
693
694
695
696
697
        if slotCount:
            #d.putField("childtype", ".")
            d.putField("childnumchild", "0")
        if d.isExpandedIName(item.iname + ".slots"):
            d.beginChildren()
            for slot in xrange(0, slotCount):
                d.beginHash()
                offset = metaData[14 + 5 * (signalCount + slot)]
698
699
700
                d.putName("slot %d" % slot)
                d.putType(" ")
                d.putValue(extractCString(metaStringData, offset))
hjk's avatar
hjk committed
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
                d.endHash()
            d.endChildren()
        d.endHash()

        d.endChildren()


# QObject

#   static const uint qt_meta_data_QObject[] = {

#   int revision;
#   int className;
#   int classInfoCount, classInfoData;
#   int methodCount, methodData;
#   int propertyCount, propertyData;
#   int enumeratorCount, enumeratorData;
#   int constructorCount, constructorData; //since revision 2
#   int flags; //since revision 3
#   int signalCount; //since revision 4

#    // content:
#          4,       // revision
#          0,       // classname
#          0,    0, // classinfo
#          4,   14, // methods
#          1,   34, // properties
#          0,    0, // enums/sets
#          2,   37, // constructors
#          0,       // flags
#          2,       // signalCount

#  /* 14 */

#    // signals: signature, parameters, type, tag, flags
#          9,    8,    8,    8, 0x05,
#         29,    8,    8,    8, 0x25,

#  /* 24 */
#    // slots: signature, parameters, type, tag, flags
#         41,    8,    8,    8, 0x0a,
#         55,    8,    8,    8, 0x08,

#  /* 34 */
#    // properties: name, type, flags
#         90,   82, 0x0a095103,

#  /* 37 */
#    // constructors: signature, parameters, type, tag, flags
#        108,  101,    8,    8, 0x0e,
#        126,    8,    8,    8, 0x2e,

#          0        // eod
#   };

#   static const char qt_meta_stringdata_QObject[] = {
#       "QObject\0\0destroyed(QObject*)\0destroyed()\0"
#       "deleteLater()\0_q_reregisterTimers(void*)\0"
#       "QString\0objectName\0parent\0QObject(QObject*)\0"
#       "QObject()\0"
#   };


# QSignalMapper

#   static const uint qt_meta_data_QSignalMapper[] = {

#    // content:
#          4,       // revision
#          0,       // classname
#          0,    0, // classinfo
#          7,   14, // methods
#          0,    0, // properties
#          0,    0, // enums/sets
#          0,    0, // constructors
#          0,       // flags
#          4,       // signalCount

#    // signals: signature, parameters, type, tag, flags
#         15,   14,   14,   14, 0x05,
#         27,   14,   14,   14, 0x05,
#         43,   14,   14,   14, 0x05,
#         60,   14,   14,   14, 0x05,

#    // slots: signature, parameters, type, tag, flags
#         77,   14,   14,   14, 0x0a,
#         90,   83,   14,   14, 0x0a,
#        104,   14,   14,   14, 0x08,

#          0        // eod
#   };

#   static const char qt_meta_stringdata_QSignalMapper[] = {
#       "QSignalMapper\0\0mapped(int)\0mapped(QString)\0"
#       "mapped(QWidget*)\0mapped(QObject*)\0"
#       "map()\0sender\0map(QObject*)\0"
#       "_q_senderDestroyed()\0"
#   };

#   const QMetaObject QSignalMapper::staticMetaObject = {
#       { &QObject::staticMetaObject, qt_meta_stringdata_QSignalMapper,
#         qt_meta_data_QSignalMapper, 0 }
#   };



#     checkAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
#     const QObject *ob = reinterpret_cast<const QObject *>(d.data)
#     const QMetaObject *mo = ob->metaObject()
810
#     d.putValue(ob->objectName(), 2)
hjk's avatar
hjk committed
811
812
813
814
815
816
817
818
819
820
821
822
823
#     d.putField("type", d.ns + "QObject")
#     d.putField("displayedtype", mo->className())
#     d.putField("numchild", 4)
#     if d.isExpanded(item):
#         int slotCount = 0
#         int signalCount = 0
#         for (int i = mo->methodCount(); --i >= 0; ) {
#             QMetaMethod::MethodType mt = mo->method(i).methodType()
#             signalCount += (mt == QMetaMethod::Signal)
#             slotCount += (mt == QMetaMethod::Slot)
#         }
#         d.beginChildren()
#         d.beginHash()
824
#             d.putName("properties")
hjk's avatar
hjk committed
825
826
827
828
829
830
831
832
833
#             // using 'addr' does not work in gdb as 'exp' is recreated as
#             // (type *)addr, and here we have different 'types':
#             // QObject vs QObjectPropertyList!
#             d.putField("addr", d.data)
#             d.putField("type", d.ns + "QObjectPropertyList")
#             d.putItemCount(mo->propertyCount())
#             d.putField("numchild", mo->propertyCount())
#         d.endHash()
#         d.beginHash()
834
#             d.putName("signals")
hjk's avatar
hjk committed
835
836
837
838
839
840
#             d.putField("addr", d.data)
#             d.putField("type", d.ns + "QObjectSignalList")
#             d.putItemCount(signalCount)
#             d.putField("numchild", signalCount)
#         d.endHash()
#         d.beginHash()
841
#             d.putName("slots")
hjk's avatar
hjk committed
842
843
844
845
846
847
848
849
#             d.putField("addr", d.data)
#             d.putField("type", d.ns + "QObjectSlotList")
#             d.putItemCount(slotCount)
#             d.putField("numchild", slotCount)
#         d.endHash()
#         const QObjectList objectChildren = ob->children()
#         if !objectChildren.empty()) {
#             d.beginHash()
850
#             d.putName("children")
hjk's avatar
hjk committed
851
852
853
854
855
856
857
#             d.putField("addr", d.data)
#             d.putField("type", ns + "QObjectChildList")
#             d.putItemCount(objectChildren.size())
#             d.putField("numchild", objectChildren.size())
#             d.endHash()
#         }
#         d.beginHash()
858
#             d.putName("parent")
hjk's avatar
hjk committed
859
860
861
862
#             dumpInnerValueHelper(d, ns + "QObject *", ob->parent())
#         d.endHash()
# #if 1
#         d.beginHash()
863
864
#             d.putName("className")
#             d.putValue(ob->metaObject()->className())
hjk's avatar
hjk committed
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
#             d.putField("type", "")
#             d.putField("numchild", "0")
#         d.endHash()
# #endif
#         d.endChildren()


# #if USE_QT_GUI
# static const char *sizePolicyEnumValue(QSizePolicy::Policy p)
# {
#     switch (p) {
#     case QSizePolicy::Fixed:
#         return "Fixed"
#     case QSizePolicy::Minimum:
#         return "Minimum"
#     case QSizePolicy::Maximum:
#         return "Maximum"
#     case QSizePolicy::Preferred:
#         return "Preferred"
#     case QSizePolicy::Expanding:
#         return "Expanding"
#     case QSizePolicy::MinimumExpanding:
#         return "MinimumExpanding"
#     case QSizePolicy::Ignored:
#         break
#     }
#     return "Ignored"
# }
#
# static QString sizePolicyValue(const QSizePolicy &sp)
# {
#     QString rc
#     QTextStream str(&rc)
#     // Display as in Designer
#     str << '[' << sizePolicyEnumValue(sp.horizontalPolicy())
#         << ", " << sizePolicyEnumValue(sp.verticalPolicy())
#         << ", " << sp.horizontalStretch() << ", " << sp.verticalStretch() << ']'
#     return rc
# }
# #endif
#
# // Meta enumeration helpers
# static inline void dumpMetaEnumType(QDumper &d, const QMetaEnum &me)
# {
#     QByteArray type = me.scope()
#     if !type.isEmpty())
#         type += "::"
#     type += me.name()
#     d.putField("type", type.constData())
# }
#
# static inline void dumpMetaEnumValue(QDumper &d, const QMetaProperty &mop,
#                                      int value)
# {
#
#     const QMetaEnum me = mop.enumerator()
#     dumpMetaEnumType(d, me)
#     if const char *enumValue = me.valueToKey(value)) {
923
#         d.putValue(enumValue)
hjk's avatar
hjk committed
924
#     } else {
925
#         d.putValue(value)
hjk's avatar
hjk committed
926
927
928
929
930
931
932
933
934
935
#     }
#     d.putField("numchild", 0)
# }
#
# static inline void dumpMetaFlagValue(QDumper &d, const QMetaProperty &mop,
#                                      int value)
# {
#     const QMetaEnum me = mop.enumerator()
#     dumpMetaEnumType(d, me)
#     const QByteArray flagsValue = me.valueToKeys(value)
936
937
938
939
940
#     if flagsValue.isEmpty():
#         d.putValue(value)
#     else:
#         d.putValue(flagsValue.constData())
#     d.putNumChild(0)
hjk's avatar
hjk committed
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
# }
#
# #ifndef QT_BOOTSTRAPPED
# static void dumpQObjectProperty(QDumper &d)
# {
#     const QObject *ob = (const QObject *)d.data
#     const QMetaObject *mob = ob->metaObject()
#     // extract "local.Object.property"
#     QString iname = d.iname
#     const int dotPos = iname.lastIndexOf(QLatin1Char('.'))
#     if dotPos == -1)
#         return
#     iname.remove(0, dotPos + 1)
#     const int index = mob->indexOfProperty(iname.toAscii())
#     if index == -1)
#         return
#     const QMetaProperty mop = mob->property(index)
#     const QVariant value = mop.read(ob)
#     const bool isInteger = value.type() == QVariant::Int
#     if isInteger and mop.isEnumType()) {
#         dumpMetaEnumValue(d, mop, value.toInt())
#     } elif isInteger and mop.isFlagType()) {
#         dumpMetaFlagValue(d, mop, value.toInt())
#     } else {
#         dumpQVariant(d, &value)
#     }
#     d.disarm()
# }
#
# static void dumpQObjectPropertyList(QDumper &d)
# {
#     const QObject *ob = (const QObject *)d.data
#     const QMetaObject *mo = ob->metaObject()
#     const int propertyCount = mo->propertyCount()
#     d.putField("addr", "<synthetic>")
#     d.putField("type", ns + "QObjectPropertyList")
#     d.putField("numchild", propertyCount)
#     d.putItemCount(propertyCount)
#     if d.isExpanded(item):
#         d.beginChildren()
#         for (int i = propertyCount; --i >= 0; ) {
#             const QMetaProperty & prop = mo->property(i)
#             d.beginHash()
984
#             d.putName(prop.name())
hjk's avatar
hjk committed
985
986
987
#             switch (prop.type()) {
#             case QVariant::String:
#                 d.putField("type", prop.typeName())
988
#                 d.putValue(prop.read(ob).toString(), 2)
hjk's avatar
hjk committed
989
990
991
992
#                 d.putField("numchild", "0")
#                 break
#             case QVariant::Bool:
#                 d.putField("type", prop.typeName())
993
#                 d.putValue((prop.read(ob).toBool() ? "true" : "false"))
hjk's avatar
hjk committed
994
995
996
997
998
999
1000
1001
#                 d.putField("numchild", "0")
#                 break
#             case QVariant::Int:
#                 if prop.isEnumType()) {
#                     dumpMetaEnumValue(d, prop, prop.read(ob).toInt())
#                 } elif prop.isFlagType()) {
#                     dumpMetaFlagValue(d, prop, prop.read(ob).toInt())
#                 } else {
1002
#                     d.putValue(prop.read(ob).toInt())
hjk's avatar
hjk committed
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
#                     d.putField("numchild", "0")
#                 }
#                 break
#             default:
#                 d.putField("addr", d.data)
#                 d.putField("type", ns + "QObjectProperty")
#                 d.putField("numchild", "1")
#                 break
#             }
#             d.endHash()
#         }
#         d.endChildren()
#     }
#     d.disarm()
# }
#
# static void dumpQObjectMethodList(QDumper &d)
# {
#     const QObject *ob = (const QObject *)d.data
#     const QMetaObject *mo = ob->metaObject()
#     d.putField("addr", "<synthetic>")
#     d.putField("type", ns + "QObjectMethodList")
#     d.putField("numchild", mo->methodCount())
#     if d.isExpanded(item):
#         d.putField("childtype", ns + "QMetaMethod::Method")
#         d.putField("childnumchild", "0")
#         d.beginChildren()
#         for (int i = 0; i != mo->methodCount(); ++i) {
#             const QMetaMethod & method = mo->method(i)
#             int mt = method.methodType()
#             d.beginHash()
#             d.beginItem("name")
#                 d.put(i).put(" ").put(mo->indexOfMethod(method.signature()))
#                 d.put(" ").put(method.signature())
#             d.endItem()
#             d.beginItem("value")
#                 d.put((mt == QMetaMethod::Signal ? "<Signal>" : "<Slot>"))
#                 d.put(" (").put(mt).put(")")
#             d.endItem()
#             d.endHash()
#         }
#         d.endChildren()
#     }
#     d.disarm()
# }
#
# def qConnectionType(type):
#     Qt::ConnectionType connType = static_cast<Qt::ConnectionType>(type)
#     const char *output = "unknown"
#     switch (connType) {
#         case Qt::AutoConnection: output = "auto"; break
#         case Qt::DirectConnection: output = "direct"; break
#         case Qt::QueuedConnection: output = "queued"; break
#         case Qt::BlockingQueuedConnection: output = "blockingqueued"; break
#         case 3: output = "autocompat"; break
# #if QT_VERSION >= 0x040600
#         case Qt::UniqueConnection: break; // Can't happen.
# #endif
#     return output
#
# #if QT_VERSION >= 0x040400
# static const ConnectionList &qConnectionList(const QObject *ob, int signalNumber)
# {
#     static const ConnectionList emptyList
#     const ObjectPrivate *p = reinterpret_cast<const ObjectPrivate *>(dfunc(ob))
#     if !p->connectionLists)
#         return emptyList
#     typedef QVector<ConnectionList> ConnLists
#     const ConnLists *lists = reinterpret_cast<const ConnLists *>(p->connectionLists)
#     // there's an optimization making the lists only large enough to hold the
#     // last non-empty item
#     if signalNumber >= lists->size())
#         return emptyList
#     return lists->at(signalNumber)
# }
# #endif
#
# // Write party involved in a slot/signal element,
# // avoid to recursion to self.
# static inline void dumpQObjectConnectionPart(QDumper &d,
#                                               const QObject *owner,
#                                               const QObject *partner,
#                                               int number, const char *namePostfix)
# {
#     d.beginHash()
#     d.beginItem("name")
#     d.put(number).put(namePostfix)
#     d.endItem()
#     if partner == owner) {
1092
#         d.putValue("<this>")
hjk's avatar
hjk committed
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
#         d.putField("type", owner->metaObject()->className())
#         d.putField("numchild", 0)
#         d.putField("addr", owner)
#     } else {
#         dumpInnerValueHelper(d, ns + "QObject *", partner)
#     }
#     d.endHash()
#
# static void dumpQObjectSignal(QDumper &d)
# {
#     unsigned signalNumber = d.extraInt[0]
#
#     d.putField("addr", "<synthetic>")
#     d.putField("numchild", "1")
#     d.putField("type", ns + "QObjectSignal")
#
# #if QT_VERSION >= 0x040400
#     if d.isExpanded(item):
#         const QObject *ob = reinterpret_cast<const QObject *>(d.data)
#         d.beginChildren()
#         const ConnectionList &connList = qConnectionList(ob, signalNumber)
#         for (int i = 0; i != connList.size(); ++i) {
#             const Connection &conn = connectionAt(connList, i)
#             dumpQObjectConnectionPart(d, ob, conn.receiver, i, " receiver")
#             d.beginHash()
#                 d.beginItem("name")
#                     d.put(i).put(" slot")
#                 d.endItem()
#                 d.putField("type", "")
#                 if conn.receiver)
1123
#                     d.putValue(conn.receiver->metaObject()->method(conn.method).signature())
hjk's avatar
hjk committed
1124
#                 else
1125
#                     d.putValue("<invalid receiver>")
hjk's avatar
hjk committed
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
#                 d.putField("numchild", "0")
#             d.endHash()
#             d.beginHash()
#                 d.beginItem("name")
#                     d.put(i).put(" type")
#                 d.endItem()
#                 d.putField("type", "")
#                 d.beginItem("value")
#                     d.put("<").put(qConnectionType(conn.connectionType)).put(" connection>")
#                 d.endItem()
#                 d.putField("numchild", "0")
#             d.endHash()
#         }
#         d.endChildren()
#         d.putField("numchild", connList.size())
# #endif
#
# static void dumpQObjectSignalList(QDumper &d)
# {
#     const QObject *ob = reinterpret_cast<const QObject *>(d.data)
#     const QMetaObject *mo = ob->metaObject()
#     int count = 0
#     const int methodCount = mo->methodCount()
#     for (int i = methodCount; --i >= 0; )
#         count += (mo->method(i).methodType() == QMetaMethod::Signal)
#     d.putField("type", ns + "QObjectSignalList")
#     d.putItemCount(count)
#     d.putField("addr", d.data)
#     d.putField("numchild", count)
# #if QT_VERSION >= 0x040400
#     if d.isExpanded(item):
#         d.beginChildren()
#         for (int i = 0; i != methodCount; ++i) {
#             const QMetaMethod & method = mo->method(i)
#             if method.methodType() == QMetaMethod::Signal) {
#                 int k = mo->indexOfSignal(method.signature())
#                 const ConnectionList &connList = qConnectionList(ob, k)
#                 d.beginHash()
1164
1165
#                 d.putName(k)
#                 d.putValue(method.signature())
hjk's avatar
hjk committed
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
#                 d.putField("numchild", connList.size())
#                 d.putField("addr", d.data)
#                 d.putField("type", ns + "QObjectSignal")
#                 d.endHash()
# #endif
#
# static void dumpQObjectSlot(QDumper &d)
# {
#     int slotNumber = d.extraInt[0]
#
#     d.putField("addr", d.data)
#     d.putField("numchild", "1")
#     d.putField("type", ns + "QObjectSlot")
#
# #if QT_VERSION >= 0x040400
#     if d.isExpanded(item):
#         d.beginChildren()
#         int numchild = 0
#         const QObject *ob = reinterpret_cast<const QObject *>(d.data)
#         const ObjectPrivate *p = reinterpret_cast<const ObjectPrivate *>(dfunc(ob))
# #if QT_VERSION >= 0x040600
#         int s = 0
#         for (SenderList senderList = p->senders; senderList != 0
#              senderList = senderList->next, ++s) {
#             const QObject *sender = senderList->sender
#             int signal = senderList->method; // FIXME: 'method' is wrong.
# #else
#         for (int s = 0; s != p->senders.size(); ++s) {
#             const QObject *sender = senderAt(p->senders, s)
#             int signal = signalAt(p->senders, s)
# #endif
#             const ConnectionList &connList = qConnectionList(sender, signal)
#             for (int i = 0; i != connList.size(); ++i) {
#                 const Connection &conn = connectionAt(connList, i)
#                 if conn.receiver == ob and conn.method == slotNumber) {
#                     ++numchild
#                     const QMetaMethod &method = sender->metaObject()->method(signal)
#                     dumpQObjectConnectionPart(d, ob, sender, s, " sender")
#                     d.beginHash()
#                         d.beginItem("name")
#                             d.put(s).put(" signal")
#                         d.endItem()
#                         d.putField("type", "")
1209
#                         d.putValue(method.signature())
hjk's avatar
hjk committed
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
#                         d.putField("numchild", "0")
#                     d.endHash()
#                     d.beginHash()
#                         d.beginItem("name")
#                             d.put(s).put(" type")
#                         d.endItem()
#                         d.putField("type", "")
#                         d.beginItem("value")
#                             d.put("<").put(qConnectionType(conn.method))
#                             d.put(" connection>")
#                         d.endItem()
#                         d.putField("numchild", "0")
#                     d.endHash()
#                 }
#             }
#         }
#         d.endChildren()
#         d.putField("numchild", numchild)
#     }
# #endif
#     d.disarm()
# }
#
# static void dumpQObjectSlotList(QDumper &d)
# {
#     const QObject *ob = reinterpret_cast<const QObject *>(d.data)
# #if QT_VERSION >= 0x040400
#     const ObjectPrivate *p = reinterpret_cast<const ObjectPrivate *>(dfunc(ob))
# #endif
#     const QMetaObject *mo = ob->metaObject()
#
#     int count = 0
#     const int methodCount = mo->methodCount()
#     for (int i = methodCount; --i >= 0; )
#         count += (mo->method(i).methodType() == QMetaMethod::Slot)
#
#     d.putField("numchild", count)
#     d.putItemCount(count)
#     d.putField("type", ns + "QObjectSlotList")
#     if d.isExpanded(item):
#         d.beginChildren()
# #if QT_VERSION >= 0x040400
#         for (int i = 0; i != methodCount; ++i) {
#             const QMetaMethod & method = mo->method(i)
#             if method.methodType() == QMetaMethod::Slot) {
#                 d.beginHash()
#                 int k = mo->indexOfSlot(method.signature())
1257
1258
#                 d.putName(k)
#                 d.putValue(method.signature())
hjk's avatar
hjk committed
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
#
#                 // count senders. expensive...
#                 int numchild = 0
# #if QT_VERSION >= 0x040600
#                 int s = 0
#                 for (SenderList senderList = p->senders; senderList != 0
#                      senderList = senderList->next, ++s) {
#                     const QObject *sender = senderList->sender
#                     int signal = senderList->method; // FIXME: 'method' is wrong.
# #else
#                 for (int s = 0; s != p->senders.size(); ++s) {
#                     const QObject *sender = senderAt(p->senders, s)
#                     int signal = signalAt(p->senders, s)
# #endif
#                     const ConnectionList &connList = qConnectionList(sender, signal)
#                     for (int c = 0; c != connList.size(); ++c) {
#                         const Connection &conn = connectionAt(connList, c)
#                         if conn.receiver == ob and conn.method == k)
#                             ++numchild
#                     }
#                 }
#                 d.putField("numchild", numchild)
#                 d.putField("addr", d.data)
#                 d.putField("type", ns + "QObjectSlot")
#                 d.endHash()
#             }
#         }
# #endif
#         d.endChildren()
#
# #endif // QT_BOOTSTRAPPED


1292
def qdump__QPixmap(d, item):
hjk's avatar
hjk committed
1293
1294
1295
1296
    painters = item.value["painters"]
    check(0 <= painters and painters < 1000)
    d_ptr = item.value["data"]["d"]
    if isNull(d_ptr):
1297
        d.putValue("(null)")
hjk's avatar
hjk committed
1298
1299
    else:
        check(d_ptr["ref"]["_q_value"] > 0)
1300
1301
        d.putValue("(%dx%d)" % (d_ptr["w"], d_ptr["h"]))
    d.putNumChild(0)
hjk's avatar
hjk committed
1302
1303


1304
def qdump__QPoint(d, item):
hjk's avatar
hjk committed
1305
1306
1307
1308
1309
    x = item.value["xp"]
    y = item.value["yp"]
    # should not be needed, but sometimes yield myns::QVariant::Private::Data::qreal
    x = x.cast(x.type.strip_typedefs())
    y = y.cast(y.type.strip_typedefs())
1310
    d.putValue("(%s, %s)" % (x, y))
hjk's avatar
hjk committed
1311
1312
    d.putNumChild(2)
    if d.isExpanded(item):
1313
        d.beginChildren(2, x.type.strip_typedefs())
hjk's avatar
hjk committed
1314
1315
1316
1317
1318
        d.putItem(Item(x, None, None, "x"))
        d.putItem(Item(y, None, None, "y"))
        d.endChildren()


1319
1320
def qdump__QPointF(d, item):
    qdump__QPoint(d, item)
hjk's avatar
hjk committed
1321
1322


1323
def qdump__QRect(d, item):
1324
    def pp(l): return select(l >= 0, "+%s" % l, l)
hjk's avatar
hjk committed
1325
1326
1327
1328
1329
1330
    x1 = item.value["x1"]
    y1 = item.value["y1"]
    x2 = item.value["x2"]
    y2 = item.value["y2"]
    w = x2 - x1 + 1
    h = y2 - y1 + 1
1331
    d.putValue("%sx%s%s%s" % (w, h, pp(x1), pp(y1)))
hjk's avatar
hjk committed
1332
1333
    d.putNumChild(4)
    if d.isExpanded(item):
1334
        d.beginChildren(4, x1.type.strip_typedefs())
hjk's avatar
hjk committed
1335
1336
1337
1338
1339
1340
1341
        d.putItem(Item(x1, None, None, "x1"))
        d.putItem(Item(y1, None, None, "y1"))
        d.putItem(Item(x2, None, None, "x2"))
        d.putItem(Item(y2, None, None, "y2"))
        d.endChildren()


1342
def qdump__QRectF(d, item):
1343
    def pp(l): return select(l >= 0, "+%s" % l, l)
hjk's avatar
hjk committed
1344
1345
1346
1347
1348
1349
1350
1351
1352
    x = item.value["xp"]
    y = item.value["yp"]
    w = item.value["w"]
    h = item.value["h"]
    # FIXME: workaround, see QPoint
    x = x.cast(x.type.strip_typedefs())
    y = y.cast(y.type.strip_typedefs())
    w = w.cast(w.type.strip_typedefs())
    h = h.cast(h.type.strip_typedefs())
1353
    d.putValue("%sx%s%s%s" % (w, h, pp(x), pp(y)))
hjk's avatar
hjk committed
1354
1355
    d.putNumChild(4)
    if d.isExpanded(item):
1356
        d.beginChildren(4, x.type.strip_typedefs())
hjk's avatar
hjk committed
1357
1358
1359
1360
1361
1362
1363
        d.putItem(Item(x, None, None, "x"))
        d.putItem(Item(y, None, None, "y"))
        d.putItem(Item(w, None, None, "w"))
        d.putItem(Item(h, None, None, "h"))
        d.endChildren()


1364
def qdump__QSet(d, item):
hjk's avatar
hjk committed
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405

    def hashDataFirstNode(value):
        value = value.cast(hashDataType)
        bucket = value["buckets"]
        e = value.cast(hashNodeType)
        for n in xrange(value["numBuckets"] - 1, -1, -1):
            n = n - 1
            if n < 0:
                break
            if bucket.dereference() != e:
                return bucket.dereference()
            bucket = bucket + 1
        return e;

    def hashDataNextNode(node):
        next = node["next"]
        if next["next"]:
            return next
        d = node.cast(hashDataType.pointer()).dereference()
        numBuckets = d["numBuckets"]
        start = (node["h"] % numBuckets) + 1
        bucket = d["buckets"] + start
        for n in xrange(0, numBuckets - start):
            if bucket.dereference() != next:
                return bucket.dereference()
            bucket += 1
        return node

    keyType = item.value.type.template_argument(0)

    d_ptr = item.value["q_hash"]["d"]
    e_ptr = item.value["q_hash"]["e"]
    n = d_ptr["size"]

    hashDataType = d_ptr.type
    hashNodeType = e_ptr.type

    check(0 <= n and n <= 100 * 1000 * 1000)
    check(d_ptr["ref"]["_q_value"] > 0)

    d.putItemCount(n)
1406
    d.putNumChild(n)
hjk's avatar
hjk committed
1407
1408
1409
1410
1411
1412
1413
1414
1415
    if d.isExpanded(item):
        if n > 1000:
            n = 1000

        isSimpleKey = isSimpleType(keyType)

        node = hashDataFirstNode(item.value)

        innerType = e_ptr.dereference().type
1416
        d.beginChildren(n, keyType)
hjk's avatar
hjk committed
1417
1418
1419
1420
1421
1422
        for i in xrange(0, n):
            it = node.dereference().cast(innerType)
            d.beginHash()
            key = it["key"]
            if isSimpleKey:
                d.putType(keyType)
1423
                d.putItemHelper(Item(key, None, None, None))
hjk's avatar
hjk committed
1424
1425
1426
1427
1428
1429
1430
            else:
                d.putItemHelper(Item(key, item.iname, i, None))
            d.endHash()
            node = hashDataNextNode(node)
        d.endChildren()


1431
1432
def qdump__QSharedPointer(d, item):
    qdump__QWeakPointer(d, item)
hjk's avatar
hjk committed
1433
1434


1435
def qdump__QSize(d, item):
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
    w = item.value["wd"]
    h = item.value["ht"]
    d.putValue("(%s, %s)" % (w, h))
    d.putNumChild(2)
    if d.isExpanded(item):
        d.beginChildren(2, w.type)
        d.putItem(Item(w, item.iname, "w", "w"))
        d.putItem(Item(h, item.iname, "h", "h"))
        d.endChildren()


1447
1448
def qdump__QSizeF(d, item):
    qdump__QSize(d, item)
1449
1450


1451
1452
def qdump__QStack(d, item):
    qdump__QVector(d, item)
hjk's avatar
hjk committed
1453
1454


1455
def qdump__QString(d, item):
1456
1457
1458
1459
    d.putStringValue(item.value)
    d.putNumChild(0)


1460
def qdump__QStringList(d, item):
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
    d_ptr = item.value['d']
    begin = d_ptr['begin']
    end = d_ptr['end']
    n = end - begin
    check(n >= 0)
    check(n <= 10 * 1000 * 1000)
    #    checkAccess(&list.front())
    #    checkAccess(&list.back())
    check(d_ptr["ref"]["_q_value"] > 0)
    d.putItemCount(n)
    d.putNumChild(n)
    if d.isExpanded(item):
        if n > 1000:
            n = 1000
        innerType = gdb.lookup_type(d.ns + "QString")
        ptr = gdb.Value(d_ptr["array"]).cast(innerType.pointer())
        d.beginChildren(n, innerType)
        for i in xrange(0, n):
            d.putItem(Item(ptr.dereference(), item.iname, i, None))
            ptr += 1
        if n < end - begin:
            d.putEllipsis()
        d.endChildren()


1486
1487
def qdump__QTemporaryFile(d, item):
    qdump__QFile(d, item)
hjk's avatar
hjk committed
1488
1489


1490
def qdump__QTextCodec(d, item):
1491
1492
1493
    value = call(item.value, "name()")
    d.putValue(encodeByteArray(value), 6)
    d.putNumChild(2)
hjk's avatar
hjk committed
1494
1495
    if d.isExpanded(item):
        d.beginChildren()
1496
1497
        d.putCallItem("name", item, "name()")
        d.putCallItem("mibEnum", item, "mibEnum()")
hjk's avatar
hjk committed
1498
1499
1500
        d.endChildren()


1501
def qdump__QVariant(d, item):
hjk's avatar
hjk committed
1502
1503
1504
1505
1506
1507
1508
    union = item.value["d"]
    data = union["data"]
    variantType = int(union["type"])
    #warn("VARIANT TYPE: %s : " % variantType)
    inner = ""
    innert = ""
    if variantType == 0: # QVariant::Invalid
1509
        d.putValue("(invalid)")
hjk's avatar
hjk committed
1510
1511
        d.putNumChild(0)
    elif variantType == 1: # QVariant::Bool
1512
        d.putValue(select(data["b"], "true", "false"))
hjk's avatar
hjk committed
1513
1514
        d.putNumChild(0)
    elif variantType == 2: # QVariant::Int
1515
        d.putValue(data["i"])
hjk's avatar
hjk committed
1516
1517
        d.putNumChild(0)
    elif variantType == 3: # uint
1518
        d.putValue(data["u"])
hjk's avatar
hjk committed
1519
1520
        d.putNumChild(0)
    elif variantType == 4: # qlonglong
1521
        d.putValue(data["ll"])
hjk's avatar
hjk committed
1522
1523
        d.putNumChild(0)
    elif variantType == 5: # qulonglong
1524
        d.putValue(data["ull"])
hjk's avatar
hjk committed
1525
1526
1527
        d.putNumChild(0)
    elif variantType == 6: # QVariant::Double
        value = data["d"]
1528
        d.putValue(data["d"])
hjk's avatar
hjk committed
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
        d.putNumChild(0)
    elif variantType == 7: # QVariant::QChar
        inner = d.ns + "QChar"
    elif variantType == 8: # QVariant::VariantMap
        inner = d.ns + "QMap<" + d.ns + "QString, " + d.ns + "QVariant>"
        innert = d.ns + "QVariantMap"
    elif variantType == 9: # QVariant::VariantList
        inner = d.ns + "QList<" + d.ns + "QVariant>"
        innert = d.ns + "QVariantList"
    elif variantType == 10: # QVariant::String
        inner = d.ns + "QString"
    elif variantType == 11: # QVariant::StringList
        inner = d.ns + "QStringList"
    elif variantType == 12: # QVariant::ByteArray
        inner = d.ns + "QByteArray"
    elif variantType == 13: # QVariant::BitArray
        inner = d.ns + "QBitArray"
    elif variantType == 14: # QVariant::Date
        inner = d.ns + "QDate"
    elif variantType == 15: # QVariant::Time
        inner = d.ns + "QTime"
    elif variantType == 16: # QVariant::DateTime
        inner = d.ns + "QDateTime"
    elif variantType == 17: # QVariant::Url
        inner = d.ns + "QUrl"
    elif variantType == 18: # QVariant::Locale
        inner = d.ns + "QLocale"
    elif variantType == 19: # QVariant::Rect
        inner = d.ns + "QRect"
    elif variantType == 20: # QVariant::RectF
        inner = d.ns + "QRectF"
    elif variantType == 21: # QVariant::Size
        inner = d.ns + "QSize"
    elif variantType == 22: # QVariant::SizeF
        inner = d.ns + "QSizeF"
    elif variantType == 23: # QVariant::Line
        inner = d.ns + "QLine"
    elif variantType == 24: # QVariant::LineF
        inner = d.ns + "QLineF"
    elif variantType == 25: # QVariant::Point
        inner = d.ns + "QPoint"
    elif variantType == 26: # QVariant::PointF
        inner = d.ns + "QPointF"
    elif variantType == 27: # QVariant::RegExp
        inner = d.ns + "QRegExp"
    elif variantType == 28: # QVariant::VariantHash
        inner = d.ns + "QHash<" + d.ns + "QString, " + d.ns + "QVariant>"
        innert = d.ns + "QVariantHash"
    elif variantType == 64: # QVariant::Font
        inner = d.ns + "QFont"
hjk's avatar
hjk committed
1579
1580
1581
1582
    elif variantType == 65: # QVariant::Pixmap
        inner = d.ns + "QPixmap"
    elif variantType == 66: # QVariant::Brush
        inner = d.ns + "QBrush"
hjk's avatar
hjk committed
1583
1584
    elif variantType == 67: # QVariant::Color
        inner = d.ns + "QColor"
hjk's avatar
hjk committed
1585
1586
1587
1588
1589
1590
    elif variantType == 68: # QVariant::Palette
        inner = d.ns + "QPalette"
    elif variantType == 69: # QVariant::Icon
        inner = d.ns + "QIcon"
    elif variantType == 70: # QVariant::Image
        inner = d.ns + "QImage"
hjk's avatar
hjk committed
1591
    elif variantType == 71: # QVariant::Polygon and PointArray
hjk's avatar
hjk committed
1592
1593
1594
1595
1596
1597
1598
        inner = d.ns + "QPolygon"
    elif variantType == 72: # QVariant::Region
        inner = d.ns + "QRegion"
    elif variantType == 73: # QVariant::Bitmap
        inner = d.ns + "QBitmap"
    elif variantType == 74: # QVariant::Cursor
        inner = d.ns + "QCursor"
hjk's avatar
hjk committed
1599
1600
1601
1602
    elif variantType == 75: # QVariant::SizePolicy
        inner = d.ns + "QSizePolicy"
    elif variantType == 76: # QVariant::KeySequence
        inner = d.ns + "QKeySequence"
hjk's avatar
hjk committed
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
    elif variantType == 77: # QVariant::Pen
        inner = d.ns + "QPen"
    elif variantType == 78: # QVariant::TextLength
        inner = d.ns + "QTextLength"
    elif variantType == 79: # QVariant::TextFormat
        inner = d.ns + "QTextFormat"
    elif variantType == 81: # QVariant::Transform
        inner = d.ns + "QTransform"
    elif variantType == 82: # QVariant::Matrix4x4
        inner = d.ns + "QMatrix4x4"
    elif variantType == 83: # QVariant::Vector2D
        inner = d.ns + "QVector2D"
    elif variantType == 84: # QVariant::Vector3D
        inner = d.ns + "QVector3D"
    elif variantType == 85: # QVariant::Vector4D
        inner = d.ns + "QVector4D"
    elif variantType == 86: # QVariant::Quadernion
hjk's avatar
hjk committed
1620
1621
1622
        inner = d.ns + "QQuadernion"
    else:
        # FIXME: handle User types
1623
        d.putValue("(unknown type %d)" % variantType)
hjk's avatar
hjk committed
1624
1625
1626
1627
1628
1629
1630
        # typeName = QMetaType::typeName(typ)
        # exp =  "'qVariantValue<%s >'(*('"NS"QVariant'*)%p)"
        d.putNumChild(0)

    if len(inner):
        if len(innert) == 0:
            innert = inner
1631
        d.putValue("(%s)" % innert)
hjk's avatar
hjk committed
1632
1633
1634
1635
1636
        d.putNumChild(1)
        if d.isExpanded(item):
            innerType = gdb.lookup_type(inner)
            d.beginChildren()
            d.beginHash()