【发布时间】:2015-07-14 20:27:16
【问题描述】:
最近升级到 g++ 4.8.1 后,我发现在 gdb 中调试是完全不可能的。 g++ 似乎隐藏了 gdb 中的所有变量,无论优化选项如何。在接下来的会话中,runner.cpp如下:
#include <vector>
using namespace std;
int main(void) {
vector<int> arr;
int a = 3;
int b = 2;
b = a + 3;
arr.push_back(1);
arr.push_back(2);
arr.push_back(3);
arr.push_back(4);
return 0;
}
这是结果:
Script started on Tue 14 Jul 2015 01:11:14 PM PDT
me@ministation:~/Development/clib$ g++ -g -O0 runner.cpp
me@ministation:~/Development/clib$ gdb -q ./a.out
Reading symbols from /home/me/Development/clib/a.out...done.
(gdb) break 11
Breakpoint 1 at 0x40095c: file runner.cpp, line 11.
(gdb) run
Starting program: /home/me/Development/clib/a.out
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
Breakpoint 1, main () at runner.cpp:11
11 arr.push_back(1);
(gdb) print a
$1 = {i = {0, 1045149306}, d = 1.2904777690891933e-08} ## I have no idea what this means
(gdb) print b
$2 = {i = {0, 1068498944}, d = 0.0625}
(gdb) print arr
No symbol "arr" in current context.
(gdb) info locals
No locals.
(gdb) next
12 arr.push_back(2);
(gdb)
13 arr.push_back(3);
(gdb) print arr
No symbol "arr" in current context.
(gdb) next
14 arr.push_back(4);
(gdb)
16 return 0;
(gdb) print arr
No symbol "arr" in current context.
(gdb) q
A debugging session is active.
Inferior 1 [process 6392] will be killed.
Quit anyway? (y or n) y
me@ministation:~/Development/clib$
Script done on Tue 14 Jul 2015 01:12:05 PM PDT
我看过一些类似的帖子,其中推荐了 -O0 标志,但它似乎在这里不起作用。使用 g++4.6 编译后的完全相同的会话会产生预期的结果。关于 g++4.8 导致这种情况的任何想法?
【问题讨论】:
-
您还需要更新 gdb 或使用
-gdwarf-3标志集进行编译 -
无法使用
4.8.2进行复制。你的gdb是什么版本? -
它是 7.4 版。我通过升级到 7.9 来修复它。我不认为 valgrind 也必须更新?