This is the mail archive of the gdb-patches@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]

[rfa/c++] Print virtual baseclasses correctly


If the virtual base was outside of the particular object we're reading at
the moment (which it often is if we are printing a baseclass of some derived
class with virtual bases), we used to lose offsets inside cp_print_value. 
The symptom was that "p (baseclass)obj" would be correct, but "p obj" would
show corrupted values for <baseclass>.  This will (eventually, once my other
patches go in) fix two failures v3 for me in inherit.exp (print g_vD and
print g_vE).

OK to commit?

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

2001-12-03  Daniel Jacobowitz  <drow@mvista.com>

	* cp-valprint.c (cp_print_value): Preserve offset if
	the virtual base is outside of this object.

Index: cp-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-valprint.c,v
retrieving revision 1.9
diff -u -p -r1.9 cp-valprint.c
--- cp-valprint.c	2001/11/10 20:44:37	1.9
+++ cp-valprint.c	2001/12/04 05:17:21
@@ -33,6 +33,7 @@
 #include "gdb_string.h"
 #include "c-lang.h"
 #include "target.h"
+#include "cp-abi.h"
 
 /* Indication of presence of HP-compiled object files */
 extern int hp_som_som_object_present;	/* defined in symtab.c */
@@ -504,6 +505,8 @@ cp_print_value (struct type *type, struc
   struct type **last_dont_print
     = (struct type **) obstack_next_free (&dont_print_vb_obstack);
   int i, n_baseclasses = TYPE_N_BASECLASSES (type);
+  int thisoffset;
+  struct type *thistype;
 
   if (dont_print_vb == 0)
     {
@@ -538,6 +541,8 @@ cp_print_value (struct type *type, struc
 	  obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
 	}
 
+      thisoffset = offset;
+      thistype = real_type;
       if (TYPE_HAS_VTABLE (type) && BASETYPE_VIA_VIRTUAL (type, i))
 	{
 	  /* Assume HP/Taligent runtime convention */
@@ -566,9 +571,12 @@ cp_print_value (struct type *type, struc
 		      || (boffset + offset) >= TYPE_LENGTH (type)))
 		{
 		  base_valaddr = (char *) alloca (TYPE_LENGTH (baseclass));
-		  if (target_read_memory (address + boffset, base_valaddr,
+		  if (target_read_memory (address + offset + boffset, base_valaddr,
 					  TYPE_LENGTH (baseclass)) != 0)
 		    skip = 1;
+		  thisoffset = 0;
+		  boffset = 0;
+		  thistype = baseclass;
 		}
 	      else
 		base_valaddr = valaddr;
@@ -593,8 +601,8 @@ cp_print_value (struct type *type, struc
       if (skip >= 1)
 	fprintf_filtered (stream, "<invalid address>");
       else
-	cp_print_value_fields (baseclass, real_type, base_valaddr,
-			       offset + boffset, address, stream, format,
+	cp_print_value_fields (baseclass, thistype, base_valaddr,
+			       thisoffset + boffset, address, stream, format,
 			       recurse, pretty,
 			       ((struct type **)
 				obstack_base (&dont_print_vb_obstack)),


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