Bug 9688 - gdb core dump c++ virtual inheritance
Summary: gdb core dump c++ virtual inheritance
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.8
: P2 critical
Target Milestone: 7.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-27 15:14 UTC by Chrystian Kondej
Modified: 2010-02-02 16:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2010-01-28 19:28:05


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chrystian Kondej 2008-12-27 15:14:58 UTC
Gdb core dumps on virtual inheritance, ONLY when base class implementation and
specification is separated. Note that base class specification is in file
`base.h` a implementation is in `base.cpp`.

Release:
GNU gdb 6.8-debian

Environment:
Linux 2.6.26-1-686 #1 SMP Thu Oct 9 15:18:09 UTC 2008 i686 GNU/Linux
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1'
--with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3
--program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --enable-mpfr --enable-targets=all --enable-cld
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1)



How-To-Repeat:

///FILE base.h

#ifndef __BASE_H__
#define __BASE_H__
class Base {
public:
	Base();
	virtual ~Base();
	virtual void run();
};
#endif

///FILE base.cpp

#include "base.h"
#include <iostream>

Base::Base()
{	 std::cout << "base\n"; }
Base::~Base()
{ }
void Base::run()
{ }

///FILE gdb_bug.cpp

#include "base.h"

class Derived1 : virtual public Base{	
protected:
	int i;					
public:	
	Derived1(){};		
};

class Derived2 : public Derived1 {
public:
	Derived2(){};
	~Derived2(){};
};

class Derived3 : virtual public Base {
public:
	Derived3(){};
	~Derived3(){};
};

class Bug : public Derived2, public Derived3{
public:		
	Bug(){};
	~Bug(){};				
	virtual void run(){};
};

int main(int argc, char *argv[])
{
	Bug b;	
	int a =2; // breakpoint here. Command `print b` makes gdb SEG FAULT
			
	return 0;
}

//-------------------------------
g++ -O0 -g3 base.cpp gdb_bug.cpp -o bug 
gdb ./bug
break main
run
n
print b
************* SEGMENTAION FAULT ************
Comment 1 Tom Tromey 2009-07-24 18:27:25 UTC
gdb now prints:

$1 = (Bug [incomplete object]) {
  <Derived2> = {
    <Derived1> = {
      <Base> = {
        _vptr.Base = 0x8049094
      }, 
      members of Derived1: 
      i = 134513747
    }, <No data fields>}, 
  <Derived3> = {<No data fields>}, <No data fields>}

According to cvs annotate, the "[incomplete object]" text has
been there since at least 2005.

I'm closing this as fixed.
Comment 2 Tom Tromey 2009-07-24 18:30:33 UTC
I was too hasty in closing this -- you reported this pretty recently :)
My first guess is that this is dependent on the compiler version.
I'm using the F11 system compiler, which is based on gcc 4.4.
Is there any way you could try a newer gcc?

Comment 3 Chrystian Kondej 2009-07-25 07:14:29 UTC
(In reply to comment #2)
> I was too hasty in closing this -- you reported this pretty recently :)
> My first guess is that this is dependent on the compiler version.
> I'm using the F11 system compiler, which is based on gcc 4.4.
> Is there any way you could try a newer gcc?
> 
> 

Hi. This bug still exists when using gcc4.4.

Environment:
GNU gdb 6.8-debian
Linux sirlorelaptop 2.6.29-2-686 #1 SMP Sun May 17 17:56:29 UTC 2009 i686 
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.0-5'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--enable-multiarch --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-objc-gc
--enable-targets=all --with-arch-32=i486 --with-tune=generic
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.4.0 (Debian 4.4.0-5)
Comment 4 Tom Tromey 2010-01-28 19:28:05 UTC
I think the reason I didn't see this earlier is that I have
"set print object on".

I am testing a fix.
Comment 5 Sourceware Commits 2010-02-02 16:45:56 UTC
Subject: Bug 9688

CVSROOT:	/cvs/src
Module name:	src
Changes by:	tromey@sourceware.org	2010-02-02 16:45:18

Modified files:
	gdb            : ChangeLog c-lang.h c-valprint.c cp-valprint.c 
	                 language.h valops.c 
	gdb/python     : py-prettyprint.c 
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.cp: userdef.exp 
Added files:
	gdb/testsuite/gdb.cp: virtbase.cc virtbase.exp 

Log message:
	gdb
	PR c++/11226, PR c++/9629, PR c++/9688, PR c++/8890:
	* valops.c (search_struct_field): Compute nbases after calling
	CHECK_TYPEDEF.
	(check_field): Call CHECK_TYPEDEF.
	* cp-valprint.c (cp_print_value): Pass correct address to
	baseclass_offset.  Fix check for virtual base past the end of the
	object.  Don't offset address passed to cp_print_value_fields or
	apply_val_pretty_printer.
	(cp_print_value_fields): Fix call to val_print.
	(cp_print_value_fields_rtti): New function.
	* c-valprint.c (c_val_print): Use cp_print_value_fields_rtti.
	* p-valprint.c (pascal_object_print_value_fields): Fix call to
	val_print.
	* python/py-prettyprint.c (apply_val_pretty_printer): Add embedded
	offset to address.
	* language.h (struct language_defn) <la_val_print>: Document.
	* c-lang.h (cp_print_value_fields_rtti): Declare.
	gdb/testsuite
	PR c++/11226, PR c++/9629, PR c++/9688, PR c++/8890:
	* gdb.cp/virtbase.cc: New file.
	* gdb.cp/virtbase.exp: New file.
	* gdb.cp/userdef.exp: Allow 'struct' or 'class'.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.11313&r2=1.11314
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/c-lang.h.diff?cvsroot=src&r1=1.26&r2=1.27
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/c-valprint.c.diff?cvsroot=src&r1=1.66&r2=1.67
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/cp-valprint.c.diff?cvsroot=src&r1=1.62&r2=1.63
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/language.h.diff?cvsroot=src&r1=1.62&r2=1.63
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/valops.c.diff?cvsroot=src&r1=1.233&r2=1.234
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/python/py-prettyprint.c.diff?cvsroot=src&r1=1.4&r2=1.5
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2117&r2=1.2118
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/virtbase.cc.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/virtbase.exp.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/userdef.exp.diff?cvsroot=src&r1=1.12&r2=1.13

Comment 6 Tom Tromey 2010-02-02 16:49:25 UTC
Fix checked in.