+2020-01-23  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * objfiles.h (ALL_OBJFILE_OSECTIONS): Move up.
+       (SECT_OFF_DATA): Likewise.
+       (SECT_OFF_RODATA): Likewise.
+       (SECT_OFF_TEXT): Likewise.
+       (SECT_OFF_BSS): Likewise.
+       (struct objfile) <text_section_offset, data_section_offset>: New
+       methods.
+       * amd64-windows-tdep.c (amd64_windows_find_unwind_info): Use
+       objfile::text_section_offset.
+       * coff-pe-read.c (add_pe_forwarded_sym): Likewise.
+       * coffread.c (coff_symtab_read): Likewise.
+       (enter_linenos): Likewise.
+       (process_coff_symbol): Likewise.
+       * ctfread.c (get_objfile_text_range): Likewise.
+       * dtrace-probe.c (dtrace_probe::get_relocated_address):
+       Use objfile::data_section_offset.
+       * dwarf2-frame.c (execute_cfa_program): Use
+       objfile::text_section_offset.
+       (dwarf2_frame_find_fde): Likewise.
+       * dwarf2read.c (create_addrmap_from_index): Likewise.
+       (create_addrmap_from_aranges): Likewise.
+       (dw2_find_pc_sect_compunit_symtab): Likewise.
+       (process_psymtab_comp_unit_reader): Likewise.
+       (add_partial_symbol): Likewise.
+       (add_partial_subprogram): Likewise.
+       (process_full_comp_unit): Likewise.
+       (read_file_scope): Likewise.
+       (read_func_scope): Likewise.
+       (read_lexical_block_scope): Likewise.
+       (read_call_site_scope): Likewise.
+       (dwarf2_rnglists_process): Likewise.
+       (dwarf2_ranges_process): Likewise.
+       (dwarf2_ranges_read): Likewise.
+       (dwarf_decode_lines_1): Likewise.
+       (new_symbol): Likewise.
+       (dwarf2_fetch_die_loc_sect_off): Likewise.
+       (dwarf2_per_cu_text_offset): Likewise.
+       * hppa-bsd-tdep.c (hppabsd_find_global_pointer): Likewise.
+       * hppa-tdep.c (read_unwind_info): Likewise.
+       * ia64-tdep.c (ia64_find_unwind_table): Likewise.
+       * psympriv.h (struct partial_symtab): Likewise.
+       * psymtab.c (find_pc_sect_psymtab): Likewise.
+       * solib-svr4.c (enable_break): Likewise.
+       * stap-probe.c (relocate_address): Use
+       objfile::data_section_offset.
+       * xcoffread.c (enter_line_range): Use
+       objfile::text_section_offset.
+       (read_xcoff_symtab): Likewise.
+
 2020-01-23  Simon Marchi  <simon.marchi@efficios.com>
 
        * darwin-nat.c (darwin_nat_target::wait_1): Move `inf`
 
   pe = pe_data (sec->objfile->obfd);
   dir = &pe->pe_opthdr.DataDirectory[PE_EXCEPTION_TABLE];
 
-  base = (pe->pe_opthdr.ImageBase
-         + objfile->section_offsets[SECT_OFF_TEXT (objfile)]);
+  base = pe->pe_opthdr.ImageBase + objfile->text_section_offset ();
   *image_base = base;
 
   /* Find the entry.
 
      really be relocated properly, but nevertheless we make a stab at
      it, choosing an approach consistent with the history of this
      code.  */
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   reader.record_with_info (qualified_name.c_str (), vma - baseaddr, msymtype,
                           section);
 
                  if (in_source_file)
                    complete_symtab (filestring,
                                     (cs->c_value
-                                     + objfile->section_offsets[SECT_OFF_TEXT (objfile)]),
+                                     + objfile->text_section_offset ()),
                                     main_aux.x_scn.x_scnlen);
                  in_source_file = 0;
                }
                            NULL, cstk.start_addr,
                            fcn_cs_saved.c_value
                            + fcn_aux_saved.x_sym.x_misc.x_fsize
-                           + objfile->section_offsets[SECT_OFF_TEXT (objfile)]);
+                           + objfile->text_section_offset ());
              within_function = 0;
            }
          break;
          if (strcmp (cs->c_name, ".bb") == 0)
            {
              tmpaddr = cs->c_value;
-             tmpaddr += objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+             tmpaddr += objfile->text_section_offset ();
              push_context (++depth, tmpaddr);
            }
          else if (strcmp (cs->c_name, ".eb") == 0)
                }
              if (*get_local_symbols () && !outermost_context_p ())
                {
-                 tmpaddr
-                   = (cs->c_value
-                      + objfile->section_offsets[SECT_OFF_TEXT (objfile)]);
+                 tmpaddr = cs->c_value + objfile->text_section_offset ();
                  /* Make a block for the local symbols within.  */
                  finish_block (0, cstk.old_blocks, NULL,
                                cstk.start_addr, tmpaddr);
       if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
        {
          CORE_ADDR addr = lptr.l_addr.l_paddr;
-         addr += objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+         addr += objfile->text_section_offset ();
          record_line (get_current_subfile (),
                       first_line + L_LNNO32 (&lptr),
                       gdbarch_addr_bits_remove (gdbarch, addr));
 
   if (ISFCN (cs->c_type))
     {
-      SYMBOL_VALUE (sym) += objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+      SYMBOL_VALUE (sym) += objfile->text_section_offset ();
       SYMBOL_TYPE (sym) =
        lookup_function_type (decode_function_type (cs, cs->c_type,
                                                    aux, objfile));
 
 
   codes = bfd_get_section_by_name (abfd, ".text");
   *tsize = codes ? bfd_section_size (codes) : 0;
-  return of->section_offsets[SECT_OFF_TEXT (of)];
+  return of->text_section_offset ();
 }
 
 /* Start a symtab for OBJFILE in CTF format.  */
 
 CORE_ADDR
 dtrace_probe::get_relocated_address (struct objfile *objfile)
 {
-  return (this->get_address ()
-         + objfile->section_offsets[SECT_OFF_DATA (objfile)]);
+  return this->get_address () + objfile->data_section_offset ();
 }
 
 /* Implementation of the get_argument_count method.  */
 
                                           fde->cie->ptr_size, insn_ptr,
                                           &bytes_read, fde->initial_location);
              /* Apply the objfile offset for relocatable objects.  */
-             fs->pc += fde->cie->unit->objfile->section_offsets[SECT_OFF_TEXT (fde->cie->unit->objfile)];
+             fs->pc += fde->cie->unit->objfile->text_section_offset ();
              insn_ptr += bytes_read;
              break;
 
        continue;
 
       gdb_assert (!objfile->section_offsets.empty ());
-      offset = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+      offset = objfile->text_section_offset ();
 
       gdb_assert (fde_table->num_entries > 0);
       if (*pc < offset + fde_table->entries[0]->initial_location)
 
   iter = index->address_table.data ();
   end = iter + index->address_table.size ();
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   while (iter < end)
     {
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   bfd *abfd = objfile->obfd;
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  const CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  const CORE_ADDR baseaddr = objfile->text_section_offset ();
 
   auto_obstack temp_obstack;
   addrmap *mutable_map = addrmap_create_mutable (&temp_obstack);
   if (!objfile->partial_symtabs->psymtabs_addrmap)
     return NULL;
 
-  CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  CORE_ADDR baseaddr = objfile->text_section_offset ();
   data = (struct dwarf2_per_cu_data *) addrmap_find
     (objfile->partial_symtabs->psymtabs_addrmap, pc - baseaddr);
   if (!data)
   /* This must be done before calling dwarf2_build_include_psymtabs.  */
   pst->dirname = dwarf2_string_attr (comp_unit_die, DW_AT_comp_dir, cu);
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   dwarf2_find_base_address (comp_unit_die, cu);
 
   const char *actual_name = NULL;
   CORE_ADDR baseaddr;
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   gdb::unique_xmalloc_ptr<char> built_actual_name
     = partial_die_full_name (pdi, cu);
              CORE_ADDR this_highpc;
              CORE_ADDR this_lowpc;
 
-             baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+             baseaddr = objfile->text_section_offset ();
              this_lowpc
                = (gdbarch_adjust_dwarf2_addr (gdbarch,
                                               pdi->lowpc + baseaddr)
   struct block *static_block;
   CORE_ADDR addr;
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   /* Clear the list here in case something was left over.  */
   cu->method_list.clear ();
   CORE_ADDR baseaddr;
 
   prepare_one_comp_unit (cu, die, cu->language);
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   get_scope_pc_bounds (die, &lowpc, &highpc, cu);
 
        }
     }
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   name = dwarf2_name (die, cu);
 
   struct die_info *child_die;
   CORE_ADDR baseaddr;
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   /* Ignore blocks with missing or invalid low and high pc attributes.  */
   /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
   int nparams;
   struct die_info *child_die;
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   attr = dwarf2_attr (die, DW_AT_call_return_pc, cu);
   if (attr == NULL)
     }
   buffer = dwarf2_per_objfile->rnglists.buffer + offset;
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   while (1)
     {
     }
   buffer = dwarf2_per_objfile->ranges.buffer + offset;
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   while (1)
     {
 {
   struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  const CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  const CORE_ADDR baseaddr = objfile->text_section_offset ();
   int low_set = 0;
   CORE_ADDR low = 0;
   CORE_ADDR high = 0;
      the line number program).  */
   bool record_lines_p = !decode_for_pst_p;
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   line_ptr = lh->statement_program_start;
   line_end = lh->statement_program_end;
 
   int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   name = dwarf2_name (die, cu);
   if (name)
          != dwarf2_per_objfile->abstract_to_concrete.end ()))
     {
       CORE_ADDR pc = (*get_frame_pc) (baton);
-      CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+      CORE_ADDR baseaddr = objfile->text_section_offset ();
       struct gdbarch *gdbarch = get_objfile_arch (objfile);
 
       for (const auto &cand_off
 CORE_ADDR
 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
 {
-  struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
-
-  return objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  return per_cu->dwarf2_per_objfile->objfile->text_section_offset ();
 }
 
 /* Return a type that is a generic pointer type, the size of which matches
 
                     we have to do it ourselves.  */
                  pltgot = extract_unsigned_integer (buf, sizeof buf,
                                                     byte_order);
-                 pltgot += sec->objfile->section_offsets[SECT_OFF_TEXT (sec->objfile)];
+                 pltgot += sec->objfile->text_section_offset ();
 
                  return pltgot;
                }
 
   struct hppa_unwind_info *ui;
   struct hppa_objfile_private *obj_private;
 
-  text_offset = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  text_offset = objfile->text_section_offset ();
   ui = (struct hppa_unwind_info *) obstack_alloc (&objfile->objfile_obstack,
                                           sizeof (struct hppa_unwind_info));
 
 
   ehdr = elf_tdata (bfd)->elf_header;
   phdr = elf_tdata (bfd)->phdr;
 
-  load_base = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  load_base = objfile->text_section_offset ();
 
   for (i = 0; i < ehdr->e_phnum; ++i)
     {
 
    + bfd_section_size ((s)->the_bfd_section)                           \
    + obj_section_offset (s))
 
+#define ALL_OBJFILE_OSECTIONS(objfile, osect)  \
+  for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
+    if (osect->the_bfd_section == NULL)                                        \
+      {                                                                        \
+       /* Nothing.  */                                                 \
+      }                                                                        \
+    else
+
+#define SECT_OFF_DATA(objfile) \
+     ((objfile->sect_index_data == -1) \
+      ? (internal_error (__FILE__, __LINE__, \
+                        _("sect_index_data not initialized")), -1)     \
+      : objfile->sect_index_data)
+
+#define SECT_OFF_RODATA(objfile) \
+     ((objfile->sect_index_rodata == -1) \
+      ? (internal_error (__FILE__, __LINE__, \
+                        _("sect_index_rodata not initialized")), -1)   \
+      : objfile->sect_index_rodata)
+
+#define SECT_OFF_TEXT(objfile) \
+     ((objfile->sect_index_text == -1) \
+      ? (internal_error (__FILE__, __LINE__, \
+                        _("sect_index_text not initialized")), -1)     \
+      : objfile->sect_index_text)
+
+/* Sometimes the .bss section is missing from the objfile, so we don't
+   want to die here.  Let the users of SECT_OFF_BSS deal with an
+   uninitialized section index.  */
+#define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss
+
 /* The "objstats" structure provides a place for gdb to record some
    interesting information about its internal state at runtime, on a
    per objfile basis, such as information about the number of symbols
     return separate_debug_range (this);
   }
 
+  CORE_ADDR text_section_offset () const
+  {
+    return section_offsets[SECT_OFF_TEXT (this)];
+  }
+
+  CORE_ADDR data_section_offset () const
+  {
+    return section_offsets[SECT_OFF_DATA (this)];
+  }
 
   /* The object file's original name as specified by the user,
      made absolute, and tilde-expanded.  However, it is not canonicalized
   (struct gdbarch *gdbarch,
    iterate_over_objfiles_in_search_order_cb_ftype *cb,
    void *cb_data, struct objfile *current_objfile);
-\f
-
-#define ALL_OBJFILE_OSECTIONS(objfile, osect)  \
-  for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
-    if (osect->the_bfd_section == NULL)                                        \
-      {                                                                        \
-       /* Nothing.  */                                                 \
-      }                                                                        \
-    else
-
-#define SECT_OFF_DATA(objfile) \
-     ((objfile->sect_index_data == -1) \
-      ? (internal_error (__FILE__, __LINE__, \
-                        _("sect_index_data not initialized")), -1)     \
-      : objfile->sect_index_data)
-
-#define SECT_OFF_RODATA(objfile) \
-     ((objfile->sect_index_rodata == -1) \
-      ? (internal_error (__FILE__, __LINE__, \
-                        _("sect_index_rodata not initialized")), -1)   \
-      : objfile->sect_index_rodata)
-
-#define SECT_OFF_TEXT(objfile) \
-     ((objfile->sect_index_text == -1) \
-      ? (internal_error (__FILE__, __LINE__, \
-                        _("sect_index_text not initialized")), -1)     \
-      : objfile->sect_index_text)
-
-/* Sometimes the .bss section is missing from the objfile, so we don't
-   want to die here.  Let the users of SECT_OFF_BSS deal with an
-   uninitialized section index.  */
-#define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss
 
 /* Reset the per-BFD storage area on OBJ.  */
 
 
   /* Return the relocated low text address of this partial_symtab.  */
   CORE_ADDR text_low (struct objfile *objfile) const
   {
-    return m_text_low + objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+    return m_text_low + objfile->text_section_offset ();
   }
 
   /* Return the relocated high text address of this partial_symtab.  */
   CORE_ADDR text_high (struct objfile *objfile) const
   {
-    return m_text_high + objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+    return m_text_high + objfile->text_section_offset ();
   }
 
   /* Set the low text address of this partial_symtab.  */
 
   if (objfile->partial_symtabs->psymtabs != NULL
       && objfile->partial_symtabs->psymtabs_addrmap != NULL)
     {
-      CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+      CORE_ADDR baseaddr = objfile->text_section_offset ();
 
       struct partial_symtab *pst
        = ((struct partial_symtab *)
 
          CORE_ADDR load_addr;
 
          tmp_bfd = os->objfile->obfd;
-         load_addr = os->objfile->section_offsets[SECT_OFF_TEXT (os->objfile)];
+         load_addr = os->objfile->text_section_offset ();
 
          interp_sect = bfd_get_section_by_name (tmp_bfd, ".text");
          if (interp_sect)
 
 static CORE_ADDR
 relocate_address (CORE_ADDR address, struct objfile *objfile)
 {
-  return address + objfile->section_offsets[SECT_OFF_DATA (objfile)];
+  return address + objfile->data_section_offset ();
 }
 
 /* Implementation of the get_relocated_address method.  */
 
       addr = (int_lnno.l_lnno
              ? int_lnno.l_addr.l_paddr
              : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
-      addr += objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+      addr += objfile->text_section_offset ();
 
       if (addr < startaddr || (endaddr && addr >= endaddr))
        return;
                        }
 
                      file_start_addr =
-                       cs->c_value + objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+                       cs->c_value + objfile->text_section_offset ();
                      file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
 
                      if (cs->c_name && (cs->c_name[0] == '.' || cs->c_name[0] == '@'))
        case C_FCN:
          if (strcmp (cs->c_name, ".bf") == 0)
            {
-             CORE_ADDR off = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+             CORE_ADDR off = objfile->text_section_offset ();
 
              bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
                                    0, cs->c_naux, &main_aux);
                            NULL, cstk.start_addr,
                            (fcn_cs_saved.c_value
                             + fcn_aux_saved.x_sym.x_misc.x_fsize
-                            + objfile->section_offsets[SECT_OFF_TEXT (objfile)]));
+                            + objfile->text_section_offset ()));
              within_function = 0;
            }
          break;
              depth++;
              newobj = push_context (depth,
                                  (cs->c_value
-                                  + objfile->section_offsets[SECT_OFF_TEXT (objfile)]));
+                                  + objfile->text_section_offset ()));
            }
          else if (strcmp (cs->c_name, ".eb") == 0)
            {
                                cstk.old_blocks, NULL,
                                cstk.start_addr,
                                (cs->c_value
-                                + objfile->section_offsets[SECT_OFF_TEXT (objfile)]));
+                                + objfile->text_section_offset ()));
                }
              *get_local_symbols () = cstk.locals;
            }