*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index 40f8cdeb2cb7d71287fde356a39a5eda245d88c2..127d10fc741fd7afee8f90e103777307125cf618 100644 (file)
@@ -337,7 +337,8 @@ struct dwarf2_per_cu_data
      Otherwise it's from .debug_info.  */
   unsigned int from_debug_types : 1;
 
-  /* Set iff currently read in.  */
+  /* Set to non-NULL iff this CU is currently loaded.  When it gets freed out
+     of the CU cache it gets reset to NULL again.  */
   struct dwarf2_cu *cu;
 
   /* If full symbols for this CU have been read in, then this field
@@ -396,6 +397,7 @@ struct line_header
   unsigned short version;
   unsigned int header_length;
   unsigned char minimum_instruction_length;
+  unsigned char maximum_ops_per_instruction;
   unsigned char default_is_stmt;
   int line_base;
   unsigned char line_range;
@@ -592,9 +594,6 @@ struct dwarf_block
 #define DW_FIELD_ALLOC_CHUNK 4
 #endif
 
-/* A zeroed version of a partial die for initialization purposes.  */
-static struct partial_die_info zeroed_partial_die;
-
 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
    but this would require a corresponding change in unpack_field_as_long
    and friends.  */
@@ -646,6 +645,16 @@ struct field_info
 
     /* Number of entries in the fnfieldlists array.  */
     int nfnfields;
+
+    /* typedefs defined inside this class.  TYPEDEF_FIELD_LIST contains head of
+       a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements.  */
+    struct typedef_field_list
+      {
+       struct typedef_field field;
+       struct typedef_field_list *next;
+      }
+    *typedef_field_list;
+    unsigned typedef_field_list_count;
   };
 
 /* One item on the queue of compilation units to read in full symbols
@@ -907,10 +916,9 @@ static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
 
 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
 
-static char *typename_concat (struct obstack *,
-                              const char *prefix, 
-                              const char *suffix,
-                             struct dwarf2_cu *);
+static char *typename_concat (struct obstack *obs, const char *prefix,
+                             const char *suffix, int physname,
+                             struct dwarf2_cu *cu);
 
 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
 
@@ -957,6 +965,9 @@ static void read_module (struct die_info *die, struct dwarf2_cu *cu);
 
 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
 
+static struct type *read_module_type (struct die_info *die,
+                                     struct dwarf2_cu *cu);
+
 static const char *namespace_name (struct die_info *die,
                                   int *is_anonymous, struct dwarf2_cu *);
 
@@ -964,7 +975,7 @@ static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
 
 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
 
-static enum dwarf_array_dim_ordering read_array_order (struct die_info *, 
+static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
                                                       struct dwarf2_cu *);
 
 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
@@ -1004,8 +1015,6 @@ static char *dwarf_attr_name (unsigned int);
 
 static char *dwarf_form_name (unsigned int);
 
-static char *dwarf_stack_op_name (unsigned int);
-
 static char *dwarf_bool_name (unsigned int);
 
 static char *dwarf_type_encoding_name (unsigned int);
@@ -1135,6 +1144,7 @@ dwarf2_has_info (struct objfile *objfile)
       /* Initialize per-objfile state.  */
       struct dwarf2_per_objfile *data
        = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
+
       memset (data, 0, sizeof (*data));
       set_objfile_data (objfile, dwarf2_objfile_data_key, data);
       dwarf2_per_objfile = data;
@@ -1203,6 +1213,7 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
   else if (section_is_p (sectp->name, EH_FRAME_SECTION))
     {
       flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
+
       if (aflag & SEC_HAS_CONTENTS)
         {
          dwarf2_per_objfile->eh_frame.asection = sectp;
@@ -1445,6 +1456,7 @@ offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
   unsigned int top = (cu_header->offset
                      + cu_header->length
                      + cu_header->initial_length_size);
+
   return (offset >= bottom && offset < top);
 }
 
@@ -1488,10 +1500,10 @@ partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
 
   info_ptr = read_comp_unit_head (header, info_ptr, abfd);
 
-  if (header->version != 2 && header->version != 3)
+  if (header->version != 2 && header->version != 3 && header->version != 4)
     error (_("Dwarf Error: wrong version in compilation unit header "
-          "(is %d, should be %d) [in module %s]"), header->version,
-          2, bfd_get_filename (abfd));
+          "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
+          bfd_get_filename (abfd));
 
   if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size)
     error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
@@ -1519,10 +1531,10 @@ read_type_comp_unit_head (struct comp_unit_head *cu_header,
                          ULONGEST *signature,
                          gdb_byte *types_ptr, bfd *abfd)
 {
-  unsigned int bytes_read;
   gdb_byte *initial_types_ptr = types_ptr;
 
-  dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->types);
+  dwarf2_read_section (dwarf2_per_objfile->objfile,
+                      &dwarf2_per_objfile->types);
   cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
 
   types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
@@ -1586,6 +1598,7 @@ dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
   if (attr)
     {
       unsigned int line_offset = DW_UNSND (attr);
+
       lh = dwarf_decode_line_header (line_offset, abfd, cu);
     }
   if (lh == NULL)
@@ -1600,6 +1613,7 @@ static hashval_t
 hash_type_signature (const void *item)
 {
   const struct signatured_type *type_sig = item;
+
   /* This drops the top 32 bits of the signature, but is ok for a hash.  */
   return type_sig->signature;
 }
@@ -1609,6 +1623,7 @@ eq_type_signature (const void *item_lhs, const void *item_rhs)
 {
   const struct signatured_type *lhs = item_lhs;
   const struct signatured_type *rhs = item_rhs;
+
   return lhs->signature == rhs->signature;
 }
 
@@ -1793,10 +1808,8 @@ process_psymtab_comp_unit (struct objfile *objfile,
   CORE_ADDR baseaddr;
   struct cleanup *back_to_inner;
   struct dwarf2_cu cu;
-  unsigned int bytes_read;
   int has_children, has_pc_info;
   struct attribute *attr;
-  const char *name;
   CORE_ADDR best_lowpc = 0, best_highpc = 0;
   struct die_reader_specs reader_specs;
 
@@ -1992,15 +2005,25 @@ build_type_psymtabs (struct objfile *objfile)
                          process_type_comp_unit, objfile);
 }
 
+/* A cleanup function that clears objfile's psymtabs_addrmap field.  */
+
+static void
+psymtabs_addrmap_cleanup (void *o)
+{
+  struct objfile *objfile = o;
+
+  objfile->psymtabs_addrmap = NULL;
+}
+
 /* Build the partial symbol table by doing a quick pass through the
    .debug_info and .debug_abbrev sections.  */
 
 static void
 dwarf2_build_psymtabs_hard (struct objfile *objfile)
 {
-  bfd *abfd = objfile->obfd;
   gdb_byte *info_ptr;
-  struct cleanup *back_to;
+  struct cleanup *back_to, *addrmap_cleanup;
+  struct obstack temp_obstack;
 
   dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
   info_ptr = dwarf2_per_objfile->info.buffer;
@@ -2013,8 +2036,12 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile)
 
   create_all_comp_units (objfile);
 
-  objfile->psymtabs_addrmap =
-    addrmap_create_mutable (&objfile->objfile_obstack);
+  /* Create a temporary address map on a temporary obstack.  We later
+     copy this to the final obstack.  */
+  obstack_init (&temp_obstack);
+  make_cleanup_obstack_free (&temp_obstack);
+  objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
+  addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
 
   /* Since the objects we're extracting from .debug_info vary in
      length, only the individual functions to extract them (like
@@ -2046,6 +2073,7 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile)
 
   objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
                                                    &objfile->objfile_obstack);
+  discard_cleanups (addrmap_cleanup);
 
   do_cleanups (back_to);
 }
@@ -2060,7 +2088,6 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
   gdb_byte *info_ptr, *beg_of_comp_unit;
   struct die_info *comp_unit_die;
   struct dwarf2_cu *cu;
-  unsigned int bytes_read;
   struct cleanup *back_to;
   struct attribute *attr;
   int has_children;
@@ -2135,11 +2162,10 @@ create_all_comp_units (struct objfile *objfile)
   n_allocated = 10;
   all_comp_units = xmalloc (n_allocated
                            * sizeof (struct dwarf2_per_cu_data *));
-  
+
   while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size)
     {
       unsigned int length, initial_length_size;
-      gdb_byte *beg_of_comp_unit;
       struct dwarf2_per_cu_data *this_cu;
       unsigned int offset;
 
@@ -2189,8 +2215,6 @@ static void
 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
                      CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
 {
-  struct objfile *objfile = cu->objfile;
-  bfd *abfd = objfile->obfd;
   struct partial_die_info *pdi;
 
   /* Now, march along the PDI's, descending into ones which have
@@ -2203,12 +2227,12 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
     {
       fixup_partial_die (pdi, cu);
 
-      /* Anonymous namespaces have no name but have interesting
+      /* Anonymous namespaces or modules have no name but have interesting
         children, so we need to look at them.  Ditto for anonymous
         enums.  */
 
       if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
-         || pdi->tag == DW_TAG_enumeration_type)
+         || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
        {
          switch (pdi->tag)
            {
@@ -2311,7 +2335,7 @@ partial_die_parent_scope (struct partial_die_info *pdi,
      DW_TAG_namespace DIEs with a name of "::" for the global namespace.
      Work around this problem here.  */
   if (cu->language == language_cplus
-      && parent->tag == DW_TAG_namespace 
+      && parent->tag == DW_TAG_namespace
       && strcmp (parent->name, "::") == 0
       && grandparent_scope == NULL)
     {
@@ -2321,6 +2345,7 @@ partial_die_parent_scope (struct partial_die_info *pdi,
     }
 
   if (parent->tag == DW_TAG_namespace
+      || parent->tag == DW_TAG_module
       || parent->tag == DW_TAG_structure_type
       || parent->tag == DW_TAG_class_type
       || parent->tag == DW_TAG_interface_type
@@ -2331,7 +2356,7 @@ partial_die_parent_scope (struct partial_die_info *pdi,
        parent->scope = parent->name;
       else
        parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
-                                        parent->name, cu);
+                                        parent->name, 0, cu);
     }
   else if (parent->tag == DW_TAG_enumerator)
     /* Enumerators should not get the name of the enumeration as a prefix.  */
@@ -2363,7 +2388,7 @@ partial_die_full_name (struct partial_die_info *pdi,
   if (parent_scope == NULL)
     return NULL;
   else
-    return typename_concat (NULL, parent_scope, pdi->name, cu);
+    return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
 }
 
 static void
@@ -2372,7 +2397,6 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
   struct objfile *objfile = cu->objfile;
   CORE_ADDR addr = 0;
   char *actual_name = NULL;
-  const char *my_prefix;
   const struct partial_symbol *psym = NULL;
   CORE_ADDR baseaddr;
   int built_actual_name = 0;
@@ -2534,8 +2558,6 @@ add_partial_namespace (struct partial_die_info *pdi,
                       CORE_ADDR *lowpc, CORE_ADDR *highpc,
                       int need_pc, struct dwarf2_cu *cu)
 {
-  struct objfile *objfile = cu->objfile;
-
   /* Add a symbol for the namespace.  */
 
   add_partial_symbol (pdi, cu);
@@ -2552,9 +2574,7 @@ static void
 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
                    CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
 {
-  /* Now scan partial symbols in that module.
-
-     FIXME: Support the separate Fortran module namespaces.  */
+  /* Now scan partial symbols in that module.  */
 
   if (pdi->has_children)
     scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
@@ -2564,7 +2584,7 @@ add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
    symbol for that subprogram.  When the CU language allows it, this
    routine also defines a partial symbol for each nested subprogram
    that this subprogram contains.
-   
+
    DIE my also be a lexical block, in which case we simply search
    recursively for suprograms defined inside that lexical block.
    Again, this is only performed when the CU language allows this
@@ -2603,7 +2623,7 @@ add_partial_subprogram (struct partial_die_info *pdi,
              add_partial_symbol (pdi, cu);
         }
     }
-  
+
   if (! pdi->has_children)
     return;
 
@@ -2661,8 +2681,6 @@ static void
 add_partial_enumeration (struct partial_die_info *enum_pdi,
                         struct dwarf2_cu *cu)
 {
-  struct objfile *objfile = cu->objfile;
-  bfd *abfd = objfile->obfd;
   struct partial_die_info *pdi;
 
   if (enum_pdi->name != NULL)
@@ -2776,6 +2794,8 @@ skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
        case DW_FORM_flag:
          info_ptr += 1;
          break;
+       case DW_FORM_flag_present:
+         break;
        case DW_FORM_data2:
        case DW_FORM_ref2:
          info_ptr += 2;
@@ -2793,9 +2813,11 @@ skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
          read_string (abfd, info_ptr, &bytes_read);
          info_ptr += bytes_read;
          break;
+       case DW_FORM_sec_offset:
        case DW_FORM_strp:
          info_ptr += cu->header.offset_size;
          break;
+       case DW_FORM_exprloc:
        case DW_FORM_block:
          info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
          info_ptr += bytes_read;
@@ -2891,6 +2913,7 @@ dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
              struct dwarf2_per_objfile *dpo_backlink
                = objfile_data (pst->objfile->separate_debug_objfile_backlink,
                                dwarf2_objfile_data_key);
+
              dwarf2_per_objfile->has_section_at_zero
                = dpo_backlink->has_section_at_zero;
            }
@@ -3041,7 +3064,6 @@ load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
   gdb_byte *info_ptr, *beg_of_comp_unit;
   struct cleanup *back_to, *free_cu_cleanup;
   struct attribute *attr;
-  CORE_ADDR baseaddr;
 
   gdb_assert (! per_cu->from_debug_types);
 
@@ -3111,7 +3133,6 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
   struct partial_symtab *pst = per_cu->psymtab;
   struct dwarf2_cu *cu = per_cu->cu;
   struct objfile *objfile = pst->objfile;
-  bfd *abfd = objfile->obfd;
   CORE_ADDR lowpc, highpc;
   struct symtab *symtab;
   struct cleanup *back_to;
@@ -3199,6 +3220,8 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_base_type:
     case DW_TAG_subrange_type:
     case DW_TAG_typedef:
+    case DW_TAG_const_type:
+    case DW_TAG_volatile_type:
       /* Add a typedef symbol for the type definition, if it has a
          DW_AT_name.  */
       new_symbol (die, read_type_die (die, cu), cu);
@@ -3213,6 +3236,7 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
       read_namespace (die, cu);
       break;
     case DW_TAG_module:
+      processing_has_namespace_info = 1;
       read_module (die, cu);
       break;
     case DW_TAG_imported_declaration:
@@ -3262,12 +3286,14 @@ die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
       if (dwarf2_attr (die, DW_AT_specification, cu))
        {
          struct dwarf2_cu *spec_cu = cu;
+
          return die_needs_namespace (die_specification (die, &spec_cu),
                                      spec_cu);
        }
 
       attr = dwarf2_attr (die, DW_AT_external, cu);
-      if (attr == NULL && die->parent->tag != DW_TAG_namespace)
+      if (attr == NULL && die->parent->tag != DW_TAG_namespace
+         && die->parent->tag != DW_TAG_module)
        return 0;
       /* A variable in a lexical block of some kind does not need a
         namespace, even though in C++ such variables may be external
@@ -3300,9 +3326,29 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
   if (name == NULL)
     name = dwarf2_name (die, cu);
 
+  /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
+     compute it by typename_concat inside GDB.  */
+  if (cu->language == language_ada
+      || (cu->language == language_fortran && physname))
+    {
+      /* For Ada unit, we prefer the linkage name over the name, as
+        the former contains the exported name, which the user expects
+        to be able to reference.  Ideally, we want the user to be able
+        to reference this entity using either natural or linkage name,
+        but we haven't started looking at this enhancement yet.  */
+      struct attribute *attr;
+
+      attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
+      if (attr == NULL)
+       attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
+      if (attr && DW_STRING (attr))
+       return DW_STRING (attr);
+    }
+
   /* These are the only languages we know how to qualify names in.  */
   if (name != NULL
-      && (cu->language == language_cplus || cu->language == language_java))
+      && (cu->language == language_cplus || cu->language == language_java
+         || cu->language == language_fortran))
     {
       if (die_needs_namespace (die, cu))
        {
@@ -3314,7 +3360,9 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
          buf = mem_fileopen ();
          if (*prefix != '\0')
            {
-             char *prefixed_name = typename_concat (NULL, prefix, name, cu);
+             char *prefixed_name = typename_concat (NULL, prefix, name,
+                                                    physname, cu);
+
              fputs_unfiltered (prefixed_name, buf);
              xfree (prefixed_name);
            }
@@ -3323,7 +3371,7 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
 
          /* For Java and C++ methods, append formal parameter type
             information, if PHYSNAME.  */
-         
+
          if (physname && die->tag == DW_TAG_subprogram
              && (cu->language == language_cplus
                  || cu->language == language_java))
@@ -3358,24 +3406,12 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
              char *cname
                = dwarf2_canonicalize_name (name, cu,
                                            &cu->objfile->objfile_obstack);
+
              if (cname != NULL)
                name = cname;
            }
        }
     }
-  else if (cu->language == language_ada)
-    {
-      /* For Ada unit, we prefer the linkage name over the name, as
-        the former contains the exported name, which the user expects
-        to be able to reference.  Ideally, we want the user to be able
-        to reference this entity using either natural or linkage name,
-        but we haven't started looking at this enhancement yet.  */
-      struct attribute *attr;
-
-      attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
-      if (attr && DW_STRING (attr))
-       name = DW_STRING (attr);
-    }
 
   return name;
 }
@@ -3482,7 +3518,8 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
      to the name of the imported die.  */
   imported_name_prefix = determine_prefix (imported_die, imported_cu);
 
-  if (imported_die->tag != DW_TAG_namespace)
+  if (imported_die->tag != DW_TAG_namespace
+      && imported_die->tag != DW_TAG_module)
     {
       imported_declaration = imported_name;
       canonical_name = imported_name_prefix;
@@ -3525,7 +3562,6 @@ static void
 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
-  struct comp_unit_head *cu_header = &cu->header;
   struct cleanup *back_to = make_cleanup (null_cleanup, 0);
   CORE_ADDR lowpc = ((CORE_ADDR) -1);
   CORE_ADDR highpc = ((CORE_ADDR) 0);
@@ -3536,7 +3572,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
   bfd *abfd = objfile->obfd;
   struct line_header *line_header = 0;
   CORE_ADDR baseaddr;
-  
+
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
   get_scope_pc_bounds (die, &lowpc, &highpc, cu);
@@ -3585,7 +3621,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
     }
 
   attr = dwarf2_attr (die, DW_AT_producer, cu);
-  if (attr) 
+  if (attr)
     cu->producer = DW_STRING (attr);
 
   /* We assume that we're processing GCC output. */
@@ -3634,6 +3670,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
   if (attr && line_header)
     {
       unsigned int macro_offset = DW_UNSND (attr);
+
       dwarf_decode_macros (line_header, macro_offset,
                            comp_dir, abfd, cu);
     }
@@ -3655,7 +3692,6 @@ read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
   char *comp_dir = NULL;
   struct die_info *child_die;
   bfd *abfd = objfile->obfd;
-  struct line_header *line_header = 0;
 
   /* start_symtab needs a low pc, but we don't really have one.
      Do what read_file_scope would do in the absence of such info.  */
@@ -3687,7 +3723,7 @@ read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
   /* This isn't technically needed today.  It is done for symmetry
      with read_file_scope.  */
   attr = dwarf2_attr (die, DW_AT_producer, cu);
-  if (attr) 
+  if (attr)
     cu->producer = DW_STRING (attr);
 
   /* We assume that we're processing GCC output. */
@@ -3803,6 +3839,7 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
         but GCC versions at least through 4.4 generate this (GCC PR
         40573).  */
       struct die_info *child_origin_die = child_die;
+
       while (1)
        {
          attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu);
@@ -3902,9 +3939,11 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   /* Ignore functions with missing or invalid low and high pc attributes.  */
   if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
     {
-      complaint (&symfile_complaints,
-                 _("cannot get low and high bounds for subprogram DIE at %d"),
-                 die->offset);
+      attr = dwarf2_attr (die, DW_AT_external, cu);
+      if (!attr || !DW_UNSND (attr))
+       complaint (&symfile_complaints,
+                  _("cannot get low and high bounds for subprogram DIE at %d"),
+                  die->offset);
       return;
     }
 
@@ -3946,20 +3985,45 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
 
   inherit_abstract_dies (die, cu);
 
+  /* If we have a DW_AT_specification, we might need to import using
+     directives from the context of the specification DIE.  See the
+     comment in determine_prefix.  */
+  if (cu->language == language_cplus
+      && dwarf2_attr (die, DW_AT_specification, cu))
+    {
+      struct dwarf2_cu *spec_cu = cu;
+      struct die_info *spec_die = die_specification (die, &spec_cu);
+
+      while (spec_die)
+       {
+         child_die = spec_die->child;
+         while (child_die && child_die->tag)
+           {
+             if (child_die->tag == DW_TAG_imported_module)
+               process_die (child_die, spec_cu);
+             child_die = sibling_die (child_die);
+           }
+
+         /* In some cases, GCC generates specification DIEs that
+            themselves contain DW_AT_specification attributes.  */
+         spec_die = die_specification (spec_die, &spec_cu);
+       }
+    }
+
   new = pop_context ();
   /* Make a block for the local symbols within.  */
   block = finish_block (new->name, &local_symbols, new->old_blocks,
                         lowpc, highpc, objfile);
 
   /* For C++, set the block's scope.  */
-  if (cu->language == language_cplus)
+  if (cu->language == language_cplus || cu->language == language_fortran)
     cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
                        determine_prefix (die, cu),
                        processing_has_namespace_info);
 
   /* If we have address ranges, record them.  */
   dwarf2_record_block_ranges (die, block, baseaddr, cu);
-  
+
   /* In C++, we can have functions nested inside functions (e.g., when
      a function declares a class that has methods).  This means that
      when we finish processing a function scope, we may need to go
@@ -3991,7 +4055,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
   /* Ignore blocks with missing or invalid low and high pc attributes.  */
   /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
      as multiple lexical blocks?  Handling children in a sane way would
-     be nasty.  Might be easier to properly extend generic blocks to 
+     be nasty.  Might be easier to properly extend generic blocks to
      describe ranges.  */
   if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
     return;
@@ -4244,7 +4308,7 @@ dwarf2_get_subprogram_pc_bounds (struct die_info *die,
      subprograms or lexical blocks), we're done.  */
   if (cu->language != language_ada)
     return;
-     
+
   /* Check all the children of the given DIE.  If it contains nested
      subprograms, then check their pc bounds.  Likewise, we need to
      check lexical blocks as well, as they may also contain subprogram
@@ -4287,6 +4351,7 @@ get_scope_pc_bounds (struct die_info *die,
             dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
            break;
          case DW_TAG_namespace:
+         case DW_TAG_module:
            /* FIXME: carlton/2004-01-16: Should we do this for
               DW_TAG_class_type/DW_TAG_structure_type, too?  I think
               that current GCC's always emit the DIEs corresponding
@@ -4328,10 +4393,12 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
   if (attr)
     {
       CORE_ADDR high = DW_ADDR (attr);
+
       attr = dwarf2_attr (die, DW_AT_low_pc, cu);
       if (attr)
         {
           CORE_ADDR low = DW_ADDR (attr);
+
           record_block_range (block, baseaddr + low, baseaddr + high - 1);
         }
     }
@@ -4403,8 +4470,8 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
                   return;
                 }
 
-              record_block_range (block, 
-                                  baseaddr + base + start, 
+              record_block_range (block,
+                                  baseaddr + base + start,
                                   baseaddr + base + end - 1);
             }
         }
@@ -4416,7 +4483,7 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
 static void
 dwarf2_add_field (struct field_info *fip, struct die_info *die,
                  struct dwarf2_cu *cu)
-{ 
+{
   struct objfile *objfile = cu->objfile;
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct nextfield *new_field;
@@ -4461,10 +4528,15 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
 
   fp = &new_field->field;
 
+  /* NOTE: According to the dwarf standard, static data members are
+     indicated by having DW_AT_external.
+     The check here for ! die_is_declaration is historical.
+     This test is replicated in new_symbol.  */
+
   if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
     {
       /* Data member other than a C++ static data member.  */
-      
+
       /* Get type of field.  */
       fp->type = die_type (die, cu);
 
@@ -4568,7 +4640,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
         is a declaration, but all versions of G++ as of this writing
         (so through at least 3.2.1) incorrectly generate
         DW_TAG_variable tags.  */
-      
+
       char *physname;
 
       /* Get name of field.  */
@@ -4576,6 +4648,14 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       if (fieldname == NULL)
        return;
 
+      attr = dwarf2_attr (die, DW_AT_const_value, cu);
+      if (attr)
+       {
+         /* A static const member, not much different than an enum as far as
+            we're concerned, except that we can support more types.  */
+         new_symbol (die, NULL, cu);
+       }
+
       /* Get physical name.  */
       physname = (char *) dwarf2_physname (fieldname, die, cu);
 
@@ -4611,6 +4691,39 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
     }
 }
 
+/* Add a typedef defined in the scope of the FIP's class.  */
+
+static void
+dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
+                   struct dwarf2_cu *cu)
+{
+  struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct typedef_field_list *new_field;
+  struct attribute *attr;
+  struct typedef_field *fp;
+  char *fieldname = "";
+
+  /* Allocate a new field list entry and link it in.  */
+  new_field = xzalloc (sizeof (*new_field));
+  make_cleanup (xfree, new_field);
+
+  gdb_assert (die->tag == DW_TAG_typedef);
+
+  fp = &new_field->field;
+
+  /* Get name of field.  */
+  fp->name = dwarf2_name (die, cu);
+  if (fp->name == NULL)
+    return;
+
+  fp->type = read_type_die (die, cu);
+
+  new_field->next = fip->typedef_field_list;
+  fip->typedef_field_list = new_field;
+  fip->typedef_field_list_count++;
+}
+
 /* Create the vector of fields, and attach it to the type.  */
 
 static void
@@ -4838,19 +4951,46 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
     fnp->is_artificial = 1;
 
   /* 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
+     function.  For older versions of 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 && fnp->fcontext)
+  if (attr)
     {
-      /* Support the .debug_loc offsets */
-      if (attr_form_is_block (attr))
+      if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
         {
-          fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
-        }
+         if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
+           {
+             /* Old-style GCC.  */
+             fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
+           }
+         else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
+                  || (DW_BLOCK (attr)->size > 1
+                      && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
+                      && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
+           {
+             struct dwarf_block blk;
+             int offset;
+
+             offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
+                       ? 1 : 2);
+             blk.size = DW_BLOCK (attr)->size - offset;
+             blk.data = DW_BLOCK (attr)->data + offset;
+             fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
+             if ((fnp->voffset % cu->header.addr_size) != 0)
+               dwarf2_complex_location_expr_complaint ();
+             else
+               fnp->voffset /= cu->header.addr_size;
+             fnp->voffset += 2;
+           }
+         else
+           dwarf2_complex_location_expr_complaint ();
+
+         if (!fnp->fcontext)
+           fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
+       }
       else if (attr_form_is_section_offset (attr))
         {
          dwarf2_complex_location_expr_complaint ();
@@ -4861,27 +5001,6 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
                                                 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);
@@ -4891,6 +5010,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
          complaint (&symfile_complaints,
                     _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
                     fieldname, die->offset);
+         ALLOCATE_CPLUS_STRUCT_TYPE (type);
          TYPE_CPLUS_DYNAMIC (type) = 1;
        }
     }
@@ -5019,7 +5139,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
   struct type *type;
   struct attribute *attr;
   char *name;
-  struct cleanup *back_to = make_cleanup (null_cleanup, 0);
+  struct cleanup *back_to;
 
   /* If the definition of this type lives in .debug_types, read that type.
      Don't follow DW_AT_specification though, that will take us back up
@@ -5029,6 +5149,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
     {
       struct dwarf2_cu *type_cu = cu;
       struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
+
       /* We could just recurse on read_structure_type, but we need to call
         get_die_type to ensure only one type for this DIE is created.
         This is important, for example, because for c++ classes we need
@@ -5037,6 +5158,8 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
       return set_die_type (die, type, cu);
     }
 
+  back_to = make_cleanup (null_cleanup, 0);
+
   type = alloc_type (objfile);
   INIT_CPLUS_SPECIFIC (type);
 
@@ -5096,13 +5219,14 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
        on incomplete types.  */
     TYPE_STUB (type) = 1;
 
-  set_descriptive_type (type, die, cu);
-
   /* We need to add the type field to the die immediately so we don't
      infinitely recurse when dealing with pointers to the structure
      type within the structure itself. */
   set_die_type (die, type, cu);
 
+  /* set_die_type should be already done.  */
+  set_descriptive_type (type, die, cu);
+
   if (die->child != NULL && ! die_is_declaration (die, cu))
     {
       struct field_info fi;
@@ -5134,6 +5258,8 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
              /* C++ base class field.  */
              dwarf2_add_field (&fi, child_die, cu);
            }
+         else if (child_die->tag == DW_TAG_typedef)
+           dwarf2_add_typedef (&fi, child_die, cu);
          child_die = sibling_die (child_die);
        }
 
@@ -5207,6 +5333,29 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
                }
            }
        }
+
+      /* Copy fi.typedef_field_list linked list elements content into the
+        allocated array TYPE_TYPEDEF_FIELD_ARRAY (type).  */
+      if (fi.typedef_field_list)
+       {
+         int i = fi.typedef_field_list_count;
+
+         ALLOCATE_CPLUS_STRUCT_TYPE (type);
+         TYPE_TYPEDEF_FIELD_ARRAY (type)
+           = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
+         TYPE_TYPEDEF_FIELD_COUNT (type) = i;
+
+         /* Reverse the list order to keep the debug info elements order.  */
+         while (--i >= 0)
+           {
+             struct typedef_field *dest, *src;
+
+             dest = &TYPE_TYPEDEF_FIELD (type, i);
+             src = &fi.typedef_field_list->field;
+             fi.typedef_field_list = fi.typedef_field_list->next;
+             *dest = *src;
+           }
+       }
     }
 
   quirk_gcc_member_function_pointer (type, cu->objfile);
@@ -5218,7 +5367,6 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
 static void
 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
-  struct objfile *objfile = cu->objfile;
   struct die_info *child_die = die->child;
   struct type *this_type;
 
@@ -5274,6 +5422,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
     {
       struct dwarf2_cu *type_cu = cu;
       struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
+
       type = read_type_die (type_die, type_cu);
       return set_die_type (die, type, cu);
     }
@@ -5315,7 +5464,6 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
 static void
 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
-  struct objfile *objfile = cu->objfile;
   struct die_info *child_die;
   struct field *fields;
   struct symbol *sym;
@@ -5392,7 +5540,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
   struct die_info *child_die;
-  struct type *type = NULL;
+  struct type *type;
   struct type *element_type, *range_type, *index_type;
   struct type **range_types = NULL;
   struct attribute *attr;
@@ -5402,6 +5550,11 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
 
   element_type = die_type (die, cu);
 
+  /* The die_type call above may have already set the type for this DIE.  */
+  type = get_die_type (die, cu);
+  if (type)
+    return type;
+
   /* Irix 6.2 native cc creates array types without children for
      arrays with unspecified length.  */
   if (die->child == NULL)
@@ -5419,6 +5572,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
       if (child_die->tag == DW_TAG_subrange_type)
        {
          struct type *child_type = read_type_die (child_die, cu);
+
           if (child_type != NULL)
             {
              /* The range type was succesfully read. Save it for
@@ -5445,6 +5599,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
   if (read_array_order (die, cu) == DW_ORD_col_major)
     {
       int i = 0;
+
       while (i < ndim)
        type = create_array_type (NULL, type, range_types[i++]);
     }
@@ -5467,17 +5622,20 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
   name = dwarf2_name (die, cu);
   if (name)
     TYPE_NAME (type) = name;
-  
+
+  /* Install the type in the die. */
+  set_die_type (die, type, cu);
+
+  /* set_die_type should be already done.  */
   set_descriptive_type (type, die, cu);
 
   do_cleanups (back_to);
 
-  /* Install the type in the die. */
-  return set_die_type (die, type, cu);
+  return type;
 }
 
 static enum dwarf_array_dim_ordering
-read_array_order (struct die_info *die, struct dwarf2_cu *cu) 
+read_array_order (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct attribute *attr;
 
@@ -5487,10 +5645,10 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
 
   /*
     GNU F77 is a special case, as at 08/2004 array type info is the
-    opposite order to the dwarf2 specification, but data is still 
+    opposite order to the dwarf2 specification, but data is still
     laid out as per normal fortran.
 
-    FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need 
+    FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
     version checking.
   */
 
@@ -5500,7 +5658,7 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
       return DW_ORD_row_major;
     }
 
-  switch (cu->language_defn->la_array_ordering) 
+  switch (cu->language_defn->la_array_ordering)
     {
     case array_column_major:
       return DW_ORD_col_major;
@@ -5516,7 +5674,21 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
 static struct type *
 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
 {
-  struct type *set_type = create_set_type (NULL, die_type (die, cu));
+  struct type *domain_type, *set_type;
+  struct attribute *attr;
+
+  domain_type = die_type (die, cu);
+
+  /* The die_type call above may have already set the type for this DIE.  */
+  set_type = get_die_type (die, cu);
+  if (set_type)
+    return set_type;
+
+  set_type = create_set_type (NULL, domain_type);
+
+  attr = dwarf2_attr (die, DW_AT_byte_size, cu);
+  if (attr)
+    TYPE_LENGTH (set_type) = DW_UNSND (attr);
 
   return set_die_type (die, set_type, cu);
 }
@@ -5592,6 +5764,7 @@ read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
     {
       struct die_info *ext_die;
       struct dwarf2_cu *ext_cu = cu;
+
       ext_die = dwarf2_extension (die, &ext_cu);
       type = read_type_die (ext_die, ext_cu);
       return set_die_type (die, type, cu);
@@ -5604,7 +5777,7 @@ read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
   previous_prefix = determine_prefix (die, cu);
   if (previous_prefix[0] != '\0')
     name = typename_concat (&objfile->objfile_obstack,
-                           previous_prefix, name, cu);
+                           previous_prefix, name, 0, cu);
 
   /* Create the type.  */
   type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
@@ -5612,9 +5785,7 @@ read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
   TYPE_NAME (type) = (char *) name;
   TYPE_TAG_NAME (type) = TYPE_NAME (type);
 
-  set_die_type (die, type, cu);
-
-  return type;
+  return set_die_type (die, type, cu);
 }
 
 /* Read a C++ namespace.  */
@@ -5641,6 +5812,7 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
       if (is_anonymous)
        {
          const char *previous_prefix = determine_prefix (die, cu);
+
          cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
                                  NULL, &objfile->objfile_obstack);
        }
@@ -5649,7 +5821,7 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
   if (die->child != NULL)
     {
       struct die_info *child_die = die->child;
-      
+
       while (child_die && child_die->tag)
        {
          process_die (child_die, cu);
@@ -5658,6 +5830,29 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
     }
 }
 
+/* Read a Fortran module as type.  This DIE can be only a declaration used for
+   imported module.  Still we need that type as local Fortran "use ... only"
+   declaration imports depend on the created type in determine_prefix.  */
+
+static struct type *
+read_module_type (struct die_info *die, struct dwarf2_cu *cu)
+{
+  struct objfile *objfile = cu->objfile;
+  char *module_name;
+  struct type *type;
+
+  module_name = dwarf2_name (die, cu);
+  if (!module_name)
+    complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"),
+               die->offset);
+  type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
+
+  /* determine_prefix uses TYPE_TAG_NAME.  */
+  TYPE_TAG_NAME (type) = TYPE_NAME (type);
+
+  return set_die_type (die, type, cu);
+}
+
 /* Read a Fortran module.  */
 
 static void
@@ -5665,8 +5860,6 @@ read_module (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct die_info *child_die = die->child;
 
-  /* FIXME: Support the separate Fortran module namespaces.  */
-
   while (child_die && child_die->tag)
     {
       process_die (child_die, cu);
@@ -5716,8 +5909,16 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
   struct attribute *attr_byte_size;
   struct attribute *attr_address_class;
   int byte_size, addr_class;
+  struct type *target_type;
+
+  target_type = die_type (die, cu);
+
+  /* The die_type call above may have already set the type for this DIE.  */
+  type = get_die_type (die, cu);
+  if (type)
+    return type;
 
-  type = lookup_pointer_type (die_type (die, cu));
+  type = lookup_pointer_type (target_type);
 
   attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr_byte_size)
@@ -5750,9 +5951,10 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
        {
          complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size);
        }
-      else {
-       /* Should we also complain about unhandled address classes?  */
-      }
+      else
+       {
+         /* Should we also complain about unhandled address classes?  */
+       }
     }
 
   TYPE_LENGTH (type) = byte_size;
@@ -5765,7 +5967,6 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
 static struct type *
 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
 {
-  struct objfile *objfile = cu->objfile;
   struct type *type;
   struct type *to_type;
   struct type *domain;
@@ -5773,6 +5974,11 @@ read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
   to_type = die_type (die, cu);
   domain = die_containing_type (die, cu);
 
+  /* The calls above may have already set the type for this DIE.  */
+  type = get_die_type (die, cu);
+  if (type)
+    return type;
+
   if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
     type = lookup_methodptr_type (to_type);
   else
@@ -5788,10 +5994,17 @@ static struct type *
 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct comp_unit_head *cu_header = &cu->header;
-  struct type *type;
+  struct type *type, *target_type;
   struct attribute *attr;
 
-  type = lookup_reference_type (die_type (die, cu));
+  target_type = die_type (die, cu);
+
+  /* The die_type call above may have already set the type for this DIE.  */
+  type = get_die_type (die, cu);
+  if (type)
+    return type;
+
+  type = lookup_reference_type (target_type);
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr)
     {
@@ -5810,6 +6023,12 @@ read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
   struct type *base_type, *cv_type;
 
   base_type = die_type (die, cu);
+
+  /* The die_type call above may have already set the type for this DIE.  */
+  cv_type = get_die_type (die, cu);
+  if (cv_type)
+    return cv_type;
+
   cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
   return set_die_type (die, cv_type, cu);
 }
@@ -5820,6 +6039,12 @@ read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
   struct type *base_type, *cv_type;
 
   base_type = die_type (die, cu);
+
+  /* The die_type call above may have already set the type for this DIE.  */
+  cv_type = get_die_type (die, cu);
+  if (cv_type)
+    return cv_type;
+
   cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
   return set_die_type (die, cv_type, cu);
 }
@@ -5884,6 +6109,12 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
   struct attribute *attr;
 
   type = die_type (die, cu);
+
+  /* The die_type call above may have already set the type for this DIE.  */
+  ftype = get_die_type (die, cu);
+  if (ftype)
+    return ftype;
+
   ftype = lookup_function_type (type);
 
   /* All functions in C++, Pascal and Java have prototypes.  */
@@ -5910,16 +6141,17 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
      we don't infinitely recurse when dealing with parameters
      declared as the same subroutine type. */
   set_die_type (die, ftype, cu);
-  
+
   if (die->child != NULL)
     {
+      struct type *void_type = objfile_type (cu->objfile)->builtin_void;
       struct die_info *child_die;
-      int nparams = 0;
-      int iparams = 0;
+      int nparams, iparams;
 
       /* Count the number of parameters.
          FIXME: GDB currently ignores vararg functions, but knows about
          vararg member functions.  */
+      nparams = 0;
       child_die = die->child;
       while (child_die && child_die->tag)
        {
@@ -5935,6 +6167,12 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
       TYPE_FIELDS (ftype) = (struct field *)
        TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
 
+      /* TYPE_FIELD_TYPE must never be NULL.  Pre-fill the array to ensure it
+        even if we error out during the parameters reading below.  */
+      for (iparams = 0; iparams < nparams; iparams++)
+       TYPE_FIELD_TYPE (ftype, iparams) = void_type;
+
+      iparams = 0;
       child_die = die->child;
       while (child_die && child_die->tag)
        {
@@ -5949,7 +6187,19 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
              if (attr)
                TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
              else
-               TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
+               {
+                 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
+
+                 /* GCC/43521: In java, the formal parameter
+                    "this" is sometimes not marked with DW_AT_artificial.  */
+                 if (cu->language == language_java)
+                   {
+                     const char *name = dwarf2_name (child_die, cu);
+
+                     if (name && !strcmp (name, "this"))
+                       TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
+                   }
+               }
              TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
              iparams++;
            }
@@ -5964,7 +6214,6 @@ static struct type *
 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
-  struct attribute *attr;
   const char *name = NULL;
   struct type *this_type;
 
@@ -6037,7 +6286,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        type_flags |= TYPE_FLAG_UNSIGNED;
        break;
       case DW_ATE_signed_char:
-       if (cu->language == language_ada || cu->language == language_m2 
+       if (cu->language == language_ada || cu->language == language_m2
            || cu->language == language_pascal)
          code = TYPE_CODE_CHAR;
        break;
@@ -6047,6 +6296,11 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
          code = TYPE_CODE_CHAR;
        type_flags |= TYPE_FLAG_UNSIGNED;
        break;
+      case DW_ATE_UTF:
+       /* We just treat this as an integer and then recognize the
+          type by name elsewhere.  */
+       break;
+
       default:
        complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
                   dwarf_type_encoding_name (encoding));
@@ -6076,19 +6330,16 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   LONGEST high = -1;
   char *name;
   LONGEST negative_mask;
-  
+
   base_type = die_type (die, cu);
-  if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
-    {
-      complaint (&symfile_complaints,
-                _("DW_AT_type missing from DW_TAG_subrange_type"));
-      base_type
-       = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8,
-                    0, NULL, cu->objfile);
-    }
+
+  /* The die_type call above may have already set the type for this DIE.  */
+  range_type = get_die_type (die, cu);
+  if (range_type)
+    return range_type;
 
   if (cu->language == language_fortran)
-    { 
+    {
       /* FORTRAN implies a lower bound of 1, if not given.  */
       low = 1;
     }
@@ -6102,11 +6353,11 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 
   attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
   if (attr)
-    {       
-      if (attr->form == DW_FORM_block1)
+    {
+      if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
         {
           /* GCC encodes arrays with unspecified or dynamic length
-             with a DW_FORM_block1 attribute.
+             with a DW_FORM_block1 attribute or a reference attribute.
              FIXME: GDB does not yet know how to handle dynamic
              arrays properly, treat them as arrays with unspecified
              length for now.
@@ -6121,8 +6372,56 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
       else
         high = dwarf2_get_attr_constant_value (attr, 1);
     }
+  else
+    {
+      attr = dwarf2_attr (die, DW_AT_count, cu);
+      if (attr)
+       {
+         int count = dwarf2_get_attr_constant_value (attr, 1);
+         high = low + count - 1;
+       }
+    }
 
-  negative_mask = 
+  /* Dwarf-2 specifications explicitly allows to create subrange types
+     without specifying a base type.
+     In that case, the base type must be set to the type of
+     the lower bound, upper bound or count, in that order, if any of these
+     three attributes references an object that has a type.
+     If no base type is found, the Dwarf-2 specifications say that
+     a signed integer type of size equal to the size of an address should
+     be used.
+     For the following C code: `extern char gdb_int [];'
+     GCC produces an empty range DIE.
+     FIXME: muller/2010-05-28: Possible references to object for low bound,
+     high bound or count are not yet handled by this code.
+  */
+  if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
+    {
+      struct objfile *objfile = cu->objfile;
+      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+      int addr_size = gdbarch_addr_bit (gdbarch) /8;
+      struct type *int_type = objfile_type (objfile)->builtin_int;
+
+      /* Test "int", "long int", and "long long int" objfile types,
+        and select the first one having a size above or equal to the
+        architecture address size.  */
+      if (int_type && TYPE_LENGTH (int_type) >= addr_size)
+       base_type = int_type;
+      else
+       {
+         int_type = objfile_type (objfile)->builtin_long;
+         if (int_type && TYPE_LENGTH (int_type) >= addr_size)
+           base_type = int_type;
+         else
+           {
+             int_type = objfile_type (objfile)->builtin_long_long;
+             if (int_type && TYPE_LENGTH (int_type) >= addr_size)
+               base_type = int_type;
+           }
+       }
+    }
+
+  negative_mask =
     (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
   if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
     low |= negative_mask;
@@ -6140,16 +6439,19 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   name = dwarf2_name (die, cu);
   if (name)
     TYPE_NAME (range_type) = name;
-  
+
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr)
     TYPE_LENGTH (range_type) = DW_UNSND (attr);
 
+  set_die_type (die, range_type, cu);
+
+  /* set_die_type should be already done.  */
   set_descriptive_type (range_type, die, cu);
 
-  return set_die_type (die, range_type, cu);
+  return range_type;
 }
-  
+
 static struct type *
 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
 {
@@ -6170,6 +6472,7 @@ static hashval_t
 die_hash (const void *item)
 {
   const struct die_info *die = item;
+
   return die->offset;
 }
 
@@ -6181,6 +6484,7 @@ die_eq (const void *item_lhs, const void *item_rhs)
 {
   const struct die_info *die_lhs = item_lhs;
   const struct die_info *die_rhs = item_rhs;
+
   return die_lhs->offset == die_rhs->offset;
 }
 
@@ -6388,7 +6692,7 @@ dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
 
   allocated_attrs = ATTR_ALLOC_CHUNK;
   cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
-  
+
   /* loop until we reach an abbrev number of 0 */
   while (abbrev_number)
     {
@@ -6596,6 +6900,7 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
          && abbrev->tag != DW_TAG_lexical_block
          && abbrev->tag != DW_TAG_variable
          && abbrev->tag != DW_TAG_namespace
+         && abbrev->tag != DW_TAG_module
          && abbrev->tag != DW_TAG_member)
        {
          /* Otherwise we skip to the next sibling, if any.  */
@@ -6727,6 +7032,7 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
       if (last_die->has_children
          && (load_all
              || last_die->tag == DW_TAG_namespace
+             || last_die->tag == DW_TAG_module
              || last_die->tag == DW_TAG_enumeration_type
              || (cu->language != language_c
                  && (last_die->tag == DW_TAG_class_type
@@ -6758,7 +7064,7 @@ read_partial_die (struct partial_die_info *part_die,
                  gdb_byte *buffer, gdb_byte *info_ptr,
                  struct dwarf2_cu *cu)
 {
-  unsigned int bytes_read, i;
+  unsigned int i;
   struct attribute attr;
   int has_low_pc_attr = 0;
   int has_high_pc_attr = 0;
@@ -6803,7 +7109,11 @@ read_partial_die (struct partial_die_info *part_die,
              break;
            }
          break;
+       case DW_AT_linkage_name:
        case DW_AT_MIPS_linkage_name:
+         /* Note that both forms of linkage name might appear.  We
+            assume they will be the same, and we only store the last
+            one we see.  */
          if (cu->language == language_ada)
            part_die->name = DW_STRING (&attr);
          break;
@@ -7088,6 +7398,10 @@ read_attribute_value (struct attribute *attr, unsigned form,
       DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
       info_ptr += 8;
       break;
+    case DW_FORM_sec_offset:
+      DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
+      info_ptr += bytes_read;
+      break;
     case DW_FORM_string:
       DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
       DW_STRING_IS_CANONICAL (attr) = 0;
@@ -7099,6 +7413,7 @@ read_attribute_value (struct attribute *attr, unsigned form,
       DW_STRING_IS_CANONICAL (attr) = 0;
       info_ptr += bytes_read;
       break;
+    case DW_FORM_exprloc:
     case DW_FORM_block:
       blk = dwarf_alloc_block (cu);
       blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
@@ -7123,6 +7438,9 @@ read_attribute_value (struct attribute *attr, unsigned form,
       DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
       info_ptr += 1;
       break;
+    case DW_FORM_flag_present:
+      DW_UNSND (attr) = 1;
+      break;
     case DW_FORM_sdata:
       DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
       info_ptr += bytes_read;
@@ -7323,7 +7641,7 @@ read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
      from:
 
        http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
-     
+
      This document is only a draft and is subject to change.  (So beware.)
 
      Details regarding the older, non-standard 64-bit format were
@@ -7393,6 +7711,7 @@ read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
              unsigned int *bytes_read)
 {
   LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
+
   *bytes_read = cu_header->offset_size;
   return offset;
 }
@@ -7559,6 +7878,9 @@ set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
     case DW_LANG_C_plus_plus:
       cu->language = language_cplus;
       break;
+    case DW_LANG_D:
+      cu->language = language_d;
+      break;
     case DW_LANG_Fortran77:
     case DW_LANG_Fortran90:
     case DW_LANG_Fortran95:
@@ -7639,7 +7961,7 @@ dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
 
 /* Return non-zero iff the attribute NAME is defined for the given DIE,
    and holds a non-zero value.  This function should only be used for
-   DW_FORM_flag attributes.  */
+   DW_FORM_flag or DW_FORM_flag_present attributes.  */
 
 static int
 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
@@ -7726,7 +8048,7 @@ add_include_dir (struct line_header *lh, char *include_dir)
 
   lh->include_dirs[lh->num_include_dirs++] = include_dir;
 }
+
 
 /* Add an entry to LH's file name table.  */
 static void
@@ -7761,7 +8083,7 @@ add_file_name (struct line_header *lh,
   fe->included_p = 0;
   fe->symtab = NULL;
 }
+
 
 /* Read the statement program header starting at OFFSET in
    .debug_line, according to the endianness of ABFD.  Return a pointer
@@ -7804,7 +8126,7 @@ dwarf_decode_line_header (unsigned int offset, bfd *abfd,
   line_ptr = dwarf2_per_objfile->line.buffer + offset;
 
   /* Read in the header.  */
-  lh->total_length = 
+  lh->total_length =
     read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
                                            &bytes_read, &offset_size);
   line_ptr += bytes_read;
@@ -7821,6 +8143,21 @@ dwarf_decode_line_header (unsigned int offset, bfd *abfd,
   line_ptr += offset_size;
   lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
   line_ptr += 1;
+  if (lh->version >= 4)
+    {
+      lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
+      line_ptr += 1;
+    }
+  else
+    lh->maximum_ops_per_instruction = 1;
+
+  if (lh->maximum_ops_per_instruction == 0)
+    {
+      lh->maximum_ops_per_instruction = 1;
+      complaint (&symfile_complaints,
+                _("invalid maximum_ops_per_instruction in `.debug_line' section"));
+    }
+
   lh->default_is_stmt = read_1_byte (abfd, line_ptr);
   line_ptr += 1;
   lh->line_base = read_1_signed_byte (abfd, line_ptr);
@@ -7863,7 +8200,7 @@ dwarf_decode_line_header (unsigned int offset, bfd *abfd,
       add_file_name (lh, cur_file, dir_index, mod_time, length);
     }
   line_ptr += bytes_read;
-  lh->statement_program_start = line_ptr; 
+  lh->statement_program_start = line_ptr;
 
   if (line_ptr > (dwarf2_per_objfile->line.buffer
                  + dwarf2_per_objfile->line.size))
@@ -7928,7 +8265,7 @@ check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
       to create all necessary symbol tables, and their linetables.
       The compilation directory of the file is passed in COMP_DIR,
       and must not be NULL.
-   
+
    2. If PST is not NULL, this procedure reads the program to determine
       the list of files included by the unit represented by PST, and
       builds all the associated partial symbol tables.  In this case,
@@ -7969,6 +8306,7 @@ dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
       int basic_block = 0;
       int end_sequence = 0;
       CORE_ADDR addr;
+      unsigned char op_index = 0;
 
       if (!decode_for_pst_p && lh->num_file_names >= file)
        {
@@ -7997,15 +8335,20 @@ dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
             }
 
          if (op_code >= lh->opcode_base)
-           {           
+           {
              /* Special operand.  */
              adj_opcode = op_code - lh->opcode_base;
-             address += (adj_opcode / lh->line_range)
-               * lh->minimum_instruction_length;
+             address += (((op_index + (adj_opcode / lh->line_range))
+                          / lh->maximum_ops_per_instruction)
+                         * lh->minimum_instruction_length);
+             op_index = ((op_index + (adj_opcode / lh->line_range))
+                         % lh->maximum_ops_per_instruction);
              line += lh->line_base + (adj_opcode % lh->line_range);
              if (lh->num_file_names < file || file == 0)
                dwarf2_debug_line_missing_file_complaint ();
-             else
+             /* For now we ignore lines not starting on an
+                instruction boundary.  */
+             else if (op_index == 0)
                {
                  lh->file_names[file - 1].included_p = 1;
                  if (!decode_for_pst_p && is_stmt)
@@ -8040,6 +8383,7 @@ dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
                  break;
                case DW_LNE_set_address:
                  address = read_address (abfd, line_ptr, cu, &bytes_read);
+                 op_index = 0;
                  line_ptr += bytes_read;
                  address += baseaddr;
                  break;
@@ -8047,7 +8391,7 @@ dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
                   {
                     char *cur_file;
                     unsigned int dir_index, mod_time, length;
-                    
+
                     cur_file = read_string (abfd, line_ptr, &bytes_read);
                     line_ptr += bytes_read;
                     dir_index =
@@ -8105,9 +8449,17 @@ dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
              basic_block = 0;
              break;
            case DW_LNS_advance_pc:
-             address += lh->minimum_instruction_length
-               * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
-             line_ptr += bytes_read;
+             {
+               CORE_ADDR adjust
+                 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+
+               address += (((op_index + adjust)
+                            / lh->maximum_ops_per_instruction)
+                           * lh->minimum_instruction_length);
+               op_index = ((op_index + adjust)
+                           % lh->maximum_ops_per_instruction);
+               line_ptr += bytes_read;
+             }
              break;
            case DW_LNS_advance_line:
              line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
@@ -8154,11 +8506,19 @@ dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
               instruction length since special opcode 255 would have
               scaled the the increment.  */
            case DW_LNS_const_add_pc:
-             address += (lh->minimum_instruction_length
-                         * ((255 - lh->opcode_base) / lh->line_range));
+             {
+               CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
+
+               address += (((op_index + adjust)
+                            / lh->maximum_ops_per_instruction)
+                           * lh->minimum_instruction_length);
+               op_index = ((op_index + adjust)
+                           % lh->maximum_ops_per_instruction);
+             }
              break;
            case DW_LNS_fixed_advance_pc:
              address += read_2_bytes (abfd, line_ptr);
+             op_index = 0;
              line_ptr += 2;
              break;
            default:
@@ -8234,6 +8594,7 @@ dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
       for (i = 0; i < lh->num_file_names; i++)
        {
          char *dir = NULL;
+
          fe = &lh->file_names[i];
          if (fe->dir_index)
            dir = lh->include_dirs[fe->dir_index - 1];
@@ -8393,6 +8754,13 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
       linkagename = dwarf2_physname (name, die, cu);
       SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
 
+      /* Fortran does not have mangling standard and the mangling does differ
+        between gfortran, iFort etc.  */
+      if (cu->language == language_fortran
+          && sym->ginfo.language_specific.cplus_specific.demangled_name == NULL)
+       sym->ginfo.language_specific.cplus_specific.demangled_name
+         = (char *) dwarf2_full_name (name, die, cu);
+
       /* Default assumptions.
          Use the passed type or decode it from the die.  */
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
@@ -8415,6 +8783,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
       if (attr)
        {
          int file_index = DW_UNSND (attr);
+
          if (cu->line_header == NULL
              || file_index > cu->line_header->num_file_names)
            complaint (&symfile_complaints,
@@ -8422,6 +8791,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
          else if (file_index > 0)
            {
              struct file_entry *fe;
+
              fe = &cu->line_header->file_names[file_index - 1];
              SYMBOL_SYMTAB (sym) = fe->symtab;
            }
@@ -8467,6 +8837,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
             BLOCK_FUNCTION from the blockvector.  */
          break;
        case DW_TAG_variable:
+       case DW_TAG_member:
          /* Compilation with minimal debug info may result in variables
             with missing type entries. Change the misleading `void' type
             to something sensible.  */
@@ -8475,6 +8846,17 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
              = objfile_type (objfile)->nodebug_data_symbol;
 
          attr = dwarf2_attr (die, DW_AT_const_value, cu);
+         /* In the case of DW_TAG_member, we should only be called for
+            static const members.  */
+         if (die->tag == DW_TAG_member)
+           {
+             /* NOTE: This test seems wrong according to the dwarf standard.
+                static data members are represented by DW_AT_external.
+                However, dwarf2_add_field is currently calling
+                die_is_declaration to check, so we do the same.  */
+             gdb_assert (die_is_declaration (die, cu));
+             gdb_assert (attr);
+           }
          if (attr)
            {
              dwarf2_const_value (attr, sym, cu);
@@ -8494,6 +8876,20 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
                {
                  struct pending **list_to_add;
 
+                 /* Workaround gfortran PR debug/40040 - it uses
+                    DW_AT_location for variables in -fPIC libraries which may
+                    get overriden by other libraries/executable and get
+                    a different address.  Resolve it by the minimal symbol
+                    which may come from inferior's executable using copy
+                    relocation.  Make this workaround only for gfortran as for
+                    other compilers GDB cannot guess the minimal symbol
+                    Fortran mangling kind.  */
+                 if (cu->language == language_fortran && die->parent
+                     && die->parent->tag == DW_TAG_module
+                     && cu->producer
+                     && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
+                   SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
+
                  /* A variable with DW_AT_external is never static,
                     but it may be block-scoped.  */
                  list_to_add = (cu->list_in_scope == &file_symbols
@@ -8552,6 +8948,15 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
            {
              dwarf2_const_value (attr, sym, cu);
            }
+         attr = dwarf2_attr (die, DW_AT_variable_parameter, cu);
+         if (attr && DW_UNSND (attr))
+           {
+             struct type *ref_type;
+
+             ref_type = lookup_reference_type (SYMBOL_TYPE (sym));
+             SYMBOL_TYPE (sym) = ref_type;
+           }
+
          add_symbol_to_list (sym, cu->list_in_scope);
          break;
        case DW_TAG_unspecified_parameters:
@@ -8568,28 +8973,6 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
          SYMBOL_CLASS (sym) = LOC_TYPEDEF;
          SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
 
-         /* Make sure that the symbol includes appropriate enclosing
-            classes/namespaces in its name.  These are calculated in
-            read_structure_type, and the correct name is saved in
-            the type.  */
-
-         if (cu->language == language_cplus
-             || cu->language == language_java)
-           {
-             struct type *type = SYMBOL_TYPE (sym);
-             
-             if (TYPE_TAG_NAME (type) != NULL)
-               {
-                 /* FIXME: carlton/2003-11-10: Should this use
-                    SYMBOL_SET_NAMES instead?  (The same problem also
-                    arises further down in this function.)  */
-                 /* The type's name is already allocated along with
-                    this objfile, so we don't need to duplicate it
-                    for the symbol.  */
-                 SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type);
-               }
-           }
-
          {
            /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
               really ever be static objects: otherwise, if you try
@@ -8605,7 +8988,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
                           && (cu->language == language_cplus
                               || cu->language == language_java)
                           ? &global_symbols : cu->list_in_scope);
-         
+
            add_symbol_to_list (sym, list_to_add);
 
            /* The semantics of C++ state that "struct foo { ... }" also
@@ -8624,21 +9007,19 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
          }
          break;
        case DW_TAG_typedef:
-         SYMBOL_LINKAGE_NAME (sym)
-           = (char *) dwarf2_full_name (name, die, cu);
          SYMBOL_CLASS (sym) = LOC_TYPEDEF;
          SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
          add_symbol_to_list (sym, cu->list_in_scope);
          break;
        case DW_TAG_base_type:
         case DW_TAG_subrange_type:
+        case DW_TAG_const_type:
+        case DW_TAG_volatile_type:
          SYMBOL_CLASS (sym) = LOC_TYPEDEF;
          SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
          add_symbol_to_list (sym, cu->list_in_scope);
          break;
        case DW_TAG_enumerator:
-         SYMBOL_LINKAGE_NAME (sym)
-           = (char *) dwarf2_full_name (name, die, cu);
          attr = dwarf2_attr (die, DW_AT_const_value, cu);
          if (attr)
            {
@@ -8654,7 +9035,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
                           && (cu->language == language_cplus
                               || cu->language == language_java)
                           ? &global_symbols : cu->list_in_scope);
-         
+
            add_symbol_to_list (sym, list_to_add);
          }
          break;
@@ -8701,7 +9082,7 @@ dwarf2_const_value (struct attribute *attr, struct symbol *sym,
                                                      cu_header->addr_size,
                                                      TYPE_LENGTH (SYMBOL_TYPE
                                                                   (sym)));
-      SYMBOL_VALUE_BYTES (sym) = 
+      SYMBOL_VALUE_BYTES (sym) =
        obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
       /* NOTE: cagney/2003-05-09: In-lined store_address call with
          it's body - store_unsigned_integer.  */
@@ -8720,6 +9101,7 @@ dwarf2_const_value (struct attribute *attr, struct symbol *sym,
     case DW_FORM_block2:
     case DW_FORM_block4:
     case DW_FORM_block:
+    case DW_FORM_exprloc:
       blk = DW_BLOCK (attr);
       if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
        dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
@@ -8798,7 +9180,6 @@ dwarf2_const_value_data (struct attribute *attr,
 static struct type *
 die_type (struct die_info *die, struct dwarf2_cu *cu)
 {
-  struct type *type;
   struct attribute *type_attr;
   struct die_info *type_die;
 
@@ -8811,14 +9192,7 @@ die_type (struct die_info *die, struct dwarf2_cu *cu)
 
   type_die = follow_die_ref_or_sig (die, type_attr, &cu);
 
-  type = tag_type_to_type (type_die, cu);
-  if (!type)
-    {
-      dump_die_for_error (type_die);
-      error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
-                     cu->objfile->name);
-    }
-  return type;
+  return tag_type_to_type (type_die, cu);
 }
 
 /* True iff CU's producer generates GNAT Ada auxiliary information
@@ -8847,7 +9221,6 @@ need_gnat_info (struct dwarf2_cu *cu)
 static struct type *
 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
 {
-  struct type *type;
   struct attribute *type_attr;
   struct die_info *type_die;
 
@@ -8856,14 +9229,7 @@ die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
     return NULL;
 
   type_die = follow_die_ref (die, type_attr, &cu);
-  type = tag_type_to_type (type_die, cu);
-  if (!type)
-    {
-      dump_die_for_error (type_die);
-      error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
-                     cu->objfile->name);
-    }
-  return type;
+  return tag_type_to_type (type_die, cu);
 }
 
 /* If DIE has a descriptive_type attribute, then set the TYPE's
@@ -8888,24 +9254,16 @@ set_descriptive_type (struct type *type, struct die_info *die,
 static struct type *
 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
 {
-  struct type *type = NULL;
   struct attribute *type_attr;
-  struct die_info *type_die = NULL;
+  struct die_info *type_die;
 
   type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
-  if (type_attr)
-    {
-      type_die = follow_die_ref_or_sig (die, type_attr, &cu);
-      type = tag_type_to_type (type_die, cu);
-    }
-  if (!type)
-    {
-      if (type_die)
-       dump_die_for_error (type_die);
-      error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"), 
-                     cu->objfile->name);
-    }
-  return type;
+  if (!type_attr)
+    error (_("Dwarf Error: Problem turning containing type into gdb type "
+            "[in module %s]"), cu->objfile->name);
+
+  type_die = follow_die_ref_or_sig (die, type_attr, &cu);
+  return tag_type_to_type (type_die, cu);
 }
 
 static struct type *
@@ -8916,9 +9274,18 @@ tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
   this_type = read_type_die (die, cu);
   if (!this_type)
     {
-      dump_die_for_error (die);
-      error (_("Dwarf Error: Cannot find type of die [in module %s]"), 
-            cu->objfile->name);
+      char *message, *saved;
+
+      /* read_type_die already issued a complaint.  */
+      message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
+                           cu->objfile->name,
+                           cu->header.offset,
+                           die->offset);
+      saved = obstack_copy0 (&cu->objfile->objfile_obstack,
+                            message, strlen (message));
+      xfree (message);
+
+      this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
     }
   return this_type;
 }
@@ -8987,6 +9354,9 @@ read_type_die (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_namespace:
       this_type = read_namespace_type (die, cu);
       break;
+    case DW_TAG_module:
+      this_type = read_module_type (die, cu);
+      break;
     default:
       complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
                 dwarf_tag_name (die->tag));
@@ -9018,8 +9388,8 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
   struct dwarf2_cu *spec_cu;
   struct type *parent_type;
 
-  if (cu->language != language_cplus
-      && cu->language != language_java)
+  if (cu->language != language_cplus && cu->language != language_java
+      && cu->language != language_fortran)
     return "";
 
   /* We have to be careful in the presence of DW_AT_specification.
@@ -9071,6 +9441,7 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
       case DW_TAG_interface_type:
       case DW_TAG_structure_type:
       case DW_TAG_union_type:
+      case DW_TAG_module:
        parent_type = read_type_die (parent, cu);
        if (TYPE_TAG_NAME (parent_type) != NULL)
          return TYPE_TAG_NAME (parent_type);
@@ -9090,18 +9461,27 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
    perform an obconcat, otherwise allocate storage for the result.  The CU argument
    is used to determine the language and hence, the appropriate separator.  */
 
-#define MAX_SEP_LEN 2  /* sizeof ("::")  */
+#define MAX_SEP_LEN 7  /* strlen ("__") + strlen ("_MOD_")  */
 
 static char *
-typename_concat (struct obstack *obs, const char *prefix, const char *suffix, 
-                struct dwarf2_cu *cu)
+typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
+                 int physname, struct dwarf2_cu *cu)
 {
-  char *sep;
+  const char *lead = "";
+  const char *sep;
 
   if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
     sep = "";
   else if (cu->language == language_java)
     sep = ".";
+  else if (cu->language == language_fortran && physname)
+    {
+      /* This is gfortran specific mangling.  Normally DW_AT_linkage_name or
+        DW_AT_MIPS_linkage_name is preferred and used instead.  */
+
+      lead = "__";
+      sep = "_MOD_";
+    }
   else
     sep = "::";
 
@@ -9113,7 +9493,9 @@ typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
   if (obs == NULL)
     {
       char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
-      strcpy (retval, prefix);
+
+      strcpy (retval, lead);
+      strcat (retval, prefix);
       strcat (retval, sep);
       strcat (retval, suffix);
       return retval;
@@ -9121,7 +9503,7 @@ typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
   else
     {
       /* We have an obstack.  */
-      return obconcat (obs, prefix, sep, suffix);
+      return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
     }
 }
 
@@ -9176,16 +9558,61 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
       /* These tags always have simple identifiers already; no need
         to canonicalize them.  */
       return DW_STRING (attr);
-    default:
-      if (!DW_STRING_IS_CANONICAL (attr))
+
+    case DW_TAG_subprogram:
+      /* Java constructors will all be named "<init>", so return
+        the class name when we see this special case.  */
+      if (cu->language == language_java
+         && DW_STRING (attr) != NULL
+         && strcmp (DW_STRING (attr), "<init>") == 0)
        {
-         DW_STRING (attr)
-           = dwarf2_canonicalize_name (DW_STRING (attr), cu,
-                                       &cu->objfile->objfile_obstack);
-         DW_STRING_IS_CANONICAL (attr) = 1;
+         struct dwarf2_cu *spec_cu = cu;
+         struct die_info *spec_die;
+
+         /* GCJ will output '<init>' for Java constructor names.
+            For this special case, return the name of the parent class.  */
+
+         /* GCJ may output suprogram DIEs with AT_specification set.
+            If so, use the name of the specified DIE.  */
+         spec_die = die_specification (die, &spec_cu);
+         if (spec_die != NULL)
+           return dwarf2_name (spec_die, spec_cu);
+
+         do
+           {
+             die = die->parent;
+             if (die->tag == DW_TAG_class_type)
+               return dwarf2_name (die, cu);
+           }
+         while (die->tag != DW_TAG_compile_unit);
        }
-      return DW_STRING (attr);
+      break;
+
+    case DW_TAG_class_type:
+    case DW_TAG_interface_type:
+    case DW_TAG_structure_type:
+    case DW_TAG_union_type:
+      /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
+        structures or unions.  These were of the form "._%d" in GCC 4.1,
+        or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
+        and GCC 4.4.  We work around this problem by ignoring these.  */
+      if (strncmp (DW_STRING (attr), "._", 2) == 0
+         || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)
+       return NULL;
+      break;
+
+    default:
+      break;
     }
+
+  if (!DW_STRING_IS_CANONICAL (attr))
+    {
+      DW_STRING (attr)
+       = dwarf2_canonicalize_name (DW_STRING (attr), cu,
+                                   &cu->objfile->objfile_obstack);
+      DW_STRING_IS_CANONICAL (attr) = 1;
+    }
+  return DW_STRING (attr);
 }
 
 /* Return the die that this die in an extension of, or NULL if there
@@ -9547,6 +9974,8 @@ dwarf_attr_name (unsigned attr)
     /* DWARF 4 values.  */
     case DW_AT_signature:
       return "DW_AT_signature";
+    case DW_AT_linkage_name:
+      return "DW_AT_linkage_name";
     /* SGI/MIPS extensions.  */
 #ifdef MIPS /* collides with DW_AT_HP_block_index */
     case DW_AT_MIPS_fde:
@@ -9700,8 +10129,8 @@ dwarf_form_name (unsigned form)
 
 /* Convert a DWARF stack opcode into its string name.  */
 
-static char *
-dwarf_stack_op_name (unsigned op)
+const char *
+dwarf_stack_op_name (unsigned op, int def)
 {
   switch (op)
     {
@@ -10004,32 +10433,24 @@ dwarf_stack_op_name (unsigned op)
       return "DW_OP_call4";
     case DW_OP_call_ref:
       return "DW_OP_call_ref";
-    /* GNU extensions.  */
     case DW_OP_form_tls_address:
       return "DW_OP_form_tls_address";
     case DW_OP_call_frame_cfa:
       return "DW_OP_call_frame_cfa";
     case DW_OP_bit_piece:
       return "DW_OP_bit_piece";
+    /* DWARF 4 extensions.  */
+    case DW_OP_implicit_value:
+      return "DW_OP_implicit_value";
+    case DW_OP_stack_value:
+      return "DW_OP_stack_value";
+    /* GNU extensions.  */
     case DW_OP_GNU_push_tls_address:
       return "DW_OP_GNU_push_tls_address";
     case DW_OP_GNU_uninit:
       return "DW_OP_GNU_uninit";
-    /* HP extensions. */ 
-    case DW_OP_HP_is_value:
-      return "DW_OP_HP_is_value";
-    case DW_OP_HP_fltconst4:
-      return "DW_OP_HP_fltconst4";
-    case DW_OP_HP_fltconst8:
-      return "DW_OP_HP_fltconst8";
-    case DW_OP_HP_mod_range:
-      return "DW_OP_HP_mod_range";
-    case DW_OP_HP_unmod_range:
-      return "DW_OP_HP_unmod_range";
-    case DW_OP_HP_tls:
-      return "DW_OP_HP_tls";
     default:
-      return "OP_<unknown>";
+      return def ? "OP_<unknown>" : NULL;
     }
 }
 
@@ -10082,6 +10503,9 @@ dwarf_type_encoding_name (unsigned enc)
       return "DW_ATE_unsigned_fixed";
     case DW_ATE_decimal_float:
       return "DW_ATE_decimal_float";
+    /* DWARF 4.  */
+    case DW_ATE_UTF:
+      return "DW_ATE_UTF";
     /* HP extensions.  */
     case DW_ATE_HP_float80:
       return "DW_ATE_HP_float80";
@@ -10222,6 +10646,10 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
        case DW_FORM_block1:
          fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
          break;
+       case DW_FORM_exprloc:
+         fprintf_unfiltered (f, "expression: size %u",
+                             DW_BLOCK (&die->attrs[i])->size);
+         break;
        case DW_FORM_ref1:
        case DW_FORM_ref2:
        case DW_FORM_ref4:
@@ -10237,6 +10665,10 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
          fprintf_unfiltered (f, "constant: %s",
                              pulongest (DW_UNSND (&die->attrs[i])));
          break;
+       case DW_FORM_sec_offset:
+         fprintf_unfiltered (f, "section offset: %s",
+                             pulongest (DW_UNSND (&die->attrs[i])));
+         break;
        case DW_FORM_sig8:
          if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
            fprintf_unfiltered (f, "signatured type, offset: 0x%x",
@@ -10257,6 +10689,9 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
          else
            fprintf_unfiltered (f, "flag: FALSE");
          break;
+       case DW_FORM_flag_present:
+         fprintf_unfiltered (f, "flag: TRUE");
+         break;
        case DW_FORM_indirect:
          /* the reader will have reduced the indirect form to
             the "base form" so this form should not occur */
@@ -10435,35 +10870,31 @@ follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
   return die;
 }
 
-/* Follow reference attribute ATTR of SRC_DIE.
-   On entry *REF_CU is the CU of SRC_DIE.
+/* Follow reference OFFSET.
+   On entry *REF_CU is the CU of source DIE referencing OFFSET.
    On exit *REF_CU is the CU of the result.  */
 
 static struct die_info *
-follow_die_ref (struct die_info *src_die, struct attribute *attr,
-               struct dwarf2_cu **ref_cu)
+follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
 {
-  struct die_info *die;
-  unsigned int offset;
   struct die_info temp_die;
   struct dwarf2_cu *target_cu, *cu = *ref_cu;
 
   gdb_assert (cu->per_cu != NULL);
 
-  offset = dwarf2_get_ref_die_offset (attr);
-
   if (cu->per_cu->from_debug_types)
     {
       /* .debug_types CUs cannot reference anything outside their CU.
         If they need to, they have to reference a signatured type via
         DW_FORM_sig8.  */
       if (! offset_in_cu_p (&cu->header, offset))
-       goto not_found;
+       return NULL;
       target_cu = cu;
     }
   else if (! offset_in_cu_p (&cu->header, offset))
     {
       struct dwarf2_per_cu_data *per_cu;
+
       per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
 
       /* If necessary, add it to the queue and load its DIEs.  */
@@ -10477,15 +10908,67 @@ follow_die_ref (struct die_info *src_die, struct attribute *attr,
 
   *ref_cu = target_cu;
   temp_die.offset = offset;
-  die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
-  if (die)
-    return die;
+  return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
+}
 
- not_found:
+/* Follow reference attribute ATTR of SRC_DIE.
+   On entry *REF_CU is the CU of SRC_DIE.
+   On exit *REF_CU is the CU of the result.  */
 
-  error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
-        "at 0x%x [in module %s]"),
-        offset, src_die->offset, cu->objfile->name);
+static struct die_info *
+follow_die_ref (struct die_info *src_die, struct attribute *attr,
+               struct dwarf2_cu **ref_cu)
+{
+  unsigned int offset = dwarf2_get_ref_die_offset (attr);
+  struct dwarf2_cu *cu = *ref_cu;
+  struct die_info *die;
+
+  die = follow_die_offset (offset, ref_cu);
+  if (!die)
+    error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
+          "at 0x%x [in module %s]"),
+          offset, src_die->offset, cu->objfile->name);
+
+  return die;
+}
+
+/* Return DWARF block and its CU referenced by OFFSET at PER_CU.  Returned
+   value is intended for DW_OP_call*.  */
+
+struct dwarf2_locexpr_baton
+dwarf2_fetch_die_location_block (unsigned int offset,
+                                struct dwarf2_per_cu_data *per_cu)
+{
+  struct dwarf2_cu *cu = per_cu->cu;
+  struct die_info *die;
+  struct attribute *attr;
+  struct dwarf2_locexpr_baton retval;
+
+  die = follow_die_offset (offset, &cu);
+  if (!die)
+    error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
+          offset, per_cu->cu->objfile->name);
+
+  attr = dwarf2_attr (die, DW_AT_location, cu);
+  if (!attr)
+    {
+      /* DWARF: "If there is no such attribute, then there is no effect.".  */
+
+      retval.data = NULL;
+      retval.size = 0;
+    }
+  else
+    {
+      if (!attr_form_is_block (attr))
+       error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
+                "is neither DW_FORM_block* nor DW_FORM_exprloc"),
+              offset, per_cu->cu->objfile->name);
+
+      retval.data = DW_BLOCK (attr)->data;
+      retval.size = DW_BLOCK (attr)->size;
+    }
+  retval.per_cu = cu->per_cu;
+  return retval;
 }
 
 /* Follow the signature attribute ATTR in SRC_DIE.
@@ -10669,7 +11152,6 @@ static CORE_ADDR
 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
-  struct comp_unit_head *cu_header = &cu->header;
   int i;
   int size = blk->size;
   gdb_byte *data = blk->data;
@@ -10859,7 +11341,7 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
 
        default:
          complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
-                    dwarf_stack_op_name (op));
+                    dwarf_stack_op_name (op, 1));
          return (stack[stacki]);
        }
     }
@@ -10919,7 +11401,7 @@ file_full_name (int file, struct line_header *lh, const char *comp_dir)
   if (1 <= file && file <= lh->num_file_names)
     {
       struct file_entry *fe = &lh->file_names[file - 1];
-  
+
       if (IS_ABSOLUTE_PATH (fe->name))
         return xstrdup (fe->name);
       else
@@ -10952,9 +11434,10 @@ file_full_name (int file, struct line_header *lh, const char *comp_dir)
          record the macro definitions made in the file, even if we
          won't be able to find the file by name.  */
       char fake_name[80];
+
       sprintf (fake_name, "<bad macro file number %d>", file);
 
-      complaint (&symfile_complaints, 
+      complaint (&symfile_complaints,
                  _("bad file number in macro information (%d)"),
                  file);
 
@@ -10986,7 +11469,7 @@ macro_start_file (int file, int line,
     current_file = macro_include (current_file, line, full_name);
 
   xfree (full_name);
-              
+
   return current_file;
 }
 
@@ -10997,9 +11480,9 @@ static char *
 copy_string (const char *buf, int len)
 {
   char *s = xmalloc (len + 1);
+
   memcpy (s, buf, len);
   s[len] = '\0';
-
   return s;
 }
 
@@ -11043,7 +11526,7 @@ parse_macro_definition (struct macro_source_file *file, int line,
 
      The Dwarf 2 spec says that an object-like macro's name is always
      followed by a space, but versions of GCC around March 2002 omit
-     the space when the macro's definition is the empty string. 
+     the space when the macro's definition is the empty string.
 
      The Dwarf 2 spec says that there should be no spaces between the
      formal arguments in a function-like macro's formal argument list,
@@ -11072,7 +11555,7 @@ parse_macro_definition (struct macro_source_file *file, int line,
          dwarf2_macro_malformed_definition_complaint (body);
           replacement = body + name_len;
         }
-      
+
       macro_define_object (file, line, name, replacement);
 
       xfree (name);
@@ -11130,14 +11613,14 @@ parse_macro_definition (struct macro_source_file *file, int line,
           if (*p == ' ')
             /* Perfectly formed definition, no complaints.  */
             macro_define_function (file, line, name,
-                                   argc, (const char **) argv, 
+                                   argc, (const char **) argv,
                                    p + 1);
           else if (*p == '\0')
             {
               /* Complain, but do define it.  */
              dwarf2_macro_malformed_definition_complaint (body);
               macro_define_function (file, line, name,
-                                     argc, (const char **) argv, 
+                                     argc, (const char **) argv,
                                      p);
             }
           else
@@ -11318,8 +11801,8 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
                complaint (&symfile_complaints,
                           _("debug info with no main source gives macro %s "
                             "on line %d: %s"),
-                          macinfo_type == DW_MACINFO_define ? 
-                            _("definition") : 
+                          macinfo_type == DW_MACINFO_define ?
+                            _("definition") :
                               macinfo_type == DW_MACINFO_undef ?
                                 _("undefinition") :
                                 _("something-or-other"), line, body);
@@ -11330,7 +11813,7 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
                         _("debug info gives %s macro %s with %s line %d: %s"),
                         at_commandline ? _("command-line") : _("in-file"),
                         macinfo_type == DW_MACINFO_define ?
-                          _("definition") : 
+                          _("definition") :
                             macinfo_type == DW_MACINFO_undef ?
                               _("undefinition") :
                               _("something-or-other"),
@@ -11434,7 +11917,8 @@ attr_form_is_block (struct attribute *attr)
       attr->form == DW_FORM_block1
       || attr->form == DW_FORM_block2
       || attr->form == DW_FORM_block4
-      || attr->form == DW_FORM_block);
+      || attr->form == DW_FORM_block
+      || attr->form == DW_FORM_exprloc);
 }
 
 /* Return non-zero if ATTR's value is a section offset --- classes
@@ -11449,7 +11933,8 @@ static int
 attr_form_is_section_offset (struct attribute *attr)
 {
   return (attr->form == DW_FORM_data4
-          || attr->form == DW_FORM_data8);
+          || attr->form == DW_FORM_data8
+         || attr->form == DW_FORM_sec_offset);
 }
 
 
@@ -11540,7 +12025,7 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
          baton->size = 0;
          baton->data = NULL;
        }
-      
+
       SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
       SYMBOL_LOCATION_BATON (sym) = baton;
     }
@@ -11575,14 +12060,36 @@ dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
       struct dwarf2_per_objfile *per_objfile
        = objfile_data (objfile, dwarf2_objfile_data_key);
       gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
-
       struct comp_unit_head cu_header;
+
       memset (&cu_header, 0, sizeof cu_header);
       read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
       return cu_header.addr_size;
     }
 }
 
+/* Return the offset size given in the compilation unit header for CU.  */
+
+int
+dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
+{
+  if (per_cu->cu)
+    return per_cu->cu->header.offset_size;
+  else
+    {
+      /* If the CU is not currently read in, we re-read its header.  */
+      struct objfile *objfile = per_cu->psymtab->objfile;
+      struct dwarf2_per_objfile *per_objfile
+       = objfile_data (objfile, dwarf2_objfile_data_key);
+      gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
+      struct comp_unit_head cu_header;
+
+      memset (&cu_header, 0, sizeof cu_header);
+      read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
+      return cu_header.offset_size;
+    }
+}
+
 /* Locate the .debug_info compilation unit from CU's objfile which contains
    the DIE at OFFSET.  Raises an error on failure.  */
 
@@ -11598,6 +12105,7 @@ dwarf2_find_containing_comp_unit (unsigned int offset,
   while (high > low)
     {
       int mid = low + (high - low) / 2;
+
       if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
        high = mid;
       else
@@ -11632,6 +12140,7 @@ static struct dwarf2_per_cu_data *
 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
 {
   struct dwarf2_per_cu_data *this_cu;
+
   this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
   if (this_cu->offset != offset)
     error (_("no compilation unit with offset %u."), offset);
@@ -11817,6 +12326,7 @@ static hashval_t
 offset_and_type_hash (const void *item)
 {
   const struct dwarf2_offset_and_type *ofs = item;
+
   return ofs->offset;
 }
 
@@ -11827,11 +12337,27 @@ offset_and_type_eq (const void *item_lhs, const void *item_rhs)
 {
   const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
   const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
+
   return ofs_lhs->offset == ofs_rhs->offset;
 }
 
 /* Set the type associated with DIE to TYPE.  Save it in CU's hash
-   table if necessary.  For convenience, return TYPE.  */
+   table if necessary.  For convenience, return TYPE.
+
+   The DIEs reading must have careful ordering to:
+    * Not cause infite loops trying to read in DIEs as a prerequisite for
+      reading current DIE.
+    * Not trying to dereference contents of still incompletely read in types
+      while reading in other DIEs.
+    * Enable referencing still incompletely read in types just by a pointer to
+      the type without accessing its fields.
+
+   Therefore caller should follow these rules:
+     * Try to fetch any prerequisite types we may need to build this DIE type
+       before building the type and calling set_die_type.
+     * After building typer call set_die_type for current DIE as soon as
+       possible before fetching more types to complete the current type.
+     * Make the type as complete as possible before fetching more types.  */
 
 static struct type *
 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
@@ -11869,6 +12395,10 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
   ofs.type = type;
   slot = (struct dwarf2_offset_and_type **)
     htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT);
+  if (*slot)
+    complaint (&symfile_complaints,
+              _("A problem internal to GDB: DIE 0x%x has type already set"),
+              die->offset);
   *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot));
   **slot = ofs;
   return type;
@@ -11964,6 +12494,7 @@ static hashval_t
 partial_die_hash (const void *item)
 {
   const struct partial_die_info *part_die = item;
+
   return part_die->offset;
 }
 
@@ -11975,6 +12506,7 @@ partial_die_eq (const void *item_lhs, const void *item_rhs)
 {
   const struct partial_die_info *part_die_lhs = item_lhs;
   const struct partial_die_info *part_die_rhs = item_rhs;
+
   return part_die_lhs->offset == part_die_rhs->offset;
 }
 
@@ -11989,7 +12521,7 @@ set_dwarf2_cmd (char *args, int from_tty)
 
 static void
 show_dwarf2_cmd (char *args, int from_tty)
-{ 
+{
   cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
 }
 
@@ -12004,6 +12536,7 @@ munmap_section_buffer (struct dwarf2_section_info *info)
       intptr_t begin = (intptr_t) info->buffer;
       intptr_t map_begin = begin & ~(pagesize - 1);
       size_t map_length = info->size + begin - map_begin;
+
       gdb_assert (munmap ((void *) map_begin, map_length) == 0);
 #else
       /* Without HAVE_MMAP, we should never be here to begin with.  */
@@ -12018,6 +12551,7 @@ static void
 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
 {
   struct dwarf2_per_objfile *data = d;
+
   munmap_section_buffer (&data->info);
   munmap_section_buffer (&data->abbrev);
   munmap_section_buffer (&data->line);
@@ -12029,6 +12563,17 @@ dwarf2_per_objfile_free (struct objfile *objfile, void *d)
   munmap_section_buffer (&data->eh_frame);
 }
 
+int dwarf2_always_disassemble;
+
+static void
+show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
+                               struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("\
+Whether to always disassemble DWARF expressions is %s.\n"),
+                   value);
+}
+
 void _initialize_dwarf2_read (void);
 
 void
@@ -12061,6 +12606,18 @@ caching, which can slow down startup."),
                            &set_dwarf2_cmdlist,
                            &show_dwarf2_cmdlist);
 
+  add_setshow_boolean_cmd ("always-disassemble", class_obscure,
+                          &dwarf2_always_disassemble, _("\
+Set whether `info address' always disassembles DWARF expressions."), _("\
+Show whether `info address' always disassembles DWARF expressions."), _("\
+When enabled, DWARF expressions are always printed in an assembly-like\n\
+syntax.  When disabled, expressions will be printed in a more\n\
+conversational style, when possible."),
+                          NULL,
+                          show_dwarf2_always_disassemble,
+                          &set_dwarf2_cmdlist,
+                          &show_dwarf2_cmdlist);
+
   add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
 Set debugging of the dwarf2 DIE reader."), _("\
 Show debugging of the dwarf2 DIE reader."), _("\
This page took 0.060685 seconds and 4 git commands to generate.