QtCreator Debugging Helper


#1

I was wondering if anyone had made a Debugging Helper for QtCreator for the Urho container classes, and if so would you be willing to share?
Thanks


#2

I have one for Visual Studio, but it unlikely would be helpful.

It’d be nice to gather such stuff somewhere.


#3

I’ve made fair progress with QtCreator’s Debugging Helpers – Vector and HashMap are working, and I’m in the middle of Variant. I’ll probably finish it sometime, but if anyone wants what I have so far here:

Note: I’m using QtCreator 5.5.1 with gdb 7.11.1

you can check your gdb version by running (inside gdb):

py import sys; print(sys.version)

I have the following, so it might break on yours

3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609]
#!/usr/bin/python

#this line is VERY IMPORTANT! And not mentioned in the examples/docs, I'm pretty sure. It is what was causing most of my problems...
from dumper import *
#Thank you Stack Overflow: http://stackoverflow.com/questions/34354573/how-to-write-a-debugging-helper-for-qtcreator

def qdump__Urho3D__Vector(d, value):
    array = value["buffer_"]
    size = value["size_"]
    maxDisplayItems = 100
    innerType = d.templateArgument(value.type, 0)
    p = array.cast(innerType.pointer())
    d.putValue('[{0}] @{1}'.format(size,str(array)))
    d.putItemCount(size)
    if d.isExpanded():
        d.putPlotData(p, size, innerType)
        
def qdump__Urho3D__Variant(d, value):
    t = value["type_"]
    d.putNumChild(0)
    d.putValue("{} int({})".format(str(t),int(t)))
    i = int(t)
    type_str = str(t)
    if type_str == "Urho3D::VAR_NONE":
        d.putValue("NONE")
    elif type_str == "Urho3D::VAR_INT":
        d.putValue("int {}".format(value["value_"]["int_"]))
    elif type_str == "Urho3D::VAR_BOOL":
        if value["value_"]["bool_"]:
            d.putValue("(bool) true")
        else:
            d.putValue("(bool) false")
    elif type_str == "Urho3D::VAR_FLOAT":
        d.putValue("float {}".format(value["value_"]["float_"]))
    return
    #TODO: finish
    if type_str == "Urho3D::VAR_VECTOR2":
        d.putValue("<{},{}>".format(value["value_"]["VECTOR2"]))
    if type_str == "Urho3D::VAR_VECTOR3":
        d.putValue("VECTOR3".format(value["value_"]["VECTOR3"]))
    if type_str == "Urho3D::VAR_VECTOR4":
        d.putValue("VECTOR4".format(value["value_"]["VECTOR4"]))
    if type_str == "Urho3D::VAR_QUATERNION":
        d.putValue("QUATERNION".format(value["value_"]["QUATERNION"]))
    if type_str == "Urho3D::VAR_COLOR":
        d.putValue("COLOR".format(value["value_"]["COLOR"]))
    if type_str == "Urho3D::VAR_STRING":
        d.putValue("STRING".format(value["value_"]["STRING"]))
    if type_str == "Urho3D::VAR_BUFFER":
        d.putValue("BUFFER".format(value["value_"]["BUFFER"]))
    if type_str == "Urho3D::VAR_VOIDPTR":
        d.putValue("VOIDPTR".format(value["value_"]["VOIDPTR"]))
    if type_str == "Urho3D::VAR_RESOURCEREF":
        d.putValue("RESOURCEREF".format(value["value_"]["RESOURCEREF"]))
    if type_str == "Urho3D::VAR_RESOURCEREFLIST":
        d.putValue("RESOURCEREFLIST".format(value["value_"]["RESOURCEREFLIST"]))
    if type_str == "Urho3D::VAR_VARIANTVECTOR":
        d.putValue("VARIANTVECTOR".format(value["value_"]["VARIANTVECTOR"]))
    if type_str == "Urho3D::VAR_VARIANTMAP":
        d.putValue("VARIANTMAP".format(value["value_"]["VARIANTMAP"]))
    if type_str == "Urho3D::VAR_INTRECT":
        d.putValue("INTRECT".format(value["value_"]["INTRECT"]))
    if type_str == "Urho3D::VAR_INTVECTOR2":
        d.putValue("INTVECTOR2".format(value["value_"]["INTVECTOR2"]))
    if type_str == "Urho3D::VAR_PTR":
        d.putValue("PTR".format(value["value_"]["PTR"]))
    if type_str == "Urho3D::VAR_MATRIX3":
        d.putValue("MATRIX3".format(value["value_"]["MATRIX3"]))
    if type_str == "Urho3D::VAR_MATRIX3X4":
        d.putValue("MATRIX3X4".format(value["value_"]["MATRIX3X4"]))
    if type_str == "Urho3D::VAR_MATRIX4":
        d.putValue("MATRIX4".format(value["value_"]["MATRIX4"]))
    if type_str == "Urho3D::VAR_DOUBLE":
        d.putValue("DOUBLE".format(value["value_"]["DOUBLE"]))
    if type_str == "Urho3D::VAR_STRINGVECTOR":
        d.putValue("STRINGVECTOR".format(value["value_"]["STRINGVECTOR"]))

#    for s in dir(value["value_"]):
#        d.put('nanavar="%s"'%s)


def qdump__Urho3D__SharedPtr(d, value):
#based on qdump__std__shared_ptr(d, value):
    i = value["ptr_"]
    if not i:
        d.putValue("(null)")
        d.putNumChild(0)
        return

#    if d.isSimpleType(d.templateArgument(value.type, 0)):
#        d.putValue("{} @0x{:h}".format(d.simpleValue(i.dereference()), d.pointerValue(i)))
#    else:
#        d.putValue("@0x{:h}" % d.pointerValue(i))
    #d.putValue("@0x{0:h}".format(int(i)))
    #d.putAddress(i.dereference().address)
    d.putValue("@x{0:x}".format(int(i)))
    d.putItem(i)
    d.putNumChild(3)
    if d.isExpanded():
        with Children(d, 3):
#            d.putSubItem("data", i)
            refcount = i["refCount_"]
            d.putSubItem("refs_", refcount["refs_"])
            d.putSubItem("weakRefs_", refcount["weakRefs_"])

def qdump__Urho3D__HashMap(d,value):
    keyType = d.templateArgument(value.type, 0)
    valueType = d.templateArgument(value.type, 1)
    ptrs = value["ptrs_"]
    szTypeP = d.lookupType("unsigned*")
    size = 0
    numBuckets = 0
    d.putAddress(value.address)
    if ptrs:
        size = ptrs.cast(szTypeP).dereference()
        numBuckets = (ptrs.cast(szTypeP) + 1).dereference()
    if ptrs:
        d.putValue('[{0}] in {1} @{2}'.format(size,numBuckets,str(ptrs)))
    else:
        d.putValue('empty @{2}'.format(size,numBuckets,str(ptrs)))
        
    p = value["head_"]
    end = value["tail_"]
    d.putItemCount(size)
    
    
    innerType = d.templateArgument(value.type, 0)
    n = int(size)
    p = value["head_"]
    innerType = d.lookupType(value.type.name + "::Node")
    if d.isExpanded():
        with Children(d, n):
            p = value["head_"]
            for i in range(n):
                d.putSubItem("%s" % i, d.createValue(d.pointerValue(p), innerType)["pair_"])
                p = p["next_"]