我尝试调试我的小lexer并遇到了这个问题:QtCreator-Debugger没有显示我的std :: string-variable的任何内容。我尝试在控制台中调试它,我得到了相同的结果,只是简单的结构信息。
我几天前使用的QtCreator版本确实显示了字符串的内容。所有其他STL元素,如std :: vector,std :: map,std :: multimap等,都显示正确的数据,它只是std :: string类,它不能正确执行。
经过几个小时的谷歌搜索后,我发现很多网页都描述了漂亮的打印机的创建,我真正无声的修复方法并没有帮助。我有什么想法可以摆脱这个错误吗?
注意:字符串变量的“内容”将始终显示为“无法访问”。 我将QtCreator 2.6(QT5)用于64位Linux操作系统。
编辑(1):我重新安装了从操作系统到编译器和IDE的所有内容......奇怪的是,当我使用优化级别3(-O3)构建项目时,QT可以显示std :: strings。
命令行如下: clang ++ -std = c ++ 11 -O3 -g -c foo.cpp
当我删除-O3时,std :: strings是<无法访问>。有什么想法吗?
答案 0 :(得分:6)
试试这个,它对我有用。
在Qt Creator菜单栏中:
Tools -> Options -> Debugger
Uncheck the option (Load system GDB pretty printers)
答案 1 :(得分:0)
您可以尝试修复“ /usr/share/qtcreator/debugger/stdtypes.py”。当他们使用“关于成员位置的硬编码假设”时,似乎并非在所有地方都有效。 就我而言-Linux x64,gcc 9.1,其工作原理与您描述的完全相同: string not accessible
找到函数def qdumpHelper_std__string(d, value, charType, format):
然后改变
(size, alloc, refcount) = d.split("ppp", data - 3 * d.ptrSize())
至
(size, alloc, refcount) = d.split("ppp", value.address() + d.ptrSize())
还评论d.check(0 <= size and size <= alloc and alloc <= 100*1000*1000)
或将其更改为
if size > 1000:
size = 1000
在我的系统上,std :: string具有下一个结构
pointer 8 byte
size 8 byte
union 16 byte
此union
字段可以根据字符串大小更改其含义。因此,我们需要评论size < alloc
检查。
value.address()
-字符串对象的地址,因此value.address() + d.ptrSize()
将指向大小,而value.address() + 2 * d.ptrSize()
则指向该联合,该联合有时包含alloc size
值。 / p>
只需查看您的std::string
类声明,您就可以在系统上获得结构。
修复后:
fixed debuger view
两者均可-在选中“系统GDB漂亮打印机”并清除后
答案 2 :(得分:0)
要澄清和总结AstoBasto帖子: 在文件中:/usr/share/qtcreator/debugger/stdtypes.py替换此功能:
def qdumpHelper_std__string(d, value, charType, format):
[...]
与此:
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", value.address() + d.ptrSize())
refcount = refcount & 0xffffffff
d.check(refcount >= -1) # Can be -1 according to docs.
if size > 4002:
size = 4002
d.putCharArrayHelper(data, size, charType, format)
这有效(至少在Kubuntu 19.10上有效)。