解决QTCreator在Debug时无法显示std::string类型的问题
环境:
操作系统:Ubuntu 20.04.6 LTS
QT版本:Qt Creator 4.11.0
问题:
Debug时,无法显示std::string类型的值,如下图:
解决方法:
修改/usr/share/qtcreator/debugger/stdtypes.py文件:
原代码:
def qdumpHelper_std__string(d, value, charType, format):if d.isQnxTarget():qdumpHelper__std__string__QNX(d, value, charType, format)returnif d.isMsvcTarget():qdumpHelper__std__string__MSVC(d, value, charType, format)returndata = value.extractPointer()# 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; }(size, alloc, refcount) = d.split("ppp", data - 3 * d.ptrSize())refcount = refcount & 0xffffffffd.check(refcount >= -1) # Can be -1 according to docs.d.check(0 <= size and size <= alloc and alloc <= 100*1000*1000)d.putCharArrayHelper(data, size, charType, format)修改为:
def qdumpHelper_std__string(d, value, charType, format):if d.isQnxTarget():qdumpHelper__std__string__QNX(d, value, charType, format)returnif d.isMsvcTarget():qdumpHelper__std__string__MSVC(d, value, charType, format)returndata = value.extractPointer()# 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; }(size, alloc, refcount) = d.split("ppp", value.address() + d.ptrSize())refcount = refcount & 0xffffffffd.check(refcount >= -1) # Can be -1 according to docs.if size > 4002:size = 4002d.putCharArrayHelper(data, size, charType, format)
保存后重新Debug,效果见下图: