This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gdb does not print the reference to the base class members


Hi,

I try to print reference x for the following problem. But gdb does not
print the one in class B refered to class A? Do you know how to print
its value?

Thanks,
Peng

(gdb) b 22
Breakpoint 1 at 0x8048694: file main.cc, line 22.
(gdb) b 14
Breakpoint 2 at 0x8048706: file main.cc, line 14.
(gdb) r
Failed to read a valid object file image from memory.

Breakpoint 1, main () at main.cc:22
22        B b(10);
(gdb) p x
$1 = (int &) @0xbffd86cc: 5
(gdb) c

Breakpoint 2, B (this=0xbffd86c8, a=10) at main.cc:14
14            std::cout << x << std::endl;
(gdb) p x
No symbol "x" in current context.



#include <iostream>

class A {
  public:
    A(int a) : _a(a) { }
  protected:
    int _a;
};

class B : public A {
  public:
    B(int a) : A(a) {
      int &x = A::_a;//can not print from gdb, Line 12
      std::cout << x << std::endl;
    }
};


int main(){
  int a = 5;
  int &x = a;//this one can be printed in gdb, Line 22
  B b(10);
  std::cout << x << std::endl;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]