gdb: introduce objfile text_section_offset and data_section_offset methods
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 23 Jan 2020 22:55:35 +0000 (17:55 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 23 Jan 2020 22:55:35 +0000 (17:55 -0500)
The pattern

  objfile->section_offsets[SECT_OFF_TEXT (objfile)]

... appears very often, to get the offset of the text section of an
objfile.  I thought it would be more readable to write it as:

  objfile->text_section_offset ()

... so I added this method and used it where possible.  I also added
data_section_offset, although it is not used as much.

gdb/ChangeLog:

* 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.

17 files changed:
gdb/ChangeLog
gdb/amd64-windows-tdep.c
gdb/coff-pe-read.c
gdb/coffread.c
gdb/ctfread.c
gdb/dtrace-probe.c
gdb/dwarf2-frame.c
gdb/dwarf2read.c
gdb/hppa-bsd-tdep.c
gdb/hppa-tdep.c
gdb/ia64-tdep.c
gdb/objfiles.h
gdb/psympriv.h
gdb/psymtab.c
gdb/solib-svr4.c
gdb/stap-probe.c
gdb/xcoffread.c

index a37affef5b3768a08f453ef8a4a899c95504fa36..f0bbaae7799269c455580f561344e6be59e6a4aa 100644 (file)
@@ -1,3 +1,54 @@
+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`
index b2155f347a50bbd4de4966d3ab0e9c62bf3da618..d4d79682dd187a9dc37f46d187a2dcbf548210e9 100644 (file)
@@ -953,8 +953,7 @@ amd64_windows_find_unwind_info (struct gdbarch *gdbarch, CORE_ADDR pc,
   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.
index 047f2e5ea4c0450e1ca66bc014cd44e3fce4efbb..3ecfb3d06134418225a20efb3b0900bc5f0548ac 100644 (file)
@@ -266,7 +266,7 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader,
      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);
index 227cf866b84438259bc47df38716f5ac0fa17efe..b682755bbba7d6d458122900da109255de098250 100644 (file)
@@ -920,7 +920,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
                  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;
                }
@@ -1113,7 +1113,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
                            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;
@@ -1122,7 +1122,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
          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)
@@ -1145,9 +1145,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
                }
              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);
@@ -1439,7 +1437,7 @@ enter_linenos (long file_offset, int first_line,
       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));
@@ -1574,7 +1572,7 @@ process_coff_symbol (struct coff_symbol *cs,
 
   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));
index bfca2703c55259f09dcec24c83412323a064509b..f3c067ee0b3255f037b25068d8af9f1c723c2358 100644 (file)
@@ -1165,7 +1165,7 @@ get_objfile_text_range (struct objfile *of, int *tsize)
 
   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.  */
index 71d627bcbd07fddadc84f001a2e7a296feea67a0..daa5dcc1e98f1be661ad589157695686b31e0d64 100644 (file)
@@ -685,8 +685,7 @@ dtrace_probe::is_enabled () const
 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.  */
index a043d48217bf3ad37a46ce526ca38eaf3da0569f..40eb7f564321d05ec63956cab4331c2fcb3337ab 100644 (file)
@@ -384,7 +384,7 @@ execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr,
                                           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;
 
@@ -1686,7 +1686,7 @@ dwarf2_frame_find_fde (CORE_ADDR *pc, CORE_ADDR *out_offset)
        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)
index dfa2f91d450aff627f4c1adfc4964100df443d8a..a494db790a4de976780f9cef667d3f76432d8911 100644 (file)
@@ -3213,7 +3213,7 @@ create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
   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)
     {
@@ -3259,7 +3259,7 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
   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);
@@ -5281,7 +5281,7 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile,
   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)
@@ -8076,7 +8076,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
   /* 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);
 
@@ -8954,7 +8954,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *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);
@@ -9197,7 +9197,7 @@ add_partial_subprogram (struct partial_die_info *pdi,
              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)
@@ -10399,7 +10399,7 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
   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 ();
@@ -11601,7 +11601,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
   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);
 
@@ -13704,7 +13704,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
        }
     }
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   name = dwarf2_name (die, cu);
 
@@ -13883,7 +13883,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *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
@@ -13957,7 +13957,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
   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)
@@ -14354,7 +14354,7 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
     }
   buffer = dwarf2_per_objfile->rnglists.buffer + offset;
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   while (1)
     {
@@ -14522,7 +14522,7 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
     }
   buffer = dwarf2_per_objfile->ranges.buffer + offset;
 
-  baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+  baseaddr = objfile->text_section_offset ();
 
   while (1)
     {
@@ -14600,7 +14600,7 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
 {
   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;
@@ -21425,7 +21425,7 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
      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;
@@ -21853,7 +21853,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 
   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)
@@ -23651,7 +23651,7 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
          != 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
@@ -25659,9 +25659,7 @@ dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
 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
index 34dec20298fb5217a014c19d2302e9b655247fa5..3994167a3ad9ce58535227928af3aa75a6cd99a6 100644 (file)
@@ -87,7 +87,7 @@ hppabsd_find_global_pointer (struct gdbarch *gdbarch, struct value *function)
                     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;
                }
index d8a3a56057338800a39708d997073e746667d3b2..3730a73af2a0cab5e67b9ee2e3d9c929d98a6e44 100644 (file)
@@ -357,7 +357,7 @@ read_unwind_info (struct objfile *objfile)
   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));
 
index dd07b7d4e7ea2c4f29a18e0009decc6d6cf4d30c..db02882bbe367c13cab27d7fc8957696a7fd9bef 100644 (file)
@@ -2713,7 +2713,7 @@ ia64_find_unwind_table (struct objfile *objfile, unw_word_t ip,
   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)
     {
index 1301f2c23fd215c64bd35bb9a27707d41a02e96c..b71a8a9edb8e199ec4492a790b49165bf99b0383 100644 (file)
@@ -155,6 +155,37 @@ struct obj_section
    + 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
@@ -492,6 +523,15 @@ public:
     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
@@ -737,38 +777,6 @@ extern void default_iterate_over_objfiles_in_search_order
   (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.  */
 
index e7630050e1803573ca22d4ca0c53bc9be8c30999..be03465992de58613e9f922a9038c6b53aa550fc 100644 (file)
@@ -119,13 +119,13 @@ struct partial_symtab
   /* 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.  */
index 09231bf981d259216448b17585fc0d8b48c6ccec..18580f500b58025f870f074e2afa905764228d54 100644 (file)
@@ -316,7 +316,7 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
   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 *)
index 1c769bb4015bbc3df984585c84120b3d87ba4bfa..38c832f8f5a141acbcd724d60008e3c71d71e747 100644 (file)
@@ -2273,7 +2273,7 @@ enable_break (struct svr4_info *info, int from_tty)
          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)
index 2d15212251631b2271901224eb30fd0a8f918e18..1a5ba5a1b3e090575ff1d45ea94dbe19e9728b2e 100644 (file)
@@ -1290,7 +1290,7 @@ stap_probe::parse_arguments (struct gdbarch *gdbarch)
 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.  */
index aae2e37c90f2ff6be4bff348a61e4366b7186da3..66ace43051a8dd26d694e22da022fa66ec9fe0f9 100644 (file)
@@ -865,7 +865,7 @@ enter_line_range (struct subfile *subfile, unsigned beginoffset,
       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;
@@ -1233,7 +1233,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst)
                        }
 
                      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] == '@'))
@@ -1355,7 +1355,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst)
        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);
@@ -1399,7 +1399,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst)
                            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;
@@ -1466,7 +1466,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst)
              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)
            {
@@ -1488,7 +1488,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst)
                                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;
            }