bug-gdb
[Top][All Lists]
Advanced

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

C++ Inheritance Bug


From: jamesbetts
Subject: C++ Inheritance Bug
Date: Thu, 29 Mar 2001 17:18:49 +0100

This has got to be a bug!

gdb 5.0 configured as "i586-pc-linux-gnu".

For (but with default constructors) 

class base{public: int i;};
class dervied: public base{public: int j;};

base* unknown = new derived();

Using gdb and 'print *(derived*)unknown' gives
incorrect/random values of derived::j.

In print_cmd_1 I believe the call

val = evaluate_expression (expr);

is incorrectly assigning val->enclosing_type. This should be
of type 'derived'
i.e. val->enclosing_type == val->type and not of type 'base'
which loosely speaking is what
it is being assigned to.

What happens is that the data values are transfered out via
ptrace for the size of the base class 'base' but no further
calls are made to ptrace. The values are then printed out
for the entire size of the derived class leading to randon
values of derived::j. Using another gdb, assigning
val->enclosing_type == val->type after the call to
evaluate_expression() works perfectly as data is extracted
for the entire size of 'derived'.

In my code I have to put
{
        derived* known = (derived*)unknown;
}
 
in order to print the values correctly.

Thanks for your time
  
James

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



reply via email to

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