gdb 调试器不显示类型变量的内容std::string
此外,如果您在控制台中查看 gdb,它会显示所有内容:
milai@milai:~/projects/test_project/build/bin$ gdb ./test_project
GNU gdb (Ubuntu 9.1-0ubuntu1) 9.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test_project...
(gdb) list
1 #include <string>
2 #include <iostream>
3
4 int main(int argc, char* argv[])
5 {
6 const std::string str = "abc";
7 std::cout << str << std::endl;
8 return 0;
9 }
(gdb) b 7
Breakpoint 1 at 0x12bb: file /home/milai/projects/test_project/main.cpp, line 7.
(gdb) r
Starting program: /home/milai/projects/test_project/build/bin/test_project
Breakpoint 1, main (argc=1, argv=0x7fffffffdec8) at /home/milai/projects/test_project/main.cpp:7
7 std::cout << str << std::endl;
(gdb) info locals
str = "abc"
(gdb) c
Continuing.
abc
[Inferior 1 (process 40257) exited normally]
(gdb) quit
milai@milai:~/projects/test_project/build/bin$
可能是什么问题呢?
环境:
- Ubuntu 20.04.1
- qtcreator:4.11.0
- gdb:9.1
- g++ 9.3.0
默认情况下,QtCreator 不会从 gdb 加载允许“相当复杂类型”的脚本,但这可以在设置中启用。
菜单工具->选项,然后“调试选项卡”有一个复选框“加载系统 gdb 漂亮打印机”。