'Get the PyDictObject ptr representing the attribute dictionary
(or None if there\'s a problem)'

def get_attr_dict(self):

    try:
        typeobj = self.type()
        dictoffset = int_from_int(typeobj.field('tp_dictoffset'))
        if (dictoffset != 0):
            if (dictoffset < 0):
                type_PyVarObject_ptr = gdb.lookup_type('PyVarObject').pointer()
                tsize = int_from_int(self._gdbval.cast(type_PyVarObject_ptr)['ob_size'])
                if (tsize < 0):
                    tsize = (- tsize)
                size = _PyObject_VAR_SIZE(typeobj, tsize)
                dictoffset += size
                assert (dictoffset > 0)
                assert ((dictoffset % SIZEOF_VOID_P) == 0)
            dictptr = (self._gdbval.cast(_type_char_ptr) + dictoffset)
            PyObjectPtrPtr = PyObjectPtr.get_gdb_type().pointer()
            dictptr = dictptr.cast(PyObjectPtrPtr)
            return PyObjectPtr.from_pyobject_ptr(dictptr.dereference())
    except RuntimeError:
        pass
    return None
