2011-10-11 Sterling Augustine <saugustine@google.com>
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index 82a2f0b37a83e8c80ee9564e79cc45500ccf7a98..2592bcff310fa1d1e7283bddaa1a2d097dfa7593 100644 (file)
@@ -57,6 +57,7 @@
 #include "vec.h"
 #include "c-lang.h"
 #include "valprint.h"
+#include <ctype.h>
 
 #include <fcntl.h>
 #include "gdb_string.h"
@@ -118,6 +119,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
@@ -133,11 +137,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;
@@ -148,16 +158,24 @@ DEF_VEC_I (offset_type);
    a comment by the code that writes the index.  */
 struct mapped_index
 {
+  /* Index data format version.  */
+  int version;
+
   /* The total length of the buffer.  */
   off_t total_size;
+
   /* A pointer to the address table data.  */
   const gdb_byte *address_table;
+
   /* Size of the address table data in bytes.  */
   offset_type address_table_size;
+
   /* The symbol table, implemented as a hash table.  */
   const offset_type *symbol_table;
+
   /* Size in slots, each slot is 2 offset_types.  */
   offset_type symbol_table_slots;
+
   /* A pointer to the constant pool.  */
   const char *constant_pool;
 };
@@ -169,13 +187,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;
 
@@ -234,26 +254,30 @@ 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 */
 
-/* We hold several abbreviation tables in memory at the same time. */
+/* We hold several abbreviation tables in memory at the same time.  */
 #ifndef ABBREV_HASH_SIZE
 #define ABBREV_HASH_SIZE 121
 #endif
@@ -383,6 +407,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;
 
@@ -395,6 +422,13 @@ struct dwarf2_cu
      DIEs for namespaces, we don't need to try to infer them
      from mangled names.  */
   unsigned int has_namespace_info : 1;
+
+  /* This CU references .debug_loc.  See the symtab->locations_valid field.
+     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
@@ -423,9 +457,9 @@ 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_type_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.  */
@@ -454,9 +488,6 @@ struct signatured_type
 {
   ULONGEST signature;
 
-  /* Offset in .debug_types of the TU (type_unit) for this type.  */
-  unsigned int offset;
-
   /* Offset in .debug_types of the type defined by this TU.  */
   unsigned int type_offset;
 
@@ -464,11 +495,11 @@ struct signatured_type
   struct dwarf2_per_cu_data per_cu;
 };
 
-/* Struct used to pass misc. parameters to read_die_and_children, et. al.
-   which are used for both .debug_info and .debug_types dies.
-   All parameters here are unchanging for the life of the call.
-   This struct exists to abstract away the constant parameters of
-   die reading.  */
+/* Struct used to pass misc. parameters to read_die_and_children, et
+   al.  which are used for both .debug_info and .debug_types dies.
+   All parameters here are unchanging for the life of the call.  This
+   struct exists to abstract away the constant parameters of die
+   reading.  */
 
 struct die_reader_specs
 {
@@ -531,7 +562,7 @@ struct line_header
 };
 
 /* When we construct a partial symbol table entry we only
-   need this much information. */
+   need this much information.  */
 struct partial_die_info
   {
     /* Offset of this DIE.  */
@@ -596,7 +627,7 @@ struct partial_die_info
     struct partial_die_info *die_parent, *die_child, *die_sibling;
   };
 
-/* This data structure holds the information of an abbrev. */
+/* This data structure holds the information of an abbrev.  */
 struct abbrev_info
   {
     unsigned int number;       /* number identifying abbrev */
@@ -613,7 +644,7 @@ struct attr_abbrev
     ENUM_BITFIELD(dwarf_form) form : 16;
   };
 
-/* Attributes have a name and a value */
+/* Attributes have a name and a value */
 struct attribute
   {
     ENUM_BITFIELD(dwarf_attribute) name : 16;
@@ -636,7 +667,7 @@ struct attribute
     u;
   };
 
-/* This data structure holds a complete die structure. */
+/* This data structure holds a complete die structure.  */
 struct die_info
   {
     /* DWARF-2 tag for this DIE.  */
@@ -677,7 +708,7 @@ struct function_range
   struct function_range *next;
 };
 
-/* Get at parts of an attribute structure */
+/* Get at parts of an attribute structure */
 
 #define DW_STRING(attr)    ((attr)->u.str)
 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
@@ -687,7 +718,7 @@ struct function_range
 #define DW_ADDR(attr)     ((attr)->u.addr)
 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
 
-/* Blocks are a bunch of untyped bytes. */
+/* Blocks are a bunch of untyped bytes.  */
 struct dwarf_block
   {
     unsigned int size;
@@ -713,7 +744,7 @@ static int bits_per_byte = 8;
    in an instance of a field_info structure, as defined below.  */
 struct field_info
   {
-    /* List of data member and baseclasses fields. */
+    /* List of data member and baseclasses fields.  */
     struct nextfield
       {
        struct nextfield *next;
@@ -787,13 +818,13 @@ static void
 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
                           struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
+  fprintf_filtered (file, _("The upper bound on the age of cached "
+                           "dwarf2 compilation units is %s.\n"),
                    value);
 }
 
 
-/* Various complaints about symbol reading that don't abort the process */
+/* Various complaints about symbol reading that don't abort the process */
 
 static void
 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
@@ -813,7 +844,8 @@ static void
 dwarf2_debug_line_missing_end_sequence_complaint (void)
 {
   complaint (&symfile_complaints,
-            _(".debug_line section has line program sequence without an end"));
+            _(".debug_line section has line "
+              "program sequence without an end"));
 }
 
 static void
@@ -827,22 +859,24 @@ dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
                                              int arg3)
 {
   complaint (&symfile_complaints,
-            _("const value length mismatch for '%s', got %d, expected %d"), arg1,
-            arg2, arg3);
+            _("const value length mismatch for '%s', got %d, expected %d"),
+            arg1, arg2, arg3);
 }
 
 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
 dwarf2_macro_malformed_definition_complaint (const char *arg1)
 {
   complaint (&symfile_complaints,
-            _("macro debug info contains a malformed macro definition:\n`%s'"),
+            _("macro debug info contains a "
+              "malformed macro definition:\n`%s'"),
             arg1);
 }
 
@@ -850,7 +884,8 @@ static void
 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
 {
   complaint (&symfile_complaints,
-            _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2);
+            _("invalid attribute class or form for '%s' in '%s'"),
+            arg1, arg2);
 }
 
 /* local function prototypes */
@@ -860,6 +895,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 *,
@@ -1014,7 +1052,8 @@ static struct type *die_type (struct die_info *, struct dwarf2_cu *);
 
 static int need_gnat_info (struct dwarf2_cu *);
 
-static struct type *die_descriptive_type (struct die_info *, struct dwarf2_cu *);
+static struct type *die_descriptive_type (struct die_info *,
+                                         struct dwarf2_cu *);
 
 static void set_descriptive_type (struct type *, struct die_info *,
                                  struct dwarf2_cu *);
@@ -1043,6 +1082,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 *);
 
@@ -1068,7 +1109,8 @@ static void dwarf2_add_member_fn (struct field_info *,
                                  struct dwarf2_cu *);
 
 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
-                                            struct type *, struct dwarf2_cu *);
+                                            struct type *,
+                                            struct dwarf2_cu *);
 
 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
 
@@ -1174,7 +1216,13 @@ static struct die_info *follow_die_sig (struct die_info *,
                                        struct attribute *,
                                        struct dwarf2_cu **);
 
+static struct signatured_type *lookup_signatured_type_at_offset
+    (struct objfile *objfile,
+     struct dwarf2_section_info *section,
+     unsigned int offset);
+
 static void read_signatured_type_at_offset (struct objfile *objfile,
+                                           struct dwarf2_section_info *sect,
                                            unsigned int offset);
 
 static void read_signatured_type (struct objfile *,
@@ -1194,7 +1242,9 @@ 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 *);
 
@@ -1317,10 +1367,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)
@@ -1333,23 +1386,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
@@ -1357,44 +1415,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);
 
@@ -1404,17 +1474,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);
@@ -1448,7 +1524,8 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
   int header_size = 12;
 
   if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
-      || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size)
+      || bfd_bread (compressed_buffer,
+                   compressed_size, abfd) != compressed_size)
     error (_("Dwarf Error: Can't read DWARF data from '%s'"),
            bfd_get_filename (abfd));
 
@@ -1503,6 +1580,14 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
 #endif
 }
 
+/* A helper function that decides whether a section is empty.  */
+
+static int
+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
    OBJFILE, store info about the section into INFO.
    If the section is compressed, uncompress it before returning.  */
@@ -1518,10 +1603,10 @@ 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 (info->asection == NULL || info->size == 0)
+  if (dwarf2_section_empty_p (info))
     return;
 
   /* Check if the file has a 4-byte header indicating compression.  */
@@ -1548,17 +1633,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;
        }
@@ -1586,11 +1668,28 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
           bfd_get_filename (abfd));
 }
 
+/* A helper function that returns the size of a section in a safe way.
+   If you are positive that the section has been read before using the
+   size, then it is safe to refer to the dwarf2_section_info object's
+   "size" field directly.  In other cases, you must call this
+   function, because for compressed sections the size field is not set
+   correctly until the section has been read.  */
+
+static bfd_size_type
+dwarf2_section_size (struct objfile *objfile,
+                    struct dwarf2_section_info *info)
+{
+  if (!info->readin)
+    dwarf2_read_section (objfile, info);
+  return info->size;
+}
+
 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
-   SECTION_NAME. */
+   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)
 {
@@ -1607,16 +1706,19 @@ 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");
+    }
 
-  if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
-    /* We haven't read this section in yet.  Do it now.  */
-    dwarf2_read_section (objfile, info);
+  dwarf2_read_section (objfile, info);
 
   *sectp = info->asection;
   *bufp = info->buffer;
@@ -1721,6 +1823,25 @@ create_quick_file_names_table (unsigned int nr_initial_entries)
                            delete_file_name_entry, xcalloc, xfree);
 }
 
+/* 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_type_section)
+    read_signatured_type_at_offset (per_cu->objfile,
+                                   per_cu->debug_type_section,
+                                   per_cu->offset);
+  else
+    load_full_comp_unit (per_cu, per_cu->objfile);
+
+  dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
+
+  gdb_assert (per_cu->cu != NULL);
+}
+
 /* Read in the symbols for PER_CU.  OBJFILE is the objfile from which
    this CU came.  */
 
@@ -1734,10 +1855,7 @@ dw2_do_instantiate_symtab (struct objfile *objfile,
 
   queue_comp_unit (per_cu, objfile);
 
-  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);
 
@@ -1845,6 +1963,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)
 {
@@ -1874,9 +1993,8 @@ create_signatured_type_table_from_index (struct objfile *objfile,
       type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
                                 struct signatured_type);
       type_sig->signature = signature;
-      type_sig->offset = offset;
       type_sig->type_offset = type_offset;
-      type_sig->per_cu.from_debug_types = 1;
+      type_sig->per_cu.debug_type_section = section;
       type_sig->per_cu.offset = offset;
       type_sig->per_cu.objfile = objfile;
       type_sig->per_cu.v.quick
@@ -1934,21 +2052,27 @@ create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
   do_cleanups (cleanup);
 }
 
-/* The hash function for strings in the mapped index.  This is the
-   same as the hashtab.c hash function, but we keep a separate copy to
-   maintain control over the implementation.  This is necessary
-   because the hash function is tied to the format of the mapped index
-   file.  */
+/* The hash function for strings in the mapped index.  This is the same as
+   SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
+   implementation.  This is necessary because the hash function is tied to the
+   format of the mapped index file.  The hash values do not have to match with
+   SYMBOL_HASH_NEXT.
+   
+   Use INT_MAX for INDEX_VERSION if you generate the current index format.  */
 
 static hashval_t
-mapped_index_string_hash (const void *p)
+mapped_index_string_hash (int index_version, const void *p)
 {
   const unsigned char *str = (const unsigned char *) p;
   hashval_t r = 0;
   unsigned char c;
 
   while ((c = *str++) != 0)
-    r = r * 67 + c - 113;
+    {
+      if (index_version >= 5)
+       c = tolower (c);
+      r = r * 67 + c - 113;
+    }
 
   return r;
 }
@@ -1961,11 +2085,43 @@ static int
 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
                          offset_type **vec_out)
 {
-  offset_type hash = mapped_index_string_hash (name);
+  struct cleanup *back_to = make_cleanup (null_cleanup, 0);
+  offset_type hash;
   offset_type slot, step;
+  int (*cmp) (const char *, const char *);
+
+  if (current_language->la_language == language_cplus
+      || current_language->la_language == language_java
+      || current_language->la_language == language_fortran)
+    {
+      /* NAME is already canonical.  Drop any qualifiers as .gdb_index does
+        not contain any.  */
+      const char *paren = strchr (name, '(');
+
+      if (paren)
+       {
+         char *dup;
+
+         dup = xmalloc (paren - name + 1);
+         memcpy (dup, name, paren - name);
+         dup[paren - name] = 0;
+
+         make_cleanup (xfree, dup);
+         name = dup;
+       }
+    }
+
+  /* Index version 4 did not support case insensitive searches.  But the
+     indexes for case insensitive languages are built in lowercase, therefore
+     simulate our NAME being searched is also lowercased.  */
+  hash = mapped_index_string_hash ((index->version == 4
+                                    && case_sensitivity == case_sensitive_off
+                                   ? 5 : index->version),
+                                  name);
 
   slot = hash & (index->symbol_table_slots - 1);
   step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
+  cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
 
   for (;;)
     {
@@ -1973,13 +2129,17 @@ find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
       offset_type i = 2 * slot;
       const char *str;
       if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
-       return 0;
+       {
+         do_cleanups (back_to);
+         return 0;
+       }
 
       str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
-      if (!strcmp (name, str))
+      if (!cmp (name, str))
        {
          *vec_out = (offset_type *) (index->constant_pool
                                      + MAYBE_SWAP (index->symbol_table[i + 1]));
+         do_cleanups (back_to);
          return 1;
        }
 
@@ -2002,8 +2162,7 @@ dwarf2_read_index (struct objfile *objfile)
   offset_type types_list_elements = 0;
   int i;
 
-  if (dwarf2_per_objfile->gdb_index.asection == NULL
-      || dwarf2_per_objfile->gdb_index.size == 0)
+  if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
     return 0;
 
   /* Older elfutils strip versions could keep the section in the main
@@ -2018,16 +2177,19 @@ dwarf2_read_index (struct objfile *objfile)
   /* Version check.  */
   version = MAYBE_SWAP (*(offset_type *) addr);
   /* Versions earlier than 3 emitted every copy of a psymbol.  This
-     causes the index to behave very poorly for certain requests.  So,
-     it seems better to just ignore such indices.  */
-  if (version < 3)
+     causes the index to behave very poorly for certain requests.  Version 3
+     contained incomplete addrmap.  So, it seems better to just ignore such
+     indices.  Index version 4 uses a different hash function than index
+     version 5 and later.  */
+  if (version < 4)
     return 0;
   /* Indexes with higher version than the one supported by GDB may be no
      longer backward compatible.  */
-  if (version > 3)
+  if (version > 5)
     return 0;
 
   map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
+  map->version = version;
   map->total_size = dwarf2_per_objfile->gdb_index.size;
 
   metadata = (offset_type *) (addr + sizeof (offset_type));
@@ -2060,10 +2222,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);
 
@@ -2117,8 +2292,8 @@ dw2_get_file_names (struct objfile *objfile,
   init_one_comp_unit (&cu, objfile);
   cleanups = make_cleanup (free_stack_comp_unit, &cu);
 
-  if (this_cu->from_debug_types)
-    sec = &dwarf2_per_objfile->types;
+  if (this_cu->debug_type_section)
+    sec = this_cu->debug_type_section;
   else
     sec = &dwarf2_per_objfile->info;
   dwarf2_read_section (objfile, sec);
@@ -2141,11 +2316,11 @@ dw2_get_file_names (struct objfile *objfile,
   dwarf2_read_abbrevs (abfd, &cu);
   make_cleanup (dwarf2_free_abbrev_table, &cu);
 
-  if (this_cu->from_debug_types)
+  if (this_cu->debug_type_section)
     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);
+  read_full_die (&reader_specs, &comp_unit_die, info_ptr,
+                &has_children);
 
   lh = NULL;
   slot = NULL;
@@ -2371,7 +2546,7 @@ dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
 
 static void
 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
-                                int kind, const char *name,
+                                enum block_enum block_kind, const char *name,
                                 domain_enum domain)
 {
   dw2_do_expand_symtabs_matching (objfile, name);
@@ -2480,7 +2655,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))
@@ -2517,7 +2706,7 @@ static void
 dw2_expand_symtabs_matching (struct objfile *objfile,
                             int (*file_matcher) (const char *, void *),
                             int (*name_matcher) (const char *, void *),
-                            domain_enum kind,
+                            enum search_domain kind,
                             void *data)
 {
   int i;
@@ -2531,30 +2720,31 @@ dw2_expand_symtabs_matching (struct objfile *objfile,
     return;
   index = dwarf2_per_objfile->index_table;
 
-  for (i = 0; i < (dwarf2_per_objfile->n_comp_units
-                  + dwarf2_per_objfile->n_type_comp_units); ++i)
-    {
-      int j;
-      struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
-      struct quick_file_names *file_data;
+  if (file_matcher != NULL)
+    for (i = 0; i < (dwarf2_per_objfile->n_comp_units
+                    + dwarf2_per_objfile->n_type_comp_units); ++i)
+      {
+       int j;
+       struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
+       struct quick_file_names *file_data;
 
-      per_cu->v.quick->mark = 0;
-      if (per_cu->v.quick->symtab)
-       continue;
+       per_cu->v.quick->mark = 0;
+       if (per_cu->v.quick->symtab)
+         continue;
 
-      file_data = dw2_get_file_names (objfile, per_cu);
-      if (file_data == NULL)
-       continue;
+       file_data = dw2_get_file_names (objfile, per_cu);
+       if (file_data == NULL)
+         continue;
 
-      for (j = 0; j < file_data->num_file_names; ++j)
-       {
-         if (file_matcher (file_data->file_names[j], data))
-           {
-             per_cu->v.quick->mark = 1;
-             break;
-           }
-       }
-    }
+       for (j = 0; j < file_data->num_file_names; ++j)
+         {
+           if (file_matcher (file_data->file_names[j], data))
+             {
+               per_cu->v.quick->mark = 1;
+               break;
+             }
+         }
+      }
 
   for (iter = 0; iter < index->symbol_table_slots; ++iter)
     {
@@ -2580,7 +2770,7 @@ dw2_expand_symtabs_matching (struct objfile *objfile,
          struct dwarf2_per_cu_data *per_cu;
 
          per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
-         if (per_cu->v.quick->mark)
+         if (file_matcher == NULL || per_cu->v.quick->mark)
            dw2_instantiate_symtab (objfile, per_cu);
        }
     }
@@ -2612,38 +2802,7 @@ dw2_find_pc_sect_symtab (struct objfile *objfile,
 }
 
 static void
-dw2_map_symbol_names (struct objfile *objfile,
-                     void (*fun) (const char *, void *),
-                     void *data)
-{
-  offset_type iter;
-  struct mapped_index *index;
-
-  dw2_setup (objfile);
-
-  /* index_table is NULL if OBJF_READNOW.  */
-  if (!dwarf2_per_objfile->index_table)
-    return;
-  index = dwarf2_per_objfile->index_table;
-
-  for (iter = 0; iter < index->symbol_table_slots; ++iter)
-    {
-      offset_type idx = 2 * iter;
-      const char *name;
-      offset_type *vec, vec_len, vec_idx;
-
-      if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
-       continue;
-
-      name = (index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]));
-
-      (*fun) (name, data);
-    }
-}
-
-static void
-dw2_map_symbol_filenames (struct objfile *objfile,
-                         void (*fun) (const char *, const char *, void *),
+dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
                          void *data)
 {
   int i;
@@ -2697,7 +2856,6 @@ const struct quick_symbol_functions dwarf2_gdb_index_functions =
   dw2_map_matching_symbols,
   dw2_expand_symtabs_matching,
   dw2_find_pc_sect_symtab,
-  dw2_map_symbol_names,
   dw2_map_symbol_filenames
 };
 
@@ -2739,7 +2897,6 @@ dwarf2_initialize_objfile (struct objfile *objfile)
   if (dwarf2_read_index (objfile))
     return 1;
 
-  dwarf2_build_psymtabs (objfile);
   return 0;
 }
 
@@ -2816,7 +2973,9 @@ partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
           "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
           bfd_get_filename (abfd));
 
-  if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size)
+  if (header->abbrev_offset
+      >= dwarf2_section_size (dwarf2_per_objfile->objfile,
+                             &dwarf2_per_objfile->abbrev))
     error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
           "(offset 0x%lx + 6) [in module %s]"),
           (long) header->abbrev_offset,
@@ -2839,14 +2998,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);
 
@@ -2974,78 +3133,104 @@ 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->offset = offset;
-      type_sig->type_offset = type_offset;
-      type_sig->per_cu.objfile = objfile;
-      type_sig->per_cu.from_debug_types = 1;
+         /* 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);
-      *slot = type_sig;
+         /* 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;
+           }
 
-      if (dwarf2_die_debug)
-       fprintf_unfiltered (gdb_stdlog, "  offset 0x%x, signature 0x%s\n",
-                           offset, phex (signature, sizeof (signature)));
+         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);
+
+         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_type_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;
 
-      info_ptr = info_ptr + initial_length_size + length;
+             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;
+
+         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;
@@ -3074,7 +3259,7 @@ lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
   if (dwarf2_per_objfile->signatured_types == NULL)
     {
       complaint (&symfile_complaints,
-                _("missing `.debug_types' section for DW_FORM_sig8 die"));
+                _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
       return 0;
     }
 
@@ -3091,10 +3276,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_type_section)
     {
-      gdb_assert (dwarf2_per_objfile->types.readin);
-      reader->buffer = dwarf2_per_objfile->types.buffer;
+      gdb_assert (cu->per_cu->debug_type_section->readin);
+      reader->buffer = cu->per_cu->debug_type_section->buffer;
     }
   else
     {
@@ -3159,6 +3344,7 @@ process_psymtab_comp_unit (struct objfile *objfile,
   struct attribute *attr;
   CORE_ADDR best_lowpc = 0, best_highpc = 0;
   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);
@@ -3194,16 +3380,16 @@ process_psymtab_comp_unit (struct objfile *objfile,
   make_cleanup (dwarf2_free_abbrev_table, &cu);
 
   /* Read the compilation unit die.  */
-  if (this_cu->from_debug_types)
+  if (this_cu->debug_type_section)
     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_type_section)
     {
-      /* offset,length haven't been set yet for type units.  */
-      this_cu->offset = cu.header.offset;
+      /* LENGTH has not been set yet for type units.  */
+      gdb_assert (this_cu->offset == cu.header.offset);
       this_cu->length = cu.header.length + cu.header.initial_length_size;
     }
   else if (comp_unit_die->tag == DW_TAG_partial_unit)
@@ -3218,8 +3404,12 @@ process_psymtab_comp_unit (struct objfile *objfile,
 
   /* Allocate a new partial symbol table structure.  */
   attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
+  if (attr == NULL || !DW_STRING (attr))
+    filename = "";
+  else
+    filename = DW_STRING (attr);
   pst = start_psymtab_common (objfile, objfile->section_offsets,
-                             (attr != NULL) ? DW_STRING (attr) : "",
+                             filename,
                              /* TEXTLOW and TEXTHIGH are set below.  */
                              0,
                              objfile->global_psymbols.next,
@@ -3233,7 +3423,7 @@ process_psymtab_comp_unit (struct objfile *objfile,
 
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
-  /* Store the function that reads in the rest of the symbol table */
+  /* Store the function that reads in the rest of the symbol table */
   pst->read_symtab = dwarf2_psymtab_to_symtab;
 
   this_cu->v.psymtab = pst;
@@ -3253,7 +3443,7 @@ process_psymtab_comp_unit (struct objfile *objfile,
 
   /* Check if comp unit has_children.
      If so, read the rest of the partial symbols from this comp unit.
-     If not, there's no more debug_info for this comp unit. */
+     If not, there's no more debug_info for this comp unit.  */
   if (has_children)
     {
       struct partial_die_info *first_die;
@@ -3292,7 +3482,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_type_section)
     {
       /* It's not clear we want to do anything with stmt lists here.
         Waiting to see what gcc ultimately does.  */
@@ -3321,11 +3511,12 @@ process_type_comp_unit (void **slot, void *info)
 
   this_cu = &entry->per_cu;
 
-  gdb_assert (dwarf2_per_objfile->types.readin);
+  gdb_assert (this_cu->debug_type_section->readin);
   process_psymtab_comp_unit (objfile, this_cu,
-                            dwarf2_per_objfile->types.buffer,
-                            dwarf2_per_objfile->types.buffer + entry->offset,
-                            dwarf2_per_objfile->types.size);
+                            this_cu->debug_type_section->buffer,
+                            (this_cu->debug_type_section->buffer
+                             + this_cu->offset),
+                            this_cu->debug_type_section->size);
 
   return 1;
 }
@@ -3402,7 +3593,8 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile)
     {
       struct dwarf2_per_cu_data *this_cu;
 
-      this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer,
+      this_cu = dwarf2_find_comp_unit (info_ptr
+                                      - dwarf2_per_objfile->info.buffer,
                                       objfile);
 
       info_ptr = process_psymtab_comp_unit (objfile, this_cu,
@@ -3433,7 +3625,7 @@ 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_type_section);
 
   gdb_assert (dwarf2_per_objfile->info.readin);
   info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
@@ -3486,7 +3678,7 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
 
   /* Check if comp unit has_children.
      If so, read the rest of the partial symbols from this comp unit.
-     If not, there's no more debug_info for this comp unit. */
+     If not, there's no more debug_info for this comp unit.  */
   if (has_children)
     load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
 
@@ -3521,7 +3713,8 @@ create_all_comp_units (struct objfile *objfile)
   all_comp_units = xmalloc (n_allocated
                            * sizeof (struct dwarf2_per_cu_data *));
 
-  while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size)
+  while (info_ptr < dwarf2_per_objfile->info.buffer
+        + dwarf2_per_objfile->info.size)
     {
       unsigned int length, initial_length_size;
       struct dwarf2_per_cu_data *this_cu;
@@ -3704,7 +3897,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
@@ -3715,12 +3911,10 @@ partial_die_parent_scope (struct partial_die_info *pdi,
       if (grandparent_scope == NULL)
        parent->scope = parent->name;
       else
-       parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
+       parent->scope = typename_concat (&cu->comp_unit_obstack,
+                                        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
@@ -3802,25 +3996,25 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
              of the global scope.  But in Ada, we want to be able to access
              nested procedures globally.  So all Ada subprograms are stored
              in the global scope.  */
-         /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
+         /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
             mst_text, objfile); */
-         psym = add_psymbol_to_list (actual_name, strlen (actual_name),
-                                     built_actual_name,
-                                     VAR_DOMAIN, LOC_BLOCK,
-                                     &objfile->global_psymbols,
-                                     0, pdi->lowpc + baseaddr,
-                                     cu->language, objfile);
+         add_psymbol_to_list (actual_name, strlen (actual_name),
+                              built_actual_name,
+                              VAR_DOMAIN, LOC_BLOCK,
+                              &objfile->global_psymbols,
+                              0, pdi->lowpc + baseaddr,
+                              cu->language, objfile);
        }
       else
        {
-         /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
+         /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
             mst_file_text, objfile); */
-         psym = add_psymbol_to_list (actual_name, strlen (actual_name),
-                                     built_actual_name,
-                                     VAR_DOMAIN, LOC_BLOCK,
-                                     &objfile->static_psymbols,
-                                     0, pdi->lowpc + baseaddr,
-                                     cu->language, objfile);
+         add_psymbol_to_list (actual_name, strlen (actual_name),
+                              built_actual_name,
+                              VAR_DOMAIN, LOC_BLOCK,
+                              &objfile->static_psymbols,
+                              0, pdi->lowpc + baseaddr,
+                              cu->language, objfile);
        }
       break;
     case DW_TAG_constant:
@@ -3831,10 +4025,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          list = &objfile->global_psymbols;
        else
          list = &objfile->static_psymbols;
-       psym = add_psymbol_to_list (actual_name, strlen (actual_name),
-                                   built_actual_name, VAR_DOMAIN, LOC_STATIC,
-                                   list, 0, 0, cu->language, objfile);
-
+       add_psymbol_to_list (actual_name, strlen (actual_name),
+                            built_actual_name, VAR_DOMAIN, LOC_STATIC,
+                            list, 0, 0, cu->language, objfile);
       }
       break;
     case DW_TAG_variable:
@@ -3866,30 +4059,30 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
             table building.  */
 
          if (pdi->locdesc || pdi->has_type)
-           psym = add_psymbol_to_list (actual_name, strlen (actual_name),
-                                       built_actual_name,
-                                       VAR_DOMAIN, LOC_STATIC,
-                                       &objfile->global_psymbols,
-                                       0, addr + baseaddr,
-                                       cu->language, objfile);
+           add_psymbol_to_list (actual_name, strlen (actual_name),
+                                built_actual_name,
+                                VAR_DOMAIN, LOC_STATIC,
+                                &objfile->global_psymbols,
+                                0, addr + baseaddr,
+                                cu->language, objfile);
        }
       else
        {
-         /* Static Variable. Skip symbols without location descriptors.  */
+         /* Static Variable.  Skip symbols without location descriptors.  */
          if (pdi->locdesc == NULL)
            {
              if (built_actual_name)
                xfree (actual_name);
              return;
            }
-         /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
+         /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
             mst_file_data, objfile); */
-         psym = add_psymbol_to_list (actual_name, strlen (actual_name),
-                                     built_actual_name,
-                                     VAR_DOMAIN, LOC_STATIC,
-                                     &objfile->static_psymbols,
-                                     0, addr + baseaddr,
-                                     cu->language, objfile);
+         add_psymbol_to_list (actual_name, strlen (actual_name),
+                              built_actual_name,
+                              VAR_DOMAIN, LOC_STATIC,
+                              &objfile->static_psymbols,
+                              0, addr + baseaddr,
+                              cu->language, objfile);
        }
       break;
     case DW_TAG_typedef:
@@ -4090,8 +4283,8 @@ peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
   abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
   if (!abbrev)
     {
-      error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number,
-                     bfd_get_filename (abfd));
+      error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
+            abbrev_number, bfd_get_filename (abfd));
     }
 
   return abbrev;
@@ -4140,7 +4333,8 @@ skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
          read_attribute (&attr, &abbrev->attrs[i],
                          abfd, info_ptr, cu);
          if (attr.form == DW_FORM_ref_addr)
-           complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
+           complaint (&symfile_complaints,
+                      _("ignoring absolute DW_AT_sibling"));
          else
            return buffer + dwarf2_get_ref_die_offset (&attr);
        }
@@ -4178,7 +4372,7 @@ skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
          break;
        case DW_FORM_data8:
        case DW_FORM_ref8:
-       case DW_FORM_sig8:
+       case DW_FORM_ref_sig8:
          info_ptr += 8;
          break;
        case DW_FORM_string:
@@ -4216,7 +4410,8 @@ skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
          goto skip_attribute;
 
        default:
-         error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
+         error (_("Dwarf Error: Cannot handle %s "
+                  "in DWARF reader [in module %s]"),
                 dwarf_form_name (form),
                 bfd_get_filename (abfd));
        }
@@ -4261,13 +4456,15 @@ dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
     {
       if (pst->readin)
        {
-         warning (_("bug: psymtab for %s is already read in."), pst->filename);
+         warning (_("bug: psymtab for %s is already read in."),
+                  pst->filename);
        }
       else
        {
          if (info_verbose)
            {
-             printf_filtered (_("Reading in symbols for %s..."), pst->filename);
+             printf_filtered (_("Reading in symbols for %s..."),
+                              pst->filename);
              gdb_flush (gdb_stdout);
            }
 
@@ -4394,7 +4591,7 @@ psymtab_to_symtab_1 (struct partial_symtab *pst)
             fputs_filtered ("and ", gdb_stdout);
             wrap_here ("");
             printf_filtered ("%s...", pst->dependencies[i]->filename);
-            wrap_here ("");     /* Flush output */
+            wrap_here ("");     /* Flush output */
             gdb_flush (gdb_stdout);
           }
         psymtab_to_symtab_1 (pst->dependencies[i]);
@@ -4416,7 +4613,8 @@ psymtab_to_symtab_1 (struct partial_symtab *pst)
 /* 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)
 {
   bfd *abfd = objfile->obfd;
   struct dwarf2_cu *cu;
@@ -4426,7 +4624,7 @@ load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
   struct attribute *attr;
   int read_cu = 0;
 
-  gdb_assert (! per_cu->from_debug_types);
+  gdb_assert (! per_cu->debug_type_section);
 
   /* Set local variables from the partial symbol table info.  */
   offset = per_cu->offset;
@@ -4536,10 +4734,10 @@ compute_delayed_physnames (struct dwarf2_cu *cu)
   struct delayed_method_info *mi;
   for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
     {
-      char *physname;
+      const char *physname;
       struct fn_fieldlist *fn_flp
        = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
-      physname = (char *) dwarf2_physname ((char *) mi->name, mi->die, cu);
+      physname = dwarf2_physname ((char *) mi->name, mi->die, cu);
       fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
     }
 }
@@ -4565,8 +4763,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);
 
@@ -4583,13 +4779,33 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
 
   symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
 
-  /* 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.  */
-  if (symtab != NULL
-      && !(cu->language == language_c && symtab->language != language_c))
+  if (symtab != NULL)
     {
-      symtab->language = cu->language;
+      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.  */
+      if (!(cu->language == language_c && symtab->language != language_c))
+       symtab->language = cu->language;
+
+      /* GCC-4.0 has started to support -fvar-tracking.  GCC-3.x still can
+        produce DW_AT_location with location lists but it can be possibly
+        invalid without -fvar-tracking.
+
+        For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
+        needed, it would be wrong due to missing DW_AT_producer there.
+
+        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 && 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)
@@ -4628,6 +4844,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:
@@ -4810,7 +5029,7 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
              xfree (prefixed_name);
            }
          else
-           fputs_unfiltered (name ? name : "", buf);
+           fputs_unfiltered (name, buf);
 
          /* Template parameters may be specified in the DIE's DW_AT_name, or
             as children with DW_TAG_template_type_param or
@@ -4881,7 +5100,8 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
                  if (attr == NULL)
                    {
                      complaint (&symfile_complaints,
-                                _("template parameter missing DW_AT_const_value"));
+                                _("template parameter missing "
+                                  "DW_AT_const_value"));
                      fputs_unfiltered ("UNKNOWN_VALUE", buf);
                      continue;
                    }
@@ -4912,7 +5132,8 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
                      else
                        v = value_from_longest (type, value);
 
-                     /* Specify decimal so that we do not depend on the radix.  */
+                     /* Specify decimal so that we do not depend on
+                        the radix.  */
                      get_formatted_print_options (&opts, 'd');
                      opts.raw = 1;
                      value_print (v, buf, &opts);
@@ -4945,12 +5166,12 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
            {
              struct type *type = read_type_die (die, cu);
 
-             c_type_print_args (type, buf, 0, cu->language);
+             c_type_print_args (type, buf, 1, cu->language);
 
              if (cu->language == language_java)
                {
                  /* For java, we must append the return type to method
-                    names. */
+                    names.  */
                  if (die->tag == DW_TAG_subprogram)
                    java_print_type (TYPE_TARGET_TYPE (type), "", buf,
                                     0, 0);
@@ -4965,7 +5186,8 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
                  if (TYPE_NFIELDS (type) > 0
                      && TYPE_FIELD_ARTIFICIAL (type, 0)
                      && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
-                     && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0))))
+                     && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
+                                                                       0))))
                    fputs_unfiltered (" const", buf);
                }
            }
@@ -4995,7 +5217,7 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
    not have a name.  NAME may either be from a previous call to
    dwarf2_name or NULL.
 
-   The output string will be canonicalized (if C++/Java). */
+   The output string will be canonicalized (if C++/Java).  */
 
 static const char *
 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
@@ -5013,7 +5235,91 @@ 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 attribute *attr;
+  const char *retval, *mangled = NULL, *canon = NULL;
+  struct cleanup *back_to;
+  int need_copy = 1;
+
+  /* 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);
+
+  back_to = make_cleanup (null_cleanup, NULL);
+
+  attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
+  if (!attr)
+    attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
+
+  /* DW_AT_linkage_name is missing in some cases - depend on what GDB
+     has computed.  */
+  if (attr && DW_STRING (attr))
+    {
+      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, cu->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),
+                          &cu->objfile->objfile_obstack);
+
+  do_cleanups (back_to);
+  return retval;
 }
 
 /* Read the import statement specified by the given die and record it.  */
@@ -5022,7 +5328,7 @@ static void
 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct attribute *import_attr;
-  struct die_info *imported_die;
+  struct die_info *imported_die, *child_die;
   struct dwarf2_cu *imported_cu;
   const char *imported_name;
   const char *imported_name_prefix;
@@ -5030,6 +5336,8 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
   const char *import_alias;
   const char *imported_declaration = NULL;
   const char *import_prefix;
+  VEC (const_char_ptr) *excludes = NULL;
+  struct cleanup *cleanups;
 
   char *temp;
 
@@ -5109,11 +5417,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, cu->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, cu->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,
+                         excludes,
                           &cu->objfile->objfile_obstack);
+
+  do_cleanups (cleanups);
 }
 
 static void
@@ -5173,22 +5530,50 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
     *name = "<unknown>";
 }
 
-/* Process DW_TAG_compile_unit.  */
+/* Handle DW_AT_stmt_list for a compilation unit.  */
 
 static void
-read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
+handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
+                       const char *comp_dir)
 {
-  struct objfile *objfile = cu->objfile;
-  struct cleanup *back_to = make_cleanup (null_cleanup, 0);
-  CORE_ADDR lowpc = ((CORE_ADDR) -1);
-  CORE_ADDR highpc = ((CORE_ADDR) 0);
   struct attribute *attr;
-  char *name = NULL;
-  char *comp_dir = NULL;
-  struct die_info *child_die;
+  struct objfile *objfile = cu->objfile;
   bfd *abfd = objfile->obfd;
-  struct line_header *line_header = 0;
-  CORE_ADDR baseaddr;
+
+  /* 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
+read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
+{
+  struct objfile *objfile = cu->objfile;
+  struct cleanup *back_to = make_cleanup (null_cleanup, 0);
+  CORE_ADDR lowpc = ((CORE_ADDR) -1);
+  CORE_ADDR highpc = ((CORE_ADDR) 0);
+  struct attribute *attr;
+  char *name = NULL;
+  char *comp_dir = NULL;
+  struct die_info *child_die;
+  bfd *abfd = objfile->obfd;
+  CORE_ADDR baseaddr;
 
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
@@ -5219,7 +5604,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
   if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
     cu->language = language_opencl;
 
-  /* We assume that we're processing GCC output. */
+  /* We assume that we're processing GCC output.  */
   processing_gcc_compilation = 2;
 
   processing_has_namespace_info = 0;
@@ -5230,21 +5615,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
 
   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)
@@ -5261,13 +5632,28 @@ 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)
     {
-      unsigned int macro_offset = DW_UNSND (attr);
+      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 (line_header, macro_offset,
-                           comp_dir, abfd, cu);
+      dwarf_decode_macros (cu->line_header, DW_UNSND (attr),
+                          comp_dir, abfd, cu,
+                          &dwarf2_per_objfile->macro, 1);
+    }
+  else
+    {
+      attr = dwarf2_attr (die, DW_AT_macro_info, cu);
+      if (attr && cu->line_header)
+       {
+         unsigned int macro_offset = DW_UNSND (attr);
+
+         dwarf_decode_macros (cu->line_header, macro_offset,
+                              comp_dir, abfd, cu,
+                              &dwarf2_per_objfile->macinfo, 0);
+       }
     }
   do_cleanups (back_to);
 }
@@ -5322,7 +5708,7 @@ read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
   if (attr)
     cu->producer = DW_STRING (attr);
 
-  /* We assume that we're processing GCC output. */
+  /* We assume that we're processing GCC output.  */
   processing_gcc_compilation = 2;
 
   processing_has_namespace_info = 0;
@@ -5331,6 +5717,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)
     {
@@ -5385,8 +5773,9 @@ unsigned_int_compar (const void *ap, const void *bp)
 }
 
 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
-   Inherit only the children of the DW_AT_abstract_origin DIE not being already
-   referenced by DW_AT_abstract_origin from the children of the current DIE.  */
+   Inherit only the children of the DW_AT_abstract_origin DIE not being
+   already referenced by DW_AT_abstract_origin from the children of the
+   current DIE.  */
 
 static void
 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
@@ -5484,8 +5873,9 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
         unsigned_int_compar);
   for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
     if (offsetp[-1] == *offsetp)
-      complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer "
-                                       "to DIE 0x%x as their abstract origin"),
+      complaint (&symfile_complaints,
+                _("Multiple children of DIE 0x%x refer "
+                  "to DIE 0x%x as their abstract origin"),
                 die->offset, *offsetp);
 
   offsetp = offsets;
@@ -5556,7 +5946,8 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       attr = dwarf2_attr (die, DW_AT_external, cu);
       if (!attr || !DW_UNSND (attr))
        complaint (&symfile_complaints,
-                  _("cannot get low and high bounds for subprogram DIE at %d"),
+                  _("cannot get low and high bounds "
+                    "for subprogram DIE at %d"),
                   die->offset);
       return;
     }
@@ -5750,6 +6141,258 @@ 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, cu->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, cu->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, cu->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, cu->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 objfile *objfile = cu->objfile;
+      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, cu->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, cu->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, cu->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, cu->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, cu->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, cu->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, cu->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'.  */
@@ -5840,12 +6483,25 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
          return 0;
        }
 
+      if (range_beginning > range_end)
+       {
+         /* Inverted range entries are invalid.  */
+         complaint (&symfile_complaints,
+                    _("Invalid .debug_ranges data (inverted range)"));
+         return 0;
+       }
+
+      /* Empty range entries have no effect.  */
+      if (range_beginning == range_end)
+       continue;
+
       range_beginning += base;
       range_end += base;
 
-      if (ranges_pst != NULL && range_beginning < range_end)
+      if (ranges_pst != NULL)
        addrmap_set_empty (objfile->psymtabs_addrmap,
-                          range_beginning + baseaddr, range_end - 1 + baseaddr,
+                          range_beginning + baseaddr,
+                          range_end - 1 + baseaddr,
                           ranges_pst);
 
       /* FIXME: This is recording everything as a low-high
@@ -5920,7 +6576,8 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
        }
     }
 
-  if (high < low)
+  /* read_partial_die has also the strict LOW < HIGH requirement.  */
+  if (high <= low)
     return 0;
 
   /* When using the GNU linker, .gnu.linkonce. sections are used to
@@ -5935,7 +6592,8 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
     return 0;
 
   *lowpc = low;
-  *highpc = high;
+  if (highpc)
+    *highpc = high;
   return ret;
 }
 
@@ -6023,7 +6681,7 @@ get_scope_pc_bounds (struct die_info *die,
              }
            break;
          default:
-           /* Ignore. */
+           /* Ignore.  */
            break;
          }
 
@@ -6120,10 +6778,24 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
               if (!base_known)
                 {
                   complaint (&symfile_complaints,
-                             _("Invalid .debug_ranges data (no base address)"));
+                            _("Invalid .debug_ranges data "
+                              "(no base address)"));
                   return;
                 }
 
+             if (start > end)
+               {
+                 /* Inverted range entries are invalid.  */
+                 complaint (&symfile_complaints,
+                            _("Invalid .debug_ranges data "
+                              "(inverted range)"));
+                 return;
+               }
+
+             /* Empty range entries have no effect.  */
+             if (start == end)
+               continue;
+
               record_block_range (block,
                                   baseaddr + base + start,
                                   baseaddr + base + end - 1);
@@ -6132,6 +6804,116 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
     }
 }
 
+/* Check for GCC PR debug/45124 fix which is not present in any G++ version up
+   to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
+   during 4.6.0 experimental.  */
+
+static int
+producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
+{
+  const char *cs;
+  int major, minor, release;
+
+  if (cu->producer == NULL)
+    {
+      /* For unknown compilers expect their behavior is DWARF version
+        compliant.
+
+        GCC started to support .debug_types sections by -gdwarf-4 since
+        gcc-4.5.x.  As the .debug_types sections are missing DW_AT_producer
+        for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
+        combination.  gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
+        interpreted incorrectly by GDB now - GCC PR debug/48229.  */
+
+      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 DWARF version
+        compliant.  */
+
+      return 0;
+    }
+  cs = &cu->producer[strlen ("GNU ")];
+  while (*cs && !isdigit (*cs))
+    cs++;
+  if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
+    {
+      /* Not recognized as GCC.  */
+
+      return 0;
+    }
+
+  return major < 4 || (major == 4 && minor < 6);
+}
+
+/* Return the default accessibility type if it is not overriden by
+   DW_AT_accessibility.  */
+
+static enum dwarf_access_attribute
+dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
+{
+  if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
+    {
+      /* The default DWARF 2 accessibility for members is public, the default
+        accessibility for inheritance is private.  */
+
+      if (die->tag != DW_TAG_inheritance)
+       return DW_ACCESS_public;
+      else
+       return DW_ACCESS_private;
+    }
+  else
+    {
+      /* DWARF 3+ defines the default accessibility a different way.  The same
+        rules apply now for DW_TAG_inheritance as for the members and it only
+        depends on the container kind.  */
+
+      if (die->parent->tag == DW_TAG_class_type)
+       return DW_ACCESS_private;
+      else
+       return DW_ACCESS_public;
+    }
+}
+
+/* Look for DW_AT_data_member_location.  Set *OFFSET to the byte
+   offset.  If the attribute was not found return 0, otherwise return
+   1.  If it was found but could not properly be handled, set *OFFSET
+   to 0.  */
+
+static int
+handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
+                            LONGEST *offset)
+{
+  struct attribute *attr;
+
+  attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
+  if (attr != NULL)
+    {
+      *offset = 0;
+
+      /* Note that we do not check for a section offset first here.
+        This is because DW_AT_data_member_location is new in DWARF 4,
+        so if we see it, we can assume that a constant form is really
+        a constant and not a section offset.  */
+      if (attr_form_is_constant (attr))
+       *offset = dwarf2_get_attr_constant_value (attr, 0);
+      else if (attr_form_is_section_offset (attr))
+       dwarf2_complex_location_expr_complaint ();
+      else if (attr_form_is_block (attr))
+       *offset = decode_locdesc (DW_BLOCK (attr), cu);
+      else
+       dwarf2_complex_location_expr_complaint ();
+
+      return 1;
+    }
+
+  return 0;
+}
+
 /* Add an aggregate field to the field list.  */
 
 static void
@@ -6162,28 +6944,26 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
     }
   fip->nfields++;
 
-  /* Handle accessibility and virtuality of field.
-     The default accessibility for members is public, the default
-     accessibility for inheritance is private.  */
-  if (die->tag != DW_TAG_inheritance)
-    new_field->accessibility = DW_ACCESS_public;
-  else
-    new_field->accessibility = DW_ACCESS_private;
-  new_field->virtuality = DW_VIRTUALITY_none;
-
   attr = dwarf2_attr (die, DW_AT_accessibility, cu);
   if (attr)
     new_field->accessibility = DW_UNSND (attr);
+  else
+    new_field->accessibility = dwarf2_default_access_attribute (die, cu);
   if (new_field->accessibility != DW_ACCESS_public)
     fip->non_public_fields = 1;
+
   attr = dwarf2_attr (die, DW_AT_virtuality, cu);
   if (attr)
     new_field->virtuality = DW_UNSND (attr);
+  else
+    new_field->virtuality = DW_VIRTUALITY_none;
 
   fp = &new_field->field;
 
   if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
     {
+      LONGEST offset;
+
       /* Data member other than a C++ static data member.  */
 
       /* Get type of field.  */
@@ -6203,22 +6983,8 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
        }
 
       /* Get bit offset of field.  */
-      attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
-      if (attr)
-       {
-          int byte_offset = 0;
-
-          if (attr_form_is_section_offset (attr))
-           dwarf2_complex_location_expr_complaint ();
-          else if (attr_form_is_constant (attr))
-            byte_offset = dwarf2_get_attr_constant_value (attr, 0);
-          else if (attr_form_is_block (attr))
-            byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
-         else
-           dwarf2_complex_location_expr_complaint ();
-
-          SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
-       }
+      if (handle_data_member_location (die, cu, &offset))
+       SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
       attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
       if (attr)
        {
@@ -6290,7 +7056,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
         (so through at least 3.2.1) incorrectly generate
         DW_TAG_variable tags.  */
 
-      char *physname;
+      const char *physname;
 
       /* Get name of field.  */
       fieldname = dwarf2_name (die, cu);
@@ -6311,7 +7077,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
        }
 
       /* Get physical name.  */
-      physname = (char *) dwarf2_physname (fieldname, die, cu);
+      physname = dwarf2_physname (fieldname, die, cu);
 
       /* The name is already allocated along with this objfile, so we don't
         need to duplicate it for the type.  */
@@ -6321,23 +7087,11 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
     }
   else if (die->tag == DW_TAG_inheritance)
     {
-      /* C++ base class field.  */
-      attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
-      if (attr)
-       {
-          int byte_offset = 0;
-
-          if (attr_form_is_section_offset (attr))
-           dwarf2_complex_location_expr_complaint ();
-          else if (attr_form_is_constant (attr))
-            byte_offset = dwarf2_get_attr_constant_value (attr, 0);
-          else if (attr_form_is_block (attr))
-            byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
-         else
-           dwarf2_complex_location_expr_complaint ();
+      LONGEST offset;
 
-          SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
-       }
+      /* C++ base class field.  */
+      if (handle_data_member_location (die, cu, &offset))
+       SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
       FIELD_BITSIZE (*fp) = 0;
       FIELD_TYPE (*fp) = die_type (die, cu);
       FIELD_NAME (*fp) = type_name_no_tag (fp->type);
@@ -6352,7 +7106,6 @@ dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
                    struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct typedef_field_list *new_field;
   struct attribute *attr;
   struct typedef_field *fp;
@@ -6424,9 +7177,9 @@ dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
       TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
     }
 
-  /* Copy the saved-up fields into the field vector.  Start from the head
-     of the list, adding to the tail of the field array, so that they end
-     up in the same order in the array in which they were added to the list.  */
+  /* Copy the saved-up fields into the field vector.  Start from the head of
+     the list, adding to the tail of the field array, so that they end up in
+     the same order in the array in which they were added to the list.  */
   while (nfields-- > 0)
     {
       struct nextfield *fieldp;
@@ -6473,7 +7226,7 @@ dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
            case DW_VIRTUALITY_virtual:
            case DW_VIRTUALITY_pure_virtual:
              if (cu->language == language_ada)
-               error ("unexpected virtuality in component of Ada type");
+               error (_("unexpected virtuality in component of Ada type"));
              SET_TYPE_FIELD_VIRTUAL (type, nfields);
              break;
            }
@@ -6495,9 +7248,10 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
   char *fieldname;
   struct nextfnfield *new_fnfield;
   struct type *this_type;
+  enum dwarf_access_attribute accessibility;
 
   if (cu->language == language_ada)
-    error ("unexpected member function in Ada type");
+    error (_("unexpected member function in Ada type"));
 
   /* Get name of member function.  */
   fieldname = dwarf2_name (die, cu);
@@ -6533,7 +7287,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
     }
 
   /* Create a new member function field and chain it to the field list
-     entry. */
+     entry.  */
   new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
   make_cleanup (xfree, new_fnfield);
   memset (new_fnfield, 0, sizeof (struct nextfnfield));
@@ -6552,7 +7306,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
     }
   else
     {
-      char *physname = (char *) dwarf2_physname (fieldname, die, cu);
+      const char *physname = dwarf2_physname (fieldname, die, cu);
       fnp->physname = physname ? physname : "";
     }
 
@@ -6572,10 +7326,10 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
 
       /* Handle static member functions.
          Dwarf2 has no clean way to discern C++ static and non-static
-         member functions. G++ helps GDB by marking the first
-         parameter for non-static member functions (which is the
-         this pointer) as artificial. We obtain this information
-         from read_subroutine_type via TYPE_FIELD_ARTIFICIAL.  */
+         member functions.  G++ helps GDB by marking the first
+         parameter for non-static member functions (which is the this
+         pointer) as artificial.  We obtain this information from
+         read_subroutine_type via TYPE_FIELD_ARTIFICIAL.  */
       if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
        fnp->voffset = VOFFSET_STATIC;
     }
@@ -6587,22 +7341,23 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
   if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
     fnp->fcontext = die_containing_type (die, cu);
 
-  /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
-     and is_volatile is irrelevant, as it is needed by gdb_mangle_name only.  */
+  /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
+     is_volatile is irrelevant, as it is needed by gdb_mangle_name only.  */
 
   /* Get accessibility.  */
   attr = dwarf2_attr (die, DW_AT_accessibility, cu);
   if (attr)
+    accessibility = DW_UNSND (attr);
+  else
+    accessibility = dwarf2_default_access_attribute (die, cu);
+  switch (accessibility)
     {
-      switch (DW_UNSND (attr))
-       {
-       case DW_ACCESS_private:
-         fnp->is_private = 1;
-         break;
-       case DW_ACCESS_protected:
-         fnp->is_protected = 1;
-         break;
-       }
+    case DW_ACCESS_private:
+      fnp->is_private = 1;
+      break;
+    case DW_ACCESS_protected:
+      fnp->is_protected = 1;
+      break;
     }
 
   /* Check for artificial methods.  */
@@ -6668,7 +7423,8 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
        {
          /* GCC does this, as of 2008-08-25; PR debug/37237.  */
          complaint (&symfile_complaints,
-                    _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
+                    _("Member function \"%s\" (offset %d) is virtual "
+                      "but the vtable offset is not specified"),
                     fieldname, die->offset);
          ALLOCATE_CPLUS_STRUCT_TYPE (type);
          TYPE_CPLUS_DYNAMIC (type) = 1;
@@ -6687,7 +7443,7 @@ dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
   int i;
 
   if (cu->language == language_ada)
-    error ("unexpected member functions in Ada type");
+    error (_("unexpected member functions in Ada type"));
 
   ALLOCATE_CPLUS_STRUCT_TYPE (type);
   TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
@@ -6889,7 +7645,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
 
   /* We need to add the type field to the die immediately so we don't
      infinitely recurse when dealing with pointers to the structure
-     type within the structure itself. */
+     type within the structure itself.  */
   set_die_type (die, type, cu);
 
   /* set_die_type should be already done.  */
@@ -6937,7 +7693,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
            }
          else if (child_die->tag == DW_TAG_subprogram)
            {
-             /* C++ member function. */
+             /* C++ member function.  */
              dwarf2_add_member_fn (&fi, child_die, type, cu);
            }
          else if (child_die->tag == DW_TAG_inheritance)
@@ -7014,7 +7770,8 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
                  /* Complain if virtual function table field not found.  */
                  if (i < TYPE_N_BASECLASSES (t))
                    complaint (&symfile_complaints,
-                              _("virtual function table pointer not found when defining class '%s'"),
+                              _("virtual function table pointer "
+                                "not found when defining class '%s'"),
                               TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
                               "");
                }
@@ -7071,6 +7828,9 @@ 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);
@@ -7234,6 +7994,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_type_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_type_section,
+                                           cu->per_cu->offset);
+      if (type_sig->type_offset != die->offset)
+       return;
+    }
+
   new_symbol (die, this_type, cu);
 }
 
@@ -7281,8 +8062,8 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
 
           if (child_type != NULL)
             {
-             /* The range type was succesfully read. Save it for
-                 the array type creation.  */
+             /* The range type was succesfully read.  Save it for the
+                 array type creation.  */
               if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
                 {
                   range_types = (struct type **)
@@ -7334,15 +8115,16 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
       if (DW_UNSND (attr) >= TYPE_LENGTH (type))
        TYPE_LENGTH (type) = DW_UNSND (attr);
       else
-       complaint (&symfile_complaints, _("\
-DW_AT_byte_size for array type smaller than the total size of elements"));
+       complaint (&symfile_complaints,
+                  _("DW_AT_byte_size for array type smaller "
+                    "than the total size of elements"));
     }
 
   name = dwarf2_name (die, cu);
   if (name)
     TYPE_NAME (type) = name;
 
-  /* Install the type in the die. */
+  /* Install the type in the die.  */
   set_die_type (die, type, cu);
 
   /* set_die_type should be already done.  */
@@ -7362,14 +8144,12 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
 
   if (attr) return DW_SND (attr);
 
-  /*
-    GNU F77 is a special case, as at 08/2004 array type info is the
-    opposite order to the dwarf2 specification, but data is still
-    laid out as per normal fortran.
+  /* GNU F77 is a special case, as at 08/2004 array type info is the
+     opposite order to the dwarf2 specification, but data is still
+     laid out as per normal fortran.
 
-    FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
-    version checking.
-  */
+     FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
+     version checking.  */
 
   if (cu->language == language_fortran
       && cu->producer && strstr (cu->producer, "GNU F77"))
@@ -7388,7 +8168,7 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
 }
 
 /* Extract all information from a DW_TAG_set_type DIE and put it in
-   the DIE's type field. */
+   the DIE's type field.  */
 
 static struct type *
 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
@@ -7425,7 +8205,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_location, cu);
   if (attr)
     {
-      /* Support the .debug_loc offsets */
+      /* Support the .debug_loc offsets */
       if (attr_form_is_block (attr))
         {
           base = decode_locdesc (DW_BLOCK (attr), cu);
@@ -7445,22 +8225,13 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
       child_die = die->child;
       while (child_die && child_die->tag)
        {
+         LONGEST offset;
+
          sym = new_symbol (child_die, NULL, cu);
-         attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
-         if (sym != NULL && attr != NULL)
+         if (sym != NULL
+             && handle_data_member_location (child_die, cu, &offset))
            {
-             CORE_ADDR byte_offset = 0;
-
-             if (attr_form_is_section_offset (attr))
-               dwarf2_complex_location_expr_complaint ();
-             else if (attr_form_is_constant (attr))
-               byte_offset = dwarf2_get_attr_constant_value (attr, 0);
-             else if (attr_form_is_block (attr))
-               byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
-             else
-               dwarf2_complex_location_expr_complaint ();
-
-             SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
+             SYMBOL_VALUE_ADDRESS (sym) = base + offset;
              add_symbol_to_list (sym, &global_symbols);
            }
          child_die = sibling_die (child_die);
@@ -7516,7 +8287,6 @@ static void
 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
-  const char *name;
   int is_anonymous;
 
   /* Add a symbol associated to this if we haven't seen the namespace
@@ -7530,13 +8300,13 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
       type = read_type_die (die, cu);
       new_symbol (die, type, cu);
 
-      name = namespace_name (die, &is_anonymous, cu);
+      namespace_name (die, &is_anonymous, cu);
       if (is_anonymous)
        {
          const char *previous_prefix = determine_prefix (die, cu);
 
          cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
-                                 NULL, &objfile->objfile_obstack);
+                                 NULL, NULL, &objfile->objfile_obstack);
        }
     }
 
@@ -7565,7 +8335,8 @@ read_module_type (struct die_info *die, struct dwarf2_cu *cu)
 
   module_name = dwarf2_name (die, cu);
   if (!module_name)
-    complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"),
+    complaint (&symfile_complaints,
+              _("DW_TAG_module has no name, offset 0x%x"),
                die->offset);
   type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
 
@@ -7614,7 +8385,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;
 }
@@ -7671,7 +8442,8 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
        }
       else if (TYPE_LENGTH (type) != byte_size)
        {
-         complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size);
+         complaint (&symfile_complaints,
+                    _("invalid pointer size %d"), byte_size);
        }
       else
        {
@@ -7815,7 +8587,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
     }
   else
     {
-      /* check for the DW_AT_byte_size attribute */
+      /* Check for the DW_AT_byte_size attribute.  */
       attr = dwarf2_attr (die, DW_AT_byte_size, cu);
       if (attr)
         {
@@ -7843,14 +8615,13 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
    int b;
    };
 
-   ('funcp' generates a DW_TAG_subroutine_type DIE)
- */
+   ('funcp' generates a DW_TAG_subroutine_type DIE).  */
 
 static struct type *
 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
 {
-  struct type *type;           /* Type that this function returns */
-  struct type *ftype;          /* Function that returns above type */
+  struct type *type;           /* Type that this function returns */
+  struct type *ftype;          /* Function that returns above type */
   struct attribute *attr;
 
   type = die_type (die, cu);
@@ -7880,11 +8651,16 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
      the subroutine die.  Otherwise set the calling convention to
      the default value DW_CC_normal.  */
   attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
-  TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal;
+  if (attr)
+    TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
+  else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
+    TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
+  else
+    TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
 
   /* We need to add the subroutine type to the die immediately so
      we don't infinitely recurse when dealing with parameters
-     declared as the same subroutine type. */
+     declared as the same subroutine type.  */
   set_die_type (die, ftype, cu);
 
   if (die->child != NULL)
@@ -8068,15 +8844,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;
@@ -8106,7 +8888,6 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
 static struct type *
 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
   struct type *base_type;
   struct type *range_type;
   struct attribute *attr;
@@ -8140,7 +8921,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.
@@ -8166,6 +8947,11 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
          int count = dwarf2_get_attr_constant_value (attr, 1);
          high = low + count - 1;
        }
+      else
+       {
+         /* Unspecified array length.  */
+         high = low - 1;
+       }
     }
 
   /* Dwarf-2 specifications explicitly allows to create subrange types
@@ -8179,8 +8965,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
      For the following C code: `extern char gdb_int [];'
      GCC produces an empty range DIE.
      FIXME: muller/2010-05-28: Possible references to object for low bound,
-     high bound or count are not yet handled by this code.
-  */
+     high bound or count are not yet handled by this code.  */
   if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
     {
       struct objfile *objfile = cu->objfile;
@@ -8219,7 +9004,11 @@ 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.  */
+  if (attr == NULL && cu->language != language_ada)
     TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
 
   name = dwarf2_name (die, cu);
@@ -8327,11 +9116,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_type_section
+                          ? ".debug_types"
+                          : ".debug_info"),
                          reader->abfd->filename);
       dump_die (result, dwarf2_die_debug);
     }
@@ -8477,7 +9264,7 @@ dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
   struct attr_abbrev *cur_attrs;
   unsigned int allocated_attrs;
 
-  /* Initialize dwarf2 abbrevs */
+  /* Initialize dwarf2 abbrevs */
   obstack_init (&cu->abbrev_obstack);
   cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
                                      (ABBREV_HASH_SIZE
@@ -8494,7 +9281,7 @@ dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
   allocated_attrs = ATTR_ALLOC_CHUNK;
   cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
 
-  /* loop until we reach an abbrev number of 0 */
+  /* Loop until we reach an abbrev number of 0.  */
   while (abbrev_number)
     {
       cur_abbrev = dwarf_alloc_abbrev (cu);
@@ -8761,7 +9548,7 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
       if (parent_die == NULL
          && part_die->has_specification == 0
          && part_die->is_declaration == 0
-         && (part_die->tag == DW_TAG_typedef
+         && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
              || part_die->tag == DW_TAG_base_type
              || part_die->tag == DW_TAG_subrange_type))
        {
@@ -8774,6 +9561,20 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
          continue;
        }
 
+      /* The exception for DW_TAG_typedef with has_children above is
+        a workaround of GCC PR debug/47510.  In the case of this complaint
+        type_name_no_tag_or_error will error on such types later.
+
+        GDB skipped children of DW_TAG_typedef by the shortcut above and then
+        it could not find the child DIEs referenced later, this is checked
+        above.  In correct DWARF DW_TAG_typedef should have no children.  */
+
+      if (part_die->tag == DW_TAG_typedef && part_die->has_children)
+       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);
+
       /* If we're at the second level, and we're an enumerator, and
         our parent has no specification (meaning possibly lives in a
         namespace elsewhere), then we can add the partial symbol now
@@ -8785,7 +9586,8 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
          && parent_die->has_specification == 0)
        {
          if (part_die->name == NULL)
-           complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
+           complaint (&symfile_complaints,
+                      _("malformed enumerator DIE ignored"));
          else if (building_psymtab)
            add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
                                 VAR_DOMAIN, LOC_CONST,
@@ -8966,7 +9768,7 @@ read_partial_die (struct partial_die_info *part_die,
          part_die->highpc = DW_ADDR (&attr);
          break;
        case DW_AT_location:
-          /* Support the .debug_loc offsets */
+          /* Support the .debug_loc offsets */
           if (attr_form_is_block (&attr))
             {
               part_die->locdesc = DW_BLOCK (&attr);
@@ -9000,7 +9802,8 @@ read_partial_die (struct partial_die_info *part_die,
          /* Ignore absolute siblings, they might point outside of
             the current compile unit.  */
          if (attr.form == DW_FORM_ref_addr)
-           complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
+           complaint (&symfile_complaints,
+                      _("ignoring absolute DW_AT_sibling"));
          else
            part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
          break;
@@ -9037,20 +9840,42 @@ read_partial_die (struct partial_die_info *part_die,
        }
     }
 
-  /* When using the GNU linker, .gnu.linkonce. sections are used to
-     eliminate duplicate copies of functions and vtables and such.
-     The linker will arbitrarily choose one and discard the others.
-     The AT_*_pc values for such functions refer to local labels in
-     these sections.  If the section from that file was discarded, the
-     labels are not in the output, so the relocs get a value of 0.
-     If this is a discarded function, mark the pc bounds as invalid,
-     so that GDB will ignore it.  */
-  if (has_low_pc_attr && has_high_pc_attr
-      && part_die->lowpc < part_die->highpc
-      && (part_die->lowpc != 0
-         || dwarf2_per_objfile->has_section_at_zero))
-    part_die->has_pc_info = 1;
-
+  if (has_low_pc_attr && has_high_pc_attr)
+    {
+      /* When using the GNU linker, .gnu.linkonce. sections are used to
+        eliminate duplicate copies of functions and vtables and such.
+        The linker will arbitrarily choose one and discard the others.
+        The AT_*_pc values for such functions refer to local labels in
+        these sections.  If the section from that file was discarded, the
+        labels are not in the output, so the relocs get a value of 0.
+        If this is a discarded function, mark the pc bounds as invalid,
+        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);
+
+         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);
+       }
+      /* 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);
+
+         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);
+       }
+      else
+       part_die->has_pc_info = 1;
+    }
+
   return info_ptr;
 }
 
@@ -9071,7 +9896,7 @@ find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
 /* Find a partial DIE at OFFSET, which may or may not be in CU,
    except in the case of .debug_types DIEs which do not reference
    outside their CU (they do however referencing other types via
-   DW_FORM_sig8).  */
+   DW_FORM_ref_sig8).  */
 
 static struct partial_die_info *
 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
@@ -9079,7 +9904,7 @@ find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
   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_type_section)
     {
       pd = find_partial_die_in_comp_unit (offset, cu);
       if (pd != NULL)
@@ -9140,7 +9965,8 @@ find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
 
   if (pd == NULL)
     internal_error (__FILE__, __LINE__,
-                   _("could not find partial DIE 0x%x in cache [from module %s]\n"),
+                   _("could not find partial DIE 0x%x "
+                     "in cache [from module %s]\n"),
                    offset, bfd_get_filename (cu->objfile->obfd));
   return pd;
 }
@@ -9233,7 +10059,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
@@ -9241,7 +10067,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
@@ -9249,6 +10075,36 @@ fixup_partial_die (struct partial_die_info *part_die,
          || part_die->tag == DW_TAG_union_type))
     guess_partial_die_structure_name (part_die, cu);
 
+  /* 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_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;
+
+      demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
+      if (demangled)
+       {
+         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);
+       }
+    }
+
   part_die->fixup_called = 1;
 }
 
@@ -9270,7 +10126,8 @@ read_attribute_value (struct attribute *attr, unsigned form,
       if (cu->header.version == 2)
        DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
       else
-       DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
+       DW_ADDR (attr) = read_offset (abfd, info_ptr,
+                                     &cu->header, &bytes_read);
       info_ptr += bytes_read;
       break;
     case DW_FORM_addr:
@@ -9372,7 +10229,7 @@ read_attribute_value (struct attribute *attr, unsigned form,
       DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
       info_ptr += 8;
       break;
-    case DW_FORM_sig8:
+    case DW_FORM_ref_sig8:
       /* Convert the signature to something we can record in DW_UNSND
         for later lookup.
          NOTE: This is NULL if the type wasn't found.  */
@@ -9426,7 +10283,7 @@ read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
   return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
 }
 
-/* read dwarf information from a buffer */
+/* Read dwarf information from a buffer.  */
 
 static unsigned int
 read_1_byte (bfd *abfd, gdb_byte *buf)
@@ -9446,24 +10303,12 @@ read_2_bytes (bfd *abfd, gdb_byte *buf)
   return bfd_get_16 (abfd, buf);
 }
 
-static int
-read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
-{
-  return bfd_get_signed_16 (abfd, buf);
-}
-
 static unsigned int
 read_4_bytes (bfd *abfd, gdb_byte *buf)
 {
   return bfd_get_32 (abfd, buf);
 }
 
-static int
-read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
-{
-  return bfd_get_signed_32 (abfd, buf);
-}
-
 static ULONGEST
 read_8_bytes (bfd *abfd, gdb_byte *buf)
 {
@@ -9511,7 +10356,8 @@ read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
          break;
        default:
          internal_error (__FILE__, __LINE__,
-                         _("read_address: bad switch, unsigned [in module %s]"),
+                         _("read_address: bad switch, "
+                           "unsigned [in module %s]"),
                          bfd_get_filename (abfd));
        }
     }
@@ -9674,31 +10520,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)
 {
@@ -10064,7 +10911,8 @@ dwarf_decode_line_header (unsigned int offset, bfd *abfd,
     {
       lh->maximum_ops_per_instruction = 1;
       complaint (&symfile_complaints,
-                _("invalid maximum_ops_per_instruction in `.debug_line' section"));
+                _("invalid maximum_ops_per_instruction "
+                  "in `.debug_line' section"));
     }
 
   lh->default_is_stmt = read_1_byte (abfd, line_ptr);
@@ -10114,7 +10962,8 @@ dwarf_decode_line_header (unsigned int offset, bfd *abfd,
   if (line_ptr > (dwarf2_per_objfile->line.buffer
                  + dwarf2_per_objfile->line.size))
     complaint (&symfile_complaints,
-              _("line number info header doesn't fit in `.debug_line' section"));
+              _("line number info header doesn't "
+                "fit in `.debug_line' section"));
 
   discard_cleanups (back_to);
   return lh;
@@ -10245,6 +11094,14 @@ psymtab_include_file_name (const struct line_header *lh, int file_index,
   return include_name;
 }
 
+/* Ignore this record_line request.  */
+
+static void
+noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
+{
+  return;
+}
+
 /* Decode the Line Number Program (LNP) for the given line_header
    structure and CU.  The actual information extracted and the type
    of structures created from the LNP depends on the value of PST.
@@ -10280,6 +11137,8 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   const int decode_for_pst_p = (pst != NULL);
   struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
+  void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
+    = record_line;
 
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
@@ -10349,13 +11208,13 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
                        {
                          addr = gdbarch_addr_bits_remove (gdbarch, address);
                          if (last_subfile)
-                           record_line (last_subfile, 0, addr);
+                           (*p_record_line) (last_subfile, 0, addr);
                          last_subfile = current_subfile;
                        }
                      /* Append row to matrix using current values.  */
                      addr = check_cu_functions (address, cu);
                      addr = gdbarch_addr_bits_remove (gdbarch, addr);
-                     record_line (current_subfile, line, addr);
+                     (*p_record_line) (current_subfile, line, addr);
                    }
                }
              basic_block = 0;
@@ -10363,7 +11222,8 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
          else switch (op_code)
            {
            case DW_LNS_extended_op:
-             extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+             extended_len = read_unsigned_leb128 (abfd, line_ptr,
+                                                  &bytes_read);
              line_ptr += bytes_read;
              extended_end = line_ptr + extended_len;
              extended_op = read_1_byte (abfd, line_ptr);
@@ -10371,10 +11231,27 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
              switch (extended_op)
                {
                case DW_LNE_end_sequence:
+                 p_record_line = record_line;
                  end_sequence = 1;
                  break;
                case DW_LNE_set_address:
                  address = read_address (abfd, line_ptr, cu, &bytes_read);
+
+                 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
+                   {
+                     /* This line table is for a function which has been
+                        GCd by the linker.  Ignore it.  PR gdb/12528 */
+
+                     long line_offset
+                       = line_ptr - dwarf2_per_objfile->line.buffer;
+
+                     complaint (&symfile_complaints,
+                                _(".debug_line address at offset 0x%lx is 0 "
+                                  "[in module %s]"),
+                                line_offset, cu->objfile->name);
+                     p_record_line = noop_record_line;
+                   }
+
                  op_index = 0;
                  line_ptr += bytes_read;
                  address += baseaddr;
@@ -10384,7 +11261,8 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
                     char *cur_file;
                     unsigned int dir_index, mod_time, length;
 
-                    cur_file = read_direct_string (abfd, line_ptr, &bytes_read);
+                    cur_file = read_direct_string (abfd, line_ptr,
+                                                  &bytes_read);
                     line_ptr += bytes_read;
                     dir_index =
                       read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
@@ -10430,12 +11308,12 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
                        {
                          addr = gdbarch_addr_bits_remove (gdbarch, address);
                          if (last_subfile)
-                           record_line (last_subfile, 0, addr);
+                           (*p_record_line) (last_subfile, 0, addr);
                          last_subfile = current_subfile;
                        }
                      addr = check_cu_functions (address, cu);
                      addr = gdbarch_addr_bits_remove (gdbarch, addr);
-                     record_line (current_subfile, line, addr);
+                     (*p_record_line) (current_subfile, line, addr);
                    }
                }
              basic_block = 0;
@@ -10496,7 +11374,7 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
               address increment value corresponding to special opcode
               255.  I.e., this value is scaled by the minimum
               instruction length since special opcode 255 would have
-              scaled the the increment.  */
+              scaled the increment.  */
            case DW_LNS_const_add_pc:
              {
                CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
@@ -10534,7 +11412,7 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
           if (!decode_for_pst_p)
            {
              addr = gdbarch_addr_bits_remove (gdbarch, address);
-             record_line (current_subfile, 0, addr);
+             (*p_record_line) (current_subfile, 0, addr);
            }
         }
     }
@@ -10611,7 +11489,8 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
    subfile's name.  */
 
 static void
-dwarf2_start_subfile (char *filename, const char *dirname, const char *comp_dir)
+dwarf2_start_subfile (char *filename, const char *dirname,
+                     const char *comp_dir)
 {
   char *fullname;
 
@@ -10690,6 +11569,9 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
 
   dwarf2_symbol_mark_computed (attr, sym, cu);
   SYMBOL_CLASS (sym) = LOC_COMPUTED;
+
+  if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
+    cu->has_loclist = 1;
 }
 
 /* Given a pointer to a DWARF information entry, figure out if we need
@@ -10825,9 +11707,9 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
        case DW_TAG_constant:
        case DW_TAG_variable:
        case DW_TAG_member:
-         /* Compilation with minimal debug info may result in variables
-            with missing type entries. Change the misleading `void' type
-            to something sensible.  */
+         /* Compilation with minimal debug info may result in
+            variables with missing type entries.  Change the
+            misleading `void' type to something sensible.  */
          if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
            SYMBOL_TYPE (sym)
              = objfile_type (objfile)->nodebug_data_symbol;
@@ -10940,14 +11822,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;
@@ -11036,7 +11910,7 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
          /* Not a tag we recognize.  Hopefully we aren't processing
             trash data, but since we must specifically ignore things
             we don't recognize, there is nothing else we should do at
-            this point. */
+            this point.  */
          complaint (&symfile_complaints, _("unsupported tag: '%s'"),
                     dwarf_tag_name (die->tag));
          break;
@@ -11179,16 +12053,20 @@ dwarf2_const_value_attr (struct attribute *attr, struct type *type,
         converted to host endianness, so we just need to sign- or
         zero-extend it as appropriate.  */
     case DW_FORM_data1:
-      *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 8);
+      *bytes = dwarf2_const_value_data (attr, type, name,
+                                       obstack, cu, value, 8);
       break;
     case DW_FORM_data2:
-      *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 16);
+      *bytes = dwarf2_const_value_data (attr, type, name,
+                                       obstack, cu, value, 16);
       break;
     case DW_FORM_data4:
-      *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 32);
+      *bytes = dwarf2_const_value_data (attr, type, name,
+                                       obstack, cu, value, 32);
       break;
     case DW_FORM_data8:
-      *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 64);
+      *bytes = dwarf2_const_value_data (attr, type, name,
+                                       obstack, cu, value, 64);
       break;
 
     case DW_FORM_sdata:
@@ -11344,7 +12222,7 @@ lookup_die_type (struct die_info *die, struct attribute *attr,
 
       this_type = get_die_type_at_offset (offset, cu->per_cu);
     }
-  else if (attr->form == DW_FORM_sig8)
+  else if (attr->form == DW_FORM_ref_sig8)
     {
       struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
       struct dwarf2_cu *sig_cu;
@@ -11357,8 +12235,8 @@ lookup_die_type (struct die_info *die, struct attribute *attr,
                 "at 0x%x [in module %s]"),
               die->offset, cu->objfile->name);
 
-      gdb_assert (sig_type->per_cu.from_debug_types);
-      offset = sig_type->offset + sig_type->type_offset;
+      gdb_assert (sig_type->per_cu.debug_type_section);
+      offset = sig_type->per_cu.offset + sig_type->type_offset;
       this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
     }
   else
@@ -11489,7 +12367,8 @@ read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
       this_type = read_module_type (die, cu);
       break;
     default:
-      complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
+      complaint (&symfile_complaints,
+                _("unexpected tag in read_type_die: '%s'"),
                 dwarf_tag_name (die->tag));
       break;
     }
@@ -11552,7 +12431,8 @@ guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
 
                      /* Test for '::' as a sanity check.  */
                      if (actual_name_len > die_name_len + 2
-                         && actual_name[actual_name_len - die_name_len - 1] == ':')
+                         && actual_name[actual_name_len
+                                        - die_name_len - 1] == ':')
                        name =
                          obsavestring (actual_name,
                                        actual_name_len - die_name_len - 2,
@@ -11568,6 +12448,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.
 
@@ -11589,11 +12505,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
 
@@ -11697,7 +12618,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
@@ -11713,11 +12634,11 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
       }
 }
 
-/* Return a newly-allocated string formed by concatenating PREFIX and
-   SUFFIX with appropriate separator.  If PREFIX or SUFFIX is NULL or empty, then
-   simply copy the SUFFIX or PREFIX, respectively.  If OBS is non-null,
-   perform an obconcat, otherwise allocate storage for the result.  The CU argument
-   is used to determine the language and hence, the appropriate separator.  */
+/* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
+   with appropriate separator.  If PREFIX or SUFFIX is NULL or empty, then
+   simply copy the SUFFIX or PREFIX, respectively.  If OBS is non-null, perform
+   an obconcat, otherwise allocate storage for the result.  The CU argument is
+   used to determine the language and hence, the appropriate separator.  */
 
 #define MAX_SEP_LEN 7  /* strlen ("__") + strlen ("_MOD_")  */
 
@@ -11728,7 +12649,8 @@ typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
   const char *lead = "";
   const char *sep;
 
-  if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
+  if (suffix == NULL || suffix[0] == '\0'
+      || prefix == NULL || prefix[0] == '\0')
     sep = "";
   else if (cu->language == language_java)
     sep = ".";
@@ -11750,7 +12672,8 @@ typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
 
   if (obs == NULL)
     {
-      char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
+      char *retval
+       = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
 
       strcpy (retval, lead);
       strcat (retval, prefix);
@@ -11803,7 +12726,11 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
   struct attribute *attr;
 
   attr = dwarf2_attr (die, DW_AT_name, cu);
-  if (!attr || !DW_STRING (attr))
+  if ((!attr || !DW_STRING (attr))
+      && 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;
 
   switch (die->tag)
@@ -11854,9 +12781,48 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
         structures or unions.  These were of the form "._%d" in GCC 4.1,
         or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
         and GCC 4.4.  We work around this problem by ignoring these.  */
-      if (strncmp (DW_STRING (attr), "._", 2) == 0
-         || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)
+      if (attr && DW_STRING (attr)
+         && (strncmp (DW_STRING (attr), "._", 2) == 0
+             || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
        return NULL;
+
+      /* GCC might emit a nameless typedef that has a linkage name.  See
+        http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510.  */
+      if (!attr || DW_STRING (attr) == NULL)
+       {
+         char *demangled = 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;
+
+         /* Avoid demangling DW_STRING (attr) the second time on a second
+            call for the same DIE.  */
+         if (!DW_STRING_IS_CANONICAL (attr))
+           demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
+
+         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_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;
 
     default:
@@ -12038,6 +13004,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>";
     }
@@ -12380,8 +13348,8 @@ dwarf_form_name (unsigned form)
       return "DW_FORM_exprloc";
     case DW_FORM_flag_present:
       return "DW_FORM_flag_present";
-    case DW_FORM_sig8:
-      return "DW_FORM_sig8";
+    case DW_FORM_ref_sig8:
+      return "DW_FORM_ref_sig8";
     default:
       return "DW_FORM_<unknown>";
     }
@@ -12390,7 +13358,7 @@ dwarf_form_name (unsigned form)
 /* Convert a DWARF stack opcode into its string name.  */
 
 const char *
-dwarf_stack_op_name (unsigned op, int def)
+dwarf_stack_op_name (unsigned op)
 {
   switch (op)
     {
@@ -12711,8 +13679,20 @@ dwarf_stack_op_name (unsigned op, int def)
       return "DW_OP_GNU_uninit";
     case DW_OP_GNU_implicit_pointer:
       return "DW_OP_GNU_implicit_pointer";
+    case DW_OP_GNU_entry_value:
+      return "DW_OP_GNU_entry_value";
+    case DW_OP_GNU_const_type:
+      return "DW_OP_GNU_const_type";
+    case DW_OP_GNU_regval_type:
+      return "DW_OP_GNU_regval_type";
+    case DW_OP_GNU_deref_type:
+      return "DW_OP_GNU_deref_type";
+    case DW_OP_GNU_convert:
+      return "DW_OP_GNU_convert";
+    case DW_OP_GNU_reinterpret:
+      return "DW_OP_GNU_reinterpret";
     default:
-      return def ? "OP_<unknown>" : NULL;
+      return NULL;
     }
 }
 
@@ -12788,7 +13768,7 @@ dwarf_type_encoding_name (unsigned enc)
     }
 }
 
-/* Convert a DWARF call frame info operation to its string name. */
+/* Convert a DWARF call frame info operation to its string name.  */
 
 #if 0
 static char *
@@ -12906,7 +13886,8 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
        case DW_FORM_block4:
        case DW_FORM_block:
        case DW_FORM_block1:
-         fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
+         fprintf_unfiltered (f, "block: size %d",
+                             DW_BLOCK (&die->attrs[i])->size);
          break;
        case DW_FORM_exprloc:
          fprintf_unfiltered (f, "expression: size %u",
@@ -12931,10 +13912,10 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
          fprintf_unfiltered (f, "section offset: %s",
                              pulongest (DW_UNSND (&die->attrs[i])));
          break;
-       case DW_FORM_sig8:
+       case DW_FORM_ref_sig8:
          if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
            fprintf_unfiltered (f, "signatured type, offset: 0x%x",
-                               DW_SIGNATURED_TYPE (&die->attrs[i])->offset);
+                         DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset);
          else
            fprintf_unfiltered (f, "signatured type, offset: unknown");
          break;
@@ -12955,9 +13936,10 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
          fprintf_unfiltered (f, "flag: TRUE");
          break;
        case DW_FORM_indirect:
-         /* the reader will have reduced the indirect form to
-            the "base form" so this form should not occur */
-         fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect");
+         /* The reader will have reduced the indirect form to
+            the "base form" so this form should not occur.  */
+         fprintf_unfiltered (f, 
+                             "unexpected attribute form: DW_FORM_indirect");
          break;
        default:
          fprintf_unfiltered (f, "unsupported attribute form: %d.",
@@ -12997,7 +13979,8 @@ dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
        }
       else
        {
-         fprintf_unfiltered (f, " [not printed, max nesting level reached]\n");
+         fprintf_unfiltered (f,
+                             " [not printed, max nesting level reached]\n");
        }
     }
 
@@ -13071,7 +14054,8 @@ dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
     return DW_UNSND (attr);
   else
     {
-      complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"),
+      complaint (&symfile_complaints,
+                _("Attribute value is not a constant (%s)"),
                  dwarf_form_name (attr->form));
       return default_value;
     }
@@ -13130,7 +14114,7 @@ follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
 
   if (is_ref_attr (attr))
     die = follow_die_ref (src_die, attr, ref_cu);
-  else if (attr->form == DW_FORM_sig8)
+  else if (attr->form == DW_FORM_ref_sig8)
     die = follow_die_sig (src_die, attr, ref_cu);
   else
     {
@@ -13157,11 +14141,11 @@ 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_type_section)
     {
       /* .debug_types CUs cannot reference anything outside their CU.
         If they need to, they have to reference a signatured type via
-        DW_FORM_sig8.  */
+        DW_FORM_ref_sig8.  */
       if (! offset_in_cu_p (&cu->header, offset))
        return NULL;
     }
@@ -13210,8 +14194,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,
@@ -13219,13 +14204,17 @@ 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"),
@@ -13262,9 +14251,23 @@ dwarf2_fetch_die_location_block (unsigned int offset,
       retval.size = DW_BLOCK (attr)->size;
     }
   retval.per_cu = cu->per_cu;
+
+  age_cached_comp_units ();
+
   return retval;
 }
 
+/* Return the type of the DIE at DIE_OFFSET in the CU named by
+   PER_CU.  */
+
+struct type *
+dwarf2_get_die_type (unsigned int die_offset,
+                    struct dwarf2_per_cu_data *per_cu)
+{
+  dw2_setup (per_cu->objfile);
+  return get_die_type_at_offset (die_offset, per_cu);
+}
+
 /* Follow the signature attribute ATTR in SRC_DIE.
    On entry *REF_CU is the CU of SRC_DIE.
    On exit *REF_CU is the CU of the result.  */
@@ -13302,17 +14305,19 @@ follow_die_sig (struct die_info *src_die, struct attribute *attr,
       return die;
     }
 
-  error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
-        "at 0x%x [in module %s]"),
+  error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
+        "from DIE at 0x%x [in module %s]"),
         sig_type->type_offset, src_die->offset, objfile->name);
 }
 
 /* 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;
@@ -13328,7 +14333,7 @@ lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
   /* This is only used to lookup previously recorded types.
      If we didn't find it, it's our bug.  */
   gdb_assert (type_sig != NULL);
-  gdb_assert (offset == type_sig->offset);
+  gdb_assert (offset == type_sig->per_cu.offset);
 
   return type_sig;
 }
@@ -13337,15 +14342,16 @@ lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
 
 static void
 read_signatured_type_at_offset (struct objfile *objfile,
+                               struct dwarf2_section_info *sect,
                                unsigned int 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);
+  type_sig = lookup_signatured_type_at_offset (objfile, sect, offset);
 
   gdb_assert (type_sig->per_cu.cu == NULL);
 
@@ -13365,9 +14371,10 @@ read_signatured_type (struct objfile *objfile,
   struct dwarf2_cu *cu;
   ULONGEST signature;
   struct cleanup *back_to, *free_cu_cleanup;
+  struct dwarf2_section_info *section = type_sig->per_cu.debug_type_section;
 
-  dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
-  types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset;
+  dwarf2_read_section (objfile, section);
+  types_ptr = section->buffer + type_sig->per_cu.offset;
 
   gdb_assert (type_sig->per_cu.cu == NULL);
 
@@ -13380,7 +14387,7 @@ read_signatured_type (struct objfile *objfile,
   /* If an error occurs while loading, release our storage.  */
   free_cu_cleanup = make_cleanup (free_one_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);
 
@@ -13417,6 +14424,37 @@ read_signatured_type (struct objfile *objfile,
   dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
 }
 
+/* Workaround as dwarf_expr_context_funcs.read_mem implementation before
+   a proper runtime DWARF expressions evaluator gets implemented.
+   Otherwise gnuv3_baseclass_offset would error by:
+   Expected a negative vbase offset (old compiler?)  */
+
+static void
+decode_locdesc_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr,
+                        size_t length)
+{
+  struct dwarf_expr_context *ctx = baton;
+  struct gdbarch *gdbarch = ctx->gdbarch;
+  struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
+
+  memset (buf, 0, length);
+
+  if (TYPE_LENGTH (ptr_type) == length)
+    store_typed_address (buf, ptr_type, addr);
+}
+
+static const struct dwarf_expr_context_funcs decode_locdesc_ctx_funcs =
+{
+  ctx_no_read_reg,
+  decode_locdesc_read_mem,
+  ctx_no_get_frame_base,
+  ctx_no_get_frame_cfa,
+  ctx_no_get_frame_pc,
+  ctx_no_get_tls_address,
+  ctx_no_dwarf_call,
+  ctx_no_get_base_type
+};
+
 /* Decode simple location descriptions.
    Given a pointer to a dwarf block that defines a location, compute
    the location and return the value.
@@ -13434,225 +14472,60 @@ read_signatured_type (struct objfile *objfile,
    object is optimized out.  The return value is 0 for that case.
    FIXME drow/2003-11-16: No callers check for this case any more; soon all
    callers will only want a very basic result and this can become a
-   complaint.
-
-   Note that stack[0] is unused except as a default error return.  */
+   complaint.  */
 
 static CORE_ADDR
 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
-  int i;
-  int size = blk->size;
-  gdb_byte *data = blk->data;
-  CORE_ADDR stack[64];
-  int stacki;
-  unsigned int bytes_read, unsnd;
-  gdb_byte op;
+  struct dwarf_expr_context *ctx;
+  struct cleanup *old_chain;
+  volatile struct gdb_exception ex;
 
-  i = 0;
-  stacki = 0;
-  stack[stacki] = 0;
-  stack[++stacki] = 0;
-
-  while (i < size)
-    {
-      op = data[i++];
-      switch (op)
-       {
-       case DW_OP_lit0:
-       case DW_OP_lit1:
-       case DW_OP_lit2:
-       case DW_OP_lit3:
-       case DW_OP_lit4:
-       case DW_OP_lit5:
-       case DW_OP_lit6:
-       case DW_OP_lit7:
-       case DW_OP_lit8:
-       case DW_OP_lit9:
-       case DW_OP_lit10:
-       case DW_OP_lit11:
-       case DW_OP_lit12:
-       case DW_OP_lit13:
-       case DW_OP_lit14:
-       case DW_OP_lit15:
-       case DW_OP_lit16:
-       case DW_OP_lit17:
-       case DW_OP_lit18:
-       case DW_OP_lit19:
-       case DW_OP_lit20:
-       case DW_OP_lit21:
-       case DW_OP_lit22:
-       case DW_OP_lit23:
-       case DW_OP_lit24:
-       case DW_OP_lit25:
-       case DW_OP_lit26:
-       case DW_OP_lit27:
-       case DW_OP_lit28:
-       case DW_OP_lit29:
-       case DW_OP_lit30:
-       case DW_OP_lit31:
-         stack[++stacki] = op - DW_OP_lit0;
-         break;
-
-       case DW_OP_reg0:
-       case DW_OP_reg1:
-       case DW_OP_reg2:
-       case DW_OP_reg3:
-       case DW_OP_reg4:
-       case DW_OP_reg5:
-       case DW_OP_reg6:
-       case DW_OP_reg7:
-       case DW_OP_reg8:
-       case DW_OP_reg9:
-       case DW_OP_reg10:
-       case DW_OP_reg11:
-       case DW_OP_reg12:
-       case DW_OP_reg13:
-       case DW_OP_reg14:
-       case DW_OP_reg15:
-       case DW_OP_reg16:
-       case DW_OP_reg17:
-       case DW_OP_reg18:
-       case DW_OP_reg19:
-       case DW_OP_reg20:
-       case DW_OP_reg21:
-       case DW_OP_reg22:
-       case DW_OP_reg23:
-       case DW_OP_reg24:
-       case DW_OP_reg25:
-       case DW_OP_reg26:
-       case DW_OP_reg27:
-       case DW_OP_reg28:
-       case DW_OP_reg29:
-       case DW_OP_reg30:
-       case DW_OP_reg31:
-         stack[++stacki] = op - DW_OP_reg0;
-         if (i < size)
-           dwarf2_complex_location_expr_complaint ();
-         break;
-
-       case DW_OP_regx:
-         unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
-         i += bytes_read;
-         stack[++stacki] = unsnd;
-         if (i < size)
-           dwarf2_complex_location_expr_complaint ();
-         break;
-
-       case DW_OP_addr:
-         stack[++stacki] = read_address (objfile->obfd, &data[i],
-                                         cu, &bytes_read);
-         i += bytes_read;
-         break;
-
-       case DW_OP_const1u:
-         stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
-         i += 1;
-         break;
-
-       case DW_OP_const1s:
-         stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
-         i += 1;
-         break;
-
-       case DW_OP_const2u:
-         stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
-         i += 2;
-         break;
-
-       case DW_OP_const2s:
-         stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
-         i += 2;
-         break;
-
-       case DW_OP_const4u:
-         stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
-         i += 4;
-         break;
-
-       case DW_OP_const4s:
-         stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
-         i += 4;
-         break;
-
-       case DW_OP_constu:
-         stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
-                                                 &bytes_read);
-         i += bytes_read;
-         break;
-
-       case DW_OP_consts:
-         stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
-         i += bytes_read;
-         break;
-
-       case DW_OP_dup:
-         stack[stacki + 1] = stack[stacki];
-         stacki++;
-         break;
-
-       case DW_OP_plus:
-         stack[stacki - 1] += stack[stacki];
-         stacki--;
-         break;
-
-       case DW_OP_plus_uconst:
-         stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
-         i += bytes_read;
-         break;
+  ctx = new_dwarf_expr_context ();
+  old_chain = make_cleanup_free_dwarf_expr_context (ctx);
+  make_cleanup_value_free_to_mark (value_mark ());
 
-       case DW_OP_minus:
-         stack[stacki - 1] -= stack[stacki];
-         stacki--;
-         break;
-
-       case DW_OP_deref:
-         /* If we're not the last op, then we definitely can't encode
-            this using GDB's address_class enum.  This is valid for partial
-            global symbols, although the variable's address will be bogus
-            in the psymtab.  */
-         if (i < size)
-           dwarf2_complex_location_expr_complaint ();
-         break;
+  ctx->gdbarch = get_objfile_arch (objfile);
+  ctx->addr_size = cu->header.addr_size;
+  ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (cu->per_cu);
+  ctx->offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+  ctx->baton = ctx;
+  ctx->funcs = &decode_locdesc_ctx_funcs;
 
-        case DW_OP_GNU_push_tls_address:
-         /* The top of the stack has the offset from the beginning
-            of the thread control block at which the variable is located.  */
-         /* 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.  */
-         if (i < size)
-           dwarf2_complex_location_expr_complaint ();
-          break;
-
-       case DW_OP_GNU_uninit:
-         break;
+  /* DW_AT_data_member_location expects the structure address to be pushed on
+     the stack.  Simulate the offset by address 0.  */
+  dwarf_expr_push_address (ctx, 0, 0);
 
-       default:
-         complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
-                    dwarf_stack_op_name (op, 1));
-         return (stack[stacki]);
-       }
+  TRY_CATCH (ex, RETURN_MASK_ERROR)
+    {
+      dwarf_expr_eval (ctx, blk->data, blk->size);
+    }
+  if (ex.reason < 0)
+    {
+      if (ex.message)
+       complaint (&symfile_complaints, "%s", ex.message);
+    }
+  else if (ctx->num_pieces == 0)
+    switch (ctx->location)
+      {
+      /* The returned number will be bogus, just do not complain for locations
+        in global registers - it is here only a partial symbol address.  */
+      case DWARF_VALUE_REGISTER:
 
-      /* Enforce maximum stack depth of SIZE-1 to avoid writing
-         outside of the allocated space.  Also enforce minimum>0.  */
-      if (stacki >= ARRAY_SIZE (stack) - 1)
+      case DWARF_VALUE_MEMORY:
+      case DWARF_VALUE_STACK:
        {
-         complaint (&symfile_complaints,
-                    _("location description stack overflow"));
-         return 0;
-       }
+         CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0);
 
-      if (stacki <= 0)
-       {
-         complaint (&symfile_complaints,
-                    _("location description stack underflow"));
-         return 0;
+         do_cleanups (old_chain);
+         return address;
        }
-    }
-  return (stack[stacki]);
+      }
+
+  do_cleanups (old_chain);
+  dwarf2_complex_location_expr_complaint ();
+  return 0;
 }
 
 /* memory allocation interface */
@@ -13799,7 +14672,8 @@ consume_improper_spaces (const char *p, const char *body)
   if (*p == ' ')
     {
       complaint (&symfile_complaints,
-                _("macro definition contains spaces in formal argument list:\n`%s'"),
+                _("macro definition contains spaces "
+                  "in formal argument list:\n`%s'"),
                 body);
 
       while (*p == ' ')
@@ -13950,116 +14824,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
@@ -14075,13 +15038,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
@@ -14089,50 +15054,67 @@ 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) || (line != 0 && at_commandline))
+           if ((line == 0 && !at_commandline)
+               || (line != 0 && at_commandline))
              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;
@@ -14142,7 +15124,8 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
             file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
             mac_ptr += bytes_read;
 
-           if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
+           if ((line == 0 && !at_commandline)
+               || (line != 0 && at_commandline))
              complaint (&symfile_complaints,
                         _("debug info gives source %d included "
                           "from %s at %s line %d"),
@@ -14151,26 +15134,28 @@ 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 `close_file' directive"));
+                      _("macro debug info has an unmatched "
+                        "`close_file' directive"));
           else
             {
               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
@@ -14180,7 +15165,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;
                     }
 
@@ -14189,33 +15174,209 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
                   next_type = read_1_byte (abfd, mac_ptr);
                   if (next_type != 0)
                    complaint (&symfile_complaints,
-                              _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
+                              _("no terminating 0-type entry for "
+                                "macros in `.debug_macinfo' section"));
 
                   return;
                 }
             }
           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;
-            char *string;
+         if (!section_is_gnu)
+           {
+             unsigned int bytes_read;
+             int constant;
 
-            constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
-            mac_ptr += bytes_read;
-            string = 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)
+{
+  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 (dwarf2_per_objfile->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, cu->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, cu->objfile);
+}
+
 /* Check if the attribute's form is a DW_FORM_block*
-   if so return true else false. */
+   if so return true else false.  */
 static int
 attr_form_is_block (struct attribute *attr)
 {
@@ -14300,7 +15461,8 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
       /* ".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_per_objfile->loc.size)
+      && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile,
+                                               &dwarf2_per_objfile->loc))
     {
       struct dwarf2_loclist_baton *baton;
 
@@ -14311,7 +15473,8 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
 
       if (cu->base_known == 0)
        complaint (&symfile_complaints,
-                  _("Location list used without specifying the CU base address."));
+                  _("Location list used without "
+                    "specifying the CU base address."));
 
       SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
       SYMBOL_LOCATION_BATON (sym) = baton;
@@ -14365,26 +15528,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
 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.  */
@@ -14392,21 +15571,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
@@ -14501,7 +15687,10 @@ prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
   if (attr)
     set_cu_language (DW_UNSND (attr), cu);
   else
-    set_cu_language (language_minimal, cu);
+    {
+      cu->language = language_minimal;
+      cu->language_defn = language_def (cu->language);
+    }
 }
 
 /* Release one cached compilation unit, CU.  We unlink it from the tree
@@ -14728,7 +15917,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_type_section)
     type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
   else
     type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
@@ -14768,7 +15957,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_type_section)
     type_hash = dwarf2_per_objfile->debug_types_type_hash;
   else
     type_hash = dwarf2_per_objfile->debug_info_type_hash;
@@ -14822,6 +16011,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;
@@ -14898,14 +16094,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");
@@ -14919,6 +16114,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.  */
@@ -14927,12 +16124,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
@@ -14946,13 +16150,16 @@ struct strtab_entry
   const char *str;
 };
 
-/* Hash function for a strtab_entry.  */
+/* Hash function for a strtab_entry.
+
+   Function is used only during write_hash_table so no index format backward
+   compatibility is needed.  */
 
 static hashval_t
 hash_strtab_entry (const void *e)
 {
   const struct strtab_entry *entry = e;
-  return mapped_index_string_hash (entry->str);
+  return mapped_index_string_hash (INT_MAX, entry->str);
 }
 
 /* Equality function for a strtab_entry.  */
@@ -15090,12 +16297,15 @@ cleanup_mapped_symtab (void *p)
 }
 
 /* Find a slot in SYMTAB for the symbol NAME.  Returns a pointer to
-   the slot.  */
+   the slot.
+   
+   Function is used only during write_hash_table so no index format backward
+   compatibility is needed.  */
 
 static struct symtab_index_entry **
 find_slot (struct mapped_symtab *symtab, const char *name)
 {
-  offset_type index, step, hash = mapped_index_string_hash (name);
+  offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
 
   index = hash & (symtab->size - 1);
   step = ((hash * 17) & (symtab->size - 1)) | 1;
@@ -15156,7 +16366,7 @@ add_index_entry (struct mapped_symtab *symtab, const char *name,
   /* Don't push an index twice.  Due to how we add entries we only
      have to check the last one.  */ 
   if (VEC_empty (offset_type, (*slot)->cu_indices)
-      || VEC_length (offset_type, (*slot)->cu_indices) != cu_index)
+      || VEC_last (offset_type, (*slot)->cu_indices) != cu_index)
     VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
 }
 
@@ -15285,7 +16495,7 @@ struct addrmap_index_data
   int previous_valid;
   /* Index of the CU in the table of all CUs in the index file.  */
   unsigned int previous_cu_index;
-  /* Start address of the CU. */
+  /* Start address of the CU.  */
   CORE_ADDR previous_cu_start;
 };
 
@@ -15458,16 +16668,18 @@ write_one_signatured_type (void **slot, void *d)
 
   write_psymbols (info->symtab,
                  info->psyms_seen,
-                 info->objfile->global_psymbols.list + psymtab->globals_offset,
+                 info->objfile->global_psymbols.list
+                 + psymtab->globals_offset,
                  psymtab->n_global_syms, info->cu_index,
                  0);
   write_psymbols (info->symtab,
                  info->psyms_seen,
-                 info->objfile->static_psymbols.list + psymtab->statics_offset,
+                 info->objfile->static_psymbols.list
+                 + psymtab->statics_offset,
                  psymtab->n_static_syms, info->cu_index,
                  1);
 
-  store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->offset);
+  store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset);
   obstack_grow (info->types_list, val, 8);
   store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
   obstack_grow (info->types_list, val, 8);
@@ -15479,14 +16691,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
@@ -15506,11 +16710,15 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
   htab_t cu_index_htab;
   struct psymtab_cu_index_map *psymtab_cu_index_map;
 
-  if (!objfile->psymtabs)
+  if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
     return;
+
   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);
 
@@ -15539,7 +16747,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
@@ -15549,7 +16757,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);
@@ -15560,7 +16768,8 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
      all_comp_units, but only in their own hash table.  */
   for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
     {
-      struct dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->all_comp_units[i];
+      struct dwarf2_per_cu_data *per_cu
+       = dwarf2_per_objfile->all_comp_units[i];
       struct partial_symtab *psymtab = per_cu->v.psymtab;
       gdb_byte val[8];
       struct psymtab_cu_index_map *map;
@@ -15620,7 +16829,7 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
   total_len = size_of_contents;
 
   /* The version number.  */
-  val = MAYBE_SWAP (3);
+  val = MAYBE_SWAP (5);
   obstack_grow (&contents, &val, sizeof (val));
 
   /* The offset of the CU list from the start of the file.  */
@@ -15666,75 +16875,10 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
   do_cleanups (cleanup);
 }
 
-/* The mapped index file format is designed to be directly mmap()able
-   on any architecture.  In most cases, a datum is represented using a
-   little-endian 32-bit integer value, called an offset_type.  Big
-   endian machines must byte-swap the values before using them.
-   Exceptions to this rule are noted.  The data is laid out such that
-   alignment is always respected.
-
-   A mapped index consists of several sections.
-
-   1. The file header.  This is a sequence of values, of offset_type
-   unless otherwise noted:
-
-   [0] The version number, currently 3.  Versions 1 and 2 are
-   obsolete.
-   [1] The offset, from the start of the file, of the CU list.
-   [2] The offset, from the start of the file, of the types CU list.
-   Note that this section can be empty, in which case this offset will
-   be equal to the next offset.
-   [3] The offset, from the start of the file, of the address section.
-   [4] The offset, from the start of the file, of the symbol table.
-   [5] The offset, from the start of the file, of the constant pool.
-
-   2. The CU list.  This is a sequence of pairs of 64-bit
-   little-endian values, sorted by the CU offset.  The first element
-   in each pair is the offset of a CU in the .debug_info section.  The
-   second element in each pair is the length of that CU.  References
-   to a CU elsewhere in the map are done using a CU index, which is
-   just the 0-based index into this table.  Note that if there are
-   type CUs, then conceptually CUs and type CUs form a single list for
-   the purposes of CU indices.
-
-   3. The types CU list.  This is a sequence of triplets of 64-bit
-   little-endian values.  In a triplet, the first value is the CU
-   offset, the second value is the type offset in the CU, and the
-   third value is the type signature.  The types CU list is not
-   sorted.
-
-   4. The address section.  The address section consists of a sequence
-   of address entries.  Each address entry has three elements.
-   [0] The low address.  This is a 64-bit little-endian value.
-   [1] The high address.  This is a 64-bit little-endian value.
-       Like DW_AT_high_pc, the value is one byte beyond the end.
-   [2] The CU index.  This is an offset_type value.
-
-   5. The symbol table.  This is a hash table.  The size of the hash
-   table is always a power of 2.  The initial hash and the step are
-   currently defined by the `find_slot' function.
-
-   Each slot in the hash table consists of a pair of offset_type
-   values.  The first value is the offset of the symbol's name in the
-   constant pool.  The second value is the offset of the CU vector in
-   the constant pool.
-
-   If both values are 0, then this slot in the hash table is empty.
-   This is ok because while 0 is a valid constant pool index, it
-   cannot be a valid index for both a string and a CU vector.
-
-   A string in the constant pool is stored as a \0-terminated string,
-   as you'd expect.
-
-   A CU vector in the constant pool is a sequence of offset_type
-   values.  The first value is the number of CU indices in the vector.
-   Each subsequent value is the index of a CU in the CU list.  This
-   element in the hash table is used to indicate which CUs define the
-   symbol.
-
-   6. The constant pool.  This is simply a bunch of bytes.  It is
-   organized so that alignment is correct: CU vectors are stored
-   first, followed by strings.  */
+/* Implementation of the `save gdb-index' command.
+   
+   Note that the file format used by this command is documented in the
+   GDB manual.  Any changes here must be documented there.  */
 
 static void
 save_gdb_index_command (char *arg, int from_tty)
@@ -15777,8 +16921,18 @@ static void
 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
                                struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-Whether to always disassemble DWARF expressions is %s.\n"),
+  fprintf_filtered (file,
+                   _("Whether to always disassemble "
+                     "DWARF expressions is %s.\n"),
+                   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);
 }
 
@@ -15837,6 +16991,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.183275 seconds and 4 git commands to generate.