stdtypes.py 27.7 KB
Newer Older
hjk's avatar
hjk committed
1 2
############################################################################
#
3
# Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
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
# Contact: http://www.qt-project.org/legal
#
# This file is part of Qt Creator.
#
# Commercial License Usage
# Licensees holding valid commercial Qt licenses may use this file in
# accordance with the commercial license agreement provided with the
# Software or, alternatively, in accordance with the terms contained in
# a written agreement between you and Digia.  For licensing terms and
# conditions see http://qt.digia.com/licensing.  For further information
# use the contact form at http://qt.digia.com/contact-us.
#
# GNU Lesser General Public License Usage
# Alternatively, this file may be used under the terms of the GNU Lesser
# General Public License version 2.1 as published by the Free Software
# Foundation and appearing in the file LICENSE.LGPL included in the
# packaging of this file.  Please review the following information to
# ensure the GNU Lesser General Public License version 2.1 requirements
# will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
#
# In addition, as a special exception, Digia gives you certain additional
# rights.  These rights are described in the Digia Qt LGPL Exception
# version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
#
#############################################################################

from dumper import *

32 33 34
def qform__std__array():
    return arrayForms()

hjk's avatar
hjk committed
35 36 37 38 39 40
def qdump__std__array(d, value):
    size = d.numericTemplateArgument(value.type, 1)
    d.putItemCount(size)
    d.putNumChild(size)
    if d.isExpanded():
        innerType = d.templateArgument(value.type, 0)
41 42
        d.putPlotData(innerType, d.addressOf(value), size)

hjk's avatar
hjk committed
43

44 45
def qform__std____1__array():
    return arrayForms()
hjk's avatar
hjk committed
46 47 48 49 50 51 52

def qdump__std____1__array(d, value):
    qdump__std__array(d, value)


def qdump__std__complex(d, value):
    innerType = d.templateArgument(value.type, 0)
53 54
    real = value.cast(innerType)
    imag = d.createValue(d.addressOf(value) + innerType.sizeof, innerType)
hjk's avatar
hjk committed
55 56 57 58 59 60 61 62 63
    d.putValue("(%f, %f)" % (real, imag));
    d.putNumChild(2)
    if d.isExpanded():
        with Children(d, 2, childType=innerType):
            d.putSubItem("real", real)
            d.putSubItem("imag", imag)


def qdump__std__deque(d, value):
64 65 66 67
    if d.isQnxTarget():
        qdump__std__deque__QNX(d, value)
        return

hjk's avatar
hjk committed
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
    innerType = d.templateArgument(value.type, 0)
    innerSize = innerType.sizeof
    bufsize = 1
    if innerSize < 512:
        bufsize = int(512 / innerSize)

    impl = value["_M_impl"]
    start = impl["_M_start"]
    finish = impl["_M_finish"]
    size = bufsize * toInteger(finish["_M_node"] - start["_M_node"] - 1)
    size += toInteger(finish["_M_cur"] - finish["_M_first"])
    size += toInteger(start["_M_last"] - start["_M_cur"])

    d.check(0 <= size and size <= 1000 * 1000 * 1000)
    d.putItemCount(size)
    d.putNumChild(size)
    if d.isExpanded():
        with Children(d, size, maxNumChild=2000, childType=innerType):
            pcur = start["_M_cur"]
            pfirst = start["_M_first"]
            plast = start["_M_last"]
            pnode = start["_M_node"]
            for i in d.childRange():
                d.putSubItem(i, pcur.dereference())
                pcur += 1
93
                if toInteger(pcur) == toInteger(plast):
hjk's avatar
hjk committed
94 95 96 97 98 99
                    newnode = pnode + 1
                    pnode = newnode
                    pfirst = newnode.dereference()
                    plast = pfirst + bufsize
                    pcur = pfirst

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
def qdump__std__deque__QNX(d, value):
    innerType = d.templateArgument(value.type, 0)
    innerSize = innerType.sizeof
    if innerSize <= 1:
        bufsize = 16
    elif innerSize <= 2:
        bufsize = 8
    elif innerSize <= 4:
        bufsize = 4
    elif innerSize <= 8:
        bufsize = 2
    else:
        bufsize = 1

    myoff = value['_Myoff']
    mysize = value['_Mysize']
    mapsize = value['_Mapsize']

    d.check(0 <= mapsize and mapsize <= 1000 * 1000 * 1000)
    d.putItemCount(mysize)
    d.putNumChild(mysize)
    if d.isExpanded():
        with Children(d, mysize, maxNumChild=2000, childType=innerType):
            map = value['_Map']
            for i in d.childRange():
                block = myoff / bufsize
                offset = myoff - (block * bufsize)
                if mapsize <= block:
                    block -= mapsize
                d.putSubItem(i, map[block][offset])
                myoff += 1;

hjk's avatar
hjk committed
132 133 134 135 136
def qdump__std____debug__deque(d, value):
    qdump__std__deque(d, value)


def qdump__std__list(d, value):
137 138 139 140
    if d.isQnxTarget():
        qdump__std__list__QNX(d, value)
        return

hjk's avatar
hjk committed
141 142
    impl = value["_M_impl"]
    node = impl["_M_node"]
143
    head = d.addressOf(node)
hjk's avatar
hjk committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    size = 0
    pp = d.dereference(head)
    while head != pp and size <= 1001:
        size += 1
        pp = d.dereference(pp)

    d.putItemCount(size, 1000)
    d.putNumChild(size)

    if d.isExpanded():
        p = node["_M_next"]
        innerType = d.templateArgument(value.type, 0)
        with Children(d, size, maxNumChild=1000, childType=innerType):
            for i in d.childRange():
                innerPointer = innerType.pointer()
                d.putSubItem(i, (p + 1).cast(innerPointer).dereference())
                p = p["_M_next"]

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
def qdump__std__list__QNX(d, value):
    node = value["_Myhead"]
    size = value["_Mysize"]

    d.putItemCount(size, 1000)
    d.putNumChild(size)

    if d.isExpanded():
        p = node["_Next"]
        innerType = d.templateArgument(value.type, 0)
        with Children(d, size, maxNumChild=1000, childType=innerType):
            for i in d.childRange():
                d.putSubItem(i, p['_Myval'])
                p = p["_Next"]

hjk's avatar
hjk committed
177 178 179 180 181 182 183
def qdump__std____debug__list(d, value):
    qdump__std__list(d, value)

def qform__std__map():
    return mapForms()

def qdump__std__map(d, value):
184 185 186 187
    if d.isQnxTarget():
        qdump__std__map__QNX(d, value)
        return

hjk's avatar
hjk committed
188 189 190 191 192 193 194
    impl = value["_M_t"]["_M_impl"]
    size = int(impl["_M_node_count"])
    d.check(0 <= size and size <= 100*1000*1000)
    d.putItemCount(size)
    d.putNumChild(size)

    if d.isExpanded():
195 196 197 198
        pairType = d.templateArgument(d.templateArgument(value.type, 3), 0)
        pairPointer = pairType.pointer()
        with PairedChildren(d, size, pairType, maxNumChild=1000):
            node = impl["_M_header"]["_M_left"]
hjk's avatar
hjk committed
199 200 201
            for i in d.childRange():
                with SubItem(d, i):
                    pair = (node + 1).cast(pairPointer).dereference()
202
                    d.putPair(pair)
hjk's avatar
hjk committed
203 204 205 206 207 208 209 210 211 212 213 214
                if d.isNull(node["_M_right"]):
                    parent = node["_M_parent"]
                    while node == parent["_M_right"]:
                        node = parent
                        parent = parent["_M_parent"]
                    if node["_M_right"] != parent:
                        node = parent
                else:
                    node = node["_M_right"]
                    while not d.isNull(node["_M_left"]):
                        node = node["_M_left"]

215 216 217 218 219 220 221 222 223 224 225 226 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 269 270 271
def qdump__std__map__QNX(d, value):
    size = value['_Mysize']
    d.check(0 <= size and size <= 100*1000*1000)
    d.putItemCount(size)
    d.putNumChild(size)

    if d.isExpanded():
        keyType = d.templateArgument(value.type, 0)
        valueType = d.templateArgument(value.type, 1)
        try:
            # Does not work on gcc 4.4, the allocator type (fourth template
            # argument) seems not to be available.
            pairType = d.templateArgument(d.templateArgument(value.type, 3), 0)
            pairPointer = pairType.pointer()
        except:
            # So use this as workaround:
            pairType = d.templateArgument(impl.type, 1)
            pairPointer = pairType.pointer()
        isCompact = d.isMapCompact(keyType, valueType)
        innerType = pairType
        if isCompact:
            innerType = valueType
        head = value['_Myhead']
        node = head['_Left']
        nodeType = head.type
        childType = innerType
        if size == 0:
            childType = pairType
        childNumChild = 2
        if isCompact:
            childNumChild = None
        with Children(d, size, maxNumChild=1000,
                childType=childType, childNumChild=childNumChild):
            for i in d.childRange():
                with SubItem(d, i):
                    pair = node.cast(nodeType).dereference()['_Myval']
                    if isCompact:
                        d.putMapName(pair["first"])
                        d.putItem(pair["second"])
                    else:
                        d.putEmptyValue()
                        if d.isExpanded():
                            with Children(d, 2):
                                d.putSubItem("first", pair["first"])
                                d.putSubItem("second", pair["second"])
                if not node['_Right']['_Isnil']:
                    node = node['_Right']
                    while not node['_Left']['_Isnil']:
                        node = node['_Left']
                else:
                    parent = node['_Parent']
                    while node == parent['_Right']['_Isnil']:
                        node = parent
                        parent = parent['_Parent']
                    if node['_Right'] != parent:
                        node = parent

hjk's avatar
hjk committed
272 273 274 275 276 277 278 279 280 281
def qdump__std____debug__map(d, value):
    qdump__std__map(d, value)

def qdump__std____debug__set(d, value):
    qdump__std__set(d, value)

def qdump__std____cxx1998__map(d, value):
    qdump__std__map(d, value)

def stdTreeIteratorHelper(d, value):
282
    node = value["_M_node"].dereference()
hjk's avatar
hjk committed
283 284 285
    d.putNumChild(1)
    d.putEmptyValue()
    if d.isExpanded():
286
        nodeTypeName = str(value.type).replace("_Rb_tree_iterator", "_Rb_tree_node", 1)
287
        nodeTypeName = nodeTypeName.replace("_Rb_tree_const_iterator", "_Rb_tree_node", 1)
288 289
        nodeType = d.lookupType(nodeTypeName)
        data = node.cast(nodeType)["_M_value_field"]
hjk's avatar
hjk committed
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 322 323 324 325 326 327 328 329 330 331 332
        with Children(d):
            try:
                d.putSubItem("first", data["first"])
                d.putSubItem("second", data["second"])
            except:
                d.putSubItem("value", data)
            with SubItem(d, "node"):
                d.putNumChild(1)
                d.putEmptyValue()
                d.putType(" ")
                if d.isExpanded():
                    with Children(d):
                        d.putSubItem("color", node["_M_color"])
                        d.putSubItem("left", node["_M_left"])
                        d.putSubItem("right", node["_M_right"])
                        d.putSubItem("parent", node["_M_parent"])


def qdump__std___Rb_tree_iterator(d, value):
    stdTreeIteratorHelper(d, value)

def qdump__std___Rb_tree_const_iterator(d, value):
    stdTreeIteratorHelper(d, value)

def qdump__std__map__iterator(d, value):
    stdTreeIteratorHelper(d, value)

def qdump____gnu_debug___Safe_iterator(d, value):
    d.putItem(value["_M_current"])

def qdump__std__map__const_iterator(d, value):
    stdTreeIteratorHelper(d, value)

def qdump__std__set__iterator(d, value):
    stdTreeIteratorHelper(d, value)

def qdump__std__set__const_iterator(d, value):
    stdTreeIteratorHelper(d, value)

def qdump__std____cxx1998__set(d, value):
    qdump__std__set(d, value)

def qdump__std__set(d, value):
333 334 335 336
    if d.isQnxTarget():
        qdump__std__set__QNX(d, value)
        return

hjk's avatar
hjk committed
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
    impl = value["_M_t"]["_M_impl"]
    size = int(impl["_M_node_count"])
    d.check(0 <= size and size <= 100*1000*1000)
    d.putItemCount(size)
    d.putNumChild(size)
    if d.isExpanded():
        valueType = d.templateArgument(value.type, 0)
        node = impl["_M_header"]["_M_left"]
        with Children(d, size, maxNumChild=1000, childType=valueType):
            for i in d.childRange():
                d.putSubItem(i, (node + 1).cast(valueType.pointer()).dereference())
                if d.isNull(node["_M_right"]):
                    parent = node["_M_parent"]
                    while node == parent["_M_right"]:
                        node = parent
                        parent = parent["_M_parent"]
                    if node["_M_right"] != parent:
                        node = parent
                else:
                    node = node["_M_right"]
                    while not d.isNull(node["_M_left"]):
                        node = node["_M_left"]

360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
def qdump__std__set__QNX(d, value):
    size = value['_Mysize']
    d.check(0 <= size and size <= 100*1000*1000)
    d.putItemCount(size)
    d.putNumChild(size)
    if d.isExpanded():
        valueType = d.templateArgument(value.type, 0)
        head = value['_Myhead']
        node = head['_Left']
        nodeType = head.type
        with Children(d, size, maxNumChild=1000, childType=valueType):
            for i in d.childRange():
                d.putSubItem(i, node.cast(nodeType).dereference()['_Myval'])
                if not node['_Right']['_Isnil']:
                    node = node['_Right']
                    while not node['_Left']['_Isnil']:
                        node = node['_Left']
                else:
                    parent = node['_Parent']
                    while node == parent['_Right']['_Isnil']:
                        node = parent
                        parent = parent['_Parent']
                    if node['_Right'] != parent:
                        node = parent
hjk's avatar
hjk committed
384 385

def qdump__std__stack(d, value):
386 387
    d.putItem(value["c"])
    d.putType(str(value.type))
hjk's avatar
hjk committed
388 389 390 391 392 393 394 395 396 397 398

def qdump__std____debug__stack(d, value):
    qdump__std__stack(d, value)

def qform__std__string():
    return "Inline,In Separate Window"

def qdump__std__string(d, value):
    qdump__std__stringHelper1(d, value, 1)

def qdump__std__stringHelper1(d, value, charSize):
399 400 401 402
    if d.isQnxTarget():
        qdump__std__stringHelper1__QNX(d, value, charSize)
        return

hjk's avatar
hjk committed
403 404 405 406 407 408 409
    data = value["_M_dataplus"]["_M_p"]
    # We can't lookup the std::string::_Rep type without crashing LLDB,
    # so hard-code assumption on member position
    # struct { size_type _M_length, size_type _M_capacity, int _M_refcount; }
    sizePtr = data.cast(d.sizetType().pointer())
    size = int(sizePtr[-3])
    alloc = int(sizePtr[-2])
410
    refcount = int(sizePtr[-1]) & 0xffffffff
hjk's avatar
hjk committed
411 412 413 414
    d.check(refcount >= -1) # Can be -1 accoring to docs.
    d.check(0 <= size and size <= alloc and alloc <= 100*1000*1000)
    qdump_stringHelper(d, sizePtr, size * charSize, charSize)

415 416 417 418 419 420 421 422 423 424 425 426 427 428
def qdump__std__stringHelper1__QNX(d, value, charSize):
    size = value['_Mysize']
    alloc = value['_Myres']
    _BUF_SIZE = 16 / charSize
    if _BUF_SIZE <= alloc: #(_BUF_SIZE <= _Myres ? _Bx._Ptr : _Bx._Buf);
        data = value['_Bx']['_Ptr']
    else:
        data = value['_Bx']['_Buf']
    sizePtr = data.cast(d.charType().pointer())
    refcount = int(sizePtr[-1])
    d.check(refcount >= -1) # Can be -1 accoring to docs.
    d.check(0 <= size and size <= alloc and alloc <= 100*1000*1000)
    qdump_stringHelper(d, sizePtr, size * charSize, charSize)

hjk's avatar
hjk committed
429
def qdump_stringHelper(d, data, size, charSize):
430
    cutoff = min(size, d.stringCutOff)
hjk's avatar
hjk committed
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
    mem = d.readMemory(data, cutoff)
    if charSize == 1:
        encodingType = Hex2EncodedLatin1
        displayType = DisplayLatin1String
    elif charSize == 2:
        encodingType = Hex4EncodedLittleEndian
        displayType = DisplayUtf16String
    else:
        encodingType = Hex8EncodedLittleEndian
        displayType = DisplayUtf16String

    d.putNumChild(0)
    d.putValue(mem, encodingType)

    format = d.currentItemFormat()
    if format == 1:
        d.putDisplay(StopDisplay)
    elif format == 2:
        d.putField("editformat", displayType)
        d.putField("editvalue", d.readMemory(data, size))


def qdump__std____1__string(d, value):
hjk's avatar
hjk committed
454 455 456 457 458 459 460 461 462 463
    base = d.addressOf(value)
    firstByte = d.extractByte(base)
    if firstByte & 1:
        # Long/external.
        data = d.dereference(base + 2 * d.ptrSize())
        size = d.extractInt(base + d.ptrSize())
    else:
        # Short/internal.
        size = firstByte / 2
        data = base + 1
hjk's avatar
hjk committed
464 465 466 467 468
    qdump_stringHelper(d, data, size, 1)
    d.putType("std::string")


def qdump__std____1__wstring(d, value):
hjk's avatar
hjk committed
469 470 471 472 473 474 475 476 477 478 479 480
    base = d.addressOf(value)
    firstByte = d.extractByte(base)
    if firstByte & 1:
        # Long/external.
        data = d.dereference(base + 2 * d.ptrSize())
        size = d.extractInt(base + d.ptrSize())
    else:
        # Short/internal.
        size = firstByte / 2
        data = base + 4
    qdump_stringHelper(d, data, size * 4, 4)
    d.putType("std::xxwstring")
hjk's avatar
hjk committed
481 482 483 484 485 486 487 488 489 490 491 492


def qdump__std__shared_ptr(d, value):
    i = value["_M_ptr"]
    if d.isNull(i):
        d.putValue("(null)")
        d.putNumChild(0)
        return

    if d.isSimpleType(d.templateArgument(value.type, 0)):
        d.putValue("%s @0x%x" % (i.dereference(), d.pointerValue(i)))
    else:
493
        i = d.expensiveDowncast(i)
hjk's avatar
hjk committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
        d.putValue("@0x%x" % d.pointerValue(i))

    d.putNumChild(3)
    with Children(d, 3):
        d.putSubItem("data", i)
        refcount = value["_M_refcount"]["_M_pi"]
        d.putIntItem("usecount", refcount["_M_use_count"])
        d.putIntItem("weakcount", refcount["_M_weak_count"])

def qdump__std____1__shared_ptr(d, value):
    i = value["__ptr_"]
    if d.isNull(i):
        d.putValue("(null)")
        d.putNumChild(0)
        return

    if d.isSimpleType(d.templateArgument(value.type, 0)):
        d.putValue("%s @0x%x" % (i.dereference().value, d.pointerValue(i)))
    else:
        d.putValue("@0x%x" % d.pointerValue(i))

    d.putNumChild(3)
    with Children(d, 3):
        d.putSubItem("data", i.dereference())
        d.putFields(value["__cntrl_"].dereference())
        #d.putIntItem("usecount", refcount["_M_use_count"])
        #d.putIntItem("weakcount", refcount["_M_weak_count"])

def qdump__std__unique_ptr(d, value):
    i = value["_M_t"]["_M_head_impl"]
    if d.isNull(i):
        d.putValue("(null)")
        d.putNumChild(0)
        return

    if d.isSimpleType(d.templateArgument(value.type, 0)):
        d.putValue("%s @0x%x" % (i.dereference(), d.pointerValue(i)))
    else:
532
        i = d.expensiveDowncast(i)
hjk's avatar
hjk committed
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
        d.putValue("@0x%x" % d.pointerValue(i))

    d.putNumChild(1)
    with Children(d, 1):
        d.putSubItem("data", i)

def qdump__std____1__unique_ptr(d, value):
    i = d.childAt(d.childAt(value["__ptr_"], 0), 0)
    if d.isNull(i):
        d.putValue("(null)")
        d.putNumChild(0)
        return

    if d.isSimpleType(d.templateArgument(value.type, 0)):
        d.putValue("%s @0x%x" % (i.dereference().value, d.pointerValue(i)))
    else:
        d.putValue("@0x%x" % d.pointerValue(i))

    d.putNumChild(1)
    with Children(d, 1):
        d.putSubItem("data", i.dereference())


def qform__std__unordered_map():
    return mapForms()

def qform__std____debug__unordered_map():
    return mapForms()

def qdump__std__unordered_map(d, value):
563 564 565 566 567
    keyType = d.templateArgument(value.type, 0)
    valueType = d.templateArgument(value.type, 1)
    allocatorType = d.templateArgument(value.type, 4)
    pairType = d.templateArgument(allocatorType, 0)
    ptrSize = d.ptrSize()
hjk's avatar
hjk committed
568
    try:
569
    # gcc >= 4.7
hjk's avatar
hjk committed
570 571
        size = value["_M_element_count"]
        start = value["_M_before_begin"]["_M_nxt"]
572
        offset = 0
hjk's avatar
hjk committed
573
    except:
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
            try:
                # libc++ (Mac)
                size = value["_M_h"]["_M_element_count"]
                start = value["_M_h"]["_M_bbegin"]["_M_node"]["_M_nxt"]
                offset = 0
            except:
                # gcc 4.6.2
                size = value["_M_element_count"]
                start = value["_M_buckets"].dereference()
                # FIXME: Pointer-aligned?
                offset = pairType.sizeof
                d.putItemCount(size)
                # We don't know where the data is
                d.putNumChild(0)
                return
hjk's avatar
hjk committed
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
    d.putItemCount(size)
    d.putNumChild(size)
    if d.isExpanded():
        p = d.pointerValue(start)
        if d.isMapCompact(keyType, valueType):
            with Children(d, size, childType=valueType):
                for i in d.childRange():
                    pair = d.createValue(p + ptrSize, pairType)
                    with SubItem(d, i):
                        d.putField("iname", d.currentIName)
                        d.putName("[%s] %s" % (i, pair["first"]))
                        d.putValue(pair["second"])
                    p = d.dereference(p)
        else:
            with Children(d, size, childType=pairType):
                for i in d.childRange():
605 606
                    d.putSubItem(i, d.createValue(p + ptrSize - offset, pairType))
                    p = d.dereference(p + offset)
hjk's avatar
hjk committed
607 608 609 610 611 612

def qdump__std____debug__unordered_map(d, value):
    qdump__std__unordered_map(d, value)

def qdump__std__unordered_set(d, value):
    try:
613
        # gcc >= 4.7
hjk's avatar
hjk committed
614 615
        size = value["_M_element_count"]
        start = value["_M_before_begin"]["_M_nxt"]
616
        offset = 0
hjk's avatar
hjk committed
617
    except:
618 619 620 621 622 623 624 625 626 627
            try:
                # libc++ (Mac)
                size = value["_M_h"]["_M_element_count"]
                start = value["_M_h"]["_M_bbegin"]["_M_node"]["_M_nxt"]
                offset = 0
            except:
                # gcc 4.6.2
                size = value["_M_element_count"]
                start = value["_M_buckets"].dereference()
                offset = d.ptrSize()
hjk's avatar
hjk committed
628 629 630 631 632 633 634 635
    d.putItemCount(size)
    d.putNumChild(size)
    if d.isExpanded():
        p = d.pointerValue(start)
        valueType = d.templateArgument(value.type, 0)
        with Children(d, size, childType=valueType):
            ptrSize = d.ptrSize()
            for i in d.childRange():
636 637
                d.putSubItem(i, d.createValue(p + ptrSize - offset, valueType))
                p = d.dereference(p + offset)
hjk's avatar
hjk committed
638

639 640 641 642
def qform__std____1__unordered_map():
    return mapForms()

def qdump__std____1__unordered_map(d, value):
hjk's avatar
hjk committed
643
    n = int(value["__table_"]["__p2_"]["__first_"])
644 645
    d.putItemCount(n)
    if d.isExpanded():
646
        node = value["__table_"]["__p1_"]["__first_"]["__next_"]
hjk's avatar
hjk committed
647 648 649
        pairType = node["__value_"].type
        with PairedChildren(d, n, pairType, maxNumChild=1000):
            for i in d.childRange():
650
                with SubItem(d, i):
hjk's avatar
hjk committed
651 652
                    pair = node["__value_"]
                    d.putPair(pair)
653
                node = node["__next_"]
654

hjk's avatar
hjk committed
655 656 657 658
def qdump__std____debug__unordered_set(d, value):
    qdump__std__unordered_set(d, value)


659 660 661
def qform__std__vector():
    return arrayForms()

662 663 664
def qedit__std__vector(d, value, data):
    import gdb
    values = data.split(',')
hjk's avatar
hjk committed
665
    n = len(values)
666
    innerType = d.templateArgument(value.type, 0)
hjk's avatar
hjk committed
667 668
    cmd = "set $d = (%s*)calloc(sizeof(%s)*%s,1)" % (innerType, innerType, n)
    gdb.execute(cmd)
669
    cmd = "set {void*[3]}%s = {$d, $d+%s, $d+%s}" % (value.address, n, n)
hjk's avatar
hjk committed
670
    gdb.execute(cmd)
671
    cmd = "set (%s[%d])*$d={%s}" % (innerType, n, data)
hjk's avatar
hjk committed
672 673 674
    gdb.execute(cmd)

def qdump__std__vector(d, value):
675 676 677 678
    if d.isQnxTarget():
        qdump__std__vector__QNX(d, value)
        return

hjk's avatar
hjk committed
679 680 681
    impl = value["_M_impl"]
    type = d.templateArgument(value.type, 0)
    alloc = impl["_M_end_of_storage"]
682 683 684 685
    # The allocator case below is bogus, but that's what Apple
    # LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
    # produces.
    isBool = str(type) == 'bool' or str(type) == 'std::allocator<bool>'
hjk's avatar
hjk committed
686 687 688 689
    if isBool:
        start = impl["_M_start"]["_M_p"]
        finish = impl["_M_finish"]["_M_p"]
        # FIXME: 8 is CHAR_BIT
hjk's avatar
hjk committed
690
        size = (d.pointerValue(finish) - d.pointerValue(start)) * 8
691 692
        size += int(impl["_M_finish"]["_M_offset"])
        size -= int(impl["_M_start"]["_M_offset"])
hjk's avatar
hjk committed
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
    else:
        start = impl["_M_start"]
        finish = impl["_M_finish"]
        size = finish - start

    d.check(0 <= size and size <= 1000 * 1000 * 1000)
    d.check(finish <= alloc)
    d.checkPointer(start)
    d.checkPointer(finish)
    d.checkPointer(alloc)

    d.putItemCount(size)
    d.putNumChild(size)
    if d.isExpanded():
        if isBool:
            with Children(d, size, maxNumChild=10000, childType=type):
hjk's avatar
hjk committed
709
                base = d.pointerValue(start)
hjk's avatar
hjk committed
710
                for i in d.childRange():
hjk's avatar
hjk committed
711
                    q = base + int(i / 8)
712
                    d.putBoolItem(str(i),
hjk's avatar
hjk committed
713
                        (int(d.dereference(q)) >> (i % 8)) & 1)
hjk's avatar
hjk committed
714
        else:
715
            d.putPlotData(type, start, size)
hjk's avatar
hjk committed
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
def qdump__std__vector__QNX(d, value):
    type = d.templateArgument(value.type, 0)
    isBool = str(type) == 'bool'
    if isBool:
        impl = value['_Myvec']
        start = impl['_Myfirst']
        last = impl['_Mylast']
        end = impl['_Myend']
        size = value['_Mysize']
        storagesize = start.dereference().type.sizeof * 8
    else:
        start = value['_Myfirst']
        last = value['_Mylast']
        end = value['_Myend']
        size = int (last - start)
        alloc = int (end - start)

    d.check(0 <= size and size <= 1000 * 1000 * 1000)
    d.check(last <= end)
    d.checkPointer(start)
    d.checkPointer(last)
    d.checkPointer(end)

    d.putItemCount(size)
    d.putNumChild(size)
    if d.isExpanded():
        if isBool:
            with Children(d, size, maxNumChild=10000, childType=type):
                for i in d.childRange():
                    q = start + int(i / storagesize)
                    d.putBoolItem(str(i), (q.dereference() >> (i % storagesize)) & 1)
        else:
            d.putArrayData(type, start, size)

hjk's avatar
hjk committed
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765
def qdump__std____1__vector(d, value):
    innerType = d.templateArgument(value.type, 0)
    if d.isLldb and d.childAt(value, 0).type == innerType:
        # That's old lldb automatically formatting
        begin = d.dereferenceValue(value)
        size = value.GetNumChildren()
    else:
        # Normal case
        begin = d.pointerValue(value['__begin_'])
        end = d.pointerValue(value['__end_'])
        size = (end - begin) / innerType.sizeof

    d.putItemCount(size)
    d.putNumChild(size)
    if d.isExpanded():
766 767
        d.putPlotData(innerType, begin, size)

hjk's avatar
hjk committed
768

769 770
def qform__std____debug__vector():
    return arrayForms()
hjk's avatar
hjk committed
771 772 773 774

def qdump__std____debug__vector(d, value):
    qdump__std__vector(d, value)

775

776 777
def qedit__std__string(d, value, data):
    d.call(value, "assign", '"%s"' % data.replace('"', '\\"'))
hjk's avatar
hjk committed
778

779 780
def qedit__string(d, expr, value):
    qedit__std__string(d, expr, value)
hjk's avatar
hjk committed
781 782 783 784 785 786 787 788 789 790 791 792

def qdump__string(d, value):
    qdump__std__string(d, value)

def qdump__std__wstring(d, value):
    charSize = d.lookupType('wchar_t').sizeof
    qdump__std__stringHelper1(d, value, charSize)

def qdump__std__basic_string(d, value):
    innerType = d.templateArgument(value.type, 0)
    qdump__std__stringHelper1(d, value, innerType.sizeof)

hjk's avatar
hjk committed
793 794 795 796 797 798 799 800 801
def qdump__std____1__basic_string(d, value):
    innerType = str(d.templateArgument(value.type, 0))
    if innerType == "char":
        qdump__std____1__string(d, value)
    elif innerType == "wchar_t":
        qdump__std____1__wstring(d, value)
    else:
        warn("UNKNOWN INNER TYPE %s" % innerType)

hjk's avatar
hjk committed
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
def qdump__wstring(d, value):
    qdump__std__wstring(d, value)


def qdump____gnu_cxx__hash_set(d, value):
    ht = value["_M_ht"]
    size = int(ht["_M_num_elements"])
    d.check(0 <= size and size <= 1000 * 1000 * 1000)
    d.putItemCount(size)
    d.putNumChild(size)
    type = d.templateArgument(value.type, 0)
    d.putType("__gnu__cxx::hash_set<%s>" % type)
    if d.isExpanded():
        with Children(d, size, maxNumChild=1000, childType=type):
            buckets = ht["_M_buckets"]["_M_impl"]
            bucketStart = buckets["_M_start"]
            bucketFinish = buckets["_M_finish"]
            p = bucketStart
            itemCount = 0
            for i in xrange(toInteger(bucketFinish - bucketStart)):
                if not d.isNull(p.dereference()):
                    cur = p.dereference()
                    while not d.isNull(cur):
                        with SubItem(d, itemCount):
                            d.putValue(cur["_M_val"])
                            cur = cur["_M_next"]
                            itemCount += 1
                p = p + 1


def qdump__uint8_t(d, value):
    d.putNumChild(0)
    d.putValue(int(value))

def qdump__int8_t(d, value):
    d.putNumChild(0)
    d.putValue(int(value))