我遇到了gdb 7.6和g ++ 4.8.3的问题。我有以下3个文件
main.h
class A {
public:
class B {
public:
virtual ~B();
virtual void f();
int abc;
};
};
b.cpp
#include "main.h"
A::B::~B() {}
void A::B::f() {}
的main.cpp
#include "main.h"
int main()
{
int a=0;
A::B x;
A::B *y = &x;
a = 10;
return a;
}
然后
>> g++ main.cpp b.cpp -o main -g
>> gdb ./main
GNU gdb (GDB) 7.6
Copyright (C) 2013 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-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/gdb/main...done.
(gdb) b 8
Breakpoint 1 at 0x400654: file main.cpp, line 8.
(gdb) r
Starting program: /tmp/gdb/main
Breakpoint 1, main () at main.cpp:8
8 a = 10;
(gdb) p *y
$1 = <incomplete type>
如果
,我们没有问题这是一个已知问题吗?如何解决这个问题?
答案 0 :(得分:1)
看起来这是gdb bug。我也无法使用gdb 7.12打印此变量,但是lldb调试器能够打印它:
$ lldb ./main
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named lldb.embedded_interpreter
(lldb) target create "./main"
Current executable set to './main' (x86_64).
(lldb) b 8
Breakpoint 1: where = main`main + 36 at main.cpp:8, address = 0x000000000040068a
(lldb) r
Process 9542 launched: './main' (x86_64)
Process 9542 stopped
* thread #1: tid = 9542, 0x000000000040068a main`main + 36 at main.cpp:8, name = 'main', stop reason = breakpoint 1.1
frame #0: 0x000000000040068a main`main + 36 at main.cpp:8
5 int a=0;
6 A::B x;
7 A::B *y = &x;
-> 8 a = 10;
9 return a;
10 }
(lldb) p *y
(A::B) $0 = (abc = 0)