Sigh, should have updated the copyright date in the
[deliverable/binutils-gdb.git] / gdb / cp-valprint.c
index a4f81061bf32d8383f4cb43115d18f738e99ce72..7ea9f3f94e974e136cb25cf29b4b16c9181d362d 100644 (file)
@@ -1,6 +1,6 @@
 /* Support for printing C++ values for GDB, the GNU debugger.
    Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-   2000, 2001
+   2000, 2001, 2002
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -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 */
@@ -200,6 +201,8 @@ cp_is_vtbl_ptr_type (struct type *type)
 int
 cp_is_vtbl_member (struct type *type)
 {
+  /* With older versions of g++, the vtbl field pointed to an array
+     of structures.  Nowadays it points directly to the structure. */
   if (TYPE_CODE (type) == TYPE_CODE_PTR)
     {
       type = TYPE_TARGET_TYPE (type);
@@ -214,6 +217,17 @@ cp_is_vtbl_member (struct type *type)
              return cp_is_vtbl_ptr_type (type);
            }
        }
+      else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)  /* if not using thunks */
+       {
+         return cp_is_vtbl_ptr_type (type);
+       }
+      else if (TYPE_CODE (type) == TYPE_CODE_PTR)     /* if using thunks */
+       {
+         /* The type name of the thunk pointer is NULL when using dwarf2.
+            We could test for a pointer to a function, but there is
+            no type info for the virtual table either, so it wont help.  */
+         return cp_is_vtbl_ptr_type (type);
+       }
     }
   return 0;
 }
@@ -504,6 +518,8 @@ cp_print_value (struct type *type, struct type *real_type, char *valaddr,
   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 +554,8 @@ cp_print_value (struct type *type, struct type *real_type, char *valaddr,
          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 */
@@ -565,10 +583,14 @@ cp_print_value (struct type *type, struct type *real_type, char *valaddr,
                  && ((boffset + offset) < 0
                      || (boffset + offset) >= TYPE_LENGTH (type)))
                {
+                 /* FIXME (alloca): unsafe if baseclass is really really large. */
                  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 +615,8 @@ cp_print_value (struct type *type, struct type *real_type, char *valaddr,
       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)),
This page took 0.024325 seconds and 4 git commands to generate.