1999-01-19 Fernando Nasser <fnasser@totem.to.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / values.c
index ecc11fec2b18e1a2cd2973410ffae857ef8c3a60..c7053b8df789a72bb8fb8d3114d50cd4252fbc30 100644 (file)
@@ -1025,7 +1025,9 @@ value_virtual_fn_field (arg1p, f, j, type, offset)
       /* Now context is a pointer to the basetype containing the vtbl.  */
       if (TYPE_TARGET_TYPE (context) != type1)
         {
-          arg1 = value_ind (value_cast (context, value_addr (arg1)));
+         value_ptr tmp = value_cast (context, value_addr (arg1));
+         VALUE_POINTED_TO_OFFSET (tmp) = 0;
+          arg1 = value_ind (tmp);
           type1 = check_typedef (VALUE_TYPE (arg1));
         }
 
@@ -1040,15 +1042,31 @@ value_virtual_fn_field (arg1p, f, j, type, offset)
 
       /* The virtual function table is now an array of structures
          which have the form { int16 offset, delta; void *pfn; }.  */
-      vtbl = value_ind (value_primitive_field (arg1, 0, 
-                                               TYPE_VPTR_FIELDNO (context),
-                                               TYPE_VPTR_BASETYPE (context)));
-
-      /* Index into the virtual function table.  This is hard-coded because
-         looking up a field is not cheap, and it may be important to save
-         time, e.g. if the user has set a conditional breakpoint calling
-         a virtual function.  */
-      entry = value_subscript (vtbl, vi);
+      vtbl = value_primitive_field (arg1, 0, TYPE_VPTR_FIELDNO (context),
+                                   TYPE_VPTR_BASETYPE (context));
+      
+      /* With older versions of g++, the vtbl field pointed to an array
+        of structures.  Nowadays it points directly to the structure. */
+      if (TYPE_CODE (VALUE_TYPE (vtbl)) == TYPE_CODE_PTR
+         && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (vtbl))) == TYPE_CODE_ARRAY)
+       {
+         /* Handle the case where the vtbl field points to an
+            array of structures. */
+         vtbl = value_ind (vtbl);
+
+         /* Index into the virtual function table.  This is hard-coded because
+            looking up a field is not cheap, and it may be important to save
+            time, e.g. if the user has set a conditional breakpoint calling
+            a virtual function.  */
+         entry = value_subscript (vtbl, vi);
+       }
+      else
+       {
+         /* Handle the case where the vtbl field points directly to a structure. */
+         vtbl = value_add (vtbl, vi);
+         entry = value_ind (vtbl);
+       }
+
       entry_type = check_typedef (VALUE_TYPE (entry));
 
       if (TYPE_CODE (entry_type) == TYPE_CODE_STRUCT)
This page took 0.023419 seconds and 4 git commands to generate.