* xcoffread.c (scan_xcoff_symtab): Update.
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index 5c9f3b8e8acb325e4787b397ae8fad769960bfb0..c859605361db1fa488485f9e70362447430b67c8 100644 (file)
@@ -639,9 +639,9 @@ struct field_info
        int virtuality;
        struct field field;
       }
-     *fields;
+     *fields, *baseclasses;
 
-    /* Number of fields.  */
+    /* Number of fields (including baseclasses).  */
     int nfields;
 
     /* Number of baseclasses.  */
@@ -1887,6 +1887,20 @@ process_psymtab_comp_unit (struct objfile *objfile,
 
   cu.list_in_scope = &file_symbols;
 
+  /* If this compilation unit was already read in, free the
+     cached copy in order to read it in again. This is
+     necessary because we skipped some symbols when we first
+     read in the compilation unit (see load_partial_dies).
+     This problem could be avoided, but the benefit is
+     unclear.  */
+  if (this_cu->cu != NULL)
+    free_one_cached_comp_unit (this_cu->cu);
+
+  /* Note that this is a pointer to our stack frame, being
+     added to a global data structure. It will be cleaned up
+     in free_stack_comp_unit when we finish with this
+     compilation unit. */
+  this_cu->cu = &cu;
   cu.per_cu = this_cu;
 
   /* Read the abbrevs for this compilation unit into a table.  */
@@ -1941,21 +1955,6 @@ process_psymtab_comp_unit (struct objfile *objfile,
   /* Store the function that reads in the rest of the symbol table */
   pst->read_symtab = dwarf2_psymtab_to_symtab;
 
-  /* If this compilation unit was already read in, free the
-     cached copy in order to read it in again. This is
-     necessary because we skipped some symbols when we first
-     read in the compilation unit (see load_partial_dies).
-     This problem could be avoided, but the benefit is
-     unclear.  */
-  if (this_cu->cu != NULL)
-    free_one_cached_comp_unit (this_cu->cu);
-
-  /* Note that this is a pointer to our stack frame, being
-     added to a global data structure. It will be cleaned up
-     in free_stack_comp_unit when we finish with this
-     compilation unit. */
-  this_cu->cu = &cu;
-
   this_cu->psymtab = pst;
 
   dwarf2_find_base_address (comp_unit_die, &cu);
@@ -2153,6 +2152,11 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
 
   /* ??? Missing cleanup for CU?  */
 
+  /* Link this compilation unit into the compilation unit tree.  */
+  this_cu->cu = cu;
+  cu->per_cu = this_cu;
+  cu->type_hash = this_cu->type_hash;
+
   info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
                                          dwarf2_per_objfile->info.buffer,
                                          dwarf2_per_objfile->info.size,
@@ -2178,11 +2182,6 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
   else
     set_cu_language (language_minimal, cu);
 
-  /* Link this compilation unit into the compilation unit tree.  */
-  this_cu->cu = cu;
-  cu->per_cu = this_cu;
-  cu->type_hash = this_cu->type_hash;
-
   /* Check if comp unit has_children.
      If so, read the rest of the partial symbols from this comp unit.
      If not, there's no more debug_info for this comp unit. */
@@ -2461,6 +2460,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
             mst_text, objfile); */
          psym = add_psymbol_to_list (actual_name, strlen (actual_name),
+                                     built_actual_name,
                                      VAR_DOMAIN, LOC_BLOCK,
                                      &objfile->global_psymbols,
                                      0, pdi->lowpc + baseaddr,
@@ -2471,6 +2471,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
             mst_file_text, objfile); */
          psym = add_psymbol_to_list (actual_name, strlen (actual_name),
+                                     built_actual_name,
                                      VAR_DOMAIN, LOC_BLOCK,
                                      &objfile->static_psymbols,
                                      0, pdi->lowpc + baseaddr,
@@ -2497,6 +2498,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
            addr = decode_locdesc (pdi->locdesc, cu);
          if (pdi->locdesc || pdi->has_type)
            psym = add_psymbol_to_list (actual_name, strlen (actual_name),
+                                       built_actual_name,
                                        VAR_DOMAIN, LOC_STATIC,
                                        &objfile->global_psymbols,
                                        0, addr + baseaddr,
@@ -2515,6 +2517,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
             mst_file_data, objfile); */
          psym = add_psymbol_to_list (actual_name, strlen (actual_name),
+                                     built_actual_name,
                                      VAR_DOMAIN, LOC_STATIC,
                                      &objfile->static_psymbols,
                                      0, addr + baseaddr,
@@ -2525,12 +2528,14 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     case DW_TAG_base_type:
     case DW_TAG_subrange_type:
       add_psymbol_to_list (actual_name, strlen (actual_name),
+                          built_actual_name,
                           VAR_DOMAIN, LOC_TYPEDEF,
                           &objfile->static_psymbols,
                           0, (CORE_ADDR) 0, cu->language, objfile);
       break;
     case DW_TAG_namespace:
       add_psymbol_to_list (actual_name, strlen (actual_name),
+                          built_actual_name,
                           VAR_DOMAIN, LOC_TYPEDEF,
                           &objfile->global_psymbols,
                           0, (CORE_ADDR) 0, cu->language, objfile);
@@ -2555,6 +2560,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
       /* NOTE: carlton/2003-10-07: See comment in new_symbol about
         static vs. global.  */
       add_psymbol_to_list (actual_name, strlen (actual_name),
+                          built_actual_name,
                           STRUCT_DOMAIN, LOC_TYPEDEF,
                           (cu->language == language_cplus
                            || cu->language == language_java)
@@ -2565,6 +2571,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
       break;
     case DW_TAG_enumerator:
       add_psymbol_to_list (actual_name, strlen (actual_name),
+                          built_actual_name,
                           VAR_DOMAIN, LOC_CONST,
                           (cu->language == language_cplus
                            || cu->language == language_java)
@@ -4358,8 +4365,17 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
   new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
   make_cleanup (xfree, new_field);
   memset (new_field, 0, sizeof (struct nextfield));
-  new_field->next = fip->fields;
-  fip->fields = new_field;
+
+  if (die->tag == DW_TAG_inheritance)
+    {
+      new_field->next = fip->baseclasses;
+      fip->baseclasses = new_field;
+    }
+  else
+    {
+      new_field->next = fip->fields;
+      fip->fields = new_field;
+    }
   fip->nfields++;
 
   /* Handle accessibility and virtuality of field.
@@ -4476,6 +4492,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
          pointer or virtual base class pointer) to private.  */
       if (dwarf2_attr (die, DW_AT_artificial, cu))
        {
+         FIELD_ARTIFICIAL (*fp) = 1;
          new_field->accessibility = DW_ACCESS_private;
          fip->non_public_fields = 1;
        }
@@ -4582,8 +4599,21 @@ dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
      up in the same order in the array in which they were added to the list.  */
   while (nfields-- > 0)
     {
-      TYPE_FIELD (type, nfields) = fip->fields->field;
-      switch (fip->fields->accessibility)
+      struct nextfield *fieldp;
+
+      if (fip->fields)
+       {
+         fieldp = fip->fields;
+         fip->fields = fieldp->next;
+       }
+      else
+       {
+         fieldp = fip->baseclasses;
+         fip->baseclasses = fieldp->next;
+       }
+
+      TYPE_FIELD (type, nfields) = fieldp->field;
+      switch (fieldp->accessibility)
        {
        case DW_ACCESS_private:
          SET_TYPE_FIELD_PRIVATE (type, nfields);
@@ -4600,13 +4630,13 @@ dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
          /* Unknown accessibility.  Complain and treat it as public.  */
          {
            complaint (&symfile_complaints, _("unsupported accessibility %d"),
-                      fip->fields->accessibility);
+                      fieldp->accessibility);
          }
          break;
        }
       if (nfields < fip->nbaseclasses)
        {
-         switch (fip->fields->virtuality)
+         switch (fieldp->virtuality)
            {
            case DW_VIRTUALITY_virtual:
            case DW_VIRTUALITY_pure_virtual:
@@ -4614,7 +4644,6 @@ dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
              break;
            }
        }
-      fip->fields = fip->fields->next;
     }
 }
 
@@ -4738,9 +4767,14 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
   if (attr && DW_UNSND (attr) != 0)
     fnp->is_artificial = 1;
 
-  /* Get index in virtual function table if it is a virtual member function.  */
+  /* Get index in virtual function table if it is a virtual member
+     function.  For GCC, this is an offset in the appropriate
+     virtual table, as specified by DW_AT_containing_type.  For
+     everyone else, it is an expression to be evaluated relative
+     to the object address.  */
+
   attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
-  if (attr)
+  if (attr && fnp->fcontext)
     {
       /* Support the .debug_loc offsets */
       if (attr_form_is_block (attr))
@@ -4756,7 +4790,40 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
          dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
                                                 fieldname);
         }
-   }
+    }
+  else if (attr)
+    {
+      /* We only support trivial expressions here.  This hack will work
+        for v3 classes, which always start with the vtable pointer.  */
+      if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0
+         && DW_BLOCK (attr)->data[0] == DW_OP_deref)
+       {
+         struct dwarf_block blk;
+         blk.size = DW_BLOCK (attr)->size - 1;
+         blk.data = DW_BLOCK (attr)->data + 1;
+         fnp->voffset = decode_locdesc (&blk, cu);
+         if ((fnp->voffset % cu->header.addr_size) != 0)
+           dwarf2_complex_location_expr_complaint ();
+         else
+           fnp->voffset /= cu->header.addr_size;
+         fnp->voffset += 2;
+         fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
+       }
+      else
+       dwarf2_complex_location_expr_complaint ();
+    }
+  else
+    {
+      attr = dwarf2_attr (die, DW_AT_virtuality, cu);
+      if (attr && DW_UNSND (attr))
+       {
+         /* GCC does this, as of 2008-08-25; PR debug/37237.  */
+         complaint (&symfile_complaints,
+                    _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
+                    fieldname, die->offset);
+         TYPE_CPLUS_DYNAMIC (type) = 1;
+       }
+    }
 }
 
 /* Create the vector of member function fields, and attach it to the type.  */
@@ -5018,7 +5085,8 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
 
          /* Get the type which refers to the base class (possibly this
             class itself) which contains the vtable pointer for the current
-            class from the DW_AT_containing_type attribute.  */
+            class from the DW_AT_containing_type attribute.  This use of
+            DW_AT_containing_type is a GNU extension.  */
 
          if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
            {
@@ -6512,7 +6580,7 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
              || part_die->tag == DW_TAG_subrange_type))
        {
          if (building_psymtab && part_die->name != NULL)
-           add_psymbol_to_list (part_die->name, strlen (part_die->name),
+           add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
                                 VAR_DOMAIN, LOC_TYPEDEF,
                                 &cu->objfile->static_psymbols,
                                 0, (CORE_ADDR) 0, cu->language, cu->objfile);
@@ -6533,7 +6601,7 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
          if (part_die->name == NULL)
            complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
          else if (building_psymtab)
-           add_psymbol_to_list (part_die->name, strlen (part_die->name),
+           add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
                                 VAR_DOMAIN, LOC_CONST,
                                 (cu->language == language_cplus
                                  || cu->language == language_java)
@@ -8265,7 +8333,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
 
       /* Cache this symbol's name and the name's demangled form (if any).  */
       SYMBOL_LANGUAGE (sym) = cu->language;
-      SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
+      SYMBOL_SET_NAMES (sym, name, strlen (name), 0, objfile);
 
       /* Default assumptions.
          Use the passed type or decode it from the die.  */
This page took 0.030266 seconds and 4 git commands to generate.