bug-gdb
[Top][All Lists]
Advanced

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

problem with printing value of member variable


From: Markus Grabner
Subject: problem with printing value of member variable
Date: Mon, 24 Sep 2001 19:16:26 +0200

Under certain conditions, GDB refuses to print member variables of
*this. In the given example, "print x" gives a message like "Cannot
access memory at address 0xc1047bb6". However, explicitly adding the
member variable offset to the address of the class instance and
dereferencing the resulting (properly cast) pointer gives the expected
result, but the command looks terrible.

Do the following:
        *) extract "test.cpp" and "script.txt" from this mail
        *) g++ -g -O0 test.cpp -o test
        *) gdb test < script.txt

        Thanks,
                Markus


system information:

=== GDB version ===
GNU gdb 2001-09-24-cvs (MI_OUT)
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "i686-pc-linux-gnu".

=== OS version ===
Linux fcggpc41 2.4.4-64GB-SMP #1 SMP Wed May 16 01:20:45 GMT 2001 i686
unknown

=== compiler version (to compile both GDB and the test program) ===
gcc-2.95.3

=== compiler command (to compile the test program) ===
g++ -g -O0 test.cpp -o test


-- 
Markus Grabner - Computer Graphics and Vision
Graz University of Technology, Inffeldgasse 16/II, 8010 Graz, Austria
Phone: +43/316/873-5041, Fax: +43/316/873-5050
Email: address@hidden, WWW:
http://www.icg.tu-graz.ac.at/~grabner
/*
  1.) save this program as "test.cpp" and compile it with "g++ -g test.cpp -o 
test"
  2.) start gdb as "gdb test" and step into the constructor cls3::cls3()
  3.) type "print x" to demonstrate the bug
  4.) step out of the constructor and type "print obj3" to see that the code 
has been compiled correctly
*/

struct cls1
{
};

struct cls2
{
  static cls1 obj1;
  virtual ~cls2() {}
};

struct cls3: public cls2
{
  static cls1 obj2;
  int x;

  cls3();
};

cls3::
cls3()
{
  x = 12345;
}  // step to this line and type "print x"

int
main()
{
  cls3 obj3;
  return 0;   // step to this line and type "print obj3"
}
break main
run
step
step
step
step
step
print x
print *(int *)((char *)this + (int)(&cls3::x))
step
print obj3

reply via email to

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