* elf64-mips.c (mips_elf64_be_swap_reloca_out): Handle type2 and type3.
[deliverable/binutils-gdb.git] / gdb / cp-valprint.c
index 6b01e0c60e621adc844c4d1283fdb0a7a31c54f2..28dc0259c24cc34ddafed4da9d5483976ed3c17c 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
+   2000, 2001, 2002
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -21,7 +21,7 @@
    Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
-#include "obstack.h"
+#include "gdb_obstack.h"
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "expression.h"
@@ -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 */
@@ -48,7 +49,7 @@ static struct obstack dont_print_statmem_obstack;
 
 extern void _initialize_cp_valprint (void);
 
-static void cp_print_static_field (struct type *, value_ptr,
+static void cp_print_static_field (struct type *, struct value *,
                                   struct ui_file *, int, int,
                                   enum val_prettyprint);
 
@@ -57,7 +58,7 @@ static void cp_print_value (struct type *, struct type *, char *, int,
                            enum val_prettyprint, struct type **);
 
 static void cp_print_hpacc_virtual_table_entries (struct type *, int *,
-                                                 value_ptr,
+                                                 struct value *,
                                                  struct ui_file *, int,
                                                  int,
                                                  enum val_prettyprint);
@@ -96,13 +97,11 @@ cp_print_class_method (char *valaddr,
          f = TYPE_FN_FIELDLIST1 (domain, i);
          len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
 
+         check_stub_method_group (domain, i);
          for (j = 0; j < len2; j++)
            {
-             QUIT;
              if (TYPE_FN_FIELD_VOFFSET (f, j) == offset)
                {
-                 if (TYPE_FN_FIELD_STUB (f, j))
-                   check_stub_method (domain, i, j);
                  kind = "virtual ";
                  goto common;
                }
@@ -128,15 +127,11 @@ cp_print_class_method (char *valaddr,
          f = TYPE_FN_FIELDLIST1 (domain, i);
          len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
 
+         check_stub_method_group (domain, i);
          for (j = 0; j < len2; j++)
            {
-             QUIT;
-             if (TYPE_FN_FIELD_STUB (f, j))
-               check_stub_method (domain, i, j);
              if (STREQ (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
-               {
-                 goto common;
-               }
+               goto common;
            }
        }
     }
@@ -200,6 +195,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 +211,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;
 }
@@ -348,7 +356,7 @@ cp_print_value_fields (struct type *type, struct type *real_type, char *valaddr,
 
          if (!TYPE_FIELD_STATIC (type, i) && TYPE_FIELD_PACKED (type, i))
            {
-             value_ptr v;
+             struct value *v;
 
              /* Bitfields require special handling, especially due to byte
                 order problems.  */
@@ -374,7 +382,7 @@ cp_print_value_fields (struct type *type, struct type *real_type, char *valaddr,
                }
              else if (TYPE_FIELD_STATIC (type, i))
                {
-                 value_ptr v = value_static_field (type, i);
+                 struct value *v = value_static_field (type, i);
                  if (v == NULL)
                    fputs_filtered ("<optimized out>", stream);
                  else
@@ -413,7 +421,7 @@ cp_print_value_fields (struct type *type, struct type *real_type, char *valaddr,
                 hpacc_vtbl_ptr_name, 
                 5))
     {
-      value_ptr v;
+      struct value *v;
       /* First get the virtual table pointer and print it out */
 
 #if 0
@@ -504,6 +512,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 +548,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 +577,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 +609,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)),
@@ -627,7 +643,7 @@ cp_print_value (struct type *type, struct type *real_type, char *valaddr,
 
 static void
 cp_print_static_field (struct type *type,
-                      value_ptr val,
+                      struct value *val,
                       struct ui_file *stream,
                       int format,
                       int recurse,
@@ -745,7 +761,7 @@ cp_print_class_member (char *valaddr, struct type *domain,
 
 static void
 cp_print_hpacc_virtual_table_entries (struct type *type, int *vfuncs,
-                                     value_ptr v, struct ui_file *stream,
+                                     struct value *v, struct ui_file *stream,
                                      int format, int recurse,
                                      enum val_prettyprint pretty)
 {
@@ -774,7 +790,7 @@ cp_print_hpacc_virtual_table_entries (struct type *type, int *vfuncs,
                    - 1);
 
          /* Get the address of the vfunction entry */
-         value_ptr vf = value_copy (v);
+         struct value *vf = value_copy (v);
          if (VALUE_LAZY (vf))
            (void) value_fetch_lazy (vf);
          /* adjust by offset */
This page took 0.027132 seconds and 4 git commands to generate.