1

I have the problem with gdb 7.6 and g++ 4.8.3. I have the following 3 files

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;
}

Then

>> 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>

We do not have the problem if

  1. the definition of those methods is in main.h.
  2. the methods are virtual.

Is this a known issue? How to workaround the problem?

ks1322
  • 33,961
  • 14
  • 109
  • 164
Joe C
  • 2,757
  • 2
  • 26
  • 46

1 Answers1

1

Looks like this is gdb bug. I also failed to print this variable with gdb 7.12, but lldb debugger was able to print it:

$ 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)
ks1322
  • 33,961
  • 14
  • 109
  • 164