在银河麒麟V10或Ubuntu下使用QtCreator调试代码时,std::string类型变量在大多数情况下不显示实际内容,而是显示"<无法访问>"字样,鼠标点击进去也是看不见任何有用信息,这样非常影响调试效率,为此,提供以下解决方法:
注:银河麒麟V10是一款基于Ubuntu的Linux操作系统。
1、找到Qt安装路径下的stdtypes.py文件,例如:
/home/admin/Qt5.12.4/Tools/QtCreator/share/qtcreator/debugger/stdtypes.py
注:忘记Qt装哪了,找不到没关系,桌面右键菜单里打开终端(快捷键Ctrl+Alt+T,或者Win+T),输入find -name "stdtypes.py"
,该命令用来搜索文件。输入pwd
,该命令用来显示当前工作目录的绝对路径。二者组合形成文件所在的绝对路径/home/admin/Qt5.12.4/Tools/QtCreator/share/qtcreator/debugger/stdtypes.py
2、修改stdtypes.py文件内容
打开该文件,找到
def qdumpHelper_std__string(d, value, charType, format):
修改1:将
(size, alloc, refcount) = d.split("ppp", data - 3 * d.ptrSize())
修改为
(size, alloc, refcount) = d.split("ppp", value.address() + d.ptrSize())
修改2:将
d.check(0 <= size and size <= alloc and alloc <= 100*1000*1000)
修改为
if size > 4002:
size = 4002
2处内容全部修改后,该段内容显示如下:
def qdumpHelper_std__string(d, value, charType, format):
if d.isQnxTarget():
qdumpHelper__std__string__QNX(d, value, charType, format)
return
if d.isMsvcTarget():
qdumpHelper__std__string__MSVC(d, value, charType, format)
return
data = 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())
(size, alloc, refcount) = d.split("ppp", value.address() + d.ptrSize())
refcount = refcount & 0xffffffff
d.check(refcount >= -1) # Can be -1 according to docs.
# 注释原内容 d.check(0 <= size and size <= alloc and alloc <= 100*1000*1000)
if size > 4002:
size = 4002
d.putCharArrayHelper(data, size, charType, format)
3、QtCreator调试运行