This is the mail archive of the gdb-prs@sources.redhat.com 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]

c++/1084: set print object on does not work correctly in some cases


>Number:         1084
>Category:       c++
>Synopsis:       set print object on does not work correctly in some cases
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 21 21:28:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Salman Khilji
>Release:        GDB 5.1.1
>Organization:
>Environment:
gcc 2.95.3 in SuSE Linux 8.0
>Description:
I suppose a picture would describe the bug better than words, so here it is:

(gdb) print b1
$1 = (Base *) 0x804a4a0
(gdb) print b2
$2 = (Base_2 *) 0x804a4cc
(gdb) print b3
$3 = (Base_3 *) 0x401b9bd8
(gdb) set print object on
(gdb) print b1
Cannot access memory at address 0x4
(gdb) print b2
$4 = (virtual baseclass botch
(gdb) print b3
$5 = (suspicious *) 0x401b9bd8


I have attached the source code to reproduce this bug and also the complete gdb session history.  If the complete history does not make it, here it is again

salman at linux:~> /usr/bin/gcc --version
2.95.3
salman at linux:~> /usr/bin/gdb --version
GNU gdb 5.1.1
Copyright 2002 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 "i386-suse-linux".
salman at linux:~> /usr/bin/g++ -g -o class class.cpp
salman at linux:~> /usr/bin/gdb class
GNU gdb 5.1.1
Copyright 2002 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 "i386-suse-linux"...
(gdb) b main
Breakpoint 1 at 0x80487e6: file class.cpp, line 43.
(gdb) run
Starting program: /home/salman/class

Breakpoint 1, main () at class.cpp:43
43        g_Derived.print();
(gdb) n
100 200 300
10 20 30
45        cout << endl << endl;
(gdb)


47        cout << "Dumping g_Derived . . . " << endl;
(gdb)
Dumping g_Derived . . .
49        cout << &g_Derived << endl;
(gdb)
0x804a4a0
51        Base* b1  = &g_Derived;
(gdb)
52        Base_2* b2  = &g_Derived;
(gdb)
53        Base_3* b3  = &g_Derived;
(gdb) print b1
$1 = (Base *) 0x804a4a0
(gdb) print b2
$2 = (Base_2 *) 0x804a4cc
(gdb) print b3
$3 = (Base_3 *) 0x401b9bd8
(gdb) set print object on
(gdb) print b1
Cannot access memory at address 0x4
(gdb) print b2
$4 = (virtual baseclass botch
(gdb) print b3
$5 = (suspicious *) 0x401b9bd8
(gdb) quit
The program is running.  Exit anyway? (y or n) n
Not confirmed.
(gdb) quit
The program is running.  Exit anyway? (y or n) y
salman at linux:~>





Here is the source code again


#include <iostream>

using namespace std;

/* lets test out a case in which the derived classes are hiding
   variables from the base class */

class Base {
public:
  Base(): m_Public_B1(10), m_Protected_B1(20), m_Private_B1(30) {}
  virtual ~Base() {}
  virtual void print() {  cout << m_Public_B1 << " " << m_Protected_B1 << " " <<m_Private_B1 << endl; }
  int m_Public_B1;
  int m_Protected_B1;
  int m_Private_B1;
};

class Base_2 {
public:
  virtual ~Base_2() {}
  int mBase_2Junk;
};

class Base_3 {
public:
  virtual ~Base_3() {}
  int mBase_3Junk;
};

class Derived : public virtual Base_3, public Base, public virtual Base_2 {
public:
  Derived(): m_Public_D(100), m_Protected_D(200), m_Private_D(300) {}
  virtual void print() {   cout << m_Public_D << " " << m_Protected_D << " " << m_Private_D << endl; Base::print(); }
  int m_Public_D;
  int m_Protected_D;
  int m_Private_D;
};

Derived g_Derived;

int main()
{
  g_Derived.print();

  cout << endl << endl;
  
  cout << "Dumping g_Derived . . . " << endl;

  cout << &g_Derived << endl;

  Base* b1  = &g_Derived;
  Base_2* b2  = &g_Derived;
  Base_3* b3  = &g_Derived;

  return 0;
}



>How-To-Repeat:
just compile the attachment with -g  option and follow the gdb session as follows:

salman at linux:~> /usr/bin/gcc --version
2.95.3
salman at linux:~> /usr/bin/gdb --version
GNU gdb 5.1.1
Copyright 2002 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 "i386-suse-linux".
salman at linux:~> /usr/bin/g++ -g -o class class.cpp
salman at linux:~> /usr/bin/gdb class
GNU gdb 5.1.1
Copyright 2002 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 "i386-suse-linux"...
(gdb) b main
Breakpoint 1 at 0x80487e6: file class.cpp, line 43.
(gdb) run
Starting program: /home/salman/class

Breakpoint 1, main () at class.cpp:43
43        g_Derived.print();
(gdb) n
100 200 300
10 20 30
45        cout << endl << endl;
(gdb)


47        cout << "Dumping g_Derived . . . " << endl;
(gdb)
Dumping g_Derived . . .
49        cout << &g_Derived << endl;
(gdb)
0x804a4a0
51        Base* b1  = &g_Derived;
(gdb)
52        Base_2* b2  = &g_Derived;
(gdb)
53        Base_3* b3  = &g_Derived;
(gdb) print b1
$1 = (Base *) 0x804a4a0
(gdb) print b2
$2 = (Base_2 *) 0x804a4cc
(gdb) print b3
$3 = (Base_3 *) 0x401b9bd8
(gdb) set print object on
(gdb) print b1
Cannot access memory at address 0x4
(gdb) print b2
$4 = (virtual baseclass botch
(gdb) print b3
$5 = (suspicious *) 0x401b9bd8
(gdb) quit
The program is running.  Exit anyway? (y or n) n
Not confirmed.
(gdb) quit
The program is running.  Exit anyway? (y or n) y
salman at linux:~>
>Fix:
Dont know :-(
>Release-Note:
>Audit-Trail:
>Unformatted:


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