PR symtab/12984:
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index ce43284248976d44cb966dfc49dde7eacc12e367..a373b09c62b3bd620e2daea2dce128ed26757310 100644 (file)
@@ -119,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
@@ -142,6 +145,9 @@ struct dwarf2_section_info
   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;
@@ -183,11 +189,12 @@ struct dwarf2_per_objfile
   struct dwarf2_section_info macinfo;
   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;
 
@@ -444,9 +451,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.  */
@@ -881,6 +888,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 *,
@@ -1198,6 +1208,7 @@ static struct die_info *follow_die_sig (struct die_info *,
                                        struct dwarf2_cu **);
 
 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 *,
@@ -1449,8 +1460,14 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
     }
   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, &names->gdb_index))
     {
@@ -1785,6 +1802,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.  */
 
@@ -1798,10 +1834,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);
 
@@ -1909,6 +1942,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)
 {
@@ -1939,7 +1973,7 @@ create_signatured_type_table_from_index (struct objfile *objfile,
                                 struct signatured_type);
       type_sig->signature = signature;
       type_sig->type_offset = type_offset;
-      type_sig->per_cu.from_debug_types = 1;
+      type_sig->per_cu.debug_type_section = section;
       type_sig->per_cu.offset = offset;
       type_sig->per_cu.objfile = objfile;
       type_sig->per_cu.v.quick
@@ -2167,10 +2201,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);
 
@@ -2224,8 +2271,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);
@@ -2248,7 +2295,7 @@ 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);
   read_full_die (&reader_specs, &comp_unit_die, info_ptr,
@@ -2916,14 +2963,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);
 
@@ -3051,91 +3098,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->type_offset = type_offset;
-      type_sig->per_cu.objfile = objfile;
-      type_sig->per_cu.from_debug_types = 1;
-      type_sig->per_cu.offset = offset;
+         /* We need to read the type's signature in order to build the hash
+            table, but we don't need to read anything else just yet.  */
 
-      slot = htab_find_slot (types_htab, type_sig, INSERT);
-      gdb_assert (slot != NULL);
-      if (*slot != NULL)
-       {
-         const struct signatured_type *dup_sig = *slot;
+         /* Sanity check to ensure entire cu is present.  */
+         length = read_initial_length (objfile->obfd, ptr,
+                                       &initial_length_size);
+         if (ptr + length + initial_length_size > end_ptr)
+           {
+             complaint (&symfile_complaints,
+                        _("debug type entry runs off end "
+                          "of `.debug_types' section, ignored"));
+             break;
+           }
 
-         complaint (&symfile_complaints,
-                    _("debug type entry at offset 0x%x is duplicate to the "
-                      "entry at offset 0x%x, signature 0x%s"),
-                    offset, dup_sig->per_cu.offset,
-                    phex (signature, sizeof (signature)));
-         gdb_assert (signature == dup_sig->signature);
-       }
-      *slot = type_sig;
+         offset_size = initial_length_size == 4 ? 4 : 8;
+         ptr += initial_length_size;
+         version = bfd_get_16 (objfile->obfd, ptr);
+         ptr += 2;
+         ptr += offset_size; /* abbrev offset */
+         ptr += 1; /* address size */
+         signature = bfd_get_64 (objfile->obfd, ptr);
+         ptr += 8;
+         type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
+
+         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;
 
-      if (dwarf2_die_debug)
-       fprintf_unfiltered (gdb_stdlog, "  offset 0x%x, signature 0x%s\n",
-                           offset, phex (signature, sizeof (signature)));
+             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;
+         info_ptr = info_ptr + initial_length_size + length;
+       }
     }
 
   dwarf2_per_objfile->signatured_types = types_htab;
@@ -3181,10 +3241,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
     {
@@ -3285,13 +3345,13 @@ 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)
     {
       /* LENGTH has not been set yet for type units.  */
       gdb_assert (this_cu->offset == cu.header.offset);
@@ -3387,7 +3447,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.  */
@@ -3416,11 +3476,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 + this_cu->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;
 }
@@ -3529,7 +3590,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;
@@ -4528,7 +4589,7 @@ load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
   struct attribute *attr;
   int read_cu = 0;
 
-  gdb_assert (! per_cu->from_debug_types);
+  gdb_assert (! per_cu->debug_type_section);
 
   /* Set local variables from the partial symbol table info.  */
   offset = per_cu->offset;
@@ -4646,10 +4707,12 @@ compute_delayed_physnames (struct dwarf2_cu *cu)
     }
 }
 
-/* Check for GCC >= 4.0.  */
+/* Check for GCC >= 4.x.  Return minor version (x) of 4.x in such case.  If it
+   is not GCC or it is GCC older than 4.x return -1.  If it is GCC 5.x or
+   higher return INT_MAX.  */
 
 static int
-producer_is_gcc_ge_4_0 (struct dwarf2_cu *cu)
+producer_is_gcc_ge_4 (struct dwarf2_cu *cu)
 {
   const char *cs;
   int major, minor;
@@ -4660,7 +4723,7 @@ producer_is_gcc_ge_4_0 (struct dwarf2_cu *cu)
         this case can also happen for -gdwarf-4 type units supported since
         gcc-4.5.  */
 
-      return 0;
+      return -1;
     }
 
   /* Skip any identifier after "GNU " - such as "C++" or "Java".  */
@@ -4669,7 +4732,7 @@ producer_is_gcc_ge_4_0 (struct dwarf2_cu *cu)
     {
       /* For non-GCC compilers expect their behavior is not compliant.  */
 
-      return 0;
+      return -1;
     }
   cs = &cu->producer[strlen ("GNU ")];
   while (*cs && !isdigit (*cs))
@@ -4678,10 +4741,14 @@ producer_is_gcc_ge_4_0 (struct dwarf2_cu *cu)
     {
       /* Not recognized as GCC.  */
 
-      return 0;
+      return -1;
     }
 
-  return major >= 4;
+  if (major < 4)
+    return -1;
+  if (major > 4)
+    return INT_MAX;
+  return minor;
 }
 
 /* Generate full symbol information for PST and CU, whose DIEs have
@@ -4705,8 +4772,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);
 
@@ -4725,6 +4790,8 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
 
   if (symtab != NULL)
     {
+      int gcc_4_minor = producer_is_gcc_ge_4 (cu);
+
       /* 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.  */
@@ -4741,8 +4808,11 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
         Still one can confuse GDB by using non-standard GCC compilation
         options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
         */ 
-      if (cu->has_loclist && producer_is_gcc_ge_4_0 (cu))
+      if (cu->has_loclist && gcc_4_minor >= 0)
        symtab->locations_valid = 1;
+
+      if (gcc_4_minor >= 5)
+       symtab->epilogue_unwind_valid = 1;
     }
 
   if (dwarf2_per_objfile->using_index)
@@ -5169,7 +5239,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.  */
@@ -5380,6 +5534,35 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
     *name = "<unknown>";
 }
 
+/* Handle DW_AT_stmt_list for a compilation unit.  */
+
+static void
+handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
+                       const char *comp_dir)
+{
+  struct attribute *attr;
+  struct objfile *objfile = cu->objfile;
+  bfd *abfd = objfile->obfd;
+
+  /* Decode line number information if present.  We do this before
+     processing child DIEs, so that the line header table is available
+     for DW_AT_decl_file.  */
+  attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
+  if (attr)
+    {
+      unsigned int line_offset = DW_UNSND (attr);
+      struct line_header *line_header
+       = dwarf_decode_line_header (line_offset, abfd, cu);
+
+      if (line_header)
+        {
+          cu->line_header = line_header;
+          make_cleanup (free_cu_line_header, cu);
+          dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
+        }
+    }
+}
+
 /* Process DW_TAG_compile_unit.  */
 
 static void
@@ -5394,7 +5577,6 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
   char *comp_dir = NULL;
   struct die_info *child_die;
   bfd *abfd = objfile->obfd;
-  struct line_header *line_header = 0;
   CORE_ADDR baseaddr;
 
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
@@ -5437,21 +5619,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)
@@ -5469,11 +5637,11 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
      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)
+  if (attr && cu->line_header)
     {
       unsigned int macro_offset = DW_UNSND (attr);
 
-      dwarf_decode_macros (line_header, macro_offset,
+      dwarf_decode_macros (cu->line_header, macro_offset,
                            comp_dir, abfd, cu);
     }
   do_cleanups (back_to);
@@ -5538,6 +5706,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)
     {
@@ -7394,6 +7564,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);
@@ -8463,7 +8636,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.
@@ -8546,7 +8719,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   /* Mark arrays with dynamic length at least as an array of unspecified
      length.  GDB could check the boundary but before it gets implemented at
      least allow accessing the array elements.  */
-  if (attr && attr->form == DW_FORM_block1)
+  if (attr && attr_form_is_block (attr))
     TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
 
   /* Ada expects an empty array on no boundary attributes.  */
@@ -8658,11 +8831,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);
     }
@@ -9448,7 +9619,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)
@@ -9611,7 +9782,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
@@ -11788,7 +11959,7 @@ 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);
+      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);
     }
@@ -12130,7 +12301,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
@@ -13642,7 +13813,7 @@ follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
 
   target_cu = cu;
 
-  if (cu->per_cu->from_debug_types)
+  if (cu->per_cu->debug_type_section)
     {
       /* .debug_types CUs cannot reference anything outside their CU.
         If they need to, they have to reference a signatured type via
@@ -13696,7 +13867,8 @@ follow_die_ref (struct die_info *src_die, struct attribute *attr,
 }
 
 /* Return DWARF block and its CU referenced by OFFSET at PER_CU.  Returned
-   value is intended for DW_OP_call*.  */
+   value is intended for DW_OP_call*.  You must call xfree on returned
+   dwarf2_locexpr_baton->data.  */
 
 struct dwarf2_locexpr_baton
 dwarf2_fetch_die_location_block (unsigned int offset,
@@ -13704,13 +13876,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"),
@@ -13747,6 +13923,12 @@ dwarf2_fetch_die_location_block (unsigned int offset,
       retval.size = DW_BLOCK (attr)->size;
     }
   retval.per_cu = cu->per_cu;
+
+  if (retval.data)
+    retval.data = xmemdup (retval.data, retval.size, retval.size);
+
+  age_cached_comp_units ();
+
   return retval;
 }
 
@@ -13806,9 +13988,11 @@ follow_die_sig (struct die_info *src_die, struct attribute *attr,
 /* Given an offset of a signatured type, return its signatured_type.  */
 
 static struct signatured_type *
-lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
+lookup_signatured_type_at_offset (struct objfile *objfile,
+                                 struct dwarf2_section_info *section,
+                                 unsigned int offset)
 {
-  gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
+  gdb_byte *info_ptr = section->buffer + offset;
   unsigned int length, initial_length_size;
   unsigned int sig_offset;
   struct signatured_type find_entry, *type_sig;
@@ -13833,15 +14017,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);
 
@@ -13861,9 +14046,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->per_cu.offset;
+  dwarf2_read_section (objfile, section);
+  types_ptr = section->buffer + type_sig->per_cu.offset;
 
   gdb_assert (type_sig->per_cu.cu == NULL);
 
@@ -13876,7 +14062,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);
 
@@ -15244,7 +15430,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;
@@ -15284,7 +15470,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;
@@ -15338,6 +15524,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;
@@ -15434,6 +15627,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.  */
@@ -15444,10 +15639,16 @@ dwarf2_per_objfile_free (struct objfile *objfile, void *d)
   munmap_section_buffer (&data->macinfo);
   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
@@ -16035,6 +16236,9 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
   if (dwarf2_per_objfile->using_index)
     error (_("Cannot use an index to create the index"));
 
+  if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
+    error (_("Cannot make an index when the file has multiple .debug_types sections"));
+
   if (stat (objfile->name, &st) < 0)
     perror_with_name (objfile->name);
 
@@ -16243,6 +16447,15 @@ show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
                    value);
 }
 
+static void
+show_check_physname (struct ui_file *file, int from_tty,
+                    struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file,
+                   _("Whether to check \"physname\" is %s.\n"),
+                   value);
+}
+
 void _initialize_dwarf2_read (void);
 
 void
@@ -16298,6 +16511,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.048991 seconds and 4 git commands to generate.