Replace some symbol accessor macros with functions.
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index 57a2e65246132cf8ce37143d5212ef9c8abae4fc..378c3b142aa1d1fa403544b4ef6be9812f0c6801 100644 (file)
@@ -55,7 +55,6 @@
 #include "typeprint.h"
 #include "jv-lang.h"
 #include "psympriv.h"
-#include "exceptions.h"
 #include <sys/stat.h>
 #include "completer.h"
 #include "vec.h"
@@ -716,10 +715,10 @@ struct type_unit_group
      and is deleted afterwards and not used again.  */
   VEC (sig_type_ptr) *tus;
 
-  /* The primary symtab.
+  /* The compunit symtab.
      Type units in a group needn't all be defined in the same source file,
-     so we create an essentially anonymous symtab as the primary symtab.  */
-  struct symtab *primary_symtab;
+     so we create an essentially anonymous symtab as the compunit symtab.  */
+  struct compunit_symtab *compunit_symtab;
 
   /* The data used to construct the hash key.  */
   struct stmt_list_hash hash;
@@ -1387,10 +1386,10 @@ static void add_partial_symbol (struct partial_die_info *,
 
 static void add_partial_namespace (struct partial_die_info *pdi,
                                   CORE_ADDR *lowpc, CORE_ADDR *highpc,
-                                  int need_pc, struct dwarf2_cu *cu);
+                                  int set_addrmap, struct dwarf2_cu *cu);
 
 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
-                               CORE_ADDR *highpc, int need_pc,
+                               CORE_ADDR *highpc, int set_addrmap,
                                struct dwarf2_cu *cu);
 
 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
@@ -1513,12 +1512,13 @@ static struct line_header *dwarf_decode_line_header (unsigned int offset,
 
 static void dwarf_decode_lines (struct line_header *, const char *,
                                struct dwarf2_cu *, struct partial_symtab *,
-                               int);
+                               CORE_ADDR);
 
-static void dwarf2_start_subfile (const char *, const char *, const char *);
+static void dwarf2_start_subfile (const char *, const char *);
 
-static void dwarf2_start_symtab (struct dwarf2_cu *,
-                                const char *, const char *, CORE_ADDR);
+static struct compunit_symtab *dwarf2_start_symtab (struct dwarf2_cu *,
+                                                   const char *, const char *,
+                                                   CORE_ADDR);
 
 static struct symbol *new_symbol (struct die_info *, struct type *,
                                  struct dwarf2_cu *);
@@ -1717,8 +1717,7 @@ static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
 
 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
 
-static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int,
-                                const char *, int);
+static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int, int);
 
 static int attr_form_is_block (const struct attribute *);
 
@@ -2497,7 +2496,7 @@ struct dwarf2_per_cu_quick_data
 
   /* The corresponding symbol table.  This is NULL if symbols for this
      CU have not yet been read.  */
-  struct symtab *symtab;
+  struct compunit_symtab *compunit_symtab;
 
   /* A temporary mark bit used when iterating over all CUs in
      expand_symtabs_matching.  */
@@ -2618,7 +2617,7 @@ dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
   back_to = make_cleanup (dwarf2_release_queue, NULL);
 
   if (dwarf2_per_objfile->using_index
-      ? per_cu->v.quick->symtab == NULL
+      ? per_cu->v.quick->compunit_symtab == NULL
       : (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin))
     {
       queue_comp_unit (per_cu, language_minimal);
@@ -2649,11 +2648,11 @@ dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
    the objfile from which this CU came.  Returns the resulting symbol
    table.  */
 
-static struct symtab *
+static struct compunit_symtab *
 dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
 {
   gdb_assert (dwarf2_per_objfile->using_index);
-  if (!per_cu->v.quick->symtab)
+  if (!per_cu->v.quick->compunit_symtab)
     {
       struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
       increment_reading_symtab ();
@@ -2661,7 +2660,8 @@ dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
       process_cu_includes ();
       do_cleanups (back_to);
     }
-  return per_cu->v.quick->symtab;
+
+  return per_cu->v.quick->compunit_symtab;
 }
 
 /* Return the CU/TU given its index.
@@ -2824,6 +2824,7 @@ create_signatured_type_table_from_index (struct objfile *objfile,
 static void
 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   const gdb_byte *iter, *end;
   struct obstack temp_obstack;
   struct addrmap *mutable_map;
@@ -2865,8 +2866,9 @@ create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
          continue;
        }
 
-      addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
-                        dw2_get_cutu (cu_index));
+      lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr);
+      hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr);
+      addrmap_set_empty (mutable_map, lo, hi - 1, dw2_get_cutu (cu_index));
     }
 
   objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
@@ -2918,18 +2920,16 @@ find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
     {
       /* NAME is already canonical.  Drop any qualifiers as .gdb_index does
         not contain any.  */
-      const char *paren = strchr (name, '(');
 
-      if (paren)
+      if (strchr (name, '(') != NULL)
        {
-         char *dup;
+         char *without_params = cp_remove_params (name);
 
-         dup = xmalloc (paren - name + 1);
-         memcpy (dup, name, paren - name);
-         dup[paren - name] = 0;
-
-         make_cleanup (xfree, dup);
-         name = dup;
+         if (without_params != NULL)
+           {
+             make_cleanup (xfree, without_params);
+             name = without_params;
+           }
        }
     }
 
@@ -3306,11 +3306,15 @@ dw2_get_real_path (struct objfile *objfile,
 static struct symtab *
 dw2_find_last_source_symtab (struct objfile *objfile)
 {
+  struct compunit_symtab *cust;
   int index;
 
   dw2_setup (objfile);
   index = dwarf2_per_objfile->n_comp_units - 1;
-  return dw2_instantiate_symtab (dw2_get_cutu (index));
+  cust = dw2_instantiate_symtab (dw2_get_cutu (index));
+  if (cust == NULL)
+    return NULL;
+  return compunit_primary_filetab (cust);
 }
 
 /* Traversal function for dw2_forget_cached_source_info.  */
@@ -3353,10 +3357,10 @@ dw2_map_expand_apply (struct objfile *objfile,
                      int (*callback) (struct symtab *, void *),
                      void *data)
 {
-  struct symtab *last_made = objfile->symtabs;
+  struct compunit_symtab *last_made = objfile->compunit_symtabs;
 
   /* Don't visit already-expanded CUs.  */
-  if (per_cu->v.quick->symtab)
+  if (per_cu->v.quick->compunit_symtab)
     return 0;
 
   /* This may expand more than one symtab, and we want to iterate over
@@ -3364,7 +3368,7 @@ dw2_map_expand_apply (struct objfile *objfile,
   dw2_instantiate_symtab (per_cu);
 
   return iterate_over_some_symtabs (name, real_path, callback, data,
-                                   objfile->symtabs, last_made);
+                                   objfile->compunit_symtabs, last_made);
 }
 
 /* Implementation of the map_symtabs_matching_filename method.  */
@@ -3390,7 +3394,7 @@ dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
       struct quick_file_names *file_data;
 
       /* We only need to look at symtabs not already expanded.  */
-      if (per_cu->v.quick->symtab)
+      if (per_cu->v.quick->compunit_symtab)
        continue;
 
       file_data = dw2_get_file_names (per_cu);
@@ -3537,7 +3541,7 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
       per_cu = dw2_get_cutu (cu_index);
 
       /* Skip if already read in.  */
-      if (per_cu->v.quick->symtab)
+      if (per_cu->v.quick->compunit_symtab)
        continue;
 
       /* Check static vs global.  */
@@ -3585,11 +3589,11 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
   return NULL;
 }
 
-static struct symtab *
+static struct compunit_symtab *
 dw2_lookup_symbol (struct objfile *objfile, int block_index,
                   const char *name, domain_enum domain)
 {
-  struct symtab *stab_best = NULL;
+  struct compunit_symtab *stab_best = NULL;
   struct mapped_index *index;
 
   dw2_setup (objfile);
@@ -3607,18 +3611,14 @@ dw2_lookup_symbol (struct objfile *objfile, int block_index,
       while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
        {
          struct symbol *sym = NULL;
-         struct symtab *stab = dw2_instantiate_symtab (per_cu);
+         struct compunit_symtab *stab = dw2_instantiate_symtab (per_cu);
+         const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
+         struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
 
          /* Some caution must be observed with overloaded functions
             and methods, since the index will not contain any overload
             information (but NAME might contain it).  */
-         if (stab->primary)
-           {
-             const struct blockvector *bv = BLOCKVECTOR (stab);
-             struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
-
-             sym = lookup_block_symbol (block, name, domain);
-           }
+         sym = block_lookup_symbol (block, name, domain);
 
          if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
            {
@@ -3647,7 +3647,7 @@ dw2_print_stats (struct objfile *objfile)
     {
       struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
 
-      if (!per_cu->v.quick->symtab)
+      if (!per_cu->v.quick->compunit_symtab)
        ++count;
     }
   printf_filtered (_("  Number of read CUs: %d\n"), total - count);
@@ -3744,7 +3744,7 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile,
       struct quick_file_names *file_data;
 
       /* We only need to look at symtabs not already expanded.  */
-      if (per_cu->v.quick->symtab)
+      if (per_cu->v.quick->compunit_symtab)
        continue;
 
       file_data = dw2_get_file_names (per_cu);
@@ -3824,7 +3824,7 @@ dw2_expand_symtabs_matching
          per_cu->v.quick->mark = 0;
 
          /* We only need to look at symtabs not already expanded.  */
-         if (per_cu->v.quick->symtab)
+         if (per_cu->v.quick->compunit_symtab)
            continue;
 
          file_data = dw2_get_file_names (per_cu);
@@ -3959,26 +3959,27 @@ dw2_expand_symtabs_matching
     }
 }
 
-/* A helper for dw2_find_pc_sect_symtab which finds the most specific
+/* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
    symtab.  */
 
-static struct symtab *
-recursively_find_pc_sect_symtab (struct symtab *symtab, CORE_ADDR pc)
+static struct compunit_symtab *
+recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust,
+                                         CORE_ADDR pc)
 {
   int i;
 
-  if (BLOCKVECTOR (symtab) != NULL
-      && blockvector_contains_pc (BLOCKVECTOR (symtab), pc))
-    return symtab;
+  if (COMPUNIT_BLOCKVECTOR (cust) != NULL
+      && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust), pc))
+    return cust;
 
-  if (symtab->includes == NULL)
+  if (cust->includes == NULL)
     return NULL;
 
-  for (i = 0; symtab->includes[i]; ++i)
+  for (i = 0; cust->includes[i]; ++i)
     {
-      struct symtab *s = symtab->includes[i];
+      struct compunit_symtab *s = cust->includes[i];
 
-      s = recursively_find_pc_sect_symtab (s, pc);
+      s = recursively_find_pc_sect_compunit_symtab (s, pc);
       if (s != NULL)
        return s;
     }
@@ -3986,15 +3987,15 @@ recursively_find_pc_sect_symtab (struct symtab *symtab, CORE_ADDR pc)
   return NULL;
 }
 
-static struct symtab *
-dw2_find_pc_sect_symtab (struct objfile *objfile,
-                        struct bound_minimal_symbol msymbol,
-                        CORE_ADDR pc,
-                        struct obj_section *section,
-                        int warn_if_readin)
+static struct compunit_symtab *
+dw2_find_pc_sect_compunit_symtab (struct objfile *objfile,
+                                 struct bound_minimal_symbol msymbol,
+                                 CORE_ADDR pc,
+                                 struct obj_section *section,
+                                 int warn_if_readin)
 {
   struct dwarf2_per_cu_data *data;
-  struct symtab *result;
+  struct compunit_symtab *result;
 
   dw2_setup (objfile);
 
@@ -4005,11 +4006,13 @@ dw2_find_pc_sect_symtab (struct objfile *objfile,
   if (!data)
     return NULL;
 
-  if (warn_if_readin && data->v.quick->symtab)
+  if (warn_if_readin && data->v.quick->compunit_symtab)
     warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
             paddress (get_objfile_arch (objfile), pc));
 
-  result = recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data), pc);
+  result
+    = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data),
+                                               pc);
   gdb_assert (result != NULL);
   return result;
 }
@@ -4034,7 +4037,7 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
     {
       struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
 
-      if (per_cu->v.quick->symtab)
+      if (per_cu->v.quick->compunit_symtab)
        {
          void **slot = htab_find_slot (visited, per_cu->v.quick->file_names,
                                        INSERT);
@@ -4051,7 +4054,7 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
       void **slot;
 
       /* We only need to look at symtabs not already expanded.  */
-      if (per_cu->v.quick->symtab)
+      if (per_cu->v.quick->compunit_symtab)
        continue;
 
       file_data = dw2_get_file_names (per_cu);
@@ -4102,7 +4105,7 @@ const struct quick_symbol_functions dwarf2_gdb_index_functions =
   dw2_expand_symtabs_with_fullname,
   dw2_map_matching_symbols,
   dw2_expand_symtabs_matching,
-  dw2_find_pc_sect_symtab,
+  dw2_find_pc_sect_compunit_symtab,
   dw2_map_symbol_filenames
 };
 
@@ -4420,7 +4423,7 @@ dwarf2_create_include_psymtab (const char *name, struct partial_symtab *pst,
   subpst->n_global_syms = 0;
   subpst->statics_offset = 0;
   subpst->n_static_syms = 0;
-  subpst->symtab = NULL;
+  subpst->compunit_symtab = NULL;
   subpst->read_symtab = pst->read_symtab;
   subpst->readin = 0;
 
@@ -4449,7 +4452,7 @@ dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
     return;  /* No linetable, so no includes.  */
 
   /* NOTE: pst->dirname is DW_AT_comp_dir (if present).  */
-  dwarf_decode_lines (lh, pst->dirname, cu, pst, 1);
+  dwarf_decode_lines (lh, pst->dirname, cu, pst, pst->textlow);
 
   free_line_header (lh);
 }
@@ -4758,7 +4761,7 @@ fill_in_sig_entry_from_dwo_entry (struct objfile *objfile,
   if (dwarf2_per_objfile->using_index)
     {
       gdb_assert (sig_entry->per_cu.v.quick != NULL);
-      gdb_assert (sig_entry->per_cu.v.quick->symtab == NULL);
+      gdb_assert (sig_entry->per_cu.v.quick->compunit_symtab == NULL);
     }
   else
       gdb_assert (sig_entry->per_cu.v.psymtab == NULL);
@@ -5848,6 +5851,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 {
   struct dwarf2_cu *cu = reader->cu;
   struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct dwarf2_per_cu_data *per_cu = cu->per_cu;
   struct attribute *attr;
   CORE_ADDR baseaddr;
@@ -5892,8 +5896,11 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
     /* Store the contiguous range if it is not empty; it can be empty for
        CUs with no code.  */
     addrmap_set_empty (objfile->psymtabs_addrmap,
-                      best_lowpc + baseaddr,
-                      best_highpc + baseaddr - 1, pst);
+                      gdbarch_adjust_dwarf2_addr (gdbarch,
+                                                  best_lowpc + baseaddr),
+                      gdbarch_adjust_dwarf2_addr (gdbarch,
+                                                  best_highpc + baseaddr) - 1,
+                      pst);
 
   /* Check if comp unit has_children.
      If so, read the rest of the partial symbols from this comp unit.
@@ -5924,8 +5931,8 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
          best_highpc = highpc;
        }
     }
-  pst->textlow = best_lowpc + baseaddr;
-  pst->texthigh = best_highpc + baseaddr;
+  pst->textlow = gdbarch_adjust_dwarf2_addr (gdbarch, best_lowpc + baseaddr);
+  pst->texthigh = gdbarch_adjust_dwarf2_addr (gdbarch, best_highpc + baseaddr);
 
   pst->n_global_syms = objfile->global_psymbols.next -
     (objfile->global_psymbols.list + pst->globals_offset);
@@ -6542,15 +6549,15 @@ create_all_comp_units (struct objfile *objfile)
 }
 
 /* Process all loaded DIEs for compilation unit CU, starting at
-   FIRST_DIE.  The caller should pass NEED_PC == 1 if the compilation
+   FIRST_DIE.  The caller should pass SET_ADDRMAP == 1 if the compilation
    unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
-   DW_AT_ranges).  If NEED_PC is set, then this function will set
-   *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
-   and record the covered ranges in the addrmap.  */
+   DW_AT_ranges).  See the comments of add_partial_subprogram on how
+   SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated.  */
 
 static void
 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
-                     CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
+                     CORE_ADDR *highpc, int set_addrmap,
+                     struct dwarf2_cu *cu)
 {
   struct partial_die_info *pdi;
 
@@ -6575,7 +6582,7 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
          switch (pdi->tag)
            {
            case DW_TAG_subprogram:
-             add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
+             add_partial_subprogram (pdi, lowpc, highpc, set_addrmap, cu);
              break;
            case DW_TAG_constant:
            case DW_TAG_variable:
@@ -6605,10 +6612,10 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
              add_partial_symbol (pdi, cu);
              break;
            case DW_TAG_namespace:
-             add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
+             add_partial_namespace (pdi, lowpc, highpc, set_addrmap, cu);
              break;
            case DW_TAG_module:
-             add_partial_module (pdi, lowpc, highpc, need_pc, cu);
+             add_partial_module (pdi, lowpc, highpc, set_addrmap, cu);
              break;
            case DW_TAG_imported_unit:
              {
@@ -6788,6 +6795,7 @@ static void
 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   CORE_ADDR addr = 0;
   const char *actual_name = NULL;
   CORE_ADDR baseaddr;
@@ -6805,31 +6813,30 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
   switch (pdi->tag)
     {
     case DW_TAG_subprogram:
+      addr = gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr);
       if (pdi->is_external || cu->language == language_ada)
        {
           /* brobecker/2007-12-26: Normally, only "external" DIEs are part
              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,
-            mst_text, objfile); */
+         /* prim_record_minimal_symbol (actual_name, addr, mst_text,
+            objfile); */
          add_psymbol_to_list (actual_name, strlen (actual_name),
                               built_actual_name != NULL,
                               VAR_DOMAIN, LOC_BLOCK,
                               &objfile->global_psymbols,
-                              0, pdi->lowpc + baseaddr,
-                              cu->language, objfile);
+                              0, addr, cu->language, objfile);
        }
       else
        {
-         /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
-            mst_file_text, objfile); */
+         /* prim_record_minimal_symbol (actual_name, addr, mst_file_text,
+            objfile); */
          add_psymbol_to_list (actual_name, strlen (actual_name),
                               built_actual_name != NULL,
                               VAR_DOMAIN, LOC_BLOCK,
                               &objfile->static_psymbols,
-                              0, pdi->lowpc + baseaddr,
-                              cu->language, objfile);
+                              0, addr, cu->language, objfile);
        }
       break;
     case DW_TAG_constant:
@@ -6975,7 +6982,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 static void
 add_partial_namespace (struct partial_die_info *pdi,
                       CORE_ADDR *lowpc, CORE_ADDR *highpc,
-                      int need_pc, struct dwarf2_cu *cu)
+                      int set_addrmap, struct dwarf2_cu *cu)
 {
   /* Add a symbol for the namespace.  */
 
@@ -6984,14 +6991,14 @@ add_partial_namespace (struct partial_die_info *pdi,
   /* Now scan partial symbols in that namespace.  */
 
   if (pdi->has_children)
-    scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
+    scan_partial_symbols (pdi->die_child, lowpc, highpc, set_addrmap, cu);
 }
 
 /* Read a partial die corresponding to a Fortran module.  */
 
 static void
 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
-                   CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
+                   CORE_ADDR *highpc, int set_addrmap, struct dwarf2_cu *cu)
 {
   /* Add a symbol for the namespace.  */
 
@@ -7000,23 +7007,25 @@ add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
   /* Now scan partial symbols in that module.  */
 
   if (pdi->has_children)
-    scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
+    scan_partial_symbols (pdi->die_child, lowpc, highpc, set_addrmap, cu);
 }
 
 /* Read a partial die corresponding to a subprogram and create a partial
    symbol for that subprogram.  When the CU language allows it, this
    routine also defines a partial symbol for each nested subprogram
-   that this subprogram contains.
+   that this subprogram contains.  If SET_ADDRMAP is true, record the
+   covered ranges in the addrmap.  Set *LOWPC and *HIGHPC to the lowest
+   and highest PC values found in PDI.
 
-   DIE my also be a lexical block, in which case we simply search
-   recursively for suprograms defined inside that lexical block.
+   PDI may also be a lexical block, in which case we simply search
+   recursively for subprograms defined inside that lexical block.
    Again, this is only performed when the CU language allows this
    type of definitions.  */
 
 static void
 add_partial_subprogram (struct partial_die_info *pdi,
                        CORE_ADDR *lowpc, CORE_ADDR *highpc,
-                       int need_pc, struct dwarf2_cu *cu)
+                       int set_addrmap, struct dwarf2_cu *cu)
 {
   if (pdi->tag == DW_TAG_subprogram)
     {
@@ -7026,16 +7035,21 @@ add_partial_subprogram (struct partial_die_info *pdi,
             *lowpc = pdi->lowpc;
           if (pdi->highpc > *highpc)
             *highpc = pdi->highpc;
-         if (need_pc)
+         if (set_addrmap)
            {
-             CORE_ADDR baseaddr;
              struct objfile *objfile = cu->objfile;
+             struct gdbarch *gdbarch = get_objfile_arch (objfile);
+             CORE_ADDR baseaddr;
+             CORE_ADDR highpc;
+             CORE_ADDR lowpc;
 
              baseaddr = ANOFFSET (objfile->section_offsets,
                                   SECT_OFF_TEXT (objfile));
-             addrmap_set_empty (objfile->psymtabs_addrmap,
-                                pdi->lowpc + baseaddr,
-                                pdi->highpc - 1 + baseaddr,
+             lowpc = gdbarch_adjust_dwarf2_addr (gdbarch,
+                                                 pdi->lowpc + baseaddr);
+             highpc = gdbarch_adjust_dwarf2_addr (gdbarch,
+                                                  pdi->highpc + baseaddr);
+             addrmap_set_empty (objfile->psymtabs_addrmap, lowpc, highpc - 1,
                                 cu->per_cu->v.psymtab);
            }
         }
@@ -7062,7 +7076,7 @@ add_partial_subprogram (struct partial_die_info *pdi,
          fixup_partial_die (pdi, cu);
          if (pdi->tag == DW_TAG_subprogram
              || pdi->tag == DW_TAG_lexical_block)
-           add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
+           add_partial_subprogram (pdi, lowpc, highpc, set_addrmap, cu);
          pdi = pdi->die_sibling;
        }
     }
@@ -7121,8 +7135,10 @@ peek_die_abbrev (const gdb_byte *info_ptr, unsigned int *bytes_read,
   abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number);
   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 %s"
+              " at offset 0x%x [in module %s]"),
+            abbrev_number, cu->per_cu->is_debug_types ? "TU" : "CU",
+            cu->header.offset.sect_off, bfd_get_filename (abfd));
     }
 
   return abbrev;
@@ -7445,7 +7461,7 @@ process_queue (void)
   for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
     {
       if (dwarf2_per_objfile->using_index
-         ? !item->per_cu->v.quick->symtab
+         ? !item->per_cu->v.quick->compunit_symtab
          : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
        {
          struct dwarf2_per_cu_data *per_cu = item->per_cu;
@@ -7730,8 +7746,9 @@ fixup_go_packaging (struct dwarf2_cu *cu)
                  if (strcmp (package_name, this_package_name) != 0)
                    complaint (&symfile_complaints,
                               _("Symtab %s has objects from two different Go packages: %s and %s"),
-                              (SYMBOL_SYMTAB (sym)
-                         ? symtab_to_filename_for_display (SYMBOL_SYMTAB (sym))
+                              (symbol_symtab (sym) != NULL
+                               ? symtab_to_filename_for_display
+                                   (symbol_symtab (sym))
                                : objfile_name (cu->objfile)),
                               this_package_name, package_name);
                  xfree (this_package_name);
@@ -7772,26 +7789,26 @@ fixup_go_packaging (struct dwarf2_cu *cu)
 /* Return the symtab for PER_CU.  This works properly regardless of
    whether we're using the index or psymtabs.  */
 
-static struct symtab *
-get_symtab (struct dwarf2_per_cu_data *per_cu)
+static struct compunit_symtab *
+get_compunit_symtab (struct dwarf2_per_cu_data *per_cu)
 {
   return (dwarf2_per_objfile->using_index
-         ? per_cu->v.quick->symtab
-         : per_cu->v.psymtab->symtab);
+         ? per_cu->v.quick->compunit_symtab
+         : per_cu->v.psymtab->compunit_symtab);
 }
 
 /* A helper function for computing the list of all symbol tables
    included by PER_CU.  */
 
 static void
-recursively_compute_inclusions (VEC (symtab_ptr) **result,
+recursively_compute_inclusions (VEC (compunit_symtab_ptr) **result,
                                htab_t all_children, htab_t all_type_symtabs,
                                struct dwarf2_per_cu_data *per_cu,
-                               struct symtab *immediate_parent)
+                               struct compunit_symtab *immediate_parent)
 {
   void **slot;
   int ix;
-  struct symtab *symtab;
+  struct compunit_symtab *cust;
   struct dwarf2_per_cu_data *iter;
 
   slot = htab_find_slot (all_children, per_cu, INSERT);
@@ -7803,27 +7820,27 @@ recursively_compute_inclusions (VEC (symtab_ptr) **result,
 
   *slot = per_cu;
   /* Only add a CU if it has a symbol table.  */
-  symtab = get_symtab (per_cu);
-  if (symtab != NULL)
+  cust = get_compunit_symtab (per_cu);
+  if (cust != NULL)
     {
       /* If this is a type unit only add its symbol table if we haven't
         seen it yet (type unit per_cu's can share symtabs).  */
       if (per_cu->is_debug_types)
        {
-         slot = htab_find_slot (all_type_symtabs, symtab, INSERT);
+         slot = htab_find_slot (all_type_symtabs, cust, INSERT);
          if (*slot == NULL)
            {
-             *slot = symtab;
-             VEC_safe_push (symtab_ptr, *result, symtab);
-             if (symtab->user == NULL)
-               symtab->user = immediate_parent;
+             *slot = cust;
+             VEC_safe_push (compunit_symtab_ptr, *result, cust);
+             if (cust->user == NULL)
+               cust->user = immediate_parent;
            }
        }
       else
        {
-         VEC_safe_push (symtab_ptr, *result, symtab);
-         if (symtab->user == NULL)
-           symtab->user = immediate_parent;
+         VEC_safe_push (compunit_symtab_ptr, *result, cust);
+         if (cust->user == NULL)
+           cust->user = immediate_parent;
        }
     }
 
@@ -7832,15 +7849,15 @@ recursively_compute_inclusions (VEC (symtab_ptr) **result,
        ++ix)
     {
       recursively_compute_inclusions (result, all_children,
-                                     all_type_symtabs, iter, symtab);
+                                     all_type_symtabs, iter, cust);
     }
 }
 
-/* Compute the symtab 'includes' fields for the symtab related to
+/* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
    PER_CU.  */
 
 static void
-compute_symtab_includes (struct dwarf2_per_cu_data *per_cu)
+compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu)
 {
   gdb_assert (! per_cu->is_debug_types);
 
@@ -7848,13 +7865,13 @@ compute_symtab_includes (struct dwarf2_per_cu_data *per_cu)
     {
       int ix, len;
       struct dwarf2_per_cu_data *per_cu_iter;
-      struct symtab *symtab_iter;
-      VEC (symtab_ptr) *result_symtabs = NULL;
+      struct compunit_symtab *compunit_symtab_iter;
+      VEC (compunit_symtab_ptr) *result_symtabs = NULL;
       htab_t all_children, all_type_symtabs;
-      struct symtab *symtab = get_symtab (per_cu);
+      struct compunit_symtab *cust = get_compunit_symtab (per_cu);
 
       /* If we don't have a symtab, we can just skip this case.  */
-      if (symtab == NULL)
+      if (cust == NULL)
        return;
 
       all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
@@ -7869,21 +7886,22 @@ compute_symtab_includes (struct dwarf2_per_cu_data *per_cu)
        {
          recursively_compute_inclusions (&result_symtabs, all_children,
                                          all_type_symtabs, per_cu_iter,
-                                         symtab);
+                                         cust);
        }
 
       /* Now we have a transitive closure of all the included symtabs.  */
-      len = VEC_length (symtab_ptr, result_symtabs);
-      symtab->includes
+      len = VEC_length (compunit_symtab_ptr, result_symtabs);
+      cust->includes
        = obstack_alloc (&dwarf2_per_objfile->objfile->objfile_obstack,
                         (len + 1) * sizeof (struct symtab *));
       for (ix = 0;
-          VEC_iterate (symtab_ptr, result_symtabs, ix, symtab_iter);
+          VEC_iterate (compunit_symtab_ptr, result_symtabs, ix,
+                       compunit_symtab_iter);
           ++ix)
-       symtab->includes[ix] = symtab_iter;
-      symtab->includes[len] = NULL;
+       cust->includes[ix] = compunit_symtab_iter;
+      cust->includes[len] = NULL;
 
-      VEC_free (symtab_ptr, result_symtabs);
+      VEC_free (compunit_symtab_ptr, result_symtabs);
       htab_delete (all_children);
       htab_delete (all_type_symtabs);
     }
@@ -7904,7 +7922,7 @@ process_cu_includes (void)
        ++ix)
     {
       if (! iter->is_debug_types)
-       compute_symtab_includes (iter);
+       compute_compunit_symtab_includes (iter);
     }
 
   VEC_free (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus);
@@ -7919,11 +7937,13 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
 {
   struct dwarf2_cu *cu = per_cu->cu;
   struct objfile *objfile = per_cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   CORE_ADDR lowpc, highpc;
-  struct symtab *symtab;
+  struct compunit_symtab *cust;
   struct cleanup *back_to, *delayed_list_cleanup;
   CORE_ADDR baseaddr;
   struct block *static_block;
+  CORE_ADDR addr;
 
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
@@ -7954,8 +7974,8 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
      it, by scanning the DIE's below the compilation unit.  */
   get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
 
-  static_block
-    = end_symtab_get_static_block (highpc + baseaddr, objfile, 0, 1);
+  addr = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr);
+  static_block = end_symtab_get_static_block (addr, 0, 1);
 
   /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
      Also, DW_AT_ranges may record ranges not belonging to any child DIEs
@@ -7964,18 +7984,19 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
      this comp unit.  */
   dwarf2_record_block_ranges (cu->dies, static_block, baseaddr, cu);
 
-  symtab = end_symtab_from_static_block (static_block, objfile,
-                                        SECT_OFF_TEXT (objfile), 0);
+  cust = end_symtab_from_static_block (static_block,
+                                      SECT_OFF_TEXT (objfile), 0);
 
-  if (symtab != NULL)
+  if (cust != NULL)
     {
       int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
 
       /* Set symtab language to language from DW_AT_language.  If the
         compilation is from a C file generated by language preprocessors, do
         not set the language if it was already deduced by start_subfile.  */
-      if (!(cu->language == language_c && symtab->language != language_c))
-       symtab->language = cu->language;
+      if (!(cu->language == language_c
+           && COMPUNIT_FILETABS (cust)->language != language_c))
+       COMPUNIT_FILETABS (cust)->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
@@ -7990,20 +8011,20 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
         options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
         */ 
       if (cu->has_loclist && gcc_4_minor >= 5)
-       symtab->locations_valid = 1;
+       cust->locations_valid = 1;
 
       if (gcc_4_minor >= 5)
-       symtab->epilogue_unwind_valid = 1;
+       cust->epilogue_unwind_valid = 1;
 
-      symtab->call_site_htab = cu->call_site_htab;
+      cust->call_site_htab = cu->call_site_htab;
     }
 
   if (dwarf2_per_objfile->using_index)
-    per_cu->v.quick->symtab = symtab;
+    per_cu->v.quick->compunit_symtab = cust;
   else
     {
       struct partial_symtab *pst = per_cu->v.psymtab;
-      pst->symtab = symtab;
+      pst->compunit_symtab = cust;
       pst->readin = 1;
     }
 
@@ -8022,7 +8043,7 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu,
 {
   struct dwarf2_cu *cu = per_cu->cu;
   struct objfile *objfile = per_cu->objfile;
-  struct symtab *symtab;
+  struct compunit_symtab *cust;
   struct cleanup *back_to, *delayed_list_cleanup;
   struct signatured_type *sig_type;
 
@@ -8055,34 +8076,34 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu,
      If this is the first TU to use this symtab, complete the construction
      of it with end_expandable_symtab.  Otherwise, complete the addition of
      this TU's symbols to the existing symtab.  */
-  if (sig_type->type_unit_group->primary_symtab == NULL)
+  if (sig_type->type_unit_group->compunit_symtab == NULL)
     {
-      symtab = end_expandable_symtab (0, objfile, SECT_OFF_TEXT (objfile));
-      sig_type->type_unit_group->primary_symtab = symtab;
+      cust = end_expandable_symtab (0, SECT_OFF_TEXT (objfile));
+      sig_type->type_unit_group->compunit_symtab = cust;
 
-      if (symtab != NULL)
+      if (cust != NULL)
        {
          /* 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;
+         if (!(cu->language == language_c
+               && COMPUNIT_FILETABS (cust)->language != language_c))
+           COMPUNIT_FILETABS (cust)->language = cu->language;
        }
     }
   else
     {
-      augment_type_symtab (objfile,
-                          sig_type->type_unit_group->primary_symtab);
-      symtab = sig_type->type_unit_group->primary_symtab;
+      augment_type_symtab ();
+      cust = sig_type->type_unit_group->compunit_symtab;
     }
 
   if (dwarf2_per_objfile->using_index)
-    per_cu->v.quick->symtab = symtab;
+    per_cu->v.quick->compunit_symtab = cust;
   else
     {
       struct partial_symtab *pst = per_cu->v.psymtab;
-      pst->symtab = symtab;
+      pst->compunit_symtab = cust;
       pst->readin = 1;
     }
 
@@ -8966,12 +8987,12 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
 
 /* Handle DW_AT_stmt_list for a compilation unit.
    DIE is the DW_TAG_compile_unit die for CU.
-   COMP_DIR is the compilation directory.
-   WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed.  */
+   COMP_DIR is the compilation directory.  LOWPC is passed to
+   dwarf_decode_lines.  See dwarf_decode_lines comments about it.  */
 
 static void
 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
-                       const char *comp_dir) /* ARI: editCase function */
+                       const char *comp_dir, CORE_ADDR lowpc) /* ARI: editCase function */
 {
   struct attribute *attr;
 
@@ -8988,7 +9009,7 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
        {
          cu->line_header = line_header;
          make_cleanup (free_cu_line_header, cu);
-         dwarf_decode_lines (line_header, comp_dir, cu, NULL, 1);
+         dwarf_decode_lines (line_header, comp_dir, cu, NULL, lowpc);
        }
     }
 }
@@ -8999,6 +9020,7 @@ static void
 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct cleanup *back_to = make_cleanup (null_cleanup, 0);
   CORE_ADDR lowpc = ((CORE_ADDR) -1);
   CORE_ADDR highpc = ((CORE_ADDR) 0);
@@ -9017,8 +9039,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
      from finish_block.  */
   if (lowpc == ((CORE_ADDR) -1))
     lowpc = highpc;
-  lowpc += baseaddr;
-  highpc += baseaddr;
+  lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
 
   find_file_and_directory (die, cu, &name, &comp_dir);
 
@@ -9039,7 +9060,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *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.  */
-  handle_DW_AT_stmt_list (die, cu, comp_dir);
+  handle_DW_AT_stmt_list (die, cu, comp_dir, lowpc);
 
   /* Process all dies in compilation unit.  */
   if (die->child != NULL)
@@ -9063,7 +9084,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
        complaint (&symfile_complaints,
                   _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
 
-      dwarf_decode_macros (cu, DW_UNSND (attr), comp_dir, 1);
+      dwarf_decode_macros (cu, DW_UNSND (attr), 1);
     }
   else
     {
@@ -9072,7 +9093,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
        {
          unsigned int macro_offset = DW_UNSND (attr);
 
-         dwarf_decode_macros (cu, macro_offset, comp_dir, 0);
+         dwarf_decode_macros (cu, macro_offset, 0);
        }
     }
 
@@ -9112,7 +9133,7 @@ setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
      do it again, we could fake it and just recreate the part we need
      (file name,index -> symtab mapping).  If data shows this optimization
      is useful we can do it then.  */
-  first_time = tu_group->primary_symtab == NULL;
+  first_time = tu_group->compunit_symtab == NULL;
 
   /* We have to handle the case of both a missing DW_AT_stmt_list or bad
      debug info.  */
@@ -9129,9 +9150,9 @@ setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
       else
        {
          gdb_assert (tu_group->symtabs == NULL);
-         restart_symtab (0);
+         restart_symtab (tu_group->compunit_symtab, "", 0);
        }
-      /* Note: The primary symtab will get allocated at the end.  */
+      /* Note: The compunit symtab will get allocated at the end.  */
       return;
     }
 
@@ -9140,7 +9161,7 @@ setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
 
   if (first_time)
     {
-      dwarf2_start_symtab (cu, "", NULL, 0);
+      struct compunit_symtab *cust = dwarf2_start_symtab (cu, "", NULL, 0);
 
       tu_group->num_symtabs = lh->num_file_names;
       tu_group->symtabs = XNEWVEC (struct symtab *, lh->num_file_names);
@@ -9152,19 +9173,16 @@ setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
 
          if (fe->dir_index)
            dir = lh->include_dirs[fe->dir_index - 1];
-         dwarf2_start_subfile (fe->name, dir, NULL);
-
-         /* Note: We don't have to watch for the main subfile here, type units
-            don't have DW_AT_name.  */
+         dwarf2_start_subfile (fe->name, dir);
 
          if (current_subfile->symtab == NULL)
            {
              /* NOTE: start_subfile will recognize when it's been passed
                 a file it has already seen.  So we can't assume there's a
-                simple mapping from lh->file_names to subfiles,
+                simple mapping from lh->file_names to subfiles, plus
                 lh->file_names may contain dups.  */
-             current_subfile->symtab = allocate_symtab (current_subfile->name,
-                                                        objfile);
+             current_subfile->symtab
+               = allocate_symtab (cust, current_subfile->name);
            }
 
          fe->symtab = current_subfile->symtab;
@@ -9173,7 +9191,7 @@ setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
     }
   else
     {
-      restart_symtab (0);
+      restart_symtab (tu_group->compunit_symtab, "", 0);
 
       for (i = 0; i < lh->num_file_names; ++i)
        {
@@ -11129,6 +11147,7 @@ static void
 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct context_stack *new;
   CORE_ADDR lowpc;
   CORE_ADDR highpc;
@@ -11181,8 +11200,8 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       return;
     }
 
-  lowpc += baseaddr;
-  highpc += baseaddr;
+  lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
+  highpc = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr);
 
   /* If we have any template arguments, then we must allocate a
      different sort of symbol.  */
@@ -11258,7 +11277,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   new = pop_context ();
   /* Make a block for the local symbols within.  */
   block = finish_block (new->name, &local_symbols, new->old_blocks,
-                        lowpc, highpc, objfile);
+                        lowpc, highpc);
 
   /* For C++, set the block's scope.  */
   if ((cu->language == language_cplus || cu->language == language_fortran)
@@ -11269,6 +11288,8 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   /* If we have address ranges, record them.  */
   dwarf2_record_block_ranges (die, block, baseaddr, cu);
 
+  gdbarch_make_symbol_special (gdbarch, new->name, objfile);
+
   /* Attach template arguments to function.  */
   if (! VEC_empty (symbolp, template_args))
     {
@@ -11305,6 +11326,7 @@ static void
 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct context_stack *new;
   CORE_ADDR lowpc, highpc;
   struct die_info *child_die;
@@ -11319,8 +11341,8 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
      describe ranges.  */
   if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
     return;
-  lowpc += baseaddr;
-  highpc += baseaddr;
+  lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
+  highpc = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr);
 
   push_context (0, lowpc);
   if (die->child != NULL)
@@ -11338,7 +11360,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
     {
       struct block *block
         = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
-                        highpc, objfile);
+                        highpc);
 
       /* Note that recording ranges after traversing children, as we
          do here, means that recording a parent's ranges entails
@@ -11382,6 +11404,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
       return;
     }
   pc = attr_value_as_address (attr) + baseaddr;
+  pc = gdbarch_adjust_dwarf2_addr (gdbarch, pc);
 
   if (cu->call_site_htab == NULL)
     cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
@@ -11530,7 +11553,10 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
                         "low pc, for referencing DIE 0x%x [in module %s]"),
                       die->offset.sect_off, objfile_name (objfile));
          else
-           SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr);
+           {
+             lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
+             SET_FIELD_PHYSADDR (call_site->target, lowpc);
+           }
        }
     }
   else
@@ -11658,6 +11684,7 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
                    struct partial_symtab *ranges_pst)
 {
   struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct comp_unit_head *cu_header = &cu->header;
   bfd *obfd = objfile->obfd;
   unsigned int addr_size = cu_header->addr_size;
@@ -11765,10 +11792,17 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
        }
 
       if (ranges_pst != NULL)
-       addrmap_set_empty (objfile->psymtabs_addrmap,
-                          range_beginning + baseaddr,
-                          range_end - 1 + baseaddr,
-                          ranges_pst);
+       {
+         CORE_ADDR lowpc;
+         CORE_ADDR highpc;
+
+         lowpc = gdbarch_adjust_dwarf2_addr (gdbarch,
+                                             range_beginning + baseaddr);
+         highpc = gdbarch_adjust_dwarf2_addr (gdbarch,
+                                              range_end + baseaddr);
+         addrmap_set_empty (objfile->psymtabs_addrmap, lowpc, highpc - 1,
+                            ranges_pst);
+       }
 
       /* FIXME: This is recording everything as a low-high
         segment of consecutive addresses.  We should have a
@@ -11982,6 +12016,7 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
                             CORE_ADDR baseaddr, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct attribute *attr;
   struct attribute *attr_high;
 
@@ -11997,7 +12032,9 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
          if (cu->header.version >= 4 && attr_form_is_constant (attr_high))
            high += low;
 
-          record_block_range (block, baseaddr + low, baseaddr + high - 1);
+         low = gdbarch_adjust_dwarf2_addr (gdbarch, low + baseaddr);
+         high = gdbarch_adjust_dwarf2_addr (gdbarch, high + baseaddr);
+         record_block_range (block, low, high - 1);
         }
     }
 
@@ -12101,6 +12138,8 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
                  continue;
                }
 
+             start = gdbarch_adjust_dwarf2_addr (gdbarch, start);
+             end = gdbarch_adjust_dwarf2_addr (gdbarch, end);
               record_block_range (block, start, end - 1);
             }
         }
@@ -12964,7 +13003,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
     }
   else
     {
-      TYPE_CODE (type) = TYPE_CODE_CLASS;
+      TYPE_CODE (type) = TYPE_CODE_STRUCT;
     }
 
   if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
@@ -13015,7 +13054,7 @@ static void
 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
-  struct die_info *child_die = die->child;
+  struct die_info *child_die;
   struct type *type;
 
   type = get_die_type (die, cu);
@@ -13025,7 +13064,6 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
   if (die->child != NULL && ! die_is_declaration (die, cu))
     {
       struct field_info fi;
-      struct die_info *child_die;
       VEC (symbolp) *template_args = NULL;
       struct cleanup *back_to = make_cleanup (null_cleanup, 0);
 
@@ -13196,6 +13234,8 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
      current die is a declaration.  Normally, of course, a declaration
      won't have any children at all.  */
 
+  child_die = die->child;
+
   while (child_die != NULL && child_die->tag)
     {
       if (child_die->tag == DW_TAG_member
@@ -13229,7 +13269,7 @@ update_enumeration_type_from_children (struct die_info *die,
                                       struct dwarf2_cu *cu)
 {
   struct obstack obstack;
-  struct die_info *child_die = die->child;
+  struct die_info *child_die;
   int unsigned_enum = 1;
   int flag_enum = 1;
   ULONGEST mask = 0;
@@ -13238,13 +13278,16 @@ update_enumeration_type_from_children (struct die_info *die,
   obstack_init (&obstack);
   old_chain = make_cleanup_obstack_free (&obstack);
 
-  while (child_die != NULL && child_die->tag)
+  for (child_die = die->child;
+       child_die != NULL && child_die->tag;
+       child_die = sibling_die (child_die))
     {
       struct attribute *attr;
       LONGEST value;
       const gdb_byte *bytes;
       struct dwarf2_locexpr_baton *baton;
       const char *name;
+
       if (child_die->tag != DW_TAG_enumerator)
        continue;
 
@@ -13272,7 +13315,6 @@ update_enumeration_type_from_children (struct die_info *die,
         a flag type, no need to look at the rest of the enumerates.  */
       if (!unsigned_enum && !flag_enum)
        break;
-      child_die = sibling_die (child_die);
     }
 
   if (unsigned_enum)
@@ -15924,6 +15966,8 @@ read_attribute_value (const struct die_reader_specs *reader,
                      const gdb_byte *info_ptr)
 {
   struct dwarf2_cu *cu = reader->cu;
+  struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   bfd *abfd = reader->abfd;
   struct comp_unit_head *cu_header = &cu->header;
   unsigned int bytes_read;
@@ -15946,6 +15990,7 @@ read_attribute_value (const struct die_reader_specs *reader,
       break;
     case DW_FORM_addr:
       DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
+      DW_ADDR (attr) = gdbarch_adjust_dwarf2_addr (gdbarch, DW_ADDR (attr));
       info_ptr += bytes_read;
       break;
     case DW_FORM_block2:
@@ -16700,11 +16745,14 @@ set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
     {
     case DW_LANG_C89:
     case DW_LANG_C99:
+    case DW_LANG_C11:
     case DW_LANG_C:
     case DW_LANG_UPC:
       cu->language = language_c;
       break;
     case DW_LANG_C_plus_plus:
+    case DW_LANG_C_plus_plus_11:
+    case DW_LANG_C_plus_plus_14:
       cu->language = language_cplus;
       break;
     case DW_LANG_D:
@@ -17174,6 +17222,53 @@ noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
   return;
 }
 
+/* Return non-zero if we should add LINE to the line number table.
+   LINE is the line to add, LAST_LINE is the last line that was added,
+   LAST_SUBFILE is the subfile for LAST_LINE.
+   LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
+   had a non-zero discriminator.
+
+   We have to be careful in the presence of discriminators.
+   E.g., for this line:
+
+     for (i = 0; i < 100000; i++);
+
+   clang can emit four line number entries for that one line,
+   each with a different discriminator.
+   See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
+
+   However, we want gdb to coalesce all four entries into one.
+   Otherwise the user could stepi into the middle of the line and
+   gdb would get confused about whether the pc really was in the
+   middle of the line.
+
+   Things are further complicated by the fact that two consecutive
+   line number entries for the same line is a heuristic used by gcc
+   to denote the end of the prologue.  So we can't just discard duplicate
+   entries, we have to be selective about it.  The heuristic we use is
+   that we only collapse consecutive entries for the same line if at least
+   one of those entries has a non-zero discriminator.  PR 17276.
+
+   Note: Addresses in the line number state machine can never go backwards
+   within one sequence, thus this coalescing is ok.  */
+
+static int
+dwarf_record_line_p (unsigned int line, unsigned int last_line,
+                    int line_has_non_zero_discriminator,
+                    struct subfile *last_subfile)
+{
+  if (current_subfile != last_subfile)
+    return 1;
+  if (line != last_line)
+    return 1;
+  /* Same line for the same file that we've seen already.
+     As a last check, for pr 17276, only record the line if the line
+     has never had a non-zero discriminator.  */
+  if (!line_has_non_zero_discriminator)
+    return 1;
+  return 0;
+}
+
 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
    in the line table of subfile SUBFILE.  */
 
@@ -17184,7 +17279,7 @@ dwarf_record_line (struct gdbarch *gdbarch, struct subfile *subfile,
 {
   CORE_ADDR addr = gdbarch_addr_bits_remove (gdbarch, address);
 
-  (*p_record_line) (current_subfile, line, addr);
+  (*p_record_line) (subfile, line, addr);
 }
 
 /* Subroutine of dwarf_decode_lines_1 to simplify it.
@@ -17204,8 +17299,8 @@ dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile,
    Process the line number information in LH.  */
 
 static void
-dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
-                     struct dwarf2_cu *cu, const int decode_for_pst_p)
+dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
+                     const int decode_for_pst_p, CORE_ADDR lowpc)
 {
   const gdb_byte *line_ptr, *extended_end;
   const gdb_byte *line_end;
@@ -17227,13 +17322,23 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
   /* Read the statement sequences until there's nothing left.  */
   while (line_ptr < line_end)
     {
-      /* state machine registers  */
-      CORE_ADDR address = 0;
+      /* State machine registers.  Call `gdbarch_adjust_dwarf2_line'
+         on the initial 0 address as if there was a line entry for it
+         so that the backend has a chance to adjust it and also record
+         it in case it needs it.  This is currently used by MIPS code,
+         cf. `mips_adjust_dwarf2_line'.  */
+      CORE_ADDR address = gdbarch_adjust_dwarf2_line (gdbarch, 0, 0);
       unsigned int file = 1;
       unsigned int line = 1;
       int is_stmt = lh->default_is_stmt;
       int end_sequence = 0;
       unsigned char op_index = 0;
+      unsigned int discriminator = 0;
+      /* The last line number that was recorded, used to coalesce
+        consecutive entries for the same line.  This can happen, for
+        example, when discriminators are present.  PR 17276.  */
+      unsigned int last_line = 0;
+      int line_has_non_zero_discriminator = 0;
 
       if (!decode_for_pst_p && lh->num_file_names >= file)
        {
@@ -17247,7 +17352,7 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
           if (fe->dir_index)
             dir = lh->include_dirs[fe->dir_index - 1];
 
-         dwarf2_start_subfile (fe->name, dir, comp_dir);
+         dwarf2_start_subfile (fe->name, dir);
        }
 
       /* Decode the table.  */
@@ -17265,14 +17370,20 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
            {
              /* Special opcode.  */
              unsigned char adj_opcode;
+             CORE_ADDR addr_adj;
+             int line_delta;
 
              adj_opcode = op_code - lh->opcode_base;
-             address += (((op_index + (adj_opcode / lh->line_range))
+             addr_adj = (((op_index + (adj_opcode / lh->line_range))
                           / lh->maximum_ops_per_instruction)
                          * lh->minimum_instruction_length);
+             address += gdbarch_adjust_dwarf2_line (gdbarch, addr_adj, 1);
              op_index = ((op_index + (adj_opcode / lh->line_range))
                          % lh->maximum_ops_per_instruction);
-             line += lh->line_base + (adj_opcode % lh->line_range);
+             line_delta = lh->line_base + (adj_opcode % lh->line_range);
+             line += line_delta;
+             if (line_delta != 0)
+               line_has_non_zero_discriminator = discriminator != 0;
              if (lh->num_file_names < file || file == 0)
                dwarf2_debug_line_missing_file_complaint ();
              /* For now we ignore lines not starting on an
@@ -17286,13 +17397,19 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
                        {
                          dwarf_finish_line (gdbarch, last_subfile,
                                             address, p_record_line);
-                         last_subfile = current_subfile;
                        }
-                     /* Append row to matrix using current values.  */
-                     dwarf_record_line (gdbarch, current_subfile,
-                                        line, address, p_record_line);
+                     if (dwarf_record_line_p (line, last_line,
+                                              line_has_non_zero_discriminator,
+                                              last_subfile))
+                       {
+                         dwarf_record_line (gdbarch, current_subfile,
+                                            line, address, p_record_line);
+                       }
+                     last_subfile = current_subfile;
+                     last_line = line;
                    }
                }
+             discriminator = 0;
            }
          else switch (op_code)
            {
@@ -17312,7 +17429,12 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
                case DW_LNE_set_address:
                  address = read_address (abfd, line_ptr, cu, &bytes_read);
 
-                 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
+                 /* If address < lowpc then it's not a usable value, it's
+                    outside the pc range of the CU.  However, we restrict
+                    the test to only address values of zero to preserve
+                    GDB's previous behaviour which is to handle the specific
+                    case of a function being GC'd by the linker.  */
+                 if (address == 0 && address < lowpc)
                    {
                      /* This line table is for a function which has been
                         GCd by the linker.  Ignore it.  PR gdb/12528 */
@@ -17332,6 +17454,7 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
                  op_index = 0;
                  line_ptr += bytes_read;
                  address += baseaddr;
+                 address = gdbarch_adjust_dwarf2_line (gdbarch, address, 0);
                  break;
                case DW_LNE_define_file:
                   {
@@ -17355,8 +17478,14 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
                  break;
                case DW_LNE_set_discriminator:
                  /* The discriminator is not interesting to the debugger;
-                    just ignore it.  */
-                 line_ptr = extended_end;
+                    just ignore it.  We still need to check its value though:
+                    if there are consecutive entries for the same
+                    (non-prologue) line we want to coalesce them.
+                    PR 17276.  */
+                 discriminator = read_unsigned_leb128 (abfd, line_ptr,
+                                                       &bytes_read);
+                 line_has_non_zero_discriminator |= discriminator != 0;
+                 line_ptr += bytes_read;
                  break;
                default:
                  complaint (&symfile_complaints,
@@ -17385,29 +17514,45 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
                        {
                          dwarf_finish_line (gdbarch, last_subfile,
                                             address, p_record_line);
-                         last_subfile = current_subfile;
                        }
-                     dwarf_record_line (gdbarch, current_subfile,
-                                        line, address, p_record_line);
+                     if (dwarf_record_line_p (line, last_line,
+                                              line_has_non_zero_discriminator,
+                                              last_subfile))
+                       {
+                         dwarf_record_line (gdbarch, current_subfile,
+                                            line, address, p_record_line);
+                       }
+                     last_subfile = current_subfile;
+                     last_line = line;
                    }
                }
+             discriminator = 0;
              break;
            case DW_LNS_advance_pc:
              {
                CORE_ADDR adjust
                  = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+               CORE_ADDR addr_adj;
 
-               address += (((op_index + adjust)
+               addr_adj = (((op_index + adjust)
                             / lh->maximum_ops_per_instruction)
                            * lh->minimum_instruction_length);
+               address += gdbarch_adjust_dwarf2_line (gdbarch, addr_adj, 1);
                op_index = ((op_index + adjust)
                            % lh->maximum_ops_per_instruction);
                line_ptr += bytes_read;
              }
              break;
            case DW_LNS_advance_line:
-             line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
-             line_ptr += bytes_read;
+             {
+               int line_delta
+                 = read_signed_leb128 (abfd, line_ptr, &bytes_read);
+
+               line += line_delta;
+               if (line_delta != 0)
+                 line_has_non_zero_discriminator = discriminator != 0;
+               line_ptr += bytes_read;
+             }
              break;
            case DW_LNS_set_file:
               {
@@ -17429,7 +17574,8 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
                     if (!decode_for_pst_p)
                       {
                         last_subfile = current_subfile;
-                        dwarf2_start_subfile (fe->name, dir, comp_dir);
+                       line_has_non_zero_discriminator = discriminator != 0;
+                        dwarf2_start_subfile (fe->name, dir);
                       }
                   }
               }
@@ -17451,18 +17597,25 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
            case DW_LNS_const_add_pc:
              {
                CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
+               CORE_ADDR addr_adj;
 
-               address += (((op_index + adjust)
+               addr_adj = (((op_index + adjust)
                             / lh->maximum_ops_per_instruction)
                            * lh->minimum_instruction_length);
+               address += gdbarch_adjust_dwarf2_line (gdbarch, addr_adj, 1);
                op_index = ((op_index + adjust)
                            % lh->maximum_ops_per_instruction);
              }
              break;
            case DW_LNS_fixed_advance_pc:
-             address += read_2_bytes (abfd, line_ptr);
-             op_index = 0;
-             line_ptr += 2;
+             {
+               CORE_ADDR addr_adj;
+
+               addr_adj = read_2_bytes (abfd, line_ptr);
+               address += gdbarch_adjust_dwarf2_line (gdbarch, addr_adj, 1);
+               op_index = 0;
+               line_ptr += 2;
+             }
              break;
            default:
              {
@@ -17511,19 +17664,19 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
    as the corresponding symtab.  Since COMP_DIR is not used in the name of the
    symtab we don't use it in the name of the psymtabs we create.
    E.g. expand_line_sal requires this when finding psymtabs to expand.
-   A good testcase for this is mb-inline.exp.  */
+   A good testcase for this is mb-inline.exp.
+
+   LOWPC is the lowest address in CU (or 0 if not known).  */
 
 static void
 dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
                    struct dwarf2_cu *cu, struct partial_symtab *pst,
-                   int want_line_info)
+                   CORE_ADDR lowpc)
 {
   struct objfile *objfile = cu->objfile;
   const int decode_for_pst_p = (pst != NULL);
-  struct subfile *first_subfile = current_subfile;
 
-  if (want_line_info)
-    dwarf_decode_lines_1 (lh, comp_dir, cu, decode_for_pst_p);
+  dwarf_decode_lines_1 (lh, cu, decode_for_pst_p, lowpc);
 
   if (decode_for_pst_p)
     {
@@ -17545,6 +17698,7 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
       /* Make sure a symtab is created for every file, even files
         which contain only variables (i.e. no code with associated
         line numbers).  */
+      struct compunit_symtab *cust = buildsym_compunit_symtab ();
       int i;
 
       for (i = 0; i < lh->num_file_names; i++)
@@ -17555,17 +17709,13 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
          fe = &lh->file_names[i];
          if (fe->dir_index)
            dir = lh->include_dirs[fe->dir_index - 1];
-         dwarf2_start_subfile (fe->name, dir, comp_dir);
-
-         /* Skip the main file; we don't need it, and it must be
-            allocated last, so that it will show up before the
-            non-primary symtabs in the objfile's symtab list.  */
-         if (current_subfile == first_subfile)
-           continue;
+         dwarf2_start_subfile (fe->name, dir);
 
          if (current_subfile->symtab == NULL)
-           current_subfile->symtab = allocate_symtab (current_subfile->name,
-                                                      objfile);
+           {
+             current_subfile->symtab
+               = allocate_symtab (cust, current_subfile->name);
+           }
          fe->symtab = current_subfile->symtab;
        }
     }
@@ -17573,8 +17723,7 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
 
 /* Start a subfile for DWARF.  FILENAME is the name of the file and
    DIRNAME the name of the source directory which contains FILENAME
-   or NULL if not known.  COMP_DIR is the compilation directory for the
-   linetable's compilation unit or NULL if not known.
+   or NULL if not known.
    This routine tries to keep line numbers from identical absolute and
    relative file names in a common subfile.
 
@@ -17583,7 +17732,7 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
    of /srcdir/list0.c yields the following debugging information for list0.c:
 
    DW_AT_name:          /srcdir/list0.c
-   DW_AT_comp_dir:              /compdir
+   DW_AT_comp_dir:      /compdir
    files.files[0].name: list0.h
    files.files[0].dir:  /srcdir
    files.files[1].name: list0.c
@@ -17596,15 +17745,11 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
    subfile's name.  */
 
 static void
-dwarf2_start_subfile (const char *filename, const char *dirname,
-                     const char *comp_dir)
+dwarf2_start_subfile (const char *filename, const char *dirname)
 {
   char *copy = NULL;
 
-  /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
-     `start_symtab' will always pass the contents of DW_AT_comp_dir as
-     second argument to start_subfile.  To be consistent, we do the
-     same here.  In order not to lose the line information directory,
+  /* In order not to lose the line information directory,
      we concatenate it to the filename when it makes sense.
      Note that the Dwarf3 standard says (speaking of filenames in line
      information): ``The directory index is ignored for file names
@@ -17617,7 +17762,7 @@ dwarf2_start_subfile (const char *filename, const char *dirname,
       filename = copy;
     }
 
-  start_subfile (filename, comp_dir);
+  start_subfile (filename);
 
   if (copy != NULL)
     xfree (copy);
@@ -17626,11 +17771,13 @@ dwarf2_start_subfile (const char *filename, const char *dirname,
 /* Start a symtab for DWARF.
    NAME, COMP_DIR, LOW_PC are passed to start_symtab.  */
 
-static void
+static struct compunit_symtab *
 dwarf2_start_symtab (struct dwarf2_cu *cu,
                     const char *name, const char *comp_dir, CORE_ADDR low_pc)
 {
-  start_symtab (name, comp_dir, low_pc);
+  struct compunit_symtab *cust
+    = start_symtab (cu->objfile, name, comp_dir, low_pc);
+
   record_debugformat ("DWARF 2");
   record_producer (cu->producer);
 
@@ -17638,6 +17785,8 @@ dwarf2_start_symtab (struct dwarf2_cu *cu,
   processing_gcc_compilation = 2;
 
   cu->processing_has_namespace_info = 0;
+
+  return cust;
 }
 
 static void
@@ -17718,6 +17867,7 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
                 struct symbol *space)
 {
   struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct symbol *sym = NULL;
   const char *name;
   struct attribute *attr = NULL;
@@ -17786,7 +17936,7 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
              struct file_entry *fe;
 
              fe = &cu->line_header->file_names[file_index - 1];
-             SYMBOL_SYMTAB (sym) = fe->symtab;
+             symbol_set_symtab (sym, fe->symtab);
            }
        }
 
@@ -17795,8 +17945,13 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
        case DW_TAG_label:
          attr = dwarf2_attr (die, DW_AT_low_pc, cu);
          if (attr)
-           SYMBOL_VALUE_ADDRESS (sym)
-             = attr_value_as_address (attr) + baseaddr;
+           {
+             CORE_ADDR addr;
+
+             addr = attr_value_as_address (attr);
+             addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr + baseaddr);
+             SYMBOL_VALUE_ADDRESS (sym) = addr;
+           }
          SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
          SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
          SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;
@@ -18941,7 +19096,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
          /* GCJ will output '<init>' for Java constructor names.
             For this special case, return the name of the parent class.  */
 
-         /* GCJ may output suprogram DIEs with AT_specification set.
+         /* GCJ may output subprogram DIEs with AT_specification set.
             If so, use the name of the specified DIE.  */
          spec_die = die_specification (die, &spec_cu);
          if (spec_die != NULL)
@@ -20272,8 +20427,7 @@ file_full_name (int file, struct line_header *lh, const char *comp_dir)
 static struct macro_source_file *
 macro_start_file (int file, int line,
                   struct macro_source_file *current_file,
-                  const char *comp_dir,
-                  struct line_header *lh, struct objfile *objfile)
+                  struct line_header *lh)
 {
   /* File name relative to the compilation directory of this source file.  */
   char *file_name = file_file_name (file, lh);
@@ -20282,7 +20436,7 @@ macro_start_file (int file, int line,
     {
       /* Note: We don't create a macro table for this compilation unit
         at all until we actually get a filename.  */
-      struct macro_table *macro_table = get_macro_table (objfile, comp_dir);
+      struct macro_table *macro_table = get_macro_table ();
 
       /* If we have no current file, then this must be the start_file
         directive for the compilation unit's main source file.  */
@@ -20660,13 +20814,13 @@ static void
 dwarf_decode_macro_bytes (bfd *abfd,
                          const gdb_byte *mac_ptr, const gdb_byte *mac_end,
                          struct macro_source_file *current_file,
-                         struct line_header *lh, const char *comp_dir,
+                         struct line_header *lh,
                          struct dwarf2_section_info *section,
                          int section_is_gnu, int section_is_dwz,
                          unsigned int offset_size,
-                         struct objfile *objfile,
                          htab_t include_hash)
 {
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
   enum dwarf_macro_record_type macinfo_type;
   int at_commandline;
   const gdb_byte *opcode_definitions[256];
@@ -20807,9 +20961,7 @@ dwarf_decode_macro_bytes (bfd *abfd,
                at_commandline = 0;
              }
            else
-             current_file = macro_start_file (file, line,
-                                              current_file, comp_dir,
-                                              lh, objfile);
+             current_file = macro_start_file (file, line, current_file, lh);
           }
           break;
 
@@ -20869,8 +21021,7 @@ dwarf_decode_macro_bytes (bfd *abfd,
              {
                struct dwz_file *dwz = dwarf2_get_dwz_file ();
 
-               dwarf2_read_section (dwarf2_per_objfile->objfile,
-                                    &dwz->macro);
+               dwarf2_read_section (objfile, &dwz->macro);
 
                include_section = &dwz->macro;
                include_bfd = get_section_bfd_owner (include_section);
@@ -20894,10 +21045,9 @@ dwarf_decode_macro_bytes (bfd *abfd,
                *slot = (void *) new_mac_ptr;
 
                dwarf_decode_macro_bytes (include_bfd, new_mac_ptr,
-                                         include_mac_end, current_file,
-                                         lh, comp_dir,
+                                         include_mac_end, current_file, lh,
                                          section, section_is_gnu, is_dwz,
-                                         offset_size, objfile, include_hash);
+                                         offset_size, include_hash);
 
                htab_remove_elt (include_hash, (void *) new_mac_ptr);
              }
@@ -20933,7 +21083,7 @@ dwarf_decode_macro_bytes (bfd *abfd,
 
 static void
 dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
-                     const char *comp_dir, int section_is_gnu)
+                     int section_is_gnu)
 {
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct line_header *lh = cu->line_header;
@@ -21052,8 +21202,7 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
            file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
            mac_ptr += bytes_read;
 
-           current_file = macro_start_file (file, line, current_file,
-                                            comp_dir, lh, objfile);
+           current_file = macro_start_file (file, line, current_file, lh);
          }
          break;
 
@@ -21118,9 +21267,8 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
   slot = htab_find_slot (include_hash, mac_ptr, INSERT);
   *slot = (void *) mac_ptr;
   dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end,
-                           current_file, lh, comp_dir, section,
-                           section_is_gnu, 0,
-                           offset_size, objfile, include_hash);
+                           current_file, lh, section,
+                           section_is_gnu, 0, offset_size, include_hash);
   do_cleanups (cleanup);
 }
 
This page took 0.056225 seconds and 4 git commands to generate.