gdbmacros.py 84.9 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
11
from __future__ import with_statement

hjk's avatar
hjk committed
12
13
14
15
16
def qdump__QAtomicInt(d, item):
    d.putValue(item.value["_q_value"])
    d.putNumChild(0)


17
18
19
20
21
def qdump__QBasicAtomicInt(d, item):
    d.putValue(item.value["_q_value"])
    d.putNumChild(0)


22
def qdump__QByteArray(d, item):
23
24
    d.putByteArrayValue(item.value)

hjk's avatar
hjk committed
25
26
    d_ptr = item.value['d'].dereference()
    size = d_ptr['size']
27
    d.putNumChild(size)
hjk's avatar
hjk committed
28
29

    if d.isExpanded(item):
30
        innerType = lookupType("char")
31
32
33
34
35
36
        with Children(d, [size, 1000], innerType):
            data = d_ptr['data']
            p = gdb.Value(data.cast(innerType.pointer()))
            for i in d.childRange():
                d.putItem(Item(p.dereference(), item.iname, i))
                p += 1
hjk's avatar
hjk committed
37
38


39
def qdump__QChar(d, item):
hjk's avatar
hjk committed
40
    ucs = int(item.value["ucs"])
41
    d.putValue("'%c' (%d)" % (printableChar(ucs), ucs))
hjk's avatar
hjk committed
42
43
44
    d.putNumChild(0)


45
def qdump__QAbstractItem(d, item):
hjk's avatar
hjk committed
46
47
48
49
50
51
52
53
54
55
    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
56
57
    d.putStringValue(call(m, "data(mi, Qt::DisplayRole).toString()"))
    d.putNumChild(rowCount * columnCount)
hjk's avatar
hjk committed
58
    if d.isExpanded(item):
59
        with Children(d):
60
            innerType = lookupType(d.ns + "QAbstractItem")
61
62
63
64
65
66
67
68
            for row in xrange(rowCount):
                for column in xrange(columnCount):
                    with SubItem(d):
                        child = call(m, "index(row, column, mi)")
                        d.putName("[%s,%s]" % (row, column))
                        rr = call(m, "rowCount(child)")
                        cc = call(m, "columnCount(child)")
                        d.putNumChild(rr * cc)
69
                        d.putValue(
70
                            call(m, "data(child, Qt::DisplayRole).toString())"), 6)
71

72
            #with SubItem(d):
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
            #    d.putNumChild(1)
            #    d.putName(d.ns + "QObject")
            #    d.putStringValue(call(item.value, "objectName()"))
            #    d.putType(d.ns + "QObject")
            #    d.put('addr="%s",' % cleanAddress(item.value.address))


def qdump__QAbstractItemModel(d, item):
    # Create a default-constructed QModelIndex on the stack.
    ri = makeValue(d.ns + "QModelIndex", "-1, -1, 0, 0")
    this_ = makeExpression(item.value)
    ri_ = makeExpression(ri)
    rowCount = int(parseAndEvaluate("%s.rowCount(%s)" % (this_, ri_)))
    columnCount = int(parseAndEvaluate("%s.columnCount(%s)" % (this_, ri_)))
    d.putValue("%d x %d" % (rowCount, columnCount))
    d.putNumChild(rowCount * columnCount)
    if d.isExpanded(item):
        with Children(d, rowCount * columnCount, ri.type):
            i = 0
            for row in xrange(rowCount):
                for column in xrange(columnCount):
                    with SubItem(d):
                        d.putField("iname", "%s.%d" % (item.iname, i))
                        d.putName("[%s, %s]" % (row, column))
                        mi = parseAndEvaluate("%s.index(%d,%d,%s)"
                            % (this_, row, column, ri_))
                        #warn("MI: %s " % mi)
                        #name = "[%d,%d]" % (row, column)
                        #d.putValue("%s" % mi)
                        d.putItemHelper(Item(mi, item.iname, i))
                        i = i + 1
                        #warn("MI: %s " % mi)
                        #d.putName("[%d,%d]" % (row, column))
                        #d.putValue("%s" % mi)
                        #d.putNumChild(0)
                        #d.putType(mi.type)
    #gdb.execute("call free($ri)")

def qdump__QModelIndex(d, item):
    r = item.value["r"]
    c = item.value["c"]
    p = item.value["p"]
    m = item.value["m"]
    mm = m.dereference()
    mm = mm.cast(mm.type.unqualified())
    mi = makeValue(d.ns + "QModelIndex", "%s,%s,%s,%s" % (r, c, p, m))
    mm_ = makeExpression(mm)
    mi_ = makeExpression(mi)
    rowCount = int(parseAndEvaluate("%s.rowCount(%s)" % (mm_, mi_)))
    columnCount = int(parseAndEvaluate("%s.columnCount(%s)" % (mm_, mi_)))

    try:
        # Access DisplayRole as value
        value = parseAndEvaluate("%s.data(%s, 0)" % (mm_, mi_))
        v = value["d"]["data"]["ptr"]
        d.putStringValue(makeValue(d.ns + 'QString', v))
    except:
        d.putValue("(invalid)")

    if r >= 0 and c >= 0 and not isNull(m):
        d.putNumChild(rowCount * columnCount)
        if d.isExpanded(item):
            with Children(d):
                i = 0
                for row in xrange(rowCount):
                    for column in xrange(columnCount):
                        with SubItem(d):
                            d.putField("iname", "%s.%d" % (item.iname, i))
                            d.putName("[%s, %s]" % (row, column))
                            mi2 = parseAndEvaluate("%s.index(%d,%d,%s)"
                                % (mm_, row, column, mi_))
                            d.putItemHelper(Item(mi2, item.iname, i))
                            i = i + 1
                #d.putCallItem("parent", item, "parent()")
                #with SubItem(d):
                #    d.putName("model")
                #    d.putValue(m)
                #    d.putType(d.ns + "QAbstractItemModel*")
                #    d.putNumChild(1)
    else:
        d.putValue("(invalid)")
        d.putNumChild(0)
        if d.isExpanded(item):
            with Children(d):
                pass
    #gdb.execute("call free($mi)")

hjk's avatar
hjk committed
160

161
162
163
164
165
def qdump__QDate(d, item):
    if int(item.value["jd"]) == 0:
        d.putValue("(null)")
        d.putNumChild(0)
        return
166
    d.putStringValue(call(item.value, "toString('%sQt::TextDate')" % d.ns))
167
    d.putNumChild(1)
hjk's avatar
hjk committed
168
    if d.isExpanded(item):
169
        # FIXME: This improperly uses complex return values.
170
171
172
173
174
175
176
177
178
179
180
181
182
183
        with Children(d, 8):
            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)
hjk's avatar
hjk committed
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
def qdump__QTime(d, item):
    if int(item.value["mds"]) == -1:
        d.putValue("(null)")
        d.putNumChild(0)
        return
    d.putStringValue(call(item.value, "toString('%sQt::TextDate')" % d.ns))
    d.putNumChild(1)
    if d.isExpanded(item):
        # FIXME: This improperly uses complex return values.
        with Children(d, 8):
            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)


def qdump__QDateTime(d, item):
    if int(item.value["d"]["d"].dereference()["time"]["mds"]) == -1:
        d.putValue("(null)")
        d.putNumChild(0)
        return
    d.putStringValue(call(item.value, "toString('%sQt::TextDate')" % d.ns))
    d.putNumChild(1)
    if d.isExpanded(item):
        # FIXME: This improperly uses complex return values.
        with Children(d, 8):
            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)


235
def qdump__QDir(d, item):
236
237
    d.putStringValue(call(item.value, "path()"))
    d.putNumChild(2)
hjk's avatar
hjk committed
238
    if d.isExpanded(item):
239
240
241
        with Children(d, 2):
            d.putCallItem("absolutePath", item, "absolutePath()")
            d.putCallItem("canonicalPath", item, "canonicalPath()")
hjk's avatar
hjk committed
242
243


244
def qdump__QFile(d, item):
245
246
    d.putStringValue(call(item.value, "fileName()"))
    d.putNumChild(2)
hjk's avatar
hjk committed
247
    if d.isExpanded(item):
248
249
250
        with Children(d, 2):
            d.putCallItem("fileName", item, "fileName()")
            d.putCallItem("exists", item, "exists()")
hjk's avatar
hjk committed
251
252


253
def qdump__QFileInfo(d, item):
254
255
    d.putStringValue(call(item.value, "filePath()"))
    d.putNumChild(3)
hjk's avatar
hjk committed
256
    if d.isExpanded(item):
257
        with Children(d, 10, lookupType(d.ns + "QString")):
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
            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()")
            if perms is None:
                d.putValue("<not available>")
            else:
                with SubItem(d):
                    d.putName("permissions")
                    d.putValue(" ")
                    d.putType(d.ns + "QFile::Permissions")
                    d.putNumChild(10)
                    if d.isExpandedIName(item.iname + ".permissions"):
                        with Children(d, 10):
                            perms = perms['i']
                            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)

            #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()")
hjk's avatar
hjk committed
322
323


hjk's avatar
hjk committed
324
325
326
327
328
329
def qdump__QFixed(d, item):
    v = int(item.value["val"])
    d.putValue("%s/64 = %s" % (v, v/64.0))
    d.putNumChild(0)


330
def qdump__QFlags(d, item):
331
    #warn("QFLAGS: %s" % item.value)
hjk's avatar
hjk committed
332
333
    i = item.value["i"]
    enumType = item.value.type.template_argument(0)
334
    #warn("QFLAGS: %s" % item.value["i"].cast(enumType))
335
    d.putValue("%s (%s)" % (i.cast(enumType), i))
hjk's avatar
hjk committed
336
337
338
    d.putNumChild(0)


339
def qdump__QHash(d, item):
hjk's avatar
hjk committed
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361

    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
362
        for n in xrange(numBuckets - start):
hjk's avatar
hjk committed
363
364
365
366
367
368
369
370
371
372
            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"]
373
    size = d_ptr["size"]
hjk's avatar
hjk committed
374
375
376
377

    hashDataType = d_ptr.type
    hashNodeType = e_ptr.type

378
    check(0 <= size and size <= 100 * 1000 * 1000)
379
    checkRef(d_ptr["ref"])
hjk's avatar
hjk committed
380

381
382
    d.putItemCount(size)
    d.putNumChild(size)
hjk's avatar
hjk committed
383
384
385
386
387
388
    if d.isExpanded(item):
        isSimpleKey = isSimpleType(keyType)
        isSimpleValue = isSimpleType(valueType)
        node = hashDataFirstNode(item.value)

        innerType = e_ptr.dereference().type
389
        inner = select(isSimpleKey and isSimpleValue, valueType, innerType)
390
391
392
393
394
395
396
397
398
399
400
401
402
        with Children(d, [size, 1000], inner):
            for i in d.childRange():
                it = node.dereference().cast(innerType)
                with SubItem(d):
                    key = it["key"]
                    value = it["value"]
                    if isSimpleKey and isSimpleValue:
                        d.putName(key)
                        d.putItemHelper(Item(value, item.iname, i))
                        d.putType(valueType)
                    else:
                        d.putItemHelper(Item(it, item.iname, i))
                node = hashDataNextNode(node)
hjk's avatar
hjk committed
403
404


405
def qdump__QHashNode(d, item):
hjk's avatar
hjk committed
406
407
408
409
410
    keyType = item.value.type.template_argument(0)
    valueType = item.value.type.template_argument(1)
    key = item.value["key"]
    value = item.value["value"]

411
    if isSimpleType(keyType) and isSimpleType(valueType):
412
        d.putItemHelper(Item(value, "data", item.iname))
hjk's avatar
hjk committed
413
    else:
414
        d.putValue(" ")
hjk's avatar
hjk committed
415

416
    d.putNumChild(2)
hjk's avatar
hjk committed
417
    if d.isExpanded(item):
418
419
420
421
422
423
424
        with Children(d):
            with SubItem(d):
                d.putName("key")
                d.putItemHelper(Item(key, item.iname, "key"))
            with SubItem(d):
                d.putName("value")
                d.putItemHelper(Item(value, item.iname, "value"))
hjk's avatar
hjk committed
425
426


hjk's avatar
hjk committed
427
428
429
430
431
432
433
434
435
def qdump__QHostAddress(d, item):
    data = item.value["d"]["d"].dereference()
    d.putStringValue(data["ipString"])
    d.putNumChild(1)
    if d.isExpanded(item):
        with Children(d):
           d.putFields(Item(data, item.iname))


436
def qdump__QList(d, item):
hjk's avatar
hjk committed
437
438
439
440
441
    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)
442
443
    size = end - begin
    check(size >= 0)
hjk's avatar
hjk committed
444
445
446
    #if n > 0:
    #    checkAccess(&list.front())
    #    checkAccess(&list.back())
447
    checkRef(d_ptr["ref"])
hjk's avatar
hjk committed
448
449
450
451
452
453
454

    # 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
455
        checkPointerRange(p, qmin(size, 100))
hjk's avatar
hjk committed
456

457
458
    d.putItemCount(size)
    d.putNumChild(size)
hjk's avatar
hjk committed
459
460
461
462
463
464
465
466
    if d.isExpanded(item):
        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)
467
        dummyType = lookupType("void").pointer().pointer()
468
469
        innerTypePointer = innerType.pointer()
        p = gdb.Value(array).cast(dummyType) + begin
470
471
472
473
        if innerTypeIsPointer:
            inner = innerType.target()
        else:
            inner = innerType
474
        # about 0.5s / 1000 items
475
476
477
        with Children(d, [size, 2000], inner):
            for i in d.childRange():
                if isInternal:
478
479
                    pp = p.cast(innerTypePointer).dereference();
                    d.putItem(Item(pp, item.iname, i))
480
                else:
481
482
                    pp = p.cast(innerTypePointer.pointer()).dereference()
                    d.putItem(Item(pp, item.iname, i))
483
                p += 1
hjk's avatar
hjk committed
484

hjk's avatar
hjk committed
485
486
def qform__QImage():
    return "Normal,Displayed"
hjk's avatar
hjk committed
487

488
def qdump__QImage(d, item):
hjk's avatar
hjk committed
489
490
491
492
    painters = item.value["painters"]
    check(0 <= painters and painters < 1000)
    d_ptr = item.value["d"]
    if isNull(d_ptr):
493
        d.putValue("(null)")
hjk's avatar
hjk committed
494
    else:
495
        checkRef(d_ptr["ref"])
496
        d.putValue("(%dx%d)" % (d_ptr["width"], d_ptr["height"]))
497
498
    bits = d_ptr["data"]
    nbytes = d_ptr["nbytes"]
499
    d.putNumChild(0)
hjk's avatar
hjk committed
500
501
    #d.putNumChild(1)
    if d.isExpanded(item):
502
503
504
505
506
507
        with Children(d):
            with SubItem(d):
                d.putName("data")
                d.putType(" ");
                d.putNumChild(0)
                d.putValue("size: %s bytes" % nbytes);
508
    format = d.itemFormat(item)
509
    if format == 1:
510
        d.putDisplay(StopDisplay)
511
    elif format == 2:
hjk's avatar
hjk committed
512
513
514
515
        if False:
            # Take four bytes at a time, this is critical for performance.
            # In fact, even four at a time is too slow beyond 100x100 or so.
            d.putField("editformat", 1)  # Magic marker for direct "QImage" data.
516
            d.put('%s="' % name)
hjk's avatar
hjk committed
517
518
519
            d.put("%08x" % int(d_ptr["width"]))
            d.put("%08x" % int(d_ptr["height"]))
            d.put("%08x" % int(d_ptr["format"]))
520
            p = bits.cast(lookupType("unsigned int").pointer())
hjk's avatar
hjk committed
521
522
523
            for i in xrange(nbytes / 4):
                d.put("%08x" % int(p.dereference()))
                p += 1
524
            d.put('",')
hjk's avatar
hjk committed
525
526
527
        else:
            # Write to an external file. Much faster ;-(
            file = tempfile.mkstemp(prefix="gdbpy_")
528
            filename = file[1].replace("\\", "\\\\")
529
            p = bits.cast(lookupType("unsigned char").pointer())
hjk's avatar
hjk committed
530
531
            gdb.execute("dump binary memory %s %s %s" %
                (filename, cleanAddress(p), cleanAddress(p + nbytes)))
532
533
            d.putDisplay(DisplayImage, " %d %d %d %s"
                % (d_ptr["width"], d_ptr["height"], d_ptr["format"], filename))
hjk's avatar
hjk committed
534
535


536
def qdump__QLinkedList(d, item):
hjk's avatar
hjk committed
537
538
    d_ptr = item.value["d"]
    e_ptr = item.value["e"]
539
    n = d_ptr["size"]
hjk's avatar
hjk committed
540
    check(0 <= n and n <= 100*1000*1000)
541
    checkRef(d_ptr["ref"])
hjk's avatar
hjk committed
542
    d.putItemCount(n)
543
    d.putNumChild(n)
hjk's avatar
hjk committed
544
    if d.isExpanded(item):
545
546
547
548
549
        with Children(d, [n, 1000], item.value.type.template_argument(0)):
            p = e_ptr["n"]
            for i in d.childRange():
                d.putItem(Item(p["t"], item.iname, i))
                p = p["n"]
hjk's avatar
hjk committed
550
551


552
def qdump__QLocale(d, item):
553
    d.putStringValue(call(item.value, "name()"))
554
555
556
    d.putNumChild(0)
    return
    # FIXME: Poke back for variants.
hjk's avatar
hjk committed
557
    if d.isExpanded(item):
558
        with Children(d, 1, lookupType(d.ns + "QChar"), 0):
559
560
561
562
563
            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,
564
                "timeFormat('" + d.ns + "QLocale::ShortFormat')")
565
            d.putCallItem("timeFormat_(long)", item,
566
                "timeFormat('" + d.ns + "QLocale::LongFormat')")
567
568
569
570
571
572
            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()")
hjk's avatar
hjk committed
573
574


575
def qdump__QMapNode(d, item):
576
577
    d.putValue(" ")
    d.putNumChild(2)
hjk's avatar
hjk committed
578
    if d.isExpanded(item):
579
580
581
582
583
584
585
        with Children(d, 2):
            with SubItem(d):
                d.putName("key")
                d.putItemHelper(Item(item.value["key"], item.iname, "name"))
            with SubItem(d):
                d.putName("value")
                d.putItemHelper(Item(item.value["value"], item.iname, "value"))
hjk's avatar
hjk committed
586
587


588
def qdump__QMap(d, item):
hjk's avatar
hjk committed
589
590
591
592
    d_ptr = item.value["d"].dereference()
    e_ptr = item.value["e"].dereference()
    n = d_ptr["size"]
    check(0 <= n and n <= 100*1000*1000)
593
    checkRef(d_ptr["ref"])
hjk's avatar
hjk committed
594
595

    d.putItemCount(n)
596
    d.putNumChild(n)
hjk's avatar
hjk committed
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
    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 *)
612
613
614
        nodeType = lookupType(d.ns + "QMapNode<%s, %s>" % (keyType, valueType))
        payloadSize = nodeType.sizeof - 2 * lookupType("void").pointer().sizeof
        charPtr = lookupType("char").pointer()
hjk's avatar
hjk committed
615

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

618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
        with Children(d, n, innerType):
            for i in xrange(n):
                itd = it.dereference()
                base = it.cast(charPtr) - payloadSize
                node = base.cast(nodeType.pointer()).dereference()
                with SubItem(d):
                    key = node["key"]
                    value = node["value"]
                    #if isSimpleType(item.value.type): # or isStringType(d, item.value.type):
                    if isSimpleKey and isSimpleValue:
                        #d.putType(valueType)
                        d.putName(key)
                        d.putItemHelper(Item(value, item.iname, i))
                    else:
                        d.putItemHelper(Item(node, item.iname, i))
                it = it.dereference()["forward"].dereference()
hjk's avatar
hjk committed
634
635


636
637
def qdump__MultiMap(d, item):
    qdump__Map(d, item)
hjk's avatar
hjk committed
638
639
640
641
642
643
644
645
646
647
648
649
650


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


651
def qdump__QObject(d, item):
hjk's avatar
hjk committed
652
653
654
    #warn("OBJECT: %s " % item.value)
    staticMetaObject = item.value["staticMetaObject"]
    #warn("SMO: %s " % staticMetaObject)
655
656
657
658
659
660
661
    #warn("SMO DATA: %s " % staticMetaObject["d"]["stringdata"])
    superData = staticMetaObject["d"]["superdata"]
    #warn("SUPERDATA: %s" % superData)
    #while not isNull(superData):
    #    superData = superData.dereference()["d"]["superdata"]
    #    warn("SUPERDATA: %s" % superData)

662
663
664
665
666
667
668
669
670
    privateType = lookupType(d.ns + "QObjectPrivate")
    if privateType is None:
        d.putNumChild(4)
        #d.putValue(cleanAddress(item.value.address))
        if d.isExpanded(item):
            with Children(d):
                d.putFields(item)
        return
    d_ptr = item.value["d_ptr"]["d"].cast(privateType.pointer()).dereference()
hjk's avatar
hjk committed
671
672
673
    #warn("D_PTR: %s " % d_ptr)
    objectName = d_ptr["objectName"]
    #warn("OBJECTNAME: %s " % objectName)
674
    #warn("D_PTR: %s " % d_ptr)
hjk's avatar
hjk committed
675
676
677
678
679
680
681
    mo = d_ptr["metaObject"]
    if isNull(mo):
        mo = staticMetaObject
    #warn("MO: %s " % mo)
    #warn("MO.D: %s " % mo["d"])
    metaData = mo["d"]["data"]
    metaStringData = mo["d"]["stringdata"]
682
    #extradata = mo["d"]["extradata"]   # Capitalization!
hjk's avatar
hjk committed
683
684
685
    #warn("METADATA: %s " % metaData)
    #warn("STRINGDATA: %s " % metaStringData)
    #warn("TYPE: %s " % item.value.type)
686
    #warn("INAME: %s " % item.iname)
687
688
    #d.putValue("")
    d.putStringValue(objectName)
hjk's avatar
hjk committed
689
    #QSignalMapper::staticMetaObject
690
    #checkRef(d_ptr["ref"])
hjk's avatar
hjk committed
691
692
    d.putNumChild(4)
    if d.isExpanded(item):
693
      with Children(d):
hjk's avatar
hjk committed
694
        d.putFields(item)
695
        # Parent and children.
696
697
698
        if stripClassTag(str(item.value.type)) == d.ns + "QObject":
            d.putItem(Item(d_ptr["parent"], item.iname, "parent", "parent"))
            d.putItem(Item(d_ptr["children"], item.iname, "children", "children"))
hjk's avatar
hjk committed
699

700
        # Properties.
701
        with SubItem(d):
702
            # Prolog
703
704
            extraData = d_ptr["extraData"]   # Capitalization!
            if isNull(extraData):
705
                dynamicPropertyCount = 0
706
            else:
707
                extraDataType = lookupType(
708
709
710
711
712
713
714
715
716
                    d.ns + "QObjectPrivate::ExtraData").pointer()
                extraData = extraData.cast(extraDataType)
                ed = extraData.dereference()
                names = ed["propertyNames"]
                values = ed["propertyValues"]
                #userData = ed["userData"]
                namesBegin = names["d"]["begin"]
                namesEnd = names["d"]["end"]
                namesArray = names["d"]["array"]
717
718
                dynamicPropertyCount = namesEnd - namesBegin

719
720
            #staticPropertyCount = call(mo, "propertyCount()")
            staticPropertyCount = metaData[6]
721
722
723
724
725
726
727
728
729
            #warn("PROPERTY COUNT: %s" % staticPropertyCount)
            propertyCount = staticPropertyCount + dynamicPropertyCount

            d.putName("properties")
            d.putType(" ")
            d.putItemCount(propertyCount)
            d.putNumChild(propertyCount)

            if d.isExpandedIName(item.iname + ".properties"):
730
731
                # FIXME: Make this global. Don't leak.
                variant = "'%sQVariant'" % d.ns
732
733
                # Avoid malloc symbol clash with QVector
                gdb.execute("set $d = (%s*)calloc(sizeof(%s), 1)" % (variant, variant))
734
                gdb.execute("set $d.d.is_shared = 0")
735

736
                with Children(d, [propertyCount, 500]):
737
                    # Dynamic properties.
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
                    if dynamicPropertyCount != 0:
                        dummyType = lookupType("void").pointer().pointer()
                        namesType = lookupType(d.ns + "QByteArray")
                        valuesBegin = values["d"]["begin"]
                        valuesEnd = values["d"]["end"]
                        valuesArray = values["d"]["array"]
                        valuesType = lookupType(d.ns + "QVariant")
                        p = namesArray.cast(dummyType) + namesBegin
                        q = valuesArray.cast(dummyType) + valuesBegin
                        for i in xrange(dynamicPropertyCount):
                            with SubItem(d):
                                pp = p.cast(namesType.pointer()).dereference();
                                d.putField("key", encodeByteArray(pp))
                                d.putField("keyencoded", Hex2EncodedLatin1)
                                qq = q.cast(valuesType.pointer().pointer())
                                qq = qq.dereference();
                                d.putField("addr", cleanAddress(qq))
755
756
                                d.putField("exp", "*(%s*)%s"
                                     % (variant, cleanAddress(qq)))
757
758
759
760
761
762
                                name = "%s.properties.%d" % (item.iname, i)
                                t = qdump__QVariant(d, Item(qq, name))
                                # Override the "QVariant (foo)" output
                                d.putType(t, d.currentTypePriority + 1)
                            p += 1
                            q += 1
763
764
765
766

                    # Static properties.
                    propertyData = metaData[7]
                    for i in xrange(staticPropertyCount):
767
                        with SubItem(d):
768
                            offset = propertyData + 3 * i
769
770
771
772
773
774
775
776
777
778
                            propertyName = extractCString(metaStringData, metaData[offset])
                            propertyType = extractCString(metaStringData, metaData[offset + 1])
                            d.putName(propertyName)
                            #flags = metaData[offset + 2]
                            #warn("FLAGS: %s " % flags)
                            #warn("PROPERTY: %s %s " % (propertyType, propertyName))
                            # #exp = '((\'%sQObject\'*)%s)->property("%s")' \
                            #     % (d.ns, item.value.address, propertyName)
                            #exp = '"((\'%sQObject\'*)%s)"' % (d.ns, item.value.address,)
                            #warn("EXPRESSION:  %s" % exp)
779
780
                            value = call(item.value, 'property(%s)'
                                % cleanAddress(metaStringData + metaData[offset]))
781
782
783
784
785
786
787
788
789
                            value1 = value["d"]
                            #warn("   CODE: %s" % value1["type"])
                            # Type 1 and 2 are bool and int. Try to save a few cycles in this case:
                            if int(value1["type"]) > 2:
                                # Poke back value
                                gdb.execute("set $d.d.data.ull = %s" % value1["data"]["ull"])
                                gdb.execute("set $d.d.type = %s" % value1["type"])
                                gdb.execute("set $d.d.is_null = %s" % value1["is_null"])
                                value = parseAndEvaluate("$d").dereference()
790
791
792
793
                            val, inner, innert = qdumpHelper__QVariant(d, value)
                            if len(inner):
                                # Build-in types.
                                d.putType(inner)
794
                                name = "%s.properties.%d" % (item.iname, i + dynamicPropertyCount)
795
796
797
798
799
800
801
802
803
804
                                d.putItemHelper(Item(val, item.iname + ".properties",
                                                    propertyName, propertyName))

                            else:
                                # User types.
                           #    func = "typeToName(('%sQVariant::Type')%d)" % (d.ns, variantType)
                           #    type = str(call(item.value, func))
                           #    type = type[type.find('"') + 1 : type.rfind('"')]
                           #    type = type.replace("Q", d.ns + "Q") # HACK!
                           #    data = call(item.value, "constData()")
805
                           #    tdata = data.cast(lookupType(type).pointer()).dereference()
806
807
808
809
810
811
812
813
814
815
816
817
                           #    d.putValue("(%s)" % tdata.type)
                           #    d.putType(tdata.type)
                           #    d.putNumChild(1)
                           #    if d.isExpanded(item):
                           #        with Children(d):
                           #           d.putItem(Item(tdata, item.iname, "data", "data"))
                                warn("FIXME: CUSTOM QOBJECT PROPERTIES NOT IMPLEMENTED: %s %s"
                                    % (propertyType, innert))
                                d.putType(propertyType)
                                d.putValue("...")
                                d.putNumChild(0)

818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
        # Connections.
        with SubItem(d):
            d.putName("connections")
            d.putType(" ")
            connections = d_ptr["connectionLists"]
            connectionListCount = 0
            if not isNull(connections):
                connectionListCount = connections["d"]["size"]
            d.putItemCount(connectionListCount)
            d.putNumChild(connectionListCount)
            if d.isExpandedIName(item.iname + ".connections"):
                with Children(d):
                    vectorType = connections.type.target().fields()[0].type
                    innerType = vectorType.template_argument(0)
                    # Should check:  innerType == ns::QObjectPrivate::ConnectionList
                    p = gdb.Value(connections["p"]["array"]).cast(innerType.pointer())
                    pp = 0
                    for i in xrange(connectionListCount):
                        first = p.dereference()["first"]
                        while not isNull(first):
                            d.putItem(Item(first.dereference(), item.iname + ".connections", pp))
                            first = first["next"]
                            # We need to enforce some upper limit.
                            pp += 1
                            if pp > 1000:
                                break
                        p += 1

hjk's avatar
hjk committed
846

847
        # Signals
hjk's avatar
hjk committed
848
        signalCount = metaData[13]
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
        with SubItem(d):
            d.putName("signals")
            d.putItemCount(signalCount)
            d.putType(" ")
            d.putNumChild(signalCount)
            if signalCount:
                # FIXME: empty type does not work for childtype
                #d.putField("childtype", ".")
                d.putField("childnumchild", "0")
            if d.isExpandedIName(item.iname + ".signals"):
                with Children(d):
                    for signal in xrange(signalCount):
                        with SubItem(d):
                            offset = metaData[14 + 5 * signal]
                            d.putField("iname", "%s.signals.%d" % (item.iname, signal))
                            d.putName("signal %d" % signal)
                            d.putType(" ")
                            d.putValue(extractCString(metaStringData, offset))
867
                            d.putNumChild(0)  # FIXME: List the connections here.
hjk's avatar
hjk committed
868

869
        # Slots
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
        with SubItem(d):
            slotCount = metaData[4] - signalCount
            d.putName("slots")
            d.putItemCount(slotCount)
            d.putType(" ")
            d.putNumChild(slotCount)
            if slotCount:
                #d.putField("childtype", ".")
                d.putField("childnumchild", "0")
            if d.isExpandedIName(item.iname + ".slots"):
                with Children(d):
                    for slot in xrange(slotCount):
                        with SubItem(d):
                            offset = metaData[14 + 5 * (signalCount + slot)]
                            d.putField("iname", "%s.slots.%d" % (item.iname, slot))
                            d.putName("slot %d" % slot)
                            d.putType(" ")
                            d.putValue(extractCString(metaStringData, offset))
888
                            d.putNumChild(0)  # FIXME: List the connections here.
hjk's avatar
hjk committed
889

890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
        # Active connection
        with SubItem(d):
            d.putName("currentSender")
            d.putType(" ")
            sender = d_ptr["currentSender"]
            d.putValue(cleanAddress(sender))
            if isNull(sender):
                d.putNumChild(0)
            else:
                d.putNumChild(1)
                iname = item.iname + ".currentSender"
                if d.isExpandedIName(iname):
                    with Children(d):
                        # Sending object
                        d.putItem(Item(sender["sender"], iname, "object", "object"))
                        # Signal in sending object
                        with SubItem(d):
                            d.putName("signal")
                            d.putValue(sender["signal"])
                            d.putType(" ");
                            d.putNumChild(0)

hjk's avatar
hjk committed
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
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
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
# 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()
1014
#     d.putValue(ob->objectName(), 2)
hjk's avatar
hjk committed
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
#     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)
#         }
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
#         with Children(d):
#             with SubItem(d):
#                 d.putName("properties")
#                 // 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())
#             with SubItem(d):
#                 d.putName("signals")
#                 d.putField("addr", d.data)
#                 d.putField("type", d.ns + "QObjectSignalList")
#                 d.putItemCount(signalCount)
#                 d.putField("numchild", signalCount)
#             with SubItem(d):
#                 d.putName("slots")
#                 d.putField("addr", d.data)
#                 d.putField("type", d.ns + "QObjectSlotList")
#                 d.putItemCount(slotCount)
#                 d.putField("numchild", slotCount)
#             const QObjectList objectChildren = ob->children()
#             if !objectChildren.empty()) {
#                 with SubItem(d):
#                    d.putName("children")
#                    d.putField("addr", d.data)
#                    d.putField("type", ns + "QObjectChildList")
#                    d.putItemCount(objectChildren.size())
#                    d.putField("numchild", objectChildren.size())
#             with SubItem(d):
#                 d.putName("parent")
#                 if isSimpleType(item.value.type):
#                     d.putItemHelper(d, ns + "QObject *", ob->parent())
#     #if 1
#             with SubItem(d):
#                 d.putName("className")
#                 d.putValue(ob->metaObject()->className())
#                 d.putField("type", "")
#                 d.putField("numchild", "0")
#     #endif
hjk's avatar
hjk committed
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
1092
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


# 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)) {
1119
#         d.putValue(enumValue)
hjk's avatar
hjk committed
1120
#     } else {
1121
#         d.putValue(value)
hjk's avatar
hjk committed
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
#     }
#     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)
1132
1133
1134
1135
1136
#     if flagsValue.isEmpty():
#         d.putValue(value)
#     else:
#         d.putValue(flagsValue.constData())
#     d.putNumChild(0)
hjk's avatar
hjk committed
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
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
# }
#
# #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 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")
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
#         with Children(d):
#            for (int i = 0; i != mo->methodCount(); ++i) {
#                const QMetaMethod & method = mo->method(i)
#                int mt = method.methodType()
#                with SubItem(d):
#                    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()
hjk's avatar
hjk committed
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
#
# 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)
# {
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
#     with SubItem(d):
#         d.beginItem("name")
#         d.put(number).put(namePostfix)
#         d.endItem()
#         if partner == owner) {
#             d.putValue("<this>")
#             d.putField("type", owner->metaObject()->className())
#             d.putField("numchild", 0)
#             d.putField("addr", owner)
#         } else {
#       if isSimpleType(item.value.type):
#           d.putItemHelper(ns + "QObject *", partner)
hjk's avatar
hjk committed
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
#
# 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)
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
#         with Children(d):
#              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")
#                  with SubItem(d):
#                      d.beginItem("name")
#                          d.put(i).put(" slot")
#                      d.endItem()
#                      d.putField("type", "")
#                      if conn.receiver)
#                          d.putValue(conn.receiver->metaObject()->method(conn.method).signature())
#                      else
#                          d.putValue("<invalid receiver>")
#                      d.putField("numchild", "0")
#                  with SubItem(d):
#                      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")
hjk's avatar
hjk committed
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
#         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):
1293
#         with Children(d):
hjk's avatar
hjk committed
1294
1295
1296
1297
1298
#         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)
1299
1300
1301
1302
1303
1304
#                 with SubItem(d):
#                     d.putName(k)
#                     d.putValue(method.signature())
#                     d.putField("numchild", connList.size())
#                     d.putField("addr", d.data)
#                     d.putField("type", ns + "QObjectSignal")
hjk's avatar
hjk committed
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
# #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):
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
#         with Children(d):
#             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")
#                         with SubItem(d):
#                             d.beginItem("name")
#                                 d.put(s).put(" signal")
#                             d.endItem()
#                             d.putField("type", "")
#                             d.putValue(method.signature())
#                             d.putField("numchild", "0")
#                         with SubItem(d):
#                             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")
#                     }
hjk's avatar
hjk committed
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
#                 }
#             }
#         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):
1382
1383
1384
1385
1386
1387
1388
1389
1390
#         with Children(d):
#      #if QT_VERSION >= 0x040400
#              for (int i = 0; i != methodCount; ++i) {
#                  const QMetaMethod & method = mo->method(i)
#                  if method.methodType() == QMetaMethod::Slot) {
#                      with SubItem(d):
#                           int k = mo->indexOfSlot(method.signature())
#                           d.putName(k)
#                           d.putValue(method.signature())
hjk's avatar
hjk committed
1391
#
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
#                           // 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")
#                  }
#              }
#      #endif
hjk's avatar
hjk committed
1418
1419
1420
1421
#
# #endif // QT_BOOTSTRAPPED


1422
def qdump__QPixmap(d, item):
hjk's avatar
hjk committed
1423
1424
1425
1426
    painters = item.value["painters"]
    check(0 <= painters and painters < 1000)
    d_ptr = item.value["data"]["d"]
    if isNull(d_ptr):
1427
        d.putValue("(null)")
hjk's avatar
hjk committed
1428
    else:
1429
        checkRef(d_ptr["ref"])
1430
1431
        d.putValue("(%dx%d)" % (d_ptr["w"], d_ptr["h"]))
    d.putNumChild(0)
hjk's avatar
hjk committed
1432
1433


1434
def qdump__QPoint(d, item):
hjk's avatar
hjk committed
1435
1436
1437
1438
1439
    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())
1440
    d.putValue("(%s, %s)" % (x, y))
hjk's avatar
hjk committed
1441
1442
    d.putNumChild(2)
    if d.isExpanded(item):
1443
1444
1445
        with Children(d, 2, x.type.strip_typedefs()):
            d.putItem(Item(x, None, None, "x"))
            d.putItem(Item(y, None, None, "y"))
hjk's avatar
hjk committed
1446
1447


1448
1449
def qdump__QPointF(d, item):
    qdump__QPoint(d, item)
hjk's avatar
hjk committed
1450
1451


1452
def qdump__QRect(d, item):
1453
    def pp(l): return select(l >= 0, "+%s" % l, l)
hjk's avatar
hjk committed
1454
1455
1456
1457
1458
1459
    x1 = item.value["x1"]
    y1 = item.value["y1"]
    x2 = item.value["x2"]
    y2 = item.value["y2"]
    w = x2 - x1 + 1
    h = y2 - y1 + 1
1460
    d.putValue("%sx%s%s%s" % (w, h, pp(x1), pp(y1)))
hjk's avatar
hjk committed
1461
1462
    d.putNumChild(4)
    if d.isExpanded(item):
1463
1464
1465
1466
1467
        with Children(d, 4, x1.type.strip_typedefs()):
            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"))
hjk's avatar
hjk committed
1468
1469


1470
def qdump__QRectF(d, item):
1471
    def pp(l): return select(l >= 0, "+%s" % l, l)
hjk's avatar
hjk committed
1472
1473
1474
1475
1476
1477
1478
1479
1480
    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())
1481
    d.putValue("%sx%s%s%s" % (w, h, pp(x), pp(y)))
hjk's avatar
hjk committed
1482
1483
    d.putNumChild(4)
    if d.isExpanded(item):
1484
1485
1486
1487
1488
        with Children(d, 4, x.type.strip_typedefs()):
            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"))
hjk's avatar
hjk committed
1489
1490


1491
def qdump__QRegion(d, item):
hjk's avatar
hjk committed
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
    p = item.value["d"].dereference()["qt_rgn"]
    if isNull(p):
        d.putValue("<empty>")
        d.putNumChild(0)
    else:
        n = str(p.dereference()["numRects"])
        d.putItemCount(n)
        d.putNumChild(n)
        if d.isExpanded(item):
            with Children(d):
                d.putFields(Item(p.dereference(), item.iname))
1503

1504
1505
1506
# qt_rgn might be 0
# gdb.parse_and_eval("region")["d"].dereference()["qt_rgn"].dereference()

1507
1508
1509
1510
1511
def qdump__QScopedPointer(d, item):
    d.putType(d.currentType, d.currentTypePriority + 1)
    d.putItemHelper(Item(item.value["d"], item.iname, None, None))


1512
def qdump__QSet(d, item):
hjk's avatar
hjk committed
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534

    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
1535
        for n in xrange(numBuckets - start):
hjk's avatar
hjk committed
1536
1537
1538
1539
1540
1541
1542
1543
1544
            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"]
1545
    size = d_ptr["size"]
hjk's avatar
hjk committed
1546
1547
1548
1549

    hashDataType = d_ptr.type
    hashNodeType = e_ptr.type