This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: Cannot print the content of a object
- From: Andrew Cagney <ac131313 at cygnus dot com>
- To: LiuFeng <fengliu at redflag-linux dot com>, gdb at sources dot redhat dot com
- Date: Thu, 07 Mar 2002 13:40:40 -0500
- Subject: Re: Cannot print the content of a object
- References: <3C85F6EC.FB44848F@redflag-linux.com>
Hello,
Can i suggest downloading and trying a more up-to-date GDB
(http://sources.redhat.com/gdb/current/) and GCC (http://gcc.gnu.org).
The versions you mention are both old.
Andrew
> 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.
>
>