* dwarf2read.c (dwarf2_per_cu_addr_size): Make result type an int.
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index 65317d482c1738a4b9666f0606bbf25a7b617c55..6f72bb9f731a96bde6c4135a1bcec701d93246b7 100644 (file)
@@ -1,8 +1,6 @@
 /* DWARF 2 debugging format support for GDB.
 
-   Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-                 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
-                 Free Software Foundation, Inc.
+   Copyright (C) 1994-2012 Free Software Foundation, Inc.
 
    Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
    Inc.  with support from Florida State University (under contract
@@ -34,6 +32,7 @@
 #include "dwarf2.h"
 #include "buildsym.h"
 #include "demangle.h"
+#include "gdb-demangle.h"
 #include "expression.h"
 #include "filenames.h" /* for DOSish file names */
 #include "macrotab.h"
 typedef struct symbol *symbolp;
 DEF_VEC_P (symbolp);
 
-#if 0
-/* .debug_info header for a compilation unit
-   Because of alignment constraints, this structure has padding and cannot
-   be mapped directly onto the beginning of the .debug_info section.  */
-typedef struct comp_unit_header
-  {
-    unsigned int length;       /* length of the .debug_info
-                                  contribution */
-    unsigned short version;    /* version number -- 2 for DWARF
-                                  version 2 */
-    unsigned int abbrev_offset;        /* offset into .debug_abbrev section */
-    unsigned char addr_size;   /* byte size of an address -- 4 */
-  }
-_COMP_UNIT_HEADER;
-#define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
-#endif
-
 /* .debug_line statement program prologue
    Because of alignment constraints, this structure has padding and cannot
    be mapped directly onto the beginning of the .debug_info section.  */
@@ -119,6 +101,9 @@ _STATEMENT_PROLOGUE;
 /* When non-zero, dump DIEs after they are read in.  */
 static int dwarf2_die_debug = 0;
 
+/* When non-zero, cross-check physname against demangler.  */
+static int check_physname = 0;
+
 static int pagesize;
 
 /* When set, the file that we're processing is known to have debugging
@@ -134,11 +119,17 @@ struct dwarf2_section_info
   asection *asection;
   gdb_byte *buffer;
   bfd_size_type size;
-  int was_mmapped;
+  /* Not NULL if the section was actually mmapped.  */
+  void *map_addr;
+  /* Page aligned size of mmapped area.  */
+  bfd_size_type map_len;
   /* True if we have tried to read this section.  */
   int readin;
 };
 
+typedef struct dwarf2_section_info dwarf2_section_info_def;
+DEF_VEC_O (dwarf2_section_info_def);
+
 /* All offsets in the index are of this type.  It must be
    architecture-independent.  */
 typedef uint32_t offset_type;
@@ -171,6 +162,9 @@ struct mapped_index
   const char *constant_pool;
 };
 
+/* Collection of data recorded per objfile.
+   This hangs off of dwarf2_objfile_data_key.  */
+
 struct dwarf2_per_objfile
 {
   struct dwarf2_section_info info;
@@ -178,13 +172,15 @@ struct dwarf2_per_objfile
   struct dwarf2_section_info line;
   struct dwarf2_section_info loc;
   struct dwarf2_section_info macinfo;
+  struct dwarf2_section_info macro;
   struct dwarf2_section_info str;
   struct dwarf2_section_info ranges;
-  struct dwarf2_section_info types;
   struct dwarf2_section_info frame;
   struct dwarf2_section_info eh_frame;
   struct dwarf2_section_info gdb_index;
 
+  VEC (dwarf2_section_info_def) *types;
+
   /* Back link.  */
   struct objfile *objfile;
 
@@ -243,22 +239,27 @@ struct dwarf2_per_objfile
 
 static struct dwarf2_per_objfile *dwarf2_per_objfile;
 
-/* names of the debugging sections */
+/* Default names of the debugging sections.  */
 
 /* Note that if the debugging section has been compressed, it might
    have a name like .zdebug_info.  */
 
-#define INFO_SECTION     "debug_info"
-#define ABBREV_SECTION   "debug_abbrev"
-#define LINE_SECTION     "debug_line"
-#define LOC_SECTION      "debug_loc"
-#define MACINFO_SECTION  "debug_macinfo"
-#define STR_SECTION      "debug_str"
-#define RANGES_SECTION   "debug_ranges"
-#define TYPES_SECTION    "debug_types"
-#define FRAME_SECTION    "debug_frame"
-#define EH_FRAME_SECTION "eh_frame"
-#define GDB_INDEX_SECTION "gdb_index"
+static const struct dwarf2_debug_sections dwarf2_elf_names =
+{
+  { ".debug_info", ".zdebug_info" },
+  { ".debug_abbrev", ".zdebug_abbrev" },
+  { ".debug_line", ".zdebug_line" },
+  { ".debug_loc", ".zdebug_loc" },
+  { ".debug_macinfo", ".zdebug_macinfo" },
+  { ".debug_macro", ".zdebug_macro" },
+  { ".debug_str", ".zdebug_str" },
+  { ".debug_ranges", ".zdebug_ranges" },
+  { ".debug_types", ".zdebug_types" },
+  { ".debug_frame", ".zdebug_frame" },
+  { ".eh_frame", NULL },
+  { ".gdb_index", ".zgdb_index" },
+  23
+};
 
 /* local data types */
 
@@ -330,8 +331,6 @@ struct dwarf2_cu
   /* Non-zero if base_address has been set.  */
   int base_known;
 
-  struct function_range *first_fn, *last_fn, *cached_fn;
-
   /* The language we are debugging.  */
   enum language language;
   const struct language_defn *language_defn;
@@ -392,6 +391,9 @@ struct dwarf2_cu
      after all type information has been read.  */
   VEC (delayed_method_info) *method_list;
 
+  /* To be copied to symtab->call_site_htab.  */
+  htab_t call_site_htab;
+
   /* Mark used when releasing cached dies.  */
   unsigned int mark : 1;
 
@@ -409,15 +411,12 @@ struct dwarf2_cu
      This test is imperfect as there may exist optimized debug code not using
      any location list and still facing inlining issues if handled as
      unoptimized code.  For a future better test see GCC PR other/32998.  */
-
   unsigned int has_loclist : 1;
 };
 
 /* Persistent data held for a compilation unit, even when not
    processing it.  We put a pointer to this structure in the
-   read_symtab_private field of the psymtab.  If we encounter
-   inter-compilation-unit references, we also maintain a sorted
-   list of all compilation units.  */
+   read_symtab_private field of the psymtab.  */
 
 struct dwarf2_per_cu_data
 {
@@ -439,15 +438,17 @@ struct dwarf2_per_cu_data
      hash table and don't find it.  */
   unsigned int load_all_dies : 1;
 
-  /* Non-zero if this CU is from .debug_types.
-     Otherwise it's from .debug_info.  */
-  unsigned int from_debug_types : 1;
+  /* Non-null if this CU is from .debug_types; in which case it points
+     to the section.  Otherwise it's from .debug_info.  */
+  struct dwarf2_section_info *debug_types_section;
 
   /* 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;
 
-  /* The corresponding objfile.  */
+  /* The corresponding objfile.
+     Normally we can get the objfile from dwarf2_per_objfile.
+     However we can enter this file with just a "per_cu" handle.  */
   struct objfile *objfile;
 
   /* When using partial symbol tables, the 'psymtab' field is active.
@@ -682,14 +683,6 @@ struct die_info
     struct attribute attrs[1];
   };
 
-struct function_range
-{
-  const char *name;
-  CORE_ADDR lowpc, highpc;
-  int seen_line;
-  struct function_range *next;
-};
-
 /* Get at parts of an attribute structure.  */
 
 #define DW_STRING(attr)    ((attr)->u.str)
@@ -704,6 +697,8 @@ struct function_range
 struct dwarf_block
   {
     unsigned int size;
+
+    /* Valid only if SIZE is not zero.  */
     gdb_byte *data;
   };
 
@@ -846,10 +841,11 @@ dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
 }
 
 static void
-dwarf2_macros_too_long_complaint (void)
+dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section)
 {
   complaint (&symfile_complaints,
-            _("macro info runs off end of `.debug_macinfo' section"));
+            _("macro info runs off end of `%s' section"),
+            section->asection->name);
 }
 
 static void
@@ -876,6 +872,9 @@ static void dwarf2_locate_sections (bfd *, asection *, void *);
 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
                                            struct objfile *);
 
+static void dwarf2_find_base_address (struct die_info *die,
+                                     struct dwarf2_cu *cu);
+
 static void dwarf2_build_psymtabs_hard (struct objfile *);
 
 static void scan_partial_symbols (struct partial_die_info *,
@@ -908,10 +907,12 @@ static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
 
 static void psymtab_to_symtab_1 (struct partial_symtab *);
 
-static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
+static void dwarf2_read_abbrevs (struct dwarf2_cu *cu);
 
 static void dwarf2_free_abbrev_table (void *);
 
+static unsigned int peek_abbrev_code (bfd *, gdb_byte *);
+
 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
                                            struct dwarf2_cu *);
 
@@ -1060,6 +1061,8 @@ static void read_func_scope (struct die_info *, struct dwarf2_cu *);
 
 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
 
+static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
+
 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
                               struct dwarf2_cu *, struct partial_symtab *);
 
@@ -1192,11 +1195,14 @@ static struct die_info *follow_die_sig (struct die_info *,
                                        struct attribute *,
                                        struct dwarf2_cu **);
 
-static void read_signatured_type_at_offset (struct objfile *objfile,
-                                           unsigned int offset);
+static struct signatured_type *lookup_signatured_type_at_offset
+    (struct objfile *objfile,
+     struct dwarf2_section_info *section,
+     unsigned int offset);
+
+static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu);
 
-static void read_signatured_type (struct objfile *,
-                                 struct signatured_type *type_sig);
+static void read_signatured_type (struct signatured_type *type_sig);
 
 /* memory allocation interface */
 
@@ -1206,13 +1212,10 @@ static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
 
 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
 
-static void initialize_cu_func_list (struct dwarf2_cu *);
-
-static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
-                                struct dwarf2_cu *);
-
 static void dwarf_decode_macros (struct line_header *, unsigned int,
-                                 char *, bfd *, struct dwarf2_cu *);
+                                 char *, bfd *, struct dwarf2_cu *,
+                                struct dwarf2_section_info *,
+                                int);
 
 static int attr_form_is_block (struct attribute *);
 
@@ -1245,12 +1248,12 @@ static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
   (unsigned int offset, struct objfile *objfile);
 
 static void init_one_comp_unit (struct dwarf2_cu *cu,
-                               struct objfile *objfile);
+                               struct dwarf2_per_cu_data *per_cu);
 
 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
                                   struct die_info *comp_unit_die);
 
-static void free_one_comp_unit (void *);
+static void free_heap_comp_unit (void *);
 
 static void free_cached_comp_units (void *);
 
@@ -1265,8 +1268,7 @@ static void create_all_comp_units (struct objfile *);
 
 static int create_debug_types_hash_table (struct objfile *objfile);
 
-static void load_full_comp_unit (struct dwarf2_per_cu_data *,
-                                struct objfile *);
+static void load_full_comp_unit (struct dwarf2_per_cu_data *);
 
 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
 
@@ -1284,10 +1286,9 @@ static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
 
 static void dwarf2_release_queue (void *dummy);
 
-static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
-                            struct objfile *objfile);
+static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu);
 
-static void process_queue (struct objfile *objfile);
+static void process_queue (void);
 
 static void find_file_and_directory (struct die_info *die,
                                     struct dwarf2_cu *cu,
@@ -1300,7 +1301,8 @@ static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
                                              gdb_byte *info_ptr,
                                              gdb_byte *buffer,
                                              unsigned int buffer_size,
-                                             bfd *abfd);
+                                             bfd *abfd,
+                                             int is_debug_types_section);
 
 static void init_cu_die_reader (struct die_reader_specs *reader,
                                struct dwarf2_cu *cu);
@@ -1335,10 +1337,13 @@ static const char *dwarf2_physname (char *name, struct die_info *die,
                                    struct dwarf2_cu *cu);
 
 /* Try to locate the sections we need for DWARF 2 debugging
-   information and return true if we have enough to do something.  */
+   information and return true if we have enough to do something.
+   NAMES points to the dwarf2 section names, or is NULL if the standard
+   ELF names are used.  */
 
 int
-dwarf2_has_info (struct objfile *objfile)
+dwarf2_has_info (struct objfile *objfile,
+                 const struct dwarf2_debug_sections *names)
 {
   dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
   if (!dwarf2_per_objfile)
@@ -1351,23 +1356,28 @@ dwarf2_has_info (struct objfile *objfile)
       set_objfile_data (objfile, dwarf2_objfile_data_key, data);
       dwarf2_per_objfile = data;
 
-      bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
+      bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections,
+                             (void *) names);
       dwarf2_per_objfile->objfile = objfile;
     }
   return (dwarf2_per_objfile->info.asection != NULL
          && dwarf2_per_objfile->abbrev.asection != NULL);
 }
 
-/* When loading sections, we can either look for ".<name>", or for
* ".z<name>", which indicates a compressed section.  */
+/* When loading sections, we look either for uncompressed section or for
  compressed section names.  */
 
 static int
-section_is_p (const char *section_name, const char *name)
+section_is_p (const char *section_name,
+              const struct dwarf2_section_names *names)
 {
-  return (section_name[0] == '.'
-         && (strcmp (section_name + 1, name) == 0
-             || (section_name[1] == 'z'
-                 && strcmp (section_name + 2, name) == 0)));
+  if (names->normal != NULL
+      && strcmp (section_name, names->normal) == 0)
+    return 1;
+  if (names->compressed != NULL
+      && strcmp (section_name, names->compressed) == 0)
+    return 1;
+  return 0;
 }
 
 /* This function is mapped across the sections and remembers the
@@ -1375,44 +1385,56 @@ section_is_p (const char *section_name, const char *name)
    in.  */
 
 static void
-dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
+dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
 {
-  if (section_is_p (sectp->name, INFO_SECTION))
+  const struct dwarf2_debug_sections *names;
+
+  if (vnames == NULL)
+    names = &dwarf2_elf_names;
+  else
+    names = (const struct dwarf2_debug_sections *) vnames;
+
+  if (section_is_p (sectp->name, &names->info))
     {
       dwarf2_per_objfile->info.asection = sectp;
       dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
     }
-  else if (section_is_p (sectp->name, ABBREV_SECTION))
+  else if (section_is_p (sectp->name, &names->abbrev))
     {
       dwarf2_per_objfile->abbrev.asection = sectp;
       dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
     }
-  else if (section_is_p (sectp->name, LINE_SECTION))
+  else if (section_is_p (sectp->name, &names->line))
     {
       dwarf2_per_objfile->line.asection = sectp;
       dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
     }
-  else if (section_is_p (sectp->name, LOC_SECTION))
+  else if (section_is_p (sectp->name, &names->loc))
     {
       dwarf2_per_objfile->loc.asection = sectp;
       dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
     }
-  else if (section_is_p (sectp->name, MACINFO_SECTION))
+  else if (section_is_p (sectp->name, &names->macinfo))
     {
       dwarf2_per_objfile->macinfo.asection = sectp;
       dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
     }
-  else if (section_is_p (sectp->name, STR_SECTION))
+  else if (section_is_p (sectp->name, &names->macro))
+    {
+      dwarf2_per_objfile->macro.asection = sectp;
+      dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp);
+    }
+  else if (section_is_p (sectp->name, &names->str))
     {
       dwarf2_per_objfile->str.asection = sectp;
       dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
     }
-  else if (section_is_p (sectp->name, FRAME_SECTION))
+  else if (section_is_p (sectp->name, &names->frame))
     {
       dwarf2_per_objfile->frame.asection = sectp;
       dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
     }
-  else if (section_is_p (sectp->name, EH_FRAME_SECTION))
+  else if (section_is_p (sectp->name, &names->eh_frame))
     {
       flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
 
@@ -1422,17 +1444,23 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
           dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
         }
     }
-  else if (section_is_p (sectp->name, RANGES_SECTION))
+  else if (section_is_p (sectp->name, &names->ranges))
     {
       dwarf2_per_objfile->ranges.asection = sectp;
       dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
     }
-  else if (section_is_p (sectp->name, TYPES_SECTION))
+  else if (section_is_p (sectp->name, &names->types))
     {
-      dwarf2_per_objfile->types.asection = sectp;
-      dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
+      struct dwarf2_section_info type_section;
+
+      memset (&type_section, 0, sizeof (type_section));
+      type_section.asection = sectp;
+      type_section.size = bfd_get_section_size (sectp);
+
+      VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types,
+                    &type_section);
     }
-  else if (section_is_p (sectp->name, GDB_INDEX_SECTION))
+  else if (section_is_p (sectp->name, &names->gdb_index))
     {
       dwarf2_per_objfile->gdb_index.asection = sectp;
       dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
@@ -1530,7 +1558,7 @@ dwarf2_section_empty_p (struct dwarf2_section_info *info)
   return info->asection == NULL || info->size == 0;
 }
 
-/* Read the contents of the section SECTP from object file specified by
+/* Read the contents of the section INFO from object file specified by
    OBJFILE, store info about the section into INFO.
    If the section is compressed, uncompress it before returning.  */
 
@@ -1545,7 +1573,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
   if (info->readin)
     return;
   info->buffer = NULL;
-  info->was_mmapped = 0;
+  info->map_addr = NULL;
   info->readin = 1;
 
   if (dwarf2_section_empty_p (info))
@@ -1575,17 +1603,14 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
 
   if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
     {
-      off_t pg_offset = sectp->filepos & ~(pagesize - 1);
-      size_t map_length = info->size + sectp->filepos - pg_offset;
-      caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
-                                MAP_PRIVATE, pg_offset);
+      info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ,
+                         MAP_PRIVATE, sectp->filepos,
+                         &info->map_addr, &info->map_len);
 
-      if (retbuf != MAP_FAILED)
+      if ((caddr_t)info->buffer != MAP_FAILED)
        {
-         info->was_mmapped = 1;
-         info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
 #if HAVE_POSIX_MADVISE
-         posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
+         posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED);
 #endif
          return;
        }
@@ -1633,7 +1658,8 @@ dwarf2_section_size (struct objfile *objfile,
    SECTION_NAME.  */
 
 void
-dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
+dwarf2_get_section_info (struct objfile *objfile,
+                         enum dwarf2_section_enum sect,
                          asection **sectp, gdb_byte **bufp,
                          bfd_size_type *sizep)
 {
@@ -1650,12 +1676,17 @@ dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
       *sizep = 0;
       return;
     }
-  if (section_is_p (section_name, EH_FRAME_SECTION))
-    info = &data->eh_frame;
-  else if (section_is_p (section_name, FRAME_SECTION))
-    info = &data->frame;
-  else
-    gdb_assert_not_reached ("unexpected section");
+  switch (sect)
+    {
+    case DWARF2_DEBUG_FRAME:
+      info = &data->frame;
+      break;
+    case DWARF2_EH_FRAME:
+      info = &data->eh_frame;
+      break;
+    default:
+      gdb_assert_not_reached ("unexpected section");
+    }
 
   dwarf2_read_section (objfile, info);
 
@@ -1762,25 +1793,37 @@ create_quick_file_names_table (unsigned int nr_initial_entries)
                            delete_file_name_entry, xcalloc, xfree);
 }
 
-/* Read in the symbols for PER_CU.  OBJFILE is the objfile from which
-   this CU came.  */
+/* Read in PER_CU->CU.  This function is unrelated to symtabs, symtab would
+   have to be created afterwards.  You should call age_cached_comp_units after
+   processing PER_CU->CU.  dw2_setup must have been already called.  */
+
+static void
+load_cu (struct dwarf2_per_cu_data *per_cu)
+{
+  if (per_cu->debug_types_section)
+    load_full_type_unit (per_cu);
+  else
+    load_full_comp_unit (per_cu);
+
+  gdb_assert (per_cu->cu != NULL);
+
+  dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
+}
+
+/* Read in the symbols for PER_CU.  */
 
 static void
-dw2_do_instantiate_symtab (struct objfile *objfile,
-                          struct dwarf2_per_cu_data *per_cu)
+dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
 {
   struct cleanup *back_to;
 
   back_to = make_cleanup (dwarf2_release_queue, NULL);
 
-  queue_comp_unit (per_cu, objfile);
+  queue_comp_unit (per_cu);
 
-  if (per_cu->from_debug_types)
-    read_signatured_type_at_offset (objfile, per_cu->offset);
-  else
-    load_full_comp_unit (per_cu, objfile);
+  load_cu (per_cu);
 
-  process_queue (objfile);
+  process_queue ();
 
   /* Age the cache, releasing compilation units that have not
      been used recently.  */
@@ -1794,14 +1837,13 @@ dw2_do_instantiate_symtab (struct objfile *objfile,
    table.  */
 
 static struct symtab *
-dw2_instantiate_symtab (struct objfile *objfile,
-                       struct dwarf2_per_cu_data *per_cu)
+dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
 {
   if (!per_cu->v.quick->symtab)
     {
       struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
       increment_reading_symtab ();
-      dw2_do_instantiate_symtab (objfile, per_cu);
+      dw2_do_instantiate_symtab (per_cu);
       do_cleanups (back_to);
     }
   return per_cu->v.quick->symtab;
@@ -1886,6 +1928,7 @@ create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
 
 static int
 create_signatured_type_table_from_index (struct objfile *objfile,
+                                        struct dwarf2_section_info *section,
                                         const gdb_byte *bytes,
                                         offset_type elements)
 {
@@ -1916,7 +1959,7 @@ create_signatured_type_table_from_index (struct objfile *objfile,
                                 struct signatured_type);
       type_sig->signature = signature;
       type_sig->type_offset = type_offset;
-      type_sig->per_cu.from_debug_types = 1;
+      type_sig->per_cu.debug_types_section = section;
       type_sig->per_cu.offset = offset;
       type_sig->per_cu.objfile = objfile;
       type_sig->per_cu.v.quick
@@ -2144,10 +2187,23 @@ dwarf2_read_index (struct objfile *objfile)
   if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
     return 0;
 
-  if (types_list_elements
-      && !create_signatured_type_table_from_index (objfile, types_list,
-                                                  types_list_elements))
-    return 0;
+  if (types_list_elements)
+    {
+      struct dwarf2_section_info *section;
+
+      /* We can only handle a single .debug_types when we have an
+        index.  */
+      if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
+       return 0;
+
+      section = VEC_index (dwarf2_section_info_def,
+                          dwarf2_per_objfile->types, 0);
+
+      if (!create_signatured_type_table_from_index (objfile, section,
+                                                   types_list,
+                                                   types_list_elements))
+       return 0;
+    }
 
   create_addrmap_from_index (objfile, map);
 
@@ -2182,7 +2238,7 @@ dw2_get_file_names (struct objfile *objfile,
   struct cleanup *cleanups;
   struct die_info *comp_unit_die;
   struct dwarf2_section_info* sec;
-  gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
+  gdb_byte *info_ptr, *buffer;
   int has_children, i;
   struct dwarf2_cu cu;
   unsigned int bytes_read, buffer_size;
@@ -2198,35 +2254,34 @@ dw2_get_file_names (struct objfile *objfile,
   if (this_cu->v.quick->no_file_data)
     return NULL;
 
-  init_one_comp_unit (&cu, objfile);
+  init_one_comp_unit (&cu, this_cu);
   cleanups = make_cleanup (free_stack_comp_unit, &cu);
 
-  if (this_cu->from_debug_types)
-    sec = &dwarf2_per_objfile->types;
+  if (this_cu->debug_types_section)
+    sec = this_cu->debug_types_section;
   else
     sec = &dwarf2_per_objfile->info;
   dwarf2_read_section (objfile, sec);
   buffer_size = sec->size;
   buffer = sec->buffer;
   info_ptr = buffer + this_cu->offset;
-  beg_of_comp_unit = info_ptr;
 
   info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
                                          buffer, buffer_size,
-                                         abfd);
+                                         abfd,
+                                         this_cu->debug_types_section != NULL);
 
-  /* Complete the cu_header.  */
-  cu.header.offset = beg_of_comp_unit - buffer;
-  cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
-
-  this_cu->cu = &cu;
-  cu.per_cu = this_cu;
+  /* Skip dummy compilation units.  */
+  if (info_ptr >= buffer + buffer_size
+      || peek_abbrev_code (abfd, info_ptr) == 0)
+    {
+      do_cleanups (cleanups);
+      return NULL;
+    }
 
-  dwarf2_read_abbrevs (abfd, &cu);
+  dwarf2_read_abbrevs (&cu);
   make_cleanup (dwarf2_free_abbrev_table, &cu);
 
-  if (this_cu->from_debug_types)
-    info_ptr += 8 /*signature*/ + cu.header.offset_size;
   init_cu_die_reader (&reader_specs, &cu);
   read_full_die (&reader_specs, &comp_unit_die, info_ptr,
                 &has_children);
@@ -2307,7 +2362,7 @@ dw2_find_last_source_symtab (struct objfile *objfile)
 
   dw2_setup (objfile);
   index = dwarf2_per_objfile->n_comp_units - 1;
-  return dw2_instantiate_symtab (objfile, dw2_get_cu (index));
+  return dw2_instantiate_symtab (dw2_get_cu (index));
 }
 
 /* Traversal function for dw2_forget_cached_source_info.  */
@@ -2340,13 +2395,42 @@ dw2_forget_cached_source_info (struct objfile *objfile)
                          dw2_free_cached_file_names, NULL);
 }
 
+/* Helper function for dw2_map_symtabs_matching_filename that expands
+   the symtabs and calls the iterator.  */
+
+static int
+dw2_map_expand_apply (struct objfile *objfile,
+                     struct dwarf2_per_cu_data *per_cu,
+                     const char *name,
+                     const char *full_path, const char *real_path,
+                     int (*callback) (struct symtab *, void *),
+                     void *data)
+{
+  struct symtab *last_made = objfile->symtabs;
+
+  /* Don't visit already-expanded CUs.  */
+  if (per_cu->v.quick->symtab)
+    return 0;
+
+  /* This may expand more than one symtab, and we want to iterate over
+     all of them.  */
+  dw2_instantiate_symtab (per_cu);
+
+  return iterate_over_some_symtabs (name, full_path, real_path, callback, data,
+                                   objfile->symtabs, last_made);
+}
+
+/* Implementation of the map_symtabs_matching_filename method.  */
+
 static int
-dw2_lookup_symtab (struct objfile *objfile, const char *name,
-                  const char *full_path, const char *real_path,
-                  struct symtab **result)
+dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
+                                  const char *full_path, const char *real_path,
+                                  int (*callback) (struct symtab *, void *),
+                                  void *data)
 {
   int i;
-  int check_basename = lbasename (name) == name;
+  const char *name_basename = lbasename (name);
+  int check_basename = name_basename == name;
   struct dwarf2_per_cu_data *base_cu = NULL;
 
   dw2_setup (objfile);
@@ -2358,6 +2442,7 @@ dw2_lookup_symtab (struct objfile *objfile, const char *name,
       struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
       struct quick_file_names *file_data;
 
+      /* We only need to look at symtabs not already expanded.  */
       if (per_cu->v.quick->symtab)
        continue;
 
@@ -2371,14 +2456,22 @@ dw2_lookup_symtab (struct objfile *objfile, const char *name,
 
          if (FILENAME_CMP (name, this_name) == 0)
            {
-             *result = dw2_instantiate_symtab (objfile, per_cu);
-             return 1;
+             if (dw2_map_expand_apply (objfile, per_cu,
+                                       name, full_path, real_path,
+                                       callback, data))
+               return 1;
            }
 
          if (check_basename && ! base_cu
              && FILENAME_CMP (lbasename (this_name), name) == 0)
            base_cu = per_cu;
 
+         /* Before we invoke realpath, which can get expensive when many
+            files are involved, do a quick comparison of the basenames.  */
+         if (! basenames_may_differ
+             && FILENAME_CMP (lbasename (this_name), name_basename) != 0)
+           continue;
+
          if (full_path != NULL)
            {
              const char *this_real_name = dw2_get_real_path (objfile,
@@ -2387,8 +2480,10 @@ dw2_lookup_symtab (struct objfile *objfile, const char *name,
              if (this_real_name != NULL
                  && FILENAME_CMP (full_path, this_real_name) == 0)
                {
-                 *result = dw2_instantiate_symtab (objfile, per_cu);
-                 return 1;
+                 if (dw2_map_expand_apply (objfile, per_cu,
+                                           name, full_path, real_path,
+                                           callback, data))
+                   return 1;
                }
            }
 
@@ -2400,8 +2495,10 @@ dw2_lookup_symtab (struct objfile *objfile, const char *name,
              if (this_real_name != NULL
                  && FILENAME_CMP (real_path, this_real_name) == 0)
                {
-                 *result = dw2_instantiate_symtab (objfile, per_cu);
-                 return 1;
+                 if (dw2_map_expand_apply (objfile, per_cu,
+                                           name, full_path, real_path,
+                                           callback, data))
+                   return 1;
                }
            }
        }
@@ -2409,8 +2506,10 @@ dw2_lookup_symtab (struct objfile *objfile, const char *name,
 
   if (base_cu)
     {
-      *result = dw2_instantiate_symtab (objfile, base_cu);
-      return 1;
+      if (dw2_map_expand_apply (objfile, base_cu,
+                               name, full_path, real_path,
+                               callback, data))
+       return 1;
     }
 
   return 0;
@@ -2447,7 +2546,7 @@ dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
              offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
              struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
 
-             dw2_instantiate_symtab (objfile, per_cu);
+             dw2_instantiate_symtab (per_cu);
            }
        }
     }
@@ -2511,7 +2610,7 @@ dw2_expand_all_symtabs (struct objfile *objfile)
     {
       struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
 
-      dw2_instantiate_symtab (objfile, per_cu);
+      dw2_instantiate_symtab (per_cu);
     }
 }
 
@@ -2534,6 +2633,7 @@ dw2_expand_symtabs_with_filename (struct objfile *objfile,
       struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
       struct quick_file_names *file_data;
 
+      /* We only need to look at symtabs not already expanded.  */
       if (per_cu->v.quick->symtab)
        continue;
 
@@ -2546,7 +2646,7 @@ dw2_expand_symtabs_with_filename (struct objfile *objfile,
          const char *this_name = file_data->file_names[j];
          if (FILENAME_CMP (this_name, filename) == 0)
            {
-             dw2_instantiate_symtab (objfile, per_cu);
+             dw2_instantiate_symtab (per_cu);
              break;
            }
        }
@@ -2564,7 +2664,21 @@ dw2_find_symbol_file (struct objfile *objfile, const char *name)
 
   /* index_table is NULL if OBJF_READNOW.  */
   if (!dwarf2_per_objfile->index_table)
-    return NULL;
+    {
+      struct symtab *s;
+
+      ALL_OBJFILE_SYMTABS (objfile, s)
+       if (s->primary)
+         {
+           struct blockvector *bv = BLOCKVECTOR (s);
+           const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+           struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN);
+
+           if (sym)
+             return sym->symtab->filename;
+         }
+      return NULL;
+    }
 
   if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
                                 name, &vec))
@@ -2598,11 +2712,12 @@ dw2_map_matching_symbols (const char * name, domain_enum namespace,
 }
 
 static void
-dw2_expand_symtabs_matching (struct objfile *objfile,
-                            int (*file_matcher) (const char *, void *),
-                            int (*name_matcher) (const char *, void *),
-                            enum search_domain kind,
-                            void *data)
+dw2_expand_symtabs_matching
+  (struct objfile *objfile,
+   int (*file_matcher) (const char *, void *),
+   int (*name_matcher) (const struct language_defn *, const char *, void *),
+   enum search_domain kind,
+   void *data)
 {
   int i;
   offset_type iter;
@@ -2624,6 +2739,8 @@ dw2_expand_symtabs_matching (struct objfile *objfile,
        struct quick_file_names *file_data;
 
        per_cu->v.quick->mark = 0;
+
+       /* We only need to look at symtabs not already expanded.  */
        if (per_cu->v.quick->symtab)
          continue;
 
@@ -2652,7 +2769,7 @@ dw2_expand_symtabs_matching (struct objfile *objfile,
 
       name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
 
-      if (! (*name_matcher) (name, data))
+      if (! (*name_matcher) (current_language, name, data))
        continue;
 
       /* The name was matched, now expand corresponding CUs that were
@@ -2666,7 +2783,7 @@ dw2_expand_symtabs_matching (struct objfile *objfile,
 
          per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
          if (file_matcher == NULL || per_cu->v.quick->mark)
-           dw2_instantiate_symtab (objfile, per_cu);
+           dw2_instantiate_symtab (per_cu);
        }
     }
 }
@@ -2693,13 +2810,12 @@ dw2_find_pc_sect_symtab (struct objfile *objfile,
     warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
             paddress (get_objfile_arch (objfile), pc));
 
-  return dw2_instantiate_symtab (objfile, data);
+  return dw2_instantiate_symtab (data);
 }
 
 static void
-dw2_map_symbol_filenames (struct objfile *objfile,
-                         void (*fun) (const char *, const char *, void *),
-                         void *data)
+dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
+                         void *data, int need_fullname)
 {
   int i;
 
@@ -2712,6 +2828,7 @@ dw2_map_symbol_filenames (struct objfile *objfile,
       struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
       struct quick_file_names *file_data;
 
+      /* We only need to look at symtabs not already expanded.  */
       if (per_cu->v.quick->symtab)
        continue;
 
@@ -2721,8 +2838,12 @@ dw2_map_symbol_filenames (struct objfile *objfile,
 
       for (j = 0; j < file_data->num_file_names; ++j)
        {
-         const char *this_real_name = dw2_get_real_path (objfile, file_data,
-                                                         j);
+         const char *this_real_name;
+
+         if (need_fullname)
+           this_real_name = dw2_get_real_path (objfile, file_data, j);
+         else
+           this_real_name = NULL;
          (*fun) (file_data->file_names[j], this_real_name, data);
        }
     }
@@ -2739,7 +2860,7 @@ const struct quick_symbol_functions dwarf2_gdb_index_functions =
   dw2_has_symbols,
   dw2_find_last_source_symtab,
   dw2_forget_cached_source_info,
-  dw2_lookup_symtab,
+  dw2_map_symtabs_matching_filename,
   dw2_lookup_symbol,
   dw2_pre_expand_symtabs_matching,
   dw2_print_stats,
@@ -2855,15 +2976,26 @@ read_comp_unit_head (struct comp_unit_head *cu_header,
   return info_ptr;
 }
 
+/* Read in a CU header and perform some basic error checking.  */
+
 static gdb_byte *
 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
                             gdb_byte *buffer, unsigned int buffer_size,
-                            bfd *abfd)
+                            bfd *abfd, int is_debug_types_section)
 {
   gdb_byte *beg_of_comp_unit = info_ptr;
 
+  header->offset = beg_of_comp_unit - buffer;
+
   info_ptr = read_comp_unit_head (header, info_ptr, abfd);
 
+  /* If we're reading a type unit, skip over the signature and
+     type_offset fields.  */
+  if (is_debug_types_section)
+    info_ptr += 8 /*signature*/ + header->offset_size;
+
+  header->first_die_offset = info_ptr - beg_of_comp_unit;
+
   if (header->version != 2 && header->version != 3 && header->version != 4)
     error (_("Dwarf Error: wrong version in compilation unit header "
           "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
@@ -2894,14 +3026,14 @@ partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
 
 static gdb_byte *
 read_type_comp_unit_head (struct comp_unit_head *cu_header,
+                         struct dwarf2_section_info *section,
                          ULONGEST *signature,
                          gdb_byte *types_ptr, bfd *abfd)
 {
   gdb_byte *initial_types_ptr = types_ptr;
 
-  dwarf2_read_section (dwarf2_per_objfile->objfile,
-                      &dwarf2_per_objfile->types);
-  cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
+  dwarf2_read_section (dwarf2_per_objfile->objfile, section);
+  cu_header->offset = types_ptr - section->buffer;
 
   types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
 
@@ -3029,91 +3161,112 @@ add_signatured_type_cu_to_list (void **slot, void *datum)
 static int
 create_debug_types_hash_table (struct objfile *objfile)
 {
-  gdb_byte *info_ptr;
-  htab_t types_htab;
+  htab_t types_htab = NULL;
   struct dwarf2_per_cu_data **iter;
+  int ix;
+  struct dwarf2_section_info *section;
 
-  dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
-  info_ptr = dwarf2_per_objfile->types.buffer;
-
-  if (info_ptr == NULL)
+  if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types))
     {
       dwarf2_per_objfile->signatured_types = NULL;
       return 0;
     }
 
-  types_htab = allocate_signatured_type_table (objfile);
+  for (ix = 0;
+       VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types,
+                   ix, section);
+       ++ix)
+    {
+      gdb_byte *info_ptr, *end_ptr;
 
-  if (dwarf2_die_debug)
-    fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
+      dwarf2_read_section (objfile, section);
+      info_ptr = section->buffer;
 
-  while (info_ptr < dwarf2_per_objfile->types.buffer
-        + dwarf2_per_objfile->types.size)
-    {
-      unsigned int offset;
-      unsigned int offset_size;
-      unsigned int type_offset;
-      unsigned int length, initial_length_size;
-      unsigned short version;
-      ULONGEST signature;
-      struct signatured_type *type_sig;
-      void **slot;
-      gdb_byte *ptr = info_ptr;
+      if (info_ptr == NULL)
+       continue;
 
-      offset = ptr - dwarf2_per_objfile->types.buffer;
+      if (types_htab == NULL)
+       types_htab = allocate_signatured_type_table (objfile);
 
-      /* We need to read the type's signature in order to build the hash
-        table, but we don't need to read anything else just yet.  */
+      if (dwarf2_die_debug)
+       fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
 
-      /* Sanity check to ensure entire cu is present.  */
-      length = read_initial_length (objfile->obfd, ptr, &initial_length_size);
-      if (ptr + length + initial_length_size
-         > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
+      end_ptr = info_ptr + section->size;
+      while (info_ptr < end_ptr)
        {
-         complaint (&symfile_complaints,
-                    _("debug type entry runs off end "
-                      "of `.debug_types' section, ignored"));
-         break;
-       }
+         unsigned int offset;
+         unsigned int offset_size;
+         unsigned int type_offset;
+         unsigned int length, initial_length_size;
+         unsigned short version;
+         ULONGEST signature;
+         struct signatured_type *type_sig;
+         void **slot;
+         gdb_byte *ptr = info_ptr;
 
-      offset_size = initial_length_size == 4 ? 4 : 8;
-      ptr += initial_length_size;
-      version = bfd_get_16 (objfile->obfd, ptr);
-      ptr += 2;
-      ptr += offset_size; /* abbrev offset */
-      ptr += 1; /* address size */
-      signature = bfd_get_64 (objfile->obfd, ptr);
-      ptr += 8;
-      type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
+         offset = ptr - section->buffer;
 
-      type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
-      memset (type_sig, 0, sizeof (*type_sig));
-      type_sig->signature = signature;
-      type_sig->type_offset = type_offset;
-      type_sig->per_cu.objfile = objfile;
-      type_sig->per_cu.from_debug_types = 1;
-      type_sig->per_cu.offset = offset;
+         /* We need to read the type's signature in order to build the hash
+            table, but we don't need to read anything else just yet.  */
 
-      slot = htab_find_slot (types_htab, type_sig, INSERT);
-      gdb_assert (slot != NULL);
-      if (*slot != NULL)
-       {
-         const struct signatured_type *dup_sig = *slot;
+         /* Sanity check to ensure entire cu is present.  */
+         length = read_initial_length (objfile->obfd, ptr,
+                                       &initial_length_size);
+         if (ptr + length + initial_length_size > end_ptr)
+           {
+             complaint (&symfile_complaints,
+                        _("debug type entry runs off end "
+                          "of `.debug_types' section, ignored"));
+             break;
+           }
 
-         complaint (&symfile_complaints,
-                    _("debug type entry at offset 0x%x is duplicate to the "
-                      "entry at offset 0x%x, signature 0x%s"),
-                    offset, dup_sig->per_cu.offset,
-                    phex (signature, sizeof (signature)));
-         gdb_assert (signature == dup_sig->signature);
-       }
-      *slot = type_sig;
+         offset_size = initial_length_size == 4 ? 4 : 8;
+         ptr += initial_length_size;
+         version = bfd_get_16 (objfile->obfd, ptr);
+         ptr += 2;
+         ptr += offset_size; /* abbrev offset */
+         ptr += 1; /* address size */
+         signature = bfd_get_64 (objfile->obfd, ptr);
+         ptr += 8;
+         type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
+         ptr += offset_size;
+
+         /* Skip dummy type units.  */
+         if (ptr >= end_ptr || peek_abbrev_code (objfile->obfd, ptr) == 0)
+           {
+             info_ptr = info_ptr + initial_length_size + length;
+             continue;
+           }
 
-      if (dwarf2_die_debug)
-       fprintf_unfiltered (gdb_stdlog, "  offset 0x%x, signature 0x%s\n",
-                           offset, phex (signature, sizeof (signature)));
+         type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
+         memset (type_sig, 0, sizeof (*type_sig));
+         type_sig->signature = signature;
+         type_sig->type_offset = type_offset;
+         type_sig->per_cu.objfile = objfile;
+         type_sig->per_cu.debug_types_section = section;
+         type_sig->per_cu.offset = offset;
+
+         slot = htab_find_slot (types_htab, type_sig, INSERT);
+         gdb_assert (slot != NULL);
+         if (*slot != NULL)
+           {
+             const struct signatured_type *dup_sig = *slot;
+
+             complaint (&symfile_complaints,
+                        _("debug type entry at offset 0x%x is duplicate to the "
+                          "entry at offset 0x%x, signature 0x%s"),
+                        offset, dup_sig->per_cu.offset,
+                        phex (signature, sizeof (signature)));
+             gdb_assert (signature == dup_sig->signature);
+           }
+         *slot = type_sig;
 
-      info_ptr = info_ptr + initial_length_size + length;
+         if (dwarf2_die_debug)
+           fprintf_unfiltered (gdb_stdlog, "  offset 0x%x, signature 0x%s\n",
+                               offset, phex (signature, sizeof (signature)));
+
+         info_ptr = info_ptr + initial_length_size + length;
+       }
     }
 
   dwarf2_per_objfile->signatured_types = types_htab;
@@ -3159,10 +3312,10 @@ init_cu_die_reader (struct die_reader_specs *reader,
 {
   reader->abfd = cu->objfile->obfd;
   reader->cu = cu;
-  if (cu->per_cu->from_debug_types)
+  if (cu->per_cu->debug_types_section)
     {
-      gdb_assert (dwarf2_per_objfile->types.readin);
-      reader->buffer = dwarf2_per_objfile->types.buffer;
+      gdb_assert (cu->per_cu->debug_types_section->readin);
+      reader->buffer = cu->per_cu->debug_types_section->buffer;
     }
   else
     {
@@ -3211,11 +3364,11 @@ dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
    Returns a pointer to the next CU.  */
 
 static gdb_byte *
-process_psymtab_comp_unit (struct objfile *objfile,
-                          struct dwarf2_per_cu_data *this_cu,
+process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
                           gdb_byte *buffer, gdb_byte *info_ptr,
                           unsigned int buffer_size)
 {
+  struct objfile *objfile = this_cu->objfile;
   bfd *abfd = objfile->obfd;
   gdb_byte *beg_of_comp_unit = info_ptr;
   struct die_info *comp_unit_die;
@@ -3229,19 +3382,6 @@ process_psymtab_comp_unit (struct objfile *objfile,
   struct die_reader_specs reader_specs;
   const char *filename;
 
-  init_one_comp_unit (&cu, objfile);
-  back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
-
-  info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
-                                         buffer, buffer_size,
-                                         abfd);
-
-  /* Complete the cu_header.  */
-  cu.header.offset = beg_of_comp_unit - buffer;
-  cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
-
-  cu.list_in_scope = &file_symbols;
-
   /* If this compilation unit was already read in, free the
      cached copy in order to read it in again. This is
      necessary because we skipped some symbols when we first
@@ -3255,21 +3395,36 @@ process_psymtab_comp_unit (struct objfile *objfile,
      added to a global data structure. It will be cleaned up
      in free_stack_comp_unit when we finish with this
      compilation unit. */
-  this_cu->cu = &cu;
-  cu.per_cu = this_cu;
+  init_one_comp_unit (&cu, this_cu);
+  back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
+
+  info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
+                                         buffer, buffer_size,
+                                         abfd,
+                                         this_cu->debug_types_section != NULL);
+
+  /* Skip dummy compilation units.  */
+  if (info_ptr >= buffer + buffer_size
+      || peek_abbrev_code (abfd, info_ptr) == 0)
+    {
+      info_ptr = (beg_of_comp_unit + cu.header.length
+                 + cu.header.initial_length_size);
+      do_cleanups (back_to_inner);
+      return info_ptr;
+    }
+
+  cu.list_in_scope = &file_symbols;
 
   /* Read the abbrevs for this compilation unit into a table.  */
-  dwarf2_read_abbrevs (abfd, &cu);
+  dwarf2_read_abbrevs (&cu);
   make_cleanup (dwarf2_free_abbrev_table, &cu);
 
   /* Read the compilation unit die.  */
-  if (this_cu->from_debug_types)
-    info_ptr += 8 /*signature*/ + cu.header.offset_size;
   init_cu_die_reader (&reader_specs, &cu);
   info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
                            &has_children);
 
-  if (this_cu->from_debug_types)
+  if (this_cu->debug_types_section)
     {
       /* LENGTH has not been set yet for type units.  */
       gdb_assert (this_cu->offset == cu.header.offset);
@@ -3297,6 +3452,7 @@ process_psymtab_comp_unit (struct objfile *objfile,
                              0,
                              objfile->global_psymbols.next,
                              objfile->static_psymbols.next);
+  pst->psymtabs_addrmap_supported = 1;
 
   attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
   if (attr != NULL)
@@ -3365,7 +3521,7 @@ process_psymtab_comp_unit (struct objfile *objfile,
   info_ptr = (beg_of_comp_unit + cu.header.length
              + cu.header.initial_length_size);
 
-  if (this_cu->from_debug_types)
+  if (this_cu->debug_types_section)
     {
       /* It's not clear we want to do anything with stmt lists here.
         Waiting to see what gcc ultimately does.  */
@@ -3389,16 +3545,17 @@ static int
 process_type_comp_unit (void **slot, void *info)
 {
   struct signatured_type *entry = (struct signatured_type *) *slot;
-  struct objfile *objfile = (struct objfile *) info;
   struct dwarf2_per_cu_data *this_cu;
 
+  gdb_assert (info == NULL);
   this_cu = &entry->per_cu;
 
-  gdb_assert (dwarf2_per_objfile->types.readin);
-  process_psymtab_comp_unit (objfile, this_cu,
-                            dwarf2_per_objfile->types.buffer,
-                            dwarf2_per_objfile->types.buffer + this_cu->offset,
-                            dwarf2_per_objfile->types.size);
+  gdb_assert (this_cu->debug_types_section->readin);
+  process_psymtab_comp_unit (this_cu,
+                            this_cu->debug_types_section->buffer,
+                            (this_cu->debug_types_section->buffer
+                             + this_cu->offset),
+                            this_cu->debug_types_section->size);
 
   return 1;
 }
@@ -3413,7 +3570,7 @@ build_type_psymtabs (struct objfile *objfile)
     return;
 
   htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
-                         process_type_comp_unit, objfile);
+                         process_type_comp_unit, NULL);
 }
 
 /* A cleanup function that clears objfile's psymtabs_addrmap field.  */
@@ -3479,7 +3636,7 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile)
                                       - dwarf2_per_objfile->info.buffer,
                                       objfile);
 
-      info_ptr = process_psymtab_comp_unit (objfile, this_cu,
+      info_ptr = process_psymtab_comp_unit (this_cu,
                                            dwarf2_per_objfile->info.buffer,
                                            info_ptr,
                                            dwarf2_per_objfile->info.size);
@@ -3495,11 +3652,11 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile)
 /* Load the partial DIEs for a secondary CU into memory.  */
 
 static void
-load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
-                       struct objfile *objfile)
+load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
 {
+  struct objfile *objfile = this_cu->objfile;
   bfd *abfd = objfile->obfd;
-  gdb_byte *info_ptr, *beg_of_comp_unit;
+  gdb_byte *info_ptr;
   struct die_info *comp_unit_die;
   struct dwarf2_cu *cu;
   struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
@@ -3507,34 +3664,34 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
   struct die_reader_specs reader_specs;
   int read_cu = 0;
 
-  gdb_assert (! this_cu->from_debug_types);
+  gdb_assert (! this_cu->debug_types_section);
 
   gdb_assert (dwarf2_per_objfile->info.readin);
   info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
-  beg_of_comp_unit = info_ptr;
 
   if (this_cu->cu == NULL)
     {
       cu = xmalloc (sizeof (*cu));
-      init_one_comp_unit (cu, objfile);
+      init_one_comp_unit (cu, this_cu);
 
       read_cu = 1;
 
       /* If an error occurs while loading, release our storage.  */
-      free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
+      free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
 
       info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
                                              dwarf2_per_objfile->info.buffer,
                                              dwarf2_per_objfile->info.size,
-                                             abfd);
+                                             abfd, 0);
 
-      /* Complete the cu_header.  */
-      cu->header.offset = this_cu->offset;
-      cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
-
-      /* Link this compilation unit into the compilation unit tree.  */
-      this_cu->cu = cu;
-      cu->per_cu = this_cu;
+      /* Skip dummy compilation units.  */
+      if (info_ptr >= (dwarf2_per_objfile->info.buffer
+                      + dwarf2_per_objfile->info.size)
+         || peek_abbrev_code (abfd, info_ptr) == 0)
+       {
+         do_cleanups (free_cu_cleanup);
+         return;
+       }
 
       /* Link this CU into read_in_chain.  */
       this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
@@ -3548,7 +3705,7 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
 
   /* Read the abbrevs for this compilation unit into a table.  */
   gdb_assert (cu->dwarf2_abbrevs == NULL);
-  dwarf2_read_abbrevs (abfd, cu);
+  dwarf2_read_abbrevs (cu);
   free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
 
   /* Read the compilation unit die.  */
@@ -3574,10 +3731,8 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
     }
 }
 
-/* Create a list of all compilation units in OBJFILE.  We do this only
-   if an inter-comp-unit reference is found; presumably if there is one,
-   there will be many, and one will occur early in the .debug_info section.
-   So there's no point in building this list incrementally.  */
+/* Create a list of all compilation units in OBJFILE.
+   This is only done for -readnow and building partial symtabs.  */
 
 static void
 create_all_comp_units (struct objfile *objfile)
@@ -3779,7 +3934,10 @@ partial_die_parent_scope (struct partial_die_info *pdi,
       return NULL;
     }
 
-  if (parent->tag == DW_TAG_namespace
+  if (pdi->tag == DW_TAG_enumerator)
+    /* Enumerators should not get the name of the enumeration as a prefix.  */
+    parent->scope = grandparent_scope;
+  else if (parent->tag == DW_TAG_namespace
       || parent->tag == DW_TAG_module
       || parent->tag == DW_TAG_structure_type
       || parent->tag == DW_TAG_class_type
@@ -3794,9 +3952,6 @@ partial_die_parent_scope (struct partial_die_info *pdi,
                                         grandparent_scope,
                                         parent->name, 0, cu);
     }
-  else if (parent->tag == DW_TAG_enumerator)
-    /* Enumerators should not get the name of the enumeration as a prefix.  */
-    parent->scope = grandparent_scope;
   else
     {
       /* FIXME drow/2004-04-01: What should we be doing with
@@ -4144,6 +4299,16 @@ add_partial_enumeration (struct partial_die_info *enum_pdi,
     }
 }
 
+/* Return the initial uleb128 in the die at INFO_PTR.  */
+
+static unsigned int
+peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr)
+{
+  unsigned int bytes_read;
+
+  return read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
+}
+
 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
    Return the corresponding abbrev, or NULL if the number is zero (indicating
    an empty DIE).  In either case *BYTES_READ will be set to the length of
@@ -4378,11 +4543,13 @@ dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
        }
     }
 }
+\f
+/* Reading in full CUs.  */
 
 /* Add PER_CU to the queue.  */
 
 static void
-queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
+queue_comp_unit (struct dwarf2_per_cu_data *per_cu)
 {
   struct dwarf2_queue_item *item;
 
@@ -4402,7 +4569,7 @@ queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
 /* Process the queue.  */
 
 static void
-process_queue (struct objfile *objfile)
+process_queue (void)
 {
   struct dwarf2_queue_item *item, *next_item;
 
@@ -4489,15 +4656,15 @@ psymtab_to_symtab_1 (struct partial_symtab *pst)
       return;
     }
 
-  dw2_do_instantiate_symtab (pst->objfile, per_cu);
+  dw2_do_instantiate_symtab (per_cu);
 }
 
 /* Load the DIEs associated with PER_CU into memory.  */
 
 static void
-load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
-                    struct objfile *objfile)
+load_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
 {
+  struct objfile *objfile = per_cu->objfile;
   bfd *abfd = objfile->obfd;
   struct dwarf2_cu *cu;
   unsigned int offset;
@@ -4506,7 +4673,7 @@ load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
   struct attribute *attr;
   int read_cu = 0;
 
-  gdb_assert (! per_cu->from_debug_types);
+  gdb_assert (! per_cu->debug_types_section);
 
   /* Set local variables from the partial symbol table info.  */
   offset = per_cu->offset;
@@ -4518,28 +4685,33 @@ load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
   if (per_cu->cu == NULL)
     {
       cu = xmalloc (sizeof (*cu));
-      init_one_comp_unit (cu, objfile);
+      init_one_comp_unit (cu, per_cu);
 
       read_cu = 1;
 
       /* If an error occurs while loading, release our storage.  */
-      free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
+      free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
 
       /* Read in the comp_unit header.  */
       info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
 
+      /* Skip dummy compilation units.  */
+      if (info_ptr >= (dwarf2_per_objfile->info.buffer
+                      + dwarf2_per_objfile->info.size)
+         || peek_abbrev_code (abfd, info_ptr) == 0)
+       {
+         do_cleanups (free_cu_cleanup);
+         return;
+       }
+
       /* Complete the cu_header.  */
       cu->header.offset = offset;
       cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
 
       /* Read the abbrevs for this compilation unit.  */
-      dwarf2_read_abbrevs (abfd, cu);
+      dwarf2_read_abbrevs (cu);
       free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
 
-      /* Link this compilation unit into the compilation unit tree.  */
-      per_cu->cu = cu;
-      cu->per_cu = per_cu;
-
       /* Link this CU into read_in_chain.  */
       per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
       dwarf2_per_objfile->read_in_chain = per_cu;
@@ -4553,7 +4725,7 @@ load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
   cu->dies = read_comp_unit (info_ptr, cu);
 
   /* We try not to read any attributes in this function, because not
-     all objfiles needed for references have been loaded yet, and symbol
+     all CUs needed for references have been loaded yet, and symbol
      table processing isn't initialized.  But we have to set the CU language,
      or we won't be able to build types correctly.  */
   prepare_one_comp_unit (cu, cu->dies);
@@ -4624,45 +4796,7 @@ compute_delayed_physnames (struct dwarf2_cu *cu)
     }
 }
 
-/* Check for GCC >= 4.0.  */
-
-static int
-producer_is_gcc_ge_4_0 (struct dwarf2_cu *cu)
-{
-  const char *cs;
-  int major, minor;
-
-  if (cu->producer == NULL)
-    {
-      /* For unknown compilers expect their behavior is not compliant.  For GCC
-        this case can also happen for -gdwarf-4 type units supported since
-        gcc-4.5.  */
-
-      return 0;
-    }
-
-  /* Skip any identifier after "GNU " - such as "C++" or "Java".  */
-
-  if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
-    {
-      /* For non-GCC compilers expect their behavior is not compliant.  */
-
-      return 0;
-    }
-  cs = &cu->producer[strlen ("GNU ")];
-  while (*cs && !isdigit (*cs))
-    cs++;
-  if (sscanf (cs, "%d.%d", &major, &minor) != 2)
-    {
-      /* Not recognized as GCC.  */
-
-      return 0;
-    }
-
-  return major >= 4;
-}
-
-/* Generate full symbol information for PST and CU, whose DIEs have
+/* Generate full symbol information for PER_CU, whose DIEs have
    already been loaded into memory.  */
 
 static void
@@ -4683,8 +4817,6 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
 
   cu->list_in_scope = &file_symbols;
 
-  dwarf2_find_base_address (cu->dies, cu);
-
   /* Do line number decoding in read_file_scope () */
   process_die (cu->dies, cu);
 
@@ -4703,6 +4835,8 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
 
   if (symtab != NULL)
     {
+      int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
+
       /* Set symtab language to language from DW_AT_language.  If the
         compilation is from a C file generated by language preprocessors, do
         not set the language if it was already deduced by start_subfile.  */
@@ -4719,8 +4853,13 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
         Still one can confuse GDB by using non-standard GCC compilation
         options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
         */ 
-      if (cu->has_loclist && producer_is_gcc_ge_4_0 (cu))
+      if (cu->has_loclist && gcc_4_minor >= 0)
        symtab->locations_valid = 1;
+
+      if (gcc_4_minor >= 5)
+       symtab->epilogue_unwind_valid = 1;
+
+      symtab->call_site_htab = cu->call_site_htab;
     }
 
   if (dwarf2_per_objfile->using_index)
@@ -4759,6 +4898,9 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_catch_block:
       read_lexical_block_scope (die, cu);
       break;
+    case DW_TAG_GNU_call_site:
+      read_call_site_scope (die, cu);
+      break;
     case DW_TAG_class_type:
     case DW_TAG_interface_type:
     case DW_TAG_structure_type:
@@ -4897,6 +5039,8 @@ static const char *
 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
                     int physname)
 {
+  struct objfile *objfile = cu->objfile;
+
   if (name == NULL)
     name = dwarf2_name (die, cu);
 
@@ -5104,7 +5248,7 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
                }
            }
 
-         name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
+         name = ui_file_obsavestring (buf, &objfile->objfile_obstack,
                                       &length);
          ui_file_delete (buf);
 
@@ -5112,7 +5256,7 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
            {
              char *cname
                = dwarf2_canonicalize_name (name, cu,
-                                           &cu->objfile->objfile_obstack);
+                                           &objfile->objfile_obstack);
 
              if (cname != NULL)
                name = cname;
@@ -5147,32 +5291,120 @@ dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
 static const char *
 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
 {
-  return dwarf2_compute_name (name, die, cu, 1);
-}
+  struct objfile *objfile = cu->objfile;
+  struct attribute *attr;
+  const char *retval, *mangled = NULL, *canon = NULL;
+  struct cleanup *back_to;
+  int need_copy = 1;
 
-/* Read the import statement specified by the given die and record it.  */
+  /* In this case dwarf2_compute_name is just a shortcut not building anything
+     on its own.  */
+  if (!die_needs_namespace (die, cu))
+    return dwarf2_compute_name (name, die, cu, 1);
 
-static void
-read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
-{
-  struct attribute *import_attr;
-  struct die_info *imported_die;
-  struct dwarf2_cu *imported_cu;
-  const char *imported_name;
-  const char *imported_name_prefix;
-  const char *canonical_name;
-  const char *import_alias;
-  const char *imported_declaration = NULL;
-  const char *import_prefix;
+  back_to = make_cleanup (null_cleanup, NULL);
 
-  char *temp;
+  attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
+  if (!attr)
+    attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
 
-  import_attr = dwarf2_attr (die, DW_AT_import, cu);
-  if (import_attr == NULL)
+  /* DW_AT_linkage_name is missing in some cases - depend on what GDB
+     has computed.  */
+  if (attr && DW_STRING (attr))
     {
-      complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
-                dwarf_tag_name (die->tag));
-      return;
+      char *demangled;
+
+      mangled = DW_STRING (attr);
+
+      /* Use DMGL_RET_DROP for C++ template functions to suppress their return
+        type.  It is easier for GDB users to search for such functions as
+        `name(params)' than `long name(params)'.  In such case the minimal
+        symbol names do not match the full symbol names but for template
+        functions there is never a need to look up their definition from their
+        declaration so the only disadvantage remains the minimal symbol
+        variant `long name(params)' does not have the proper inferior type.
+        */
+
+      demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
+                                           | (cu->language == language_java
+                                              ? DMGL_JAVA | DMGL_RET_POSTFIX
+                                              : DMGL_RET_DROP)));
+      if (demangled)
+       {
+         make_cleanup (xfree, demangled);
+         canon = demangled;
+       }
+      else
+       {
+         canon = mangled;
+         need_copy = 0;
+       }
+    }
+
+  if (canon == NULL || check_physname)
+    {
+      const char *physname = dwarf2_compute_name (name, die, cu, 1);
+
+      if (canon != NULL && strcmp (physname, canon) != 0)
+       {
+         /* It may not mean a bug in GDB.  The compiler could also
+            compute DW_AT_linkage_name incorrectly.  But in such case
+            GDB would need to be bug-to-bug compatible.  */
+
+         complaint (&symfile_complaints,
+                    _("Computed physname <%s> does not match demangled <%s> "
+                      "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
+                    physname, canon, mangled, die->offset, objfile->name);
+
+         /* Prefer DW_AT_linkage_name (in the CANON form) - when it
+            is available here - over computed PHYSNAME.  It is safer
+            against both buggy GDB and buggy compilers.  */
+
+         retval = canon;
+       }
+      else
+       {
+         retval = physname;
+         need_copy = 0;
+       }
+    }
+  else
+    retval = canon;
+
+  if (need_copy)
+    retval = obsavestring (retval, strlen (retval),
+                          &objfile->objfile_obstack);
+
+  do_cleanups (back_to);
+  return retval;
+}
+
+/* Read the import statement specified by the given die and record it.  */
+
+static void
+read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
+{
+  struct objfile *objfile = cu->objfile;
+  struct attribute *import_attr;
+  struct die_info *imported_die, *child_die;
+  struct dwarf2_cu *imported_cu;
+  const char *imported_name;
+  const char *imported_name_prefix;
+  const char *canonical_name;
+  const char *import_alias;
+  const char *imported_declaration = NULL;
+  const char *import_prefix;
+  VEC (const_char_ptr) *excludes = NULL;
+  struct cleanup *cleanups;
+
+  char *temp;
+
+  import_attr = dwarf2_attr (die, DW_AT_import, cu);
+  if (import_attr == NULL)
+    {
+      complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
+                dwarf_tag_name (die->tag));
+      return;
     }
 
   imported_cu = cu;
@@ -5243,17 +5475,60 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
   else
     canonical_name = imported_name;
 
+  cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes);
+
+  if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
+    for (child_die = die->child; child_die && child_die->tag;
+        child_die = sibling_die (child_die))
+      {
+       /* DWARF-4: A Fortran use statement with a “rename list” may be
+          represented by an imported module entry with an import attribute
+          referring to the module and owned entries corresponding to those
+          entities that are renamed as part of being imported.  */
+
+       if (child_die->tag != DW_TAG_imported_declaration)
+         {
+           complaint (&symfile_complaints,
+                      _("child DW_TAG_imported_declaration expected "
+                        "- DIE at 0x%x [in module %s]"),
+                      child_die->offset, objfile->name);
+           continue;
+         }
+
+       import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
+       if (import_attr == NULL)
+         {
+           complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
+                      dwarf_tag_name (child_die->tag));
+           continue;
+         }
+
+       imported_cu = cu;
+       imported_die = follow_die_ref_or_sig (child_die, import_attr,
+                                             &imported_cu);
+       imported_name = dwarf2_name (imported_die, imported_cu);
+       if (imported_name == NULL)
+         {
+           complaint (&symfile_complaints,
+                      _("child DW_TAG_imported_declaration has unknown "
+                        "imported name - DIE at 0x%x [in module %s]"),
+                      child_die->offset, objfile->name);
+           continue;
+         }
+
+       VEC_safe_push (const_char_ptr, excludes, imported_name);
+
+       process_die (child_die, cu);
+      }
+
   cp_add_using_directive (import_prefix,
                           canonical_name,
                           import_alias,
                           imported_declaration,
-                          &cu->objfile->objfile_obstack);
-}
+                         excludes,
+                          &objfile->objfile_obstack);
 
-static void
-initialize_cu_func_list (struct dwarf2_cu *cu)
-{
-  cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
+  do_cleanups (cleanups);
 }
 
 /* Cleanup function for read_file_scope.  */
@@ -5307,6 +5582,35 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
     *name = "<unknown>";
 }
 
+/* Handle DW_AT_stmt_list for a compilation unit.  */
+
+static void
+handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
+                       const char *comp_dir)
+{
+  struct attribute *attr;
+  struct objfile *objfile = cu->objfile;
+  bfd *abfd = objfile->obfd;
+
+  /* Decode line number information if present.  We do this before
+     processing child DIEs, so that the line header table is available
+     for DW_AT_decl_file.  */
+  attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
+  if (attr)
+    {
+      unsigned int line_offset = DW_UNSND (attr);
+      struct line_header *line_header
+       = dwarf_decode_line_header (line_offset, abfd, cu);
+
+      if (line_header)
+        {
+          cu->line_header = line_header;
+          make_cleanup (free_cu_line_header, cu);
+          dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
+        }
+    }
+}
+
 /* Process DW_TAG_compile_unit.  */
 
 static void
@@ -5321,7 +5625,6 @@ read_file_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;
   CORE_ADDR baseaddr;
 
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
@@ -5362,23 +5665,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
   record_debugformat ("DWARF 2");
   record_producer (cu->producer);
 
-  initialize_cu_func_list (cu);
-
-  /* Decode line number information if present.  We do this before
-     processing child DIEs, so that the line header table is available
-     for DW_AT_decl_file.  */
-  attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
-  if (attr)
-    {
-      unsigned int line_offset = DW_UNSND (attr);
-      line_header = dwarf_decode_line_header (line_offset, abfd, cu);
-      if (line_header)
-        {
-          cu->line_header = line_header;
-          make_cleanup (free_cu_line_header, cu);
-          dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
-        }
-    }
+  handle_DW_AT_stmt_list (die, cu, comp_dir);
 
   /* Process all dies in compilation unit.  */
   if (die->child != NULL)
@@ -5395,14 +5682,30 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
      refers to information in the line number info statement program
      header, so we can only read it if we've read the header
      successfully.  */
-  attr = dwarf2_attr (die, DW_AT_macro_info, cu);
-  if (attr && line_header)
+  attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
+  if (attr && cu->line_header)
+    {
+      if (dwarf2_attr (die, DW_AT_macro_info, cu))
+       complaint (&symfile_complaints,
+                  _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
+
+      dwarf_decode_macros (cu->line_header, DW_UNSND (attr),
+                          comp_dir, abfd, cu,
+                          &dwarf2_per_objfile->macro, 1);
+    }
+  else
     {
-      unsigned int macro_offset = DW_UNSND (attr);
+      attr = dwarf2_attr (die, DW_AT_macro_info, cu);
+      if (attr && cu->line_header)
+       {
+         unsigned int macro_offset = DW_UNSND (attr);
 
-      dwarf_decode_macros (line_header, macro_offset,
-                           comp_dir, abfd, cu);
+         dwarf_decode_macros (cu->line_header, macro_offset,
+                              comp_dir, abfd, cu,
+                              &dwarf2_per_objfile->macinfo, 0);
+       }
     }
+
   do_cleanups (back_to);
 }
 
@@ -5465,6 +5768,8 @@ read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
   record_debugformat ("DWARF 2");
   record_producer (cu->producer);
 
+  handle_DW_AT_stmt_list (die, cu, comp_dir);
+
   /* Process the dies in the type unit.  */
   if (die->child == NULL)
     {
@@ -5485,28 +5790,6 @@ read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
   do_cleanups (back_to);
 }
 
-static void
-add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
-                    struct dwarf2_cu *cu)
-{
-  struct function_range *thisfn;
-
-  thisfn = (struct function_range *)
-    obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
-  thisfn->name = name;
-  thisfn->lowpc = lowpc;
-  thisfn->highpc = highpc;
-  thisfn->seen_line = 0;
-  thisfn->next = NULL;
-
-  if (cu->last_fn == NULL)
-      cu->first_fn = thisfn;
-  else
-      cu->last_fn->next = thisfn;
-
-  cu->last_fn = thisfn;
-}
-
 /* qsort helper for inherit_abstract_dies.  */
 
 static int
@@ -5701,9 +5984,6 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   lowpc += baseaddr;
   highpc += baseaddr;
 
-  /* Record the function range for dwarf_decode_lines.  */
-  add_to_cu_func_list (name, lowpc, highpc, cu);
-
   /* If we have any template arguments, then we must allocate a
      different sort of symbol.  */
   for (child_die = die->child; child_die; child_die = sibling_die (child_die))
@@ -5887,6 +6167,257 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
   using_directives = new->using_directives;
 }
 
+/* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab.  */
+
+static void
+read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
+{
+  struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  CORE_ADDR pc, baseaddr;
+  struct attribute *attr;
+  struct call_site *call_site, call_site_local;
+  void **slot;
+  int nparams;
+  struct die_info *child_die;
+
+  baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+
+  attr = dwarf2_attr (die, DW_AT_low_pc, cu);
+  if (!attr)
+    {
+      complaint (&symfile_complaints,
+                _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
+                  "DIE 0x%x [in module %s]"),
+                die->offset, objfile->name);
+      return;
+    }
+  pc = DW_ADDR (attr) + baseaddr;
+
+  if (cu->call_site_htab == NULL)
+    cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
+                                              NULL, &objfile->objfile_obstack,
+                                              hashtab_obstack_allocate, NULL);
+  call_site_local.pc = pc;
+  slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
+  if (*slot != NULL)
+    {
+      complaint (&symfile_complaints,
+                _("Duplicate PC %s for DW_TAG_GNU_call_site "
+                  "DIE 0x%x [in module %s]"),
+                paddress (gdbarch, pc), die->offset, objfile->name);
+      return;
+    }
+
+  /* Count parameters at the caller.  */
+
+  nparams = 0;
+  for (child_die = die->child; child_die && child_die->tag;
+       child_die = sibling_die (child_die))
+    {
+      if (child_die->tag != DW_TAG_GNU_call_site_parameter)
+       {
+         complaint (&symfile_complaints,
+                    _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
+                      "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
+                    child_die->tag, child_die->offset, objfile->name);
+         continue;
+       }
+
+      nparams++;
+    }
+
+  call_site = obstack_alloc (&objfile->objfile_obstack,
+                            (sizeof (*call_site)
+                             + (sizeof (*call_site->parameter)
+                                * (nparams - 1))));
+  *slot = call_site;
+  memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter));
+  call_site->pc = pc;
+
+  if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
+    {
+      struct die_info *func_die;
+
+      /* Skip also over DW_TAG_inlined_subroutine.  */
+      for (func_die = die->parent;
+          func_die && func_die->tag != DW_TAG_subprogram
+          && func_die->tag != DW_TAG_subroutine_type;
+          func_die = func_die->parent);
+
+      /* DW_AT_GNU_all_call_sites is a superset
+        of DW_AT_GNU_all_tail_call_sites.  */
+      if (func_die
+          && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
+         && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
+       {
+         /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
+            not complete.  But keep CALL_SITE for look ups via call_site_htab,
+            both the initial caller containing the real return address PC and
+            the final callee containing the current PC of a chain of tail
+            calls do not need to have the tail call list complete.  But any
+            function candidate for a virtual tail call frame searched via
+            TYPE_TAIL_CALL_LIST must have the tail call list complete to be
+            determined unambiguously.  */
+       }
+      else
+       {
+         struct type *func_type = NULL;
+
+         if (func_die)
+           func_type = get_die_type (func_die, cu);
+         if (func_type != NULL)
+           {
+             gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC);
+
+             /* Enlist this call site to the function.  */
+             call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type);
+             TYPE_TAIL_CALL_LIST (func_type) = call_site;
+           }
+         else
+           complaint (&symfile_complaints,
+                      _("Cannot find function owning DW_TAG_GNU_call_site "
+                        "DIE 0x%x [in module %s]"),
+                      die->offset, objfile->name);
+       }
+    }
+
+  attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu);
+  if (attr == NULL)
+    attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
+  SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
+  if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0))
+    /* Keep NULL DWARF_BLOCK.  */;
+  else if (attr_form_is_block (attr))
+    {
+      struct dwarf2_locexpr_baton *dlbaton;
+
+      dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton));
+      dlbaton->data = DW_BLOCK (attr)->data;
+      dlbaton->size = DW_BLOCK (attr)->size;
+      dlbaton->per_cu = cu->per_cu;
+
+      SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
+    }
+  else if (is_ref_attr (attr))
+    {
+      struct dwarf2_cu *target_cu = cu;
+      struct die_info *target_die;
+
+      target_die = follow_die_ref_or_sig (die, attr, &target_cu);
+      gdb_assert (target_cu->objfile == objfile);
+      if (die_is_declaration (target_die, target_cu))
+       {
+         const char *target_physname;
+
+         target_physname = dwarf2_physname (NULL, target_die, target_cu);
+         if (target_physname == NULL)
+           complaint (&symfile_complaints,
+                      _("DW_AT_GNU_call_site_target target DIE has invalid "
+                        "physname, for referencing DIE 0x%x [in module %s]"),
+                      die->offset, objfile->name);
+         else
+           SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname);
+       }
+      else
+       {
+         CORE_ADDR lowpc;
+
+         /* DW_AT_entry_pc should be preferred.  */
+         if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL))
+           complaint (&symfile_complaints,
+                      _("DW_AT_GNU_call_site_target target DIE has invalid "
+                        "low pc, for referencing DIE 0x%x [in module %s]"),
+                      die->offset, objfile->name);
+         else
+           SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr);
+       }
+    }
+  else
+    complaint (&symfile_complaints,
+              _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
+                "block nor reference, for DIE 0x%x [in module %s]"),
+              die->offset, objfile->name);
+
+  call_site->per_cu = cu->per_cu;
+
+  for (child_die = die->child;
+       child_die && child_die->tag;
+       child_die = sibling_die (child_die))
+    {
+      struct dwarf2_locexpr_baton *dlbaton;
+      struct call_site_parameter *parameter;
+
+      if (child_die->tag != DW_TAG_GNU_call_site_parameter)
+       {
+         /* Already printed the complaint above.  */
+         continue;
+       }
+
+      gdb_assert (call_site->parameter_count < nparams);
+      parameter = &call_site->parameter[call_site->parameter_count];
+
+      /* DW_AT_location specifies the register number.  Value of the data
+        assumed for the register is contained in DW_AT_GNU_call_site_value.  */
+
+      attr = dwarf2_attr (child_die, DW_AT_location, cu);
+      if (!attr || !attr_form_is_block (attr))
+       {
+         complaint (&symfile_complaints,
+                    _("No DW_FORM_block* DW_AT_location for "
+                      "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
+                    child_die->offset, objfile->name);
+         continue;
+       }
+      parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data,
+                                &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]);
+      if (parameter->dwarf_reg == -1
+         && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data,
+                                 &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size],
+                                       &parameter->fb_offset))
+       {
+         complaint (&symfile_complaints,
+                    _("Only single DW_OP_reg or DW_OP_fbreg is supported "
+                      "for DW_FORM_block* DW_AT_location for "
+                      "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
+                    child_die->offset, objfile->name);
+         continue;
+       }
+
+      attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
+      if (!attr_form_is_block (attr))
+       {
+         complaint (&symfile_complaints,
+                    _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
+                      "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
+                    child_die->offset, objfile->name);
+         continue;
+       }
+      parameter->value = DW_BLOCK (attr)->data;
+      parameter->value_size = DW_BLOCK (attr)->size;
+
+      /* Parameters are not pre-cleared by memset above.  */
+      parameter->data_value = NULL;
+      parameter->data_value_size = 0;
+      call_site->parameter_count++;
+
+      attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
+      if (attr)
+       {
+         if (!attr_form_is_block (attr))
+           complaint (&symfile_complaints,
+                      _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
+                        "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
+                      child_die->offset, objfile->name);
+         else
+           {
+             parameter->data_value = DW_BLOCK (attr)->data;
+             parameter->data_value_size = DW_BLOCK (attr)->size;
+           }
+       }
+    }
+}
+
 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
    Return 1 if the attributes are present and valid, otherwise, return 0.
    If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'.  */
@@ -6086,7 +6617,8 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
     return 0;
 
   *lowpc = low;
-  *highpc = high;
+  if (highpc)
+    *highpc = high;
   return ret;
 }
 
@@ -6192,6 +6724,7 @@ static void
 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
                             CORE_ADDR baseaddr, struct dwarf2_cu *cu)
 {
+  struct objfile *objfile = cu->objfile;
   struct attribute *attr;
 
   attr = dwarf2_attr (die, DW_AT_high_pc, cu);
@@ -6211,7 +6744,7 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
   attr = dwarf2_attr (die, DW_AT_ranges, cu);
   if (attr)
     {
-      bfd *obfd = cu->objfile->obfd;
+      bfd *obfd = objfile->obfd;
 
       /* The value of the DW_AT_ranges attribute is the offset of the
          address range list in the .debug_ranges section.  */
@@ -7321,9 +7854,12 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
        }
 
       do_cleanups (back_to);
+
+      if (HAVE_CPLUS_STRUCT (type))
+       TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
     }
 
-  quirk_gcc_member_function_pointer (type, cu->objfile);
+  quirk_gcc_member_function_pointer (type, objfile);
 
   /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
      snapshots) has been known to create a die giving a declaration
@@ -7484,6 +8020,27 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
        TYPE_UNSIGNED (this_type) = 1;
     }
 
+  /* If we are reading an enum from a .debug_types unit, and the enum
+     is a declaration, and the enum is not the signatured type in the
+     unit, then we do not want to add a symbol for it.  Adding a
+     symbol would in some cases obscure the true definition of the
+     enum, giving users an incomplete type when the definition is
+     actually available.  Note that we do not want to do this for all
+     enums which are just declarations, because C++0x allows forward
+     enum declarations.  */
+  if (cu->per_cu->debug_types_section
+      && die_is_declaration (die, cu))
+    {
+      struct signatured_type *type_sig;
+
+      type_sig
+       = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile,
+                                           cu->per_cu->debug_types_section,
+                                           cu->per_cu->offset);
+      if (type_sig->type_offset != die->offset)
+       return;
+    }
+
   new_symbol (die, this_type, cu);
 }
 
@@ -7775,7 +8332,7 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
          const char *previous_prefix = determine_prefix (die, cu);
 
          cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
-                                 NULL, &objfile->objfile_obstack);
+                                 NULL, NULL, &objfile->objfile_obstack);
        }
     }
 
@@ -7854,7 +8411,7 @@ namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
 
   *is_anonymous = (name == NULL);
   if (*is_anonymous)
-    name = "(anonymous namespace)";
+    name = CP_ANONYMOUS_NAMESPACE_STR;
 
   return name;
 }
@@ -8089,6 +8646,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
 static struct type *
 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
 {
+  struct objfile *objfile = cu->objfile;
   struct type *type;           /* Type that this function returns.  */
   struct type *ftype;          /* Function that returns above type.  */
   struct attribute *attr;
@@ -8134,7 +8692,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
 
   if (die->child != NULL)
     {
-      struct type *void_type = objfile_type (cu->objfile)->builtin_void;
+      struct type *void_type = objfile_type (objfile)->builtin_void;
       struct die_info *child_die;
       int nparams, iparams;
 
@@ -8244,14 +8802,26 @@ read_typedef (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
   const char *name = NULL;
-  struct type *this_type;
+  struct type *this_type, *target_type;
 
   name = dwarf2_full_name (NULL, die, cu);
   this_type = init_type (TYPE_CODE_TYPEDEF, 0,
                         TYPE_FLAG_TARGET_STUB, NULL, objfile);
   TYPE_NAME (this_type) = (char *) name;
   set_die_type (die, this_type, cu);
-  TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
+  target_type = die_type (die, cu);
+  if (target_type != this_type)
+    TYPE_TARGET_TYPE (this_type) = target_type;
+  else
+    {
+      /* Self-referential typedefs are, it seems, not allowed by the DWARF
+        spec and cause infinite loops in GDB.  */
+      complaint (&symfile_complaints,
+                _("Self-referential DW_TAG_typedef "
+                  "- DIE at 0x%x [in module %s]"),
+                die->offset, objfile->name);
+      TYPE_TARGET_TYPE (this_type) = NULL;
+    }
   return this_type;
 }
 
@@ -8313,15 +8883,21 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        break;
       case DW_ATE_unsigned:
        type_flags |= TYPE_FLAG_UNSIGNED;
+       if (cu->language == language_fortran
+           && name
+           && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
+         code = TYPE_CODE_CHAR;
        break;
       case DW_ATE_signed_char:
        if (cu->language == language_ada || cu->language == language_m2
-           || cu->language == language_pascal)
+           || cu->language == language_pascal
+           || cu->language == language_fortran)
          code = TYPE_CODE_CHAR;
        break;
       case DW_ATE_unsigned_char:
        if (cu->language == language_ada || cu->language == language_m2
-           || cu->language == language_pascal)
+           || cu->language == language_pascal
+           || cu->language == language_fortran)
          code = TYPE_CODE_CHAR;
        type_flags |= TYPE_FLAG_UNSIGNED;
        break;
@@ -8384,7 +8960,7 @@ 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 || is_ref_attr (attr))
+      if (attr_form_is_block (attr) || is_ref_attr (attr))
         {
           /* GCC encodes arrays with unspecified or dynamic length
              with a DW_FORM_block1 attribute or a reference attribute.
@@ -8467,7 +9043,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   /* Mark arrays with dynamic length at least as an array of unspecified
      length.  GDB could check the boundary but before it gets implemented at
      least allow accessing the array elements.  */
-  if (attr && attr->form == DW_FORM_block1)
+  if (attr && attr_form_is_block (attr))
     TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
 
   /* Ada expects an empty array on no boundary attributes.  */
@@ -8538,7 +9114,7 @@ read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
 
   if (cu->dwarf2_abbrevs == NULL)
     {
-      dwarf2_read_abbrevs (cu->objfile->obfd, cu);
+      dwarf2_read_abbrevs (cu);
       back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
       read_abbrevs = 1;
     }
@@ -8579,11 +9155,9 @@ read_die_and_children (const struct die_reader_specs *reader,
     {
       fprintf_unfiltered (gdb_stdlog,
                          "\nRead die from %s of %s:\n",
-                         reader->buffer == dwarf2_per_objfile->info.buffer
-                         ? ".debug_info"
-                         : reader->buffer == dwarf2_per_objfile->types.buffer
-                         ? ".debug_types"
-                         : "unknown section",
+                         (reader->cu->per_cu->debug_types_section
+                          ? ".debug_types"
+                          : ".debug_info"),
                          reader->abfd->filename);
       dump_die (result, dwarf2_die_debug);
     }
@@ -8719,8 +9293,9 @@ read_full_die (const struct die_reader_specs *reader,
    the data found in the abbrev table.  */
 
 static void
-dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
+dwarf2_read_abbrevs (struct dwarf2_cu *cu)
 {
+  bfd *abfd = cu->objfile->obfd;
   struct comp_unit_head *cu_header = &cu->header;
   gdb_byte *abbrev_ptr;
   struct abbrev_info *cur_abbrev;
@@ -8893,6 +9468,7 @@ static struct partial_die_info *
 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
                   int building_psymtab, struct dwarf2_cu *cu)
 {
+  struct objfile *objfile = cu->objfile;
   struct partial_die_info *part_die;
   struct partial_die_info *parent_die, *last_die, *first_die = NULL;
   struct abbrev_info *abbrev;
@@ -9020,8 +9596,8 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
          if (building_psymtab && part_die->name != NULL)
            add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
                                 VAR_DOMAIN, LOC_TYPEDEF,
-                                &cu->objfile->static_psymbols,
-                                0, (CORE_ADDR) 0, cu->language, cu->objfile);
+                                &objfile->static_psymbols,
+                                0, (CORE_ADDR) 0, cu->language, objfile);
          info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
          continue;
        }
@@ -9038,7 +9614,7 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
        complaint (&symfile_complaints,
                   _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
                     "- DIE at 0x%x [in module %s]"),
-                  part_die->offset, cu->objfile->name);
+                  part_die->offset, objfile->name);
 
       /* If we're at the second level, and we're an enumerator, and
         our parent has no specification (meaning possibly lives in a
@@ -9058,9 +9634,9 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
                                 VAR_DOMAIN, LOC_CONST,
                                 (cu->language == language_cplus
                                  || cu->language == language_java)
-                                ? &cu->objfile->global_psymbols
-                                : &cu->objfile->static_psymbols,
-                                0, (CORE_ADDR) 0, cu->language, cu->objfile);
+                                ? &objfile->global_psymbols
+                                : &objfile->static_psymbols,
+                                0, (CORE_ADDR) 0, cu->language, objfile);
 
          info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
          continue;
@@ -9170,6 +9746,7 @@ read_partial_die (struct partial_die_info *part_die,
                  gdb_byte *buffer, gdb_byte *info_ptr,
                  struct dwarf2_cu *cu)
 {
+  struct objfile *objfile = cu->objfile;
   unsigned int i;
   struct attribute attr;
   int has_low_pc_attr = 0;
@@ -9211,7 +9788,7 @@ read_partial_die (struct partial_die_info *part_die,
            default:
              part_die->name
                = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
-                                           &cu->objfile->objfile_obstack);
+                                           &objfile->objfile_obstack);
              break;
            }
          break;
@@ -9317,25 +9894,25 @@ read_partial_die (struct partial_die_info *part_die,
         so that GDB will ignore it.  */
       if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
        {
-         struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
+         struct gdbarch *gdbarch = get_objfile_arch (objfile);
 
          complaint (&symfile_complaints,
                     _("DW_AT_low_pc %s is zero "
                       "for DIE at 0x%x [in module %s]"),
                     paddress (gdbarch, part_die->lowpc),
-                    part_die->offset, cu->objfile->name);
+                    part_die->offset, objfile->name);
        }
       /* dwarf2_get_pc_bounds has also the strict low < high requirement.  */
       else if (part_die->lowpc >= part_die->highpc)
        {
-         struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
+         struct gdbarch *gdbarch = get_objfile_arch (objfile);
 
          complaint (&symfile_complaints,
                     _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
                       "for DIE at 0x%x [in module %s]"),
                     paddress (gdbarch, part_die->lowpc),
                     paddress (gdbarch, part_die->highpc),
-                    part_die->offset, cu->objfile->name);
+                    part_die->offset, objfile->name);
        }
       else
        part_die->has_pc_info = 1;
@@ -9366,10 +9943,11 @@ find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
 static struct partial_die_info *
 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
 {
+  struct objfile *objfile = cu->objfile;
   struct dwarf2_per_cu_data *per_cu = NULL;
   struct partial_die_info *pd = NULL;
 
-  if (cu->per_cu->from_debug_types)
+  if (cu->per_cu->debug_types_section)
     {
       pd = find_partial_die_in_comp_unit (offset, cu);
       if (pd != NULL)
@@ -9384,10 +9962,10 @@ find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
        return pd;
     }
 
-  per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
+  per_cu = dwarf2_find_containing_comp_unit (offset, objfile);
 
   if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
-    load_partial_comp_unit (per_cu, cu->objfile);
+    load_partial_comp_unit (per_cu);
 
   per_cu->cu->last_used = 0;
   pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
@@ -9406,7 +9984,7 @@ find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
       back_to = make_cleanup (null_cleanup, 0);
       if (per_cu->cu->dwarf2_abbrevs == NULL)
        {
-         dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
+         dwarf2_read_abbrevs (per_cu->cu);
          make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
        }
       info_ptr = (dwarf2_per_objfile->info.buffer
@@ -9414,11 +9992,11 @@ find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
                  + per_cu->cu->header.first_die_offset);
       abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
       info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
-                                  per_cu->cu->objfile->obfd,
+                                  objfile->obfd,
                                   dwarf2_per_objfile->info.buffer, info_ptr,
                                   per_cu->cu);
       if (comp_unit_die.has_children)
-       load_partial_dies (per_cu->cu->objfile->obfd,
+       load_partial_dies (objfile->obfd,
                           dwarf2_per_objfile->info.buffer, info_ptr,
                           0, per_cu->cu);
       do_cleanups (back_to);
@@ -9432,7 +10010,7 @@ find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
     internal_error (__FILE__, __LINE__,
                    _("could not find partial DIE 0x%x "
                      "in cache [from module %s]\n"),
-                   offset, bfd_get_filename (cu->objfile->obfd));
+                   offset, bfd_get_filename (objfile->obfd));
   return pd;
 }
 
@@ -9524,7 +10102,7 @@ fixup_partial_die (struct partial_die_info *part_die,
   /* Set default names for some unnamed DIEs.  */
 
   if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
-    part_die->name = "(anonymous namespace)";
+    part_die->name = CP_ANONYMOUS_NAMESPACE_STR;
 
   /* If there is no parent die to provide a namespace, and there are
      children, see if we can determine the namespace from their linkage
@@ -9532,7 +10110,7 @@ fixup_partial_die (struct partial_die_info *part_die,
      NOTE: We need to do this even if cu->has_namespace_info != 0.
      gcc-4.5 -gdwarf-4 can drop the enclosing namespace.  */
   if (cu->language == language_cplus
-      && dwarf2_per_objfile->types.asection != NULL
+      && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
       && part_die->die_parent == NULL
       && part_die->has_children
       && (part_die->tag == DW_TAG_class_type
@@ -9543,9 +10121,10 @@ fixup_partial_die (struct partial_die_info *part_die,
   /* GCC might emit a nameless struct or union that has a linkage
      name.  See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510.  */
   if (part_die->name == NULL
-      && (part_die->tag == DW_TAG_structure_type
-         || part_die->tag == DW_TAG_union_type
-         || part_die->tag == DW_TAG_class_type)
+      && (part_die->tag == DW_TAG_class_type
+         || part_die->tag == DW_TAG_interface_type
+         || part_die->tag == DW_TAG_structure_type
+         || part_die->tag == DW_TAG_union_type)
       && part_die->linkage_name != NULL)
     {
       char *demangled;
@@ -9553,8 +10132,18 @@ fixup_partial_die (struct partial_die_info *part_die,
       demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
       if (demangled)
        {
-         part_die->name = obsavestring (demangled, strlen (demangled),
-                                        &cu->objfile->objfile_obstack);
+         const char *base;
+
+         /* Strip any leading namespaces/classes, keep only the base name.
+            DW_AT_name for named DIEs does not contain the prefixes.  */
+         base = strrchr (demangled, ':');
+         if (base && base > demangled && base[-1] == ':')
+           base++;
+         else
+           base = demangled;
+
+         part_die->name = obsavestring (base, strlen (base),
+                                        &cu->objfile->objfile_obstack);
          xfree (demangled);
        }
     }
@@ -9986,32 +10575,32 @@ read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
 }
 
 static char *
-read_indirect_string (bfd *abfd, gdb_byte *buf,
-                     const struct comp_unit_head *cu_header,
-                     unsigned int *bytes_read_ptr)
+read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
 {
-  LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
-
   dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
   if (dwarf2_per_objfile->str.buffer == NULL)
-    {
-      error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
-                     bfd_get_filename (abfd));
-      return NULL;
-    }
+    error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
+          bfd_get_filename (abfd));
   if (str_offset >= dwarf2_per_objfile->str.size)
-    {
-      error (_("DW_FORM_strp pointing outside of "
-              ".debug_str section [in module %s]"),
-            bfd_get_filename (abfd));
-      return NULL;
-    }
+    error (_("DW_FORM_strp pointing outside of "
+            ".debug_str section [in module %s]"),
+          bfd_get_filename (abfd));
   gdb_assert (HOST_CHAR_BIT == 8);
   if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
     return NULL;
   return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
 }
 
+static char *
+read_indirect_string (bfd *abfd, gdb_byte *buf,
+                     const struct comp_unit_head *cu_header,
+                     unsigned int *bytes_read_ptr)
+{
+  LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
+
+  return read_indirect_string_at_offset (abfd, str_offset);
+}
+
 static unsigned long
 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
 {
@@ -10435,52 +11024,6 @@ dwarf_decode_line_header (unsigned int offset, bfd *abfd,
   return lh;
 }
 
-/* This function exists to work around a bug in certain compilers
-   (particularly GCC 2.95), in which the first line number marker of a
-   function does not show up until after the prologue, right before
-   the second line number marker.  This function shifts ADDRESS down
-   to the beginning of the function if necessary, and is called on
-   addresses passed to record_line.  */
-
-static CORE_ADDR
-check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
-{
-  struct function_range *fn;
-
-  /* Find the function_range containing address.  */
-  if (!cu->first_fn)
-    return address;
-
-  if (!cu->cached_fn)
-    cu->cached_fn = cu->first_fn;
-
-  fn = cu->cached_fn;
-  while (fn)
-    if (fn->lowpc <= address && fn->highpc > address)
-      goto found;
-    else
-      fn = fn->next;
-
-  fn = cu->first_fn;
-  while (fn && fn != cu->cached_fn)
-    if (fn->lowpc <= address && fn->highpc > address)
-      goto found;
-    else
-      fn = fn->next;
-
-  return address;
-
- found:
-  if (fn->seen_line)
-    return address;
-  if (address != fn->lowpc)
-    complaint (&symfile_complaints,
-              _("misplaced first line number at 0x%lx for '%s'"),
-              (unsigned long) address, fn->name);
-  fn->seen_line = 1;
-  return fn->lowpc;
-}
-
 /* Subroutine of dwarf_decode_lines to simplify it.
    Return the file name of the psymtab for included file FILE_INDEX
    in line header LH of PST.
@@ -10678,8 +11221,7 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
                          last_subfile = current_subfile;
                        }
                      /* Append row to matrix using current values.  */
-                     addr = check_cu_functions (address, cu);
-                     addr = gdbarch_addr_bits_remove (gdbarch, addr);
+                     addr = gdbarch_addr_bits_remove (gdbarch, address);
                      (*p_record_line) (current_subfile, line, addr);
                    }
                }
@@ -10714,7 +11256,7 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
                      complaint (&symfile_complaints,
                                 _(".debug_line address at offset 0x%lx is 0 "
                                   "[in module %s]"),
-                                line_offset, cu->objfile->name);
+                                line_offset, objfile->name);
                      p_record_line = noop_record_line;
                    }
 
@@ -10777,8 +11319,7 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
                            (*p_record_line) (last_subfile, 0, addr);
                          last_subfile = current_subfile;
                        }
-                     addr = check_cu_functions (address, cu);
-                     addr = gdbarch_addr_bits_remove (gdbarch, addr);
+                     addr = gdbarch_addr_bits_remove (gdbarch, address);
                      (*p_record_line) (current_subfile, line, addr);
                    }
                }
@@ -10924,7 +11465,7 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
 
          if (current_subfile->symtab == NULL)
            current_subfile->symtab = allocate_symtab (current_subfile->name,
-                                                      cu->objfile);
+                                                      objfile);
          fe->symtab = current_subfile->symtab;
        }
     }
@@ -11288,14 +11829,6 @@ new_symbol_full (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;
-           }
 
          list_to_add = cu->list_in_scope;
          break;
@@ -11404,7 +11937,7 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
         namespaces based on the demangled name.  */
       if (!processing_has_namespace_info
          && cu->language == language_cplus)
-       cp_scan_for_anonymous_namespaces (sym);
+       cp_scan_for_anonymous_namespaces (sym, objfile);
     }
   return (sym);
 }
@@ -11686,6 +12219,7 @@ static struct type *
 lookup_die_type (struct die_info *die, struct attribute *attr,
                 struct dwarf2_cu *cu)
 {
+  struct objfile *objfile = cu->objfile;
   struct type *this_type;
 
   /* First see if we have it cached.  */
@@ -11707,9 +12241,9 @@ lookup_die_type (struct die_info *die, struct attribute *attr,
       if (sig_type == NULL)
        error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
                 "at 0x%x [in module %s]"),
-              die->offset, cu->objfile->name);
+              die->offset, objfile->name);
 
-      gdb_assert (sig_type->per_cu.from_debug_types);
+      gdb_assert (sig_type->per_cu.debug_types_section);
       offset = sig_type->per_cu.offset + sig_type->type_offset;
       this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
     }
@@ -11717,7 +12251,7 @@ lookup_die_type (struct die_info *die, struct attribute *attr,
     {
       dump_die_for_error (die);
       error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
-            dwarf_attr_name (attr->name), cu->objfile->name);
+            dwarf_attr_name (attr->name), objfile->name);
     }
 
   /* If not cached we need to read it in.  */
@@ -11741,14 +12275,14 @@ lookup_die_type (struct die_info *die, struct attribute *attr,
 
       /* read_type_die already issued a complaint.  */
       message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
-                           cu->objfile->name,
+                           objfile->name,
                            cu->header.offset,
                            die->offset);
-      saved = obstack_copy0 (&cu->objfile->objfile_obstack,
+      saved = obstack_copy0 (&objfile->objfile_obstack,
                             message, strlen (message));
       xfree (message);
 
-      this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
+      this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile);
     }
 
   return this_type;
@@ -11922,6 +12456,42 @@ guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
   return NULL;
 }
 
+/* GCC might emit a nameless typedef that has a linkage name.  Determine the
+   prefix part in such case.  See
+   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510.  */
+
+static char *
+anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
+{
+  struct attribute *attr;
+  char *base;
+
+  if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
+      && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
+    return NULL;
+
+  attr = dwarf2_attr (die, DW_AT_name, cu);
+  if (attr != NULL && DW_STRING (attr) != NULL)
+    return NULL;
+
+  attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
+  if (attr == NULL)
+    attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
+  if (attr == NULL || DW_STRING (attr) == NULL)
+    return NULL;
+
+  /* dwarf2_name had to be already called.  */
+  gdb_assert (DW_STRING_IS_CANONICAL (attr));
+
+  /* Strip the base name, keep any leading namespaces/classes.  */
+  base = strrchr (DW_STRING (attr), ':');
+  if (base == NULL || base == DW_STRING (attr) || base[-1] != ':')
+    return "";
+
+  return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr),
+                      &cu->objfile->objfile_obstack);
+}
+
 /* Return the name of the namespace/class that DIE is defined within,
    or "" if we can't tell.  The caller should not xfree the result.
 
@@ -11943,11 +12513,16 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
   struct die_info *parent, *spec_die;
   struct dwarf2_cu *spec_cu;
   struct type *parent_type;
+  char *retval;
 
   if (cu->language != language_cplus && cu->language != language_java
       && cu->language != language_fortran)
     return "";
 
+  retval = anonymous_struct_prefix (die, cu);
+  if (retval)
+    return retval;
+
   /* We have to be careful in the presence of DW_AT_specification.
      For example, with GCC 3.4, given the code
 
@@ -12051,7 +12626,7 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
       case DW_TAG_compile_unit:
        /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace.  Cope.  */
        if (cu->language == language_cplus
-           && dwarf2_per_objfile->types.asection != NULL
+           && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
            && die->child != NULL
            && (die->tag == DW_TAG_class_type
                || die->tag == DW_TAG_structure_type
@@ -12239,12 +12814,21 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
 
          if (demangled)
            {
+             char *base;
+
              /* FIXME: we already did this for the partial symbol... */
-             DW_STRING (attr)
-               = obsavestring (demangled, strlen (demangled),
-                               &cu->objfile->objfile_obstack);
+             DW_STRING (attr) = obsavestring (demangled, strlen (demangled),
+                                              &cu->objfile->objfile_obstack);
              DW_STRING_IS_CANONICAL (attr) = 1;
              xfree (demangled);
+
+             /* Strip any leading namespaces/classes, keep only the base name.
+                DW_AT_name for named DIEs does not contain the prefixes.  */
+             base = strrchr (DW_STRING (attr), ':');
+             if (base && base > DW_STRING (attr) && base[-1] == ':')
+               return &base[1];
+             else
+               return DW_STRING (attr);
            }
        }
       break;
@@ -12428,6 +13012,8 @@ dwarf_tag_name (unsigned tag)
       return "DW_TAG_PGI_kanji_type";
     case DW_TAG_PGI_interface_block:
       return "DW_TAG_PGI_interface_block";
+    case DW_TAG_GNU_call_site:
+      return "DW_TAG_GNU_call_site";
     default:
       return "DW_TAG_<unknown>";
     }
@@ -13519,7 +14105,7 @@ maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
     }
 
   /* Add it to the queue.  */
-  queue_comp_unit (per_cu, this_cu->objfile);
+  queue_comp_unit (per_cu);
 
   return 1;
 }
@@ -13563,7 +14149,7 @@ follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
 
   target_cu = cu;
 
-  if (cu->per_cu->from_debug_types)
+  if (cu->per_cu->debug_types_section)
     {
       /* .debug_types CUs cannot reference anything outside their CU.
         If they need to, they have to reference a signatured type via
@@ -13579,7 +14165,7 @@ follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
 
       /* If necessary, add it to the queue and load its DIEs.  */
       if (maybe_queue_comp_unit (cu, per_cu))
-       load_full_comp_unit (per_cu, cu->objfile);
+       load_full_comp_unit (per_cu);
 
       target_cu = per_cu->cu;
     }
@@ -13587,7 +14173,7 @@ follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
     {
       /* We're loading full DIEs during partial symbol reading.  */
       gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
-      load_full_comp_unit (cu->per_cu, cu->objfile);
+      load_full_comp_unit (cu->per_cu);
     }
 
   *ref_cu = target_cu;
@@ -13616,8 +14202,9 @@ follow_die_ref (struct die_info *src_die, struct attribute *attr,
   return die;
 }
 
-/* Return DWARF block and its CU referenced by OFFSET at PER_CU.  Returned
-   value is intended for DW_OP_call*.  */
+/* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
+   Returned value is intended for DW_OP_call*.  Returned
+   dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE.  */
 
 struct dwarf2_locexpr_baton
 dwarf2_fetch_die_location_block (unsigned int offset,
@@ -13625,22 +14212,27 @@ dwarf2_fetch_die_location_block (unsigned int offset,
                                 CORE_ADDR (*get_frame_pc) (void *baton),
                                 void *baton)
 {
-  struct dwarf2_cu *cu = per_cu->cu;
+  struct dwarf2_cu *cu;
   struct die_info *die;
   struct attribute *attr;
   struct dwarf2_locexpr_baton retval;
 
   dw2_setup (per_cu->objfile);
 
+  if (per_cu->cu == NULL)
+    load_cu (per_cu);
+  cu = per_cu->cu;
+
   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);
+          offset, per_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.".  */
+      /* DWARF: "If there is no such attribute, then there is no effect.".
+        DATA is ignored if SIZE is 0.  */
 
       retval.data = NULL;
       retval.size = 0;
@@ -13662,12 +14254,15 @@ dwarf2_fetch_die_location_block (unsigned int offset,
       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);
+              offset, per_cu->objfile->name);
 
       retval.data = DW_BLOCK (attr)->data;
       retval.size = DW_BLOCK (attr)->size;
     }
   retval.per_cu = cu->per_cu;
+
+  age_cached_comp_units ();
+
   return retval;
 }
 
@@ -13706,7 +14301,7 @@ follow_die_sig (struct die_info *src_die, struct attribute *attr,
   /* If necessary, add it to the queue and load its DIEs.  */
 
   if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
-    read_signatured_type (objfile, sig_type);
+    read_signatured_type (sig_type);
 
   gdb_assert (sig_type->per_cu.cu != NULL);
 
@@ -13727,9 +14322,11 @@ follow_die_sig (struct die_info *src_die, struct attribute *attr,
 /* Given an offset of a signatured type, return its signatured_type.  */
 
 static struct signatured_type *
-lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
+lookup_signatured_type_at_offset (struct objfile *objfile,
+                                 struct dwarf2_section_info *section,
+                                 unsigned int offset)
 {
-  gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
+  gdb_byte *info_ptr = section->buffer + offset;
   unsigned int length, initial_length_size;
   unsigned int sig_offset;
   struct signatured_type find_entry, *type_sig;
@@ -13750,23 +14347,29 @@ lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
   return type_sig;
 }
 
-/* Read in signatured type at OFFSET and build its CU and die(s).  */
+/* Load the DIEs associated with type unit PER_CU into memory.  */
 
 static void
-read_signatured_type_at_offset (struct objfile *objfile,
-                               unsigned int offset)
+load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
 {
+  struct objfile *objfile = per_cu->objfile;
+  struct dwarf2_section_info *sect = per_cu->debug_types_section;
+  unsigned int offset = per_cu->offset;
   struct signatured_type *type_sig;
 
-  dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
+  dwarf2_read_section (objfile, sect);
 
   /* We have the section offset, but we need the signature to do the
-     hash table lookup.         */
-  type_sig = lookup_signatured_type_at_offset (objfile, offset);
+     hash table lookup.  */
+  /* FIXME: This is sorta unnecessary, read_signatured_type only uses
+     the signature to assert we found the right one.
+     Ok, but it's a lot of work.  We should simplify things so any needed
+     assert doesn't require all this clumsiness.  */
+  type_sig = lookup_signatured_type_at_offset (objfile, sect, offset);
 
   gdb_assert (type_sig->per_cu.cu == NULL);
 
-  read_signatured_type (objfile, type_sig);
+  read_signatured_type (type_sig);
 
   gdb_assert (type_sig->per_cu.cu != NULL);
 }
@@ -13774,30 +14377,28 @@ read_signatured_type_at_offset (struct objfile *objfile,
 /* Read in a signatured type and build its CU and DIEs.  */
 
 static void
-read_signatured_type (struct objfile *objfile,
-                     struct signatured_type *type_sig)
+read_signatured_type (struct signatured_type *type_sig)
 {
+  struct objfile *objfile = type_sig->per_cu.objfile;
   gdb_byte *types_ptr;
   struct die_reader_specs reader_specs;
   struct dwarf2_cu *cu;
   ULONGEST signature;
   struct cleanup *back_to, *free_cu_cleanup;
+  struct dwarf2_section_info *section = type_sig->per_cu.debug_types_section;
 
-  dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
-  types_ptr = dwarf2_per_objfile->types.buffer + type_sig->per_cu.offset;
+  dwarf2_read_section (objfile, section);
+  types_ptr = section->buffer + type_sig->per_cu.offset;
 
   gdb_assert (type_sig->per_cu.cu == NULL);
 
   cu = xmalloc (sizeof (*cu));
-  init_one_comp_unit (cu, objfile);
-
-  type_sig->per_cu.cu = cu;
-  cu->per_cu = &type_sig->per_cu;
+  init_one_comp_unit (cu, &type_sig->per_cu);
 
   /* If an error occurs while loading, release our storage.  */
-  free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
+  free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
 
-  types_ptr = read_type_comp_unit_head (&cu->header, &signature,
+  types_ptr = read_type_comp_unit_head (&cu->header, section, &signature,
                                        types_ptr, objfile->obfd);
   gdb_assert (signature == type_sig->signature);
 
@@ -13810,7 +14411,7 @@ read_signatured_type (struct objfile *objfile,
                            hashtab_obstack_allocate,
                            dummy_obstack_deallocate);
 
-  dwarf2_read_abbrevs (cu->objfile->obfd, cu);
+  dwarf2_read_abbrevs (cu);
   back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
 
   init_cu_die_reader (&reader_specs, cu);
@@ -13819,7 +14420,7 @@ read_signatured_type (struct objfile *objfile,
                                    NULL /*parent*/);
 
   /* We try not to read any attributes in this function, because not
-     all objfiles needed for references have been loaded yet, and symbol
+     all CUs needed for references have been loaded yet, and symbol
      table processing isn't initialized.  But we have to set the CU language,
      or we won't be able to build types correctly.  */
   prepare_one_comp_unit (cu, cu->dies);
@@ -13993,6 +14594,11 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
          i += 4;
          break;
 
+       case DW_OP_const8u:
+         stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]);
+         i += 8;
+         break;
+
        case DW_OP_constu:
          stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
                                                  &bytes_read);
@@ -14040,9 +14646,12 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
          /* Nothing should follow this operator, so the top of stack would
             be returned.  */
          /* This is valid for partial global symbols, but the variable's
-            address will be bogus in the psymtab.  */
+            address will be bogus in the psymtab.  Make it always at least
+            non-zero to not look as a variable garbage collected by linker
+            which have DW_OP_addr 0.  */
          if (i < size)
            dwarf2_complex_location_expr_complaint ();
+         stack[stacki]++;
           break;
 
        case DW_OP_GNU_uninit:
@@ -14378,117 +14987,205 @@ parse_macro_definition (struct macro_source_file *file, int line,
     dwarf2_macro_malformed_definition_complaint (body);
 }
 
+/* Skip some bytes from BYTES according to the form given in FORM.
+   Returns the new pointer.  */
 
-static void
-dwarf_decode_macros (struct line_header *lh, unsigned int offset,
-                     char *comp_dir, bfd *abfd,
-                     struct dwarf2_cu *cu)
+static gdb_byte *
+skip_form_bytes (bfd *abfd, gdb_byte *bytes,
+                enum dwarf_form form,
+                unsigned int offset_size,
+                struct dwarf2_section_info *section)
 {
-  gdb_byte *mac_ptr, *mac_end;
-  struct macro_source_file *current_file = 0;
-  enum dwarf_macinfo_record_type macinfo_type;
-  int at_commandline;
+  unsigned int bytes_read;
 
-  dwarf2_read_section (dwarf2_per_objfile->objfile,
-                      &dwarf2_per_objfile->macinfo);
-  if (dwarf2_per_objfile->macinfo.buffer == NULL)
+  switch (form)
     {
-      complaint (&symfile_complaints, _("missing .debug_macinfo section"));
-      return;
+    case DW_FORM_data1:
+    case DW_FORM_flag:
+      ++bytes;
+      break;
+
+    case DW_FORM_data2:
+      bytes += 2;
+      break;
+
+    case DW_FORM_data4:
+      bytes += 4;
+      break;
+
+    case DW_FORM_data8:
+      bytes += 8;
+      break;
+
+    case DW_FORM_string:
+      read_direct_string (abfd, bytes, &bytes_read);
+      bytes += bytes_read;
+      break;
+
+    case DW_FORM_sec_offset:
+    case DW_FORM_strp:
+      bytes += offset_size;
+      break;
+
+    case DW_FORM_block:
+      bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read);
+      bytes += bytes_read;
+      break;
+
+    case DW_FORM_block1:
+      bytes += 1 + read_1_byte (abfd, bytes);
+      break;
+    case DW_FORM_block2:
+      bytes += 2 + read_2_bytes (abfd, bytes);
+      break;
+    case DW_FORM_block4:
+      bytes += 4 + read_4_bytes (abfd, bytes);
+      break;
+
+    case DW_FORM_sdata:
+    case DW_FORM_udata:
+      bytes = skip_leb128 (abfd, bytes);
+      break;
+
+    default:
+      {
+      complain:
+       complaint (&symfile_complaints,
+                  _("invalid form 0x%x in `%s'"),
+                  form,
+                  section->asection->name);
+       return NULL;
+      }
     }
 
-  /* First pass: Find the name of the base filename.
-     This filename is needed in order to process all macros whose definition
-     (or undefinition) comes from the command line.  These macros are defined
-     before the first DW_MACINFO_start_file entry, and yet still need to be
-     associated to the base file.
+  return bytes;
+}
 
-     To determine the base file name, we scan the macro definitions until we
-     reach the first DW_MACINFO_start_file entry.  We then initialize
-     CURRENT_FILE accordingly so that any macro definition found before the
-     first DW_MACINFO_start_file can still be associated to the base file.  */
+/* A helper for dwarf_decode_macros that handles skipping an unknown
+   opcode.  Returns an updated pointer to the macro data buffer; or,
+   on error, issues a complaint and returns NULL.  */
 
-  mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
-  mac_end = dwarf2_per_objfile->macinfo.buffer
-    + dwarf2_per_objfile->macinfo.size;
+static gdb_byte *
+skip_unknown_opcode (unsigned int opcode,
+                    gdb_byte **opcode_definitions,
+                    gdb_byte *mac_ptr,
+                    bfd *abfd,
+                    unsigned int offset_size,
+                    struct dwarf2_section_info *section)
+{
+  unsigned int bytes_read, i;
+  unsigned long arg;
+  gdb_byte *defn;
 
-  do
+  if (opcode_definitions[opcode] == NULL)
     {
-      /* Do we at least have room for a macinfo type byte?  */
-      if (mac_ptr >= mac_end)
-        {
-         /* Complaint is printed during the second pass as GDB will probably
-            stop the first pass earlier upon finding
-            DW_MACINFO_start_file.  */
-         break;
-        }
+      complaint (&symfile_complaints,
+                _("unrecognized DW_MACFINO opcode 0x%x"),
+                opcode);
+      return NULL;
+    }
 
-      macinfo_type = read_1_byte (abfd, mac_ptr);
-      mac_ptr++;
+  defn = opcode_definitions[opcode];
+  arg = read_unsigned_leb128 (abfd, defn, &bytes_read);
+  defn += bytes_read;
 
-      switch (macinfo_type)
-        {
-          /* A zero macinfo type indicates the end of the macro
-             information.  */
-        case 0:
-         break;
+  for (i = 0; i < arg; ++i)
+    {
+      mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section);
+      if (mac_ptr == NULL)
+       {
+         /* skip_form_bytes already issued the complaint.  */
+         return NULL;
+       }
+    }
 
-       case DW_MACINFO_define:
-       case DW_MACINFO_undef:
-         /* Only skip the data by MAC_PTR.  */
-         {
-           unsigned int bytes_read;
+  return mac_ptr;
+}
 
-           read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
-           mac_ptr += bytes_read;
-           read_direct_string (abfd, mac_ptr, &bytes_read);
-           mac_ptr += bytes_read;
-         }
-         break;
+/* A helper function which parses the header of a macro section.
+   If the macro section is the extended (for now called "GNU") type,
+   then this updates *OFFSET_SIZE.  Returns a pointer to just after
+   the header, or issues a complaint and returns NULL on error.  */
 
-       case DW_MACINFO_start_file:
-         {
-           unsigned int bytes_read;
-           int line, file;
+static gdb_byte *
+dwarf_parse_macro_header (gdb_byte **opcode_definitions,
+                         bfd *abfd,
+                         gdb_byte *mac_ptr,
+                         unsigned int *offset_size,
+                         int section_is_gnu)
+{
+  memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *));
 
-           line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
-           mac_ptr += bytes_read;
-           file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
-           mac_ptr += bytes_read;
+  if (section_is_gnu)
+    {
+      unsigned int version, flags;
 
-           current_file = macro_start_file (file, line, current_file,
-                                            comp_dir, lh, cu->objfile);
-         }
-         break;
+      version = read_2_bytes (abfd, mac_ptr);
+      if (version != 4)
+       {
+         complaint (&symfile_complaints,
+                    _("unrecognized version `%d' in .debug_macro section"),
+                    version);
+         return NULL;
+       }
+      mac_ptr += 2;
 
-       case DW_MACINFO_end_file:
-         /* No data to skip by MAC_PTR.  */
-         break;
+      flags = read_1_byte (abfd, mac_ptr);
+      ++mac_ptr;
+      *offset_size = (flags & 1) ? 8 : 4;
 
-       case DW_MACINFO_vendor_ext:
-         /* Only skip the data by MAC_PTR.  */
-         {
-           unsigned int bytes_read;
+      if ((flags & 2) != 0)
+       /* We don't need the line table offset.  */
+       mac_ptr += *offset_size;
 
-           read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
-           mac_ptr += bytes_read;
-           read_direct_string (abfd, mac_ptr, &bytes_read);
-           mac_ptr += bytes_read;
-         }
-         break;
+      /* Vendor opcode descriptions.  */
+      if ((flags & 4) != 0)
+       {
+         unsigned int i, count;
 
-       default:
-         break;
+         count = read_1_byte (abfd, mac_ptr);
+         ++mac_ptr;
+         for (i = 0; i < count; ++i)
+           {
+             unsigned int opcode, bytes_read;
+             unsigned long arg;
+
+             opcode = read_1_byte (abfd, mac_ptr);
+             ++mac_ptr;
+             opcode_definitions[opcode] = mac_ptr;
+             arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+             mac_ptr += bytes_read;
+             mac_ptr += arg;
+           }
        }
-    } while (macinfo_type != 0 && current_file == NULL);
+    }
 
-  /* Second pass: Process all entries.
+  return mac_ptr;
+}
 
-     Use the AT_COMMAND_LINE flag to determine whether we are still processing
-     command-line macro definitions/undefinitions.  This flag is unset when we
-     reach the first DW_MACINFO_start_file entry.  */
+/* A helper for dwarf_decode_macros that handles the GNU extensions,
+   including DW_GNU_MACINFO_transparent_include.  */
+
+static void
+dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
+                         struct macro_source_file *current_file,
+                         struct line_header *lh, char *comp_dir,
+                         struct dwarf2_section_info *section,
+                         int section_is_gnu,
+                         unsigned int offset_size,
+                         struct objfile *objfile)
+{
+  enum dwarf_macro_record_type macinfo_type;
+  int at_commandline;
+  gdb_byte *opcode_definitions[256];
 
-  mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
+  mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
+                                     &offset_size, section_is_gnu);
+  if (mac_ptr == NULL)
+    {
+      /* We already issued a complaint.  */
+      return;
+    }
 
   /* Determines if GDB is still before first DW_MACINFO_start_file.  If true
      GDB is still reading the definitions from command line.  First
@@ -14504,13 +15201,15 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
       /* Do we at least have room for a macinfo type byte?  */
       if (mac_ptr >= mac_end)
        {
-         dwarf2_macros_too_long_complaint ();
+         dwarf2_macros_too_long_complaint (section);
          break;
        }
 
       macinfo_type = read_1_byte (abfd, mac_ptr);
       mac_ptr++;
 
+      /* Note that we rely on the fact that the corresponding GNU and
+        DWARF constants are the same.  */
       switch (macinfo_type)
        {
          /* A zero macinfo type indicates the end of the macro
@@ -14518,29 +15217,45 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
        case 0:
          break;
 
-        case DW_MACINFO_define:
-        case DW_MACINFO_undef:
+        case DW_MACRO_GNU_define:
+        case DW_MACRO_GNU_undef:
+       case DW_MACRO_GNU_define_indirect:
+       case DW_MACRO_GNU_undef_indirect:
           {
             unsigned int bytes_read;
             int line;
             char *body;
+           int is_define;
 
-            line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
-            mac_ptr += bytes_read;
-            body = read_direct_string (abfd, mac_ptr, &bytes_read);
-            mac_ptr += bytes_read;
+           line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+           mac_ptr += bytes_read;
+
+           if (macinfo_type == DW_MACRO_GNU_define
+               || macinfo_type == DW_MACRO_GNU_undef)
+             {
+               body = read_direct_string (abfd, mac_ptr, &bytes_read);
+               mac_ptr += bytes_read;
+             }
+           else
+             {
+               LONGEST str_offset;
 
+               str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
+               mac_ptr += offset_size;
+
+               body = read_indirect_string_at_offset (abfd, str_offset);
+             }
+
+           is_define = (macinfo_type == DW_MACRO_GNU_define
+                        || macinfo_type == DW_MACRO_GNU_define_indirect);
             if (! current_file)
              {
                /* DWARF violation as no main source is present.  */
                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_undef ?
-                                _("undefinition") :
-                                _("something-or-other"), line, body);
+                          is_define ? _("definition") : _("undefinition"),
+                          line, body);
                break;
              }
            if ((line == 0 && !at_commandline)
@@ -14548,21 +15263,21 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
              complaint (&symfile_complaints,
                         _("debug info gives %s macro %s with %s line %d: %s"),
                         at_commandline ? _("command-line") : _("in-file"),
-                        macinfo_type == DW_MACINFO_define ?
-                          _("definition") :
-                            macinfo_type == DW_MACINFO_undef ?
-                              _("undefinition") :
-                              _("something-or-other"),
+                        is_define ? _("definition") : _("undefinition"),
                         line == 0 ? _("zero") : _("non-zero"), line, body);
 
-           if (macinfo_type == DW_MACINFO_define)
+           if (is_define)
              parse_macro_definition (current_file, line, body);
-           else if (macinfo_type == DW_MACINFO_undef)
-             macro_undef (current_file, line, body);
+           else
+             {
+               gdb_assert (macinfo_type == DW_MACRO_GNU_undef
+                           || macinfo_type == DW_MACRO_GNU_undef_indirect);
+               macro_undef (current_file, line, body);
+             }
           }
           break;
 
-        case DW_MACINFO_start_file:
+        case DW_MACRO_GNU_start_file:
           {
             unsigned int bytes_read;
             int line, file;
@@ -14582,17 +15297,18 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
 
            if (at_commandline)
              {
-               /* This DW_MACINFO_start_file was executed in the pass one.  */
+               /* This DW_MACRO_GNU_start_file was executed in the
+                  pass one.  */
                at_commandline = 0;
              }
            else
              current_file = macro_start_file (file, line,
                                               current_file, comp_dir,
-                                              lh, cu->objfile);
+                                              lh, objfile);
           }
           break;
 
-        case DW_MACINFO_end_file:
+        case DW_MACRO_GNU_end_file:
           if (! current_file)
            complaint (&symfile_complaints,
                       _("macro debug info has an unmatched "
@@ -14602,7 +15318,7 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
               current_file = current_file->included_by;
               if (! current_file)
                 {
-                  enum dwarf_macinfo_record_type next_type;
+                  enum dwarf_macro_record_type next_type;
 
                   /* GCC circa March 2002 doesn't produce the zero
                      type byte marking the end of the compilation
@@ -14612,7 +15328,7 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
                   /* Do we at least have room for a macinfo type byte?  */
                   if (mac_ptr >= mac_end)
                     {
-                     dwarf2_macros_too_long_complaint ();
+                     dwarf2_macros_too_long_complaint (section);
                       return;
                     }
 
@@ -14629,23 +15345,200 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
             }
           break;
 
+       case DW_MACRO_GNU_transparent_include:
+         {
+           LONGEST offset;
+
+           offset = read_offset_1 (abfd, mac_ptr, offset_size);
+           mac_ptr += offset_size;
+
+           dwarf_decode_macro_bytes (abfd,
+                                     section->buffer + offset,
+                                     mac_end, current_file,
+                                     lh, comp_dir,
+                                     section, section_is_gnu,
+                                     offset_size, objfile);
+         }
+         break;
+
         case DW_MACINFO_vendor_ext:
-          {
-            unsigned int bytes_read;
-            int constant;
+         if (!section_is_gnu)
+           {
+             unsigned int bytes_read;
+             int constant;
 
-            constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
-            mac_ptr += bytes_read;
-            read_direct_string (abfd, mac_ptr, &bytes_read);
-            mac_ptr += bytes_read;
+             constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+             mac_ptr += bytes_read;
+             read_direct_string (abfd, mac_ptr, &bytes_read);
+             mac_ptr += bytes_read;
 
-            /* We don't recognize any vendor extensions.  */
-          }
-          break;
+             /* We don't recognize any vendor extensions.  */
+             break;
+           }
+         /* FALLTHROUGH */
+
+       default:
+         mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
+                                        mac_ptr, abfd, offset_size,
+                                        section);
+         if (mac_ptr == NULL)
+           return;
+         break;
         }
     } while (macinfo_type != 0);
 }
 
+static void
+dwarf_decode_macros (struct line_header *lh, unsigned int offset,
+                     char *comp_dir, bfd *abfd,
+                     struct dwarf2_cu *cu,
+                    struct dwarf2_section_info *section,
+                    int section_is_gnu)
+{
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  gdb_byte *mac_ptr, *mac_end;
+  struct macro_source_file *current_file = 0;
+  enum dwarf_macro_record_type macinfo_type;
+  unsigned int offset_size = cu->header.offset_size;
+  gdb_byte *opcode_definitions[256];
+
+  dwarf2_read_section (objfile, section);
+  if (section->buffer == NULL)
+    {
+      complaint (&symfile_complaints, _("missing %s section"),
+                section->asection->name);
+      return;
+    }
+
+  /* First pass: Find the name of the base filename.
+     This filename is needed in order to process all macros whose definition
+     (or undefinition) comes from the command line.  These macros are defined
+     before the first DW_MACINFO_start_file entry, and yet still need to be
+     associated to the base file.
+
+     To determine the base file name, we scan the macro definitions until we
+     reach the first DW_MACINFO_start_file entry.  We then initialize
+     CURRENT_FILE accordingly so that any macro definition found before the
+     first DW_MACINFO_start_file can still be associated to the base file.  */
+
+  mac_ptr = section->buffer + offset;
+  mac_end = section->buffer + section->size;
+
+  mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
+                                     &offset_size, section_is_gnu);
+  if (mac_ptr == NULL)
+    {
+      /* We already issued a complaint.  */
+      return;
+    }
+
+  do
+    {
+      /* Do we at least have room for a macinfo type byte?  */
+      if (mac_ptr >= mac_end)
+        {
+         /* Complaint is printed during the second pass as GDB will probably
+            stop the first pass earlier upon finding
+            DW_MACINFO_start_file.  */
+         break;
+        }
+
+      macinfo_type = read_1_byte (abfd, mac_ptr);
+      mac_ptr++;
+
+      /* Note that we rely on the fact that the corresponding GNU and
+        DWARF constants are the same.  */
+      switch (macinfo_type)
+        {
+          /* A zero macinfo type indicates the end of the macro
+             information.  */
+        case 0:
+         break;
+
+       case DW_MACRO_GNU_define:
+       case DW_MACRO_GNU_undef:
+         /* Only skip the data by MAC_PTR.  */
+         {
+           unsigned int bytes_read;
+
+           read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+           mac_ptr += bytes_read;
+           read_direct_string (abfd, mac_ptr, &bytes_read);
+           mac_ptr += bytes_read;
+         }
+         break;
+
+       case DW_MACRO_GNU_start_file:
+         {
+           unsigned int bytes_read;
+           int line, file;
+
+           line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+           mac_ptr += bytes_read;
+           file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+           mac_ptr += bytes_read;
+
+           current_file = macro_start_file (file, line, current_file,
+                                            comp_dir, lh, objfile);
+         }
+         break;
+
+       case DW_MACRO_GNU_end_file:
+         /* No data to skip by MAC_PTR.  */
+         break;
+
+       case DW_MACRO_GNU_define_indirect:
+       case DW_MACRO_GNU_undef_indirect:
+         {
+           unsigned int bytes_read;
+
+           read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+           mac_ptr += bytes_read;
+           mac_ptr += offset_size;
+         }
+         break;
+
+       case DW_MACRO_GNU_transparent_include:
+         /* Note that, according to the spec, a transparent include
+            chain cannot call DW_MACRO_GNU_start_file.  So, we can just
+            skip this opcode.  */
+         mac_ptr += offset_size;
+         break;
+
+       case DW_MACINFO_vendor_ext:
+         /* Only skip the data by MAC_PTR.  */
+         if (!section_is_gnu)
+           {
+             unsigned int bytes_read;
+
+             read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+             mac_ptr += bytes_read;
+             read_direct_string (abfd, mac_ptr, &bytes_read);
+             mac_ptr += bytes_read;
+           }
+         /* FALLTHROUGH */
+
+       default:
+         mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
+                                        mac_ptr, abfd, offset_size,
+                                        section);
+         if (mac_ptr == NULL)
+           return;
+         break;
+       }
+    } while (macinfo_type != 0 && current_file == NULL);
+
+  /* Second pass: Process all entries.
+
+     Use the AT_COMMAND_LINE flag to determine whether we are still processing
+     command-line macro definitions/undefinitions.  This flag is unset when we
+     reach the first DW_MACINFO_start_file entry.  */
+
+  dwarf_decode_macro_bytes (abfd, section->buffer + offset, mac_end,
+                           current_file, lh, comp_dir, section, section_is_gnu,
+                           offset_size, objfile);
+}
+
 /* Check if the attribute's form is a DW_FORM_block*
    if so return true else false.  */
 static int
@@ -14728,16 +15621,18 @@ static void
 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
                             struct dwarf2_cu *cu)
 {
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
+
   if (attr_form_is_section_offset (attr)
       /* ".debug_loc" may not exist at all, or the offset may be outside
         the section.  If so, fall through to the complaint in the
         other branch.  */
-      && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile,
+      && DW_UNSND (attr) < dwarf2_section_size (objfile,
                                                &dwarf2_per_objfile->loc))
     {
       struct dwarf2_loclist_baton *baton;
 
-      baton = obstack_alloc (&cu->objfile->objfile_obstack,
+      baton = obstack_alloc (&objfile->objfile_obstack,
                             sizeof (struct dwarf2_loclist_baton));
 
       fill_in_loclist_baton (cu, baton, attr);
@@ -14754,7 +15649,7 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
     {
       struct dwarf2_locexpr_baton *baton;
 
-      baton = obstack_alloc (&cu->objfile->objfile_obstack,
+      baton = obstack_alloc (&objfile->objfile_obstack,
                             sizeof (struct dwarf2_locexpr_baton));
       baton->per_cu = cu->per_cu;
       gdb_assert (baton->per_cu);
@@ -14774,7 +15669,6 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
          dwarf2_invalid_attrib_class_complaint ("location description",
                                                 SYMBOL_NATURAL_NAME (sym));
          baton->size = 0;
-         baton->data = NULL;
        }
 
       SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
@@ -14799,26 +15693,42 @@ dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
   return objfile;
 }
 
+/* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
+   (CU_HEADERP is unused in such case) or prepare a temporary copy at
+   CU_HEADERP first.  */
+
+static const struct comp_unit_head *
+per_cu_header_read_in (struct comp_unit_head *cu_headerp,
+                      struct dwarf2_per_cu_data *per_cu)
+{
+  struct objfile *objfile;
+  struct dwarf2_per_objfile *per_objfile;
+  gdb_byte *info_ptr;
+
+  if (per_cu->cu)
+    return &per_cu->cu->header;
+
+  objfile = per_cu->objfile;
+  per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
+  info_ptr = per_objfile->info.buffer + per_cu->offset;
+
+  memset (cu_headerp, 0, sizeof (*cu_headerp));
+  read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd);
+
+  return cu_headerp;
+}
+
 /* Return the address size given in the compilation unit header for CU.  */
 
-CORE_ADDR
+int
 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
 {
-  if (per_cu->cu)
-    return per_cu->cu->header.addr_size;
-  else
-    {
-      /* If the CU is not currently read in, we re-read its header.  */
-      struct objfile *objfile = per_cu->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;
+  struct comp_unit_head cu_header_local;
+  const struct comp_unit_head *cu_headerp;
 
-      memset (&cu_header, 0, sizeof cu_header);
-      read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
-      return cu_header.addr_size;
-    }
+  cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
+
+  return cu_headerp->addr_size;
 }
 
 /* Return the offset size given in the compilation unit header for CU.  */
@@ -14826,21 +15736,28 @@ dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_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->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;
+  struct comp_unit_head cu_header_local;
+  const struct comp_unit_head *cu_headerp;
 
-      memset (&cu_header, 0, sizeof cu_header);
-      read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
-      return cu_header.offset_size;
-    }
+  cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
+
+  return cu_headerp->offset_size;
+}
+
+/* See its dwarf2loc.h declaration.  */
+
+int
+dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
+{
+  struct comp_unit_head cu_header_local;
+  const struct comp_unit_head *cu_headerp;
+
+  cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
+
+  if (cu_headerp->version == 2)
+    return cu_headerp->addr_size;
+  else
+    return cu_headerp->offset_size;
 }
 
 /* Return the text offset of the CU.  The returned offset comes from
@@ -14913,13 +15830,15 @@ dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
   return this_cu;
 }
 
-/* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space.  */
+/* Initialize dwarf2_cu CU, owned by PER_CU.  */
 
 static void
-init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile)
+init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu)
 {
   memset (cu, 0, sizeof (*cu));
-  cu->objfile = objfile;
+  per_cu->cu = cu;
+  cu->per_cu = per_cu;
+  cu->objfile = per_cu->objfile;
   obstack_init (&cu->comp_unit_obstack);
 }
 
@@ -14948,12 +15867,12 @@ prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
    cleanup routine.  */
 
 static void
-free_one_comp_unit (void *data)
+free_heap_comp_unit (void *data)
 {
   struct dwarf2_cu *cu = data;
 
-  if (cu->per_cu != NULL)
-    cu->per_cu->cu = NULL;
+  gdb_assert (cu->per_cu != NULL);
+  cu->per_cu->cu = NULL;
   cu->per_cu = NULL;
 
   obstack_free (&cu->comp_unit_obstack, NULL);
@@ -14973,20 +15892,18 @@ free_stack_comp_unit (void *data)
 {
   struct dwarf2_cu *cu = data;
 
+  gdb_assert (cu->per_cu != NULL);
+  cu->per_cu->cu = NULL;
+  cu->per_cu = NULL;
+
   obstack_free (&cu->comp_unit_obstack, NULL);
   cu->partial_dies = NULL;
 
-  if (cu->per_cu != NULL)
-    {
-      /* This compilation unit is on the stack in our caller, so we
-        should not xfree it.  Just unlink it.  */
-      cu->per_cu->cu = NULL;
-      cu->per_cu = NULL;
-
-      /* If we had a per-cu pointer, then we may have other compilation
-        units loaded, so age them now.  */
-      age_cached_comp_units ();
-    }
+  /* The previous code only did this if per_cu != NULL.
+     But that would always succeed, so now we just unconditionally do
+     the aging.  This seems like the wrong place to do such aging,
+     but cleaning that up is left for later.  */
+  age_cached_comp_units ();
 }
 
 /* Free all cached compilation units.  */
@@ -15004,7 +15921,7 @@ free_cached_comp_units (void *data)
 
       next_cu = per_cu->cu->read_in_chain;
 
-      free_one_comp_unit (per_cu->cu);
+      free_heap_comp_unit (per_cu->cu);
       *last_chain = next_cu;
 
       per_cu = next_cu;
@@ -15039,7 +15956,7 @@ age_cached_comp_units (void)
 
       if (!per_cu->cu->mark)
        {
-         free_one_comp_unit (per_cu->cu);
+         free_heap_comp_unit (per_cu->cu);
          *last_chain = next_cu;
        }
       else
@@ -15066,7 +15983,7 @@ free_one_cached_comp_unit (void *target_cu)
 
       if (per_cu->cu == target_cu)
        {
-         free_one_comp_unit (per_cu->cu);
+         free_heap_comp_unit (per_cu->cu);
          *last_chain = next_cu;
          break;
        }
@@ -15165,7 +16082,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
       && !HAVE_GNAT_AUX_INFO (type))
     INIT_GNAT_SPECIFIC (type);
 
-  if (cu->per_cu->from_debug_types)
+  if (cu->per_cu->debug_types_section)
     type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
   else
     type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
@@ -15205,7 +16122,7 @@ get_die_type_at_offset (unsigned int offset,
   struct dwarf2_offset_and_type *slot, ofs;
   htab_t type_hash;
 
-  if (per_cu->from_debug_types)
+  if (per_cu->debug_types_section)
     type_hash = dwarf2_per_objfile->debug_types_type_hash;
   else
     type_hash = dwarf2_per_objfile->debug_info_type_hash;
@@ -15259,6 +16176,13 @@ dwarf2_mark_helper (void **slot, void *data)
   struct dwarf2_per_cu_data *per_cu;
 
   per_cu = (struct dwarf2_per_cu_data *) *slot;
+
+  /* cu->dependencies references may not yet have been ever read if QUIT aborts
+     reading of the chain.  As such dependencies remain valid it is not much
+     useful to track and undo them during QUIT cleanups.  */
+  if (per_cu->cu == NULL)
+    return 1;
+
   if (per_cu->cu->mark)
     return 1;
   per_cu->cu->mark = 1;
@@ -15335,14 +16259,13 @@ show_dwarf2_cmd (char *args, int from_tty)
 static void
 munmap_section_buffer (struct dwarf2_section_info *info)
 {
-  if (info->was_mmapped)
+  if (info->map_addr != NULL)
     {
 #ifdef HAVE_MMAP
-      intptr_t begin = (intptr_t) info->buffer;
-      intptr_t map_begin = begin & ~(pagesize - 1);
-      size_t map_length = info->size + begin - map_begin;
+      int res;
 
-      gdb_assert (munmap ((void *) map_begin, map_length) == 0);
+      res = munmap (info->map_addr, info->map_len);
+      gdb_assert (res == 0);
 #else
       /* Without HAVE_MMAP, we should never be here to begin with.  */
       gdb_assert_not_reached ("no mmap support");
@@ -15356,6 +16279,8 @@ static void
 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
 {
   struct dwarf2_per_objfile *data = d;
+  int ix;
+  struct dwarf2_section_info *section;
 
   /* This is sorted according to the order they're defined in to make it easier
      to keep in sync.  */
@@ -15364,12 +16289,19 @@ dwarf2_per_objfile_free (struct objfile *objfile, void *d)
   munmap_section_buffer (&data->line);
   munmap_section_buffer (&data->loc);
   munmap_section_buffer (&data->macinfo);
+  munmap_section_buffer (&data->macro);
   munmap_section_buffer (&data->str);
   munmap_section_buffer (&data->ranges);
-  munmap_section_buffer (&data->types);
   munmap_section_buffer (&data->frame);
   munmap_section_buffer (&data->eh_frame);
   munmap_section_buffer (&data->gdb_index);
+
+  for (ix = 0;
+       VEC_iterate (dwarf2_section_info_def, data->types, ix, section);
+       ++ix)
+    munmap_section_buffer (section);
+
+  VEC_free (dwarf2_section_info_def, data->types);
 }
 
 \f
@@ -15850,7 +16782,7 @@ write_psymbols (struct mapped_symtab *symtab,
       if (!*slot)
        {
          *slot = lookup;
-         add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
+         add_index_entry (symtab, SYMBOL_SEARCH_NAME (*psymp), cu_index);
        }
     }
 }
@@ -15924,14 +16856,6 @@ write_one_signatured_type (void **slot, void *d)
   return 1;
 }
 
-/* A cleanup function for an htab_t.  */
-
-static void
-cleanup_htab (void *arg)
-{
-  htab_delete (arg);
-}
-
 /* Create an index file for OBJFILE in the directory DIR.  */
 
 static void
@@ -15957,6 +16881,9 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
   if (dwarf2_per_objfile->using_index)
     error (_("Cannot use an index to create the index"));
 
+  if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
+    error (_("Cannot make an index when the file has multiple .debug_types sections"));
+
   if (stat (objfile->name, &st) < 0)
     perror_with_name (objfile->name);
 
@@ -15985,7 +16912,7 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
 
   psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
                                  NULL, xcalloc, xfree);
-  make_cleanup (cleanup_htab, psyms_seen);
+  make_cleanup_htab_delete (psyms_seen);
 
   /* While we're scanning CU's create a table that maps a psymtab pointer
      (which is what addrmap records) to its index (which is what is recorded
@@ -15995,7 +16922,7 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
                                     hash_psymtab_cu_index,
                                     eq_psymtab_cu_index,
                                     NULL, xcalloc, xfree);
-  make_cleanup (cleanup_htab, cu_index_htab);
+  make_cleanup_htab_delete (cu_index_htab);
   psymtab_cu_index_map = (struct psymtab_cu_index_map *)
     xmalloc (sizeof (struct psymtab_cu_index_map)
             * dwarf2_per_objfile->n_comp_units);
@@ -16165,6 +17092,15 @@ show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
                    value);
 }
 
+static void
+show_check_physname (struct ui_file *file, int from_tty,
+                    struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file,
+                   _("Whether to check \"physname\" is %s.\n"),
+                   value);
+}
+
 void _initialize_dwarf2_read (void);
 
 void
@@ -16220,6 +17156,14 @@ The value is the maximum depth to print."),
                            NULL,
                            &setdebuglist, &showdebuglist);
 
+  add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
+Set cross-checking of \"physname\" code against demangler."), _("\
+Show cross-checking of \"physname\" code against demangler."), _("\
+When enabled, GDB's internal \"physname\" code is checked against\n\
+the demangler."),
+                          NULL, show_check_physname,
+                          &setdebuglist, &showdebuglist);
+
   c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
               _("\
 Save a gdb-index file.\n\
This page took 0.084129 seconds and 4 git commands to generate.