aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator/debugger/boosttypes.py
blob: 38cbc394ceffd35c5c5bb0e9740df10c684073dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Copyright (C) 2016 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0

from utils import DisplayFormat
from dumper import Children


def qdump__boost__bimaps__bimap(d, value):
    #leftType = value.type[0]
    #rightType = value.type[1]
    size = value["core"]["node_count"].integer()
    d.putItemCount(size)
    if d.isExpanded():
        d.putPlainChildren(value)


def qdump__boost__optional(d, value):
    innerType = value.type[0]
    (initialized, pad, payload) = d.split('b@{%s}' % innerType.name, value)
    if initialized:
        d.putItem(payload)
        d.putBetterType(value.type)
    else:
        d.putSpecialValue("uninitialized")


def qdump__boost__shared_ptr(d, value):
    # s                  boost::shared_ptr<int>
    #    px      0x0     int *
    #    pn              boost::detail::shared_count
    #        pi_ 0x0     boost::detail::sp_counted_base *
    (px, pi) = value.split("pp")
    if pi == 0:
        d.putValue("(null)")
        return

    if px == 0:
        d.putValue("(null)")
        return

    (vptr, usecount, weakcount) = d.split('pii', pi)
    d.check(weakcount >= 0)
    d.check(weakcount <= usecount)
    d.check(usecount <= 10 * 1000 * 1000)
    d.putItem(d.createValue(px, value.type[0]))
    d.putBetterType(value.type)


def qdump__boost__container__list(d, value):
    try:
        m_icont = value["m_icont"]
    except:
        m_icont = value["members_"]["m_icont"]
    r = m_icont["data_"]["root_plus_size_"]
    n = r["size_"].integer()
    d.putItemCount(n)
    if d.isExpanded():
        innerType = value.type[0]
        offset = 2 * d.ptrSize()
        with Children(d, n):
            try:
                root = r["root_"]
            except:
                root = r["m_header"]
            p = root["next_"].extractPointer()
            for i in d.childRange():
                d.putSubItem(i, d.createValue(p + offset, innerType))
                p = d.extractPointer(p)


def qform__boost__container__vector():
    return [DisplayFormat.ArrayPlot]


def qdump__boost__container__vector(d, value):
    holder = value["m_holder"]
    size = holder["m_size"].integer()
    d.putItemCount(size)

    if d.isExpanded():
        T = value.type[0]
        try:
            start = holder["m_start"].pointer()
        except:
            start = holder["storage"].address()
        d.putPlotData(start, size, T)


def qform__boost__container__static_vector():
    return [DisplayFormat.ArrayPlot]


def qdump__boost__container__static_vector(d, value):
    qdump__boost__container__vector(d, value)


def qform__boost__container__small_vector():
    return [DisplayFormat.ArrayPlot]


def qdump__boost__container__small_vector(d, value):
    qdump__boost__container__vector(d, value)


def qdump__boost__gregorian__date(d, value):
    d.putValue(value.integer(), "juliandate")


def qdump__boost__posix_time__ptime(d, value):
    ms = int(value.integer() / 1000)
    d.putValue("%s/%s" % divmod(ms, 86400000), "juliandateandmillisecondssincemidnight")


def qdump__boost__posix_time__time_duration(d, value):
    d.putValue(int(value.integer() / 1000), "millisecondssincemidnight")


def qdump__boost__unordered__unordered_set(d, value):
    innerType = value.type[0]
    if value.type.size() == 7 * d.ptrSize(): # 56 for boost 1.79+
        bases, bucketCount, bcountLog2, size, mlf, maxload, buckets = value.split('ttttttp')
        forward = True
    elif value.type.size() == 6 * d.ptrSize():  # 48 for boost 1.55+
        # boost 1.58 or 1.55
        # bases are 3? bytes, and mlf is actually a float, but since
        # its followed by size_t maxload, it's # effectively padded to a size_t
        bases, bucketCount, size, mlf, maxload, buckets = value.split('tttttp')
        # Distinguish 1.58 and 1.55. 1.58 used one template argument, 1.55 two.
        try:
            ittype = d.lookupType(value.type.name + '::iterator').target()
            forward = len(ittype.templateArguments()) == 1
        except:
            forward = True
    elif value.type.size() == 5 * d.ptrSize():  # 40 for boost 1.48
        # boost 1.48
        # Values are stored before the next pointers. Determine the offset.
        buckets, bucketCount, size, mlf, maxload = value.split('ptttt')
        forward = False
    else:
        raise Exception("Unknown boost::unordered_set layout")

    if forward:
        # boost >= 1.58
        code = 'pp{%s}' % innerType.name

        def children(p):
            while True:
                p, dummy, val = d.split(code, p)
                yield val
    else:
        # boost 1.48 or 1.55
        code = '{%s}@p' % innerType.name
        (pp, ssize, fields) = d.describeStruct(code)
        offset = fields[2].offset()

        def children(p):
            while True:
                val, pad, p = d.split(code, p - offset)
                yield val

    p = d.extractPointer(buckets + bucketCount * d.ptrSize())
    d.putItems(size, children(p), maxNumChild=10000)


def qdump__boost__variant(d, value):
    allTypes = value.type.templateArguments()
    realType = allTypes[value.split('i')[0]]
    alignment = max([t.alignment() for t in allTypes])
    dummy, val = value.split('%is{%s}' % (max(4, alignment), realType.name))
    d.putItem(val)
    d.putBetterType(value.type)


def qdump__boost__container__devector(d, value):
    inner_type = value.type[0]
    buffer = value["m_"]["buffer"].pointer()
    front_idx = value["m_"]["front_idx"].integer()
    back_idx = value["m_"]["back_idx"].integer()
    start = buffer + (front_idx * inner_type.size())
    size = int(back_idx - front_idx)
    if size > 0:
        d.checkPointer(start)
    d.putItemCount(size)
    d.putPlotData(start, size, inner_type)