bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cannot print the content of a object


From: LiuFeng
Subject: Cannot print the content of a object
Date: Wed, 06 Mar 2002 19:01:00 +0800

       Today, I found a interesting bug of gdb, (
maybe of gcc ), the code is as following,

// Begin of the test code
struct S {
        int a;
        int b;

};
class Fl_Widget {

  /*
  char parent_;
  char user_data_;
  char x_,y_,w_,h_;
  char  label_;
  char type_;
  char flags_;
  char damage_;
  char box_;
  char color_;
  char color2_;
  char align_;
  char when_;
  char callback_;
  */
  char a,b,c,d,e,f,g,h,i,j,k,l,m,n,o;
  S s;

public:
  Fl_Widget(int,int,int,int,const char* =0){};
  virtual ~Fl_Widget(){};
};

class Test: Fl_Widget {
        //char a, b, c;
        int d;
        public:
        Test (): Fl_Widget (0,0,10,10) {};
};
main () {
        Test * o = new Test ();
}
// End of the test code

 when the following conditions are all fullfilled,
gdb will "print cannot access memory at address
XXXXXXXX" when do "p *o" after the line "Test *o =
new Test();":
        1, there're 16 data member in the parent
class, more or less will not do.
        2, the parent has a virtual destructor;
        3, the child class has 1~3 private data
member, more or less will not do, public data
member will not do.
        4, the object should be create on the heap
by new, not on the stack.

        It's really funny. To check the fltk
ojects' content, I just could add a dmp data
member to the Fl_Widget class. But Why ?

        My develop environment is redhat 7.2, gcc
version is 2.96 20000731, gdb version is 5.0, I
upgrade to 5.1.1 and got the same result.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]