Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA/c++] Fix printing classes with virtual base classes
@ 2001-11-13  9:24 Daniel Jacobowitz
  2001-11-13  9:24 ` Daniel Jacobowitz
                   ` (2 more replies)
  0 siblings, 3 replies; 42+ messages in thread
From: Daniel Jacobowitz @ 2001-11-13  9:24 UTC (permalink / raw)
  To: gdb-patches

Whew.  Finally tracked this down.

The problem is in the layout of a class whose base class has a virtual
table.  Given:

class Bar {
  virtual int thunk ();
};

class Foo : public Bar {
  int test;
};

A Foo will look like this:

   /-----------------------\
   | Foo       |    test   |
   \-----------------------/

Its own vptr will be conveniently Foo's vptr.  But the type of Bar's field 0
(which is marked as having the vptr in it) is Foo, not some pointer type. 
If I explicitly cast to pointer, everything works more-or-less OK.

I'm pretty sure of the C++ side of this.  If there's a more appropriate
function for doing the cast to pointer I'd love to hear about it; otherwise,
OK to commit?

Can't really tell what effect it has on the testsuite, as just about
everything else in the relevant tests is failing anyway.  I have a few more
low-hanging bugs in this area that I'm debugging now.

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer

2001-11-26  Daniel Jacobowitz  <drow@mvista.com>

	* gnu-v3-abi.c (gnuv3_rtti_type): Explicitly cast
	the vtable pointer to a pointer before loading it.
	(gnuv3_virtual_fn_field): Likewise.

Index: gnu-v3-abi.c
===================================================================
RCS file: /cvs/src/src/gdb/gnu-v3-abi.c,v
retrieving revision 1.4
diff -u -p -r1.4 gnu-v3-abi.c
--- gnu-v3-abi.c	2001/10/16 01:58:07	1.4
+++ gnu-v3-abi.c	2001/11/27 00:21:44
@@ -188,7 +188,7 @@ gnuv3_rtti_type (struct value *value,
   struct type *vtable_type = gdbarch_data (vtable_type_gdbarch_data);
   struct type *value_type = check_typedef (VALUE_TYPE (value));
   CORE_ADDR vtable_address;
-  struct value *vtable;
+  struct value *vtable, *vtable_addr_value;
   struct minimal_symbol *vtable_symbol;
   const char *vtable_symbol_name;
   const char *class_name;
@@ -207,9 +207,17 @@ gnuv3_rtti_type (struct value *value,
     return NULL;
 
   /* Fetch VALUE's virtual table pointer, and tweak it to point at
-     an instance of our imaginary gdb_gnu_v3_abi_vtable structure.   */
+     an instance of our imaginary gdb_gnu_v3_abi_vtable structure.
+     The type of the field may not be a pointer type.  In a derived
+     class with a virtual base class, it will be the type of the base
+     class.  Thus we need to cast.  */
+  vtable_addr_value =
+    value_at (builtin_type_void_data_ptr,
+	      VALUE_ADDRESS (value_field (value,
+					  TYPE_VPTR_FIELDNO (value_type))),
+	      VALUE_BFD_SECTION (value));
   vtable_address
-    = value_as_address (value_field (value, TYPE_VPTR_FIELDNO (value_type)));
+    = value_as_address (vtable_addr_value);
   vtable = value_at_lazy (vtable_type,
                           vtable_address - vtable_address_point_offset (),
                           VALUE_BFD_SECTION (value));
@@ -277,7 +285,7 @@ gnuv3_virtual_fn_field (struct value **v
   struct type *value_type = check_typedef (VALUE_TYPE (value));
   struct type *vfn_base;
   CORE_ADDR vtable_address;
-  struct value *vtable;
+  struct value *vtable, *vtable_addr_value;
   struct value *vfn;
 
   /* Some simple sanity checks.  */
@@ -309,9 +317,16 @@ gnuv3_virtual_fn_field (struct value **v
     value = value_ind (value_cast (vfn_base, value_addr (value)));
 
   /* Now value is an object of the appropriate base type.  Fetch its
-     virtual table.  */
+     virtual table.  As in gnuv3_rtti_type, the type of the field may
+     not be a pointer type.  In a derived class with a virtual base class,
+     it will be the type of the base class.  Thus we need to cast.  */
+  vtable_addr_value =
+    value_at (builtin_type_void_data_ptr,
+	      VALUE_ADDRESS (value_field (value,
+					  TYPE_VPTR_FIELDNO (vfn_base))),
+	      VALUE_BFD_SECTION (value));
   vtable_address
-    = value_as_address (value_field (value, TYPE_VPTR_FIELDNO (vfn_base)));
+    = value_as_address (vtable_addr_value);
   vtable = value_at_lazy (vtable_type,
                           vtable_address - vtable_address_point_offset (),
                           VALUE_BFD_SECTION (value));


^ permalink raw reply	[flat|nested] 42+ messages in thread
* Re: [RFA/c++] Fix printing classes with virtual base classes
@ 2001-11-15 14:06 Michael Elizabeth Chastain
  2001-11-16 11:52 ` Daniel Berlin
  2001-11-27 20:38 ` Michael Elizabeth Chastain
  0 siblings, 2 replies; 42+ messages in thread
From: Michael Elizabeth Chastain @ 2001-11-15 14:06 UTC (permalink / raw)
  To: ac131313, jimb; +Cc: drow, gdb-patches, kevinb

And I would be happy to run tests against v2 and v3 C++ compilers
and report the results.  Most of my time is only on weekends though.

The trouble with the gdb C++ code is that it's not logic bugs, it's
perverse data structures where each bug fix may not affect the
test results much.  So Jim's judgement is much more useful than
my mechanical test results.

Michael C


^ permalink raw reply	[flat|nested] 42+ messages in thread
* Re: [RFA/c++] Fix printing classes with virtual base classes
@ 2001-11-30  9:00 Michael Elizabeth Chastain
  2001-11-21 23:07 ` Michael Elizabeth Chastain
  2001-11-22  3:17 ` Daniel Jacobowitz
  0 siblings, 2 replies; 42+ messages in thread
From: Michael Elizabeth Chastain @ 2001-11-30  9:00 UTC (permalink / raw)
  To: drow, jimb; +Cc: gdb-patches

Hi Daniel,

Just to make sure, you are talking about this patch, right?

  http://sources.redhat.com/ml/gdb-patches/2001-11/msg00487.html

I will give it some intensive testing tonight and tomorrow morning.

Michael C


^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2001-11-30 19:42 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-13  9:24 [RFA/c++] Fix printing classes with virtual base classes Daniel Jacobowitz
2001-11-13  9:24 ` Daniel Jacobowitz
2001-11-13  9:34   ` Kevin Buettner
2001-11-26 18:25     ` Kevin Buettner
2001-11-26 21:07     ` Andrew Cagney
2001-11-13 21:56       ` Andrew Cagney
2001-11-14 22:09       ` Jim Blandy
2001-11-27 12:48         ` Jim Blandy
2001-11-26 18:02   ` Daniel Jacobowitz
2001-11-13 18:02 ` Jim Blandy
2001-11-14  9:33   ` Daniel Jacobowitz
2001-11-14 22:39     ` Jim Blandy
2001-11-14 22:41       ` Daniel Jacobowitz
2001-11-27 13:26         ` Daniel Jacobowitz
2001-11-21 13:03       ` Daniel Jacobowitz
2001-11-22 13:53         ` Jim Blandy
2001-11-30 11:42           ` Jim Blandy
2001-11-29 22:41         ` Daniel Jacobowitz
2001-11-30  8:48         ` Andrew Cagney
2001-11-21 17:30           ` Andrew Cagney
2001-11-30  8:57           ` Daniel Jacobowitz
2001-11-21 23:07             ` Daniel Jacobowitz
2001-11-27 13:16       ` Jim Blandy
2001-11-26 23:08     ` Daniel Jacobowitz
2001-11-26 20:38   ` Jim Blandy
2001-11-26 21:36   ` Daniel Jacobowitz
2001-11-14  0:12     ` Daniel Jacobowitz
2001-11-26 22:05     ` Daniel Berlin
2001-11-14  0:15       ` Daniel Berlin
2001-11-27  7:15     ` Jim Blandy
2001-11-14 13:02       ` Jim Blandy
2001-11-27  7:45       ` Daniel Jacobowitz
2001-11-14 13:55         ` Daniel Jacobowitz
2001-11-26 17:19 ` Daniel Jacobowitz
2001-11-15 14:06 Michael Elizabeth Chastain
2001-11-16 11:52 ` Daniel Berlin
2001-11-27 20:49   ` Daniel Berlin
2001-11-27 20:38 ` Michael Elizabeth Chastain
2001-11-30  9:00 Michael Elizabeth Chastain
2001-11-21 23:07 ` Michael Elizabeth Chastain
2001-11-22  3:17 ` Daniel Jacobowitz
2001-11-30  9:52   ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox