]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/objfiles: make objfile::sections yield references
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 27 Aug 2025 14:38:13 +0000 (10:38 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 29 Aug 2025 15:47:16 +0000 (11:47 -0400)
I wrote this as a preparatory patch while attempting to make
objfile::section_iterator use filtered_iterator.  It turned out not so
easy, so I have put it aside for now.  But now I have this patch, so I
thought I'd send it by itself.

Since the `obj_section *` yielded by the iterator can't be nullptr, I
think it makes sense for the iterator to yield references instead.
Just like you would get if you iterated on an std::vector<obj_section>.

Change-Id: I7bbee50ed52599e64c4f3b06bdbbde597feba9aa

21 files changed:
gdb/arm-tdep.c
gdb/exec.c
gdb/gcore.c
gdb/hppa-bsd-tdep.c
gdb/hppa-linux-tdep.c
gdb/hppa-tdep.c
gdb/ia64-tdep.c
gdb/machoread.c
gdb/maint.c
gdb/minsyms.c
gdb/objfiles.c
gdb/objfiles.h
gdb/printcmd.c
gdb/solib-aix.c
gdb/solib-dsbt.c
gdb/solib-frv.c
gdb/solib-svr4.c
gdb/symfile.c
gdb/symtab.c
gdb/xstormy16-tdep.c
gdb/z80-tdep.c

index a7648250af6d6d30242c2245957c15ba924261d1..a4bc0bd3e3de0d24d23f81e77b834d137ed69a2c 100644 (file)
@@ -2504,15 +2504,15 @@ static const registry<bfd>::key<arm_exidx_data> arm_exidx_data_key;
 static struct obj_section *
 arm_obj_section_from_vma (struct objfile *objfile, bfd_vma vma)
 {
-  for (obj_section *osect : objfile->sections ())
-    if (bfd_section_flags (osect->the_bfd_section) & SEC_ALLOC)
+  for (obj_section &osect : objfile->sections ())
+    if (bfd_section_flags (osect.the_bfd_section) & SEC_ALLOC)
       {
        bfd_vma start, size;
-       start = bfd_section_vma (osect->the_bfd_section);
-       size = bfd_section_size (osect->the_bfd_section);
+       start = bfd_section_vma (osect.the_bfd_section);
+       size = bfd_section_size (osect.the_bfd_section);
 
        if (start <= vma && vma < start + size)
-         return osect;
+         return &osect;
       }
 
   return NULL;
index c2a1f8a7adaa06768017fd8736d40ec671d467bb..0db5d9030bd164b8b33c50794fbf75a0159b480e 100644 (file)
@@ -653,13 +653,13 @@ program_space::add_target_sections (struct objfile *objfile)
   gdb_assert (objfile != nullptr);
 
   /* Compute the number of sections to add.  */
-  for (obj_section *osect : objfile->sections ())
+  for (obj_section &osect : objfile->sections ())
     {
-      if (bfd_section_size (osect->the_bfd_section) == 0)
+      if (bfd_section_size (osect.the_bfd_section) == 0)
        continue;
 
-      m_target_sections.emplace_back (osect->addr (), osect->endaddr (),
-                                     osect->the_bfd_section, objfile);
+      m_target_sections.emplace_back (osect.addr (), osect.endaddr (),
+                                     osect.the_bfd_section, objfile);
     }
 }
 
index d53265240ef2a097a687f4342c41a2cff9945a32..ce5f570aa464e5f04f58a6a658e21d24b841e703 100644 (file)
@@ -425,13 +425,13 @@ gcore_create_callback (CORE_ADDR vaddr, unsigned long size, int read,
         If so, we can avoid copying its contents by clearing SEC_LOAD.  */
 
       for (objfile *objfile : current_program_space->objfiles ())
-       for (obj_section *objsec : objfile->sections ())
+       for (obj_section &objsec : objfile->sections ())
          {
            bfd *abfd = objfile->obfd.get ();
-           asection *asec = objsec->the_bfd_section;
+           asection *asec = objsec.the_bfd_section;
            bfd_vma align = (bfd_vma) 1 << bfd_section_alignment (asec);
-           bfd_vma start = objsec->addr () & -align;
-           bfd_vma end = (objsec->endaddr () + align - 1) & -align;
+           bfd_vma start = objsec.addr () & -align;
+           bfd_vma end = (objsec.endaddr () + align - 1) & -align;
 
            /* Match if either the entire memory region lies inside the
               section (i.e. a mapping covering some pages of a large
@@ -533,9 +533,9 @@ objfile_find_memory_regions (struct target_ops *self,
 
   /* Call callback function for each objfile section.  */
   for (objfile *objfile : current_program_space->objfiles ())
-    for (obj_section *objsec : objfile->sections ())
+    for (obj_section &objsec : objfile->sections ())
       {
-       asection *isec = objsec->the_bfd_section;
+       asection *isec = objsec.the_bfd_section;
        flagword flags = bfd_section_flags (isec);
 
        /* Separate debug info files are irrelevant for gcore.  */
@@ -547,7 +547,7 @@ objfile_find_memory_regions (struct target_ops *self,
            int size = bfd_section_size (isec);
            int ret;
 
-           ret = (*func) (objsec->addr (), size,
+           ret = (*func) (objsec.addr (), size,
                           1, /* All sections will be readable.  */
                           (flags & SEC_READONLY) == 0, /* Writable.  */
                           (flags & SEC_CODE) != 0, /* Executable.  */
index 715e79457a860c3870026e42ea793328218ef5c2..b9cd61e0c9791cc64aa26f8c7b8030c7e3ebce8c 100644 (file)
@@ -54,12 +54,12 @@ hppabsd_find_global_pointer (struct gdbarch *gdbarch, struct value *function)
   faddr_sec = find_pc_section (faddr);
   if (faddr_sec != NULL)
     {
-      for (struct obj_section *sec : faddr_sec->objfile->sections ())
+      for (struct obj_section &sec : faddr_sec->objfile->sections ())
        {
-         if (strcmp (sec->the_bfd_section->name, ".dynamic") == 0)
+         if (strcmp (sec.the_bfd_section->name, ".dynamic") == 0)
            {
-             CORE_ADDR addr = sec->addr ();
-             CORE_ADDR endaddr = sec->endaddr ();
+             CORE_ADDR addr = sec.addr ();
+             CORE_ADDR endaddr = sec.endaddr ();
 
              while (addr < endaddr)
                {
@@ -81,7 +81,7 @@ hppabsd_find_global_pointer (struct gdbarch *gdbarch, struct value *function)
                         DT_PLTGOT, so we have to do it ourselves.  */
                      pltgot = extract_unsigned_integer (buf, sizeof buf,
                                                         byte_order);
-                     pltgot += sec->objfile->text_section_offset ();
+                     pltgot += sec.objfile->text_section_offset ();
 
                      return pltgot;
                    }
index 2eb8d46565049c74fb8c995fe60cbb20d39238cc..d0bb56214efc89d92494b2a51f537ffa36cc0b28 100644 (file)
@@ -362,14 +362,14 @@ hppa_linux_find_global_pointer (struct gdbarch *gdbarch,
   faddr_sect = find_pc_section (faddr);
   if (faddr_sect != NULL)
     {
-      for (obj_section *osect : faddr_sect->objfile->sections ())
+      for (obj_section &osect : faddr_sect->objfile->sections ())
        {
-         if (strcmp (osect->the_bfd_section->name, ".dynamic") == 0)
+         if (strcmp (osect.the_bfd_section->name, ".dynamic") == 0)
            {
              CORE_ADDR addr, endaddr;
 
-             addr = osect->addr ();
-             endaddr = osect->endaddr ();
+             addr = osect.addr ();
+             endaddr = osect.endaddr ();
 
              while (addr < endaddr)
                {
index 61e6cb2eb02b0ba84aebc58e22eb0b4281ebdf17..6f0cebe6d95a518de9090cde94859ffe8d151e15 100644 (file)
@@ -920,12 +920,12 @@ hppa64_convert_code_addr_to_fptr (struct gdbarch *gdbarch, CORE_ADDR code)
   if (!(sec->the_bfd_section->flags & SEC_CODE))
     return code;
 
-  for (obj_section *opd : sec->objfile->sections ())
+  for (obj_section &opd : sec->objfile->sections ())
     {
-      if (strcmp (opd->the_bfd_section->name, ".opd") == 0)
+      if (strcmp (opd.the_bfd_section->name, ".opd") == 0)
        {
-         for (CORE_ADDR addr = opd->addr ();
-              addr < opd->endaddr ();
+         for (CORE_ADDR addr = opd.addr ();
+              addr < opd.endaddr ();
               addr += 2 * 8)
            {
              ULONGEST opdaddr;
index 7c6526a2b4d5d1617c2f6243890dbe6fc0389d6b..6cf29867565afd12860e2e022633b24daa4e5a29 100644 (file)
@@ -3432,12 +3432,12 @@ ia64_find_global_pointer_from_dynamic_section (struct gdbarch *gdbarch,
   faddr_sect = find_pc_section (faddr);
   if (faddr_sect != NULL)
     {
-      for (obj_section *osect : faddr_sect->objfile->sections ())
+      for (obj_section &osect : faddr_sect->objfile->sections ())
        {
-         if (strcmp (osect->the_bfd_section->name, ".dynamic") == 0)
+         if (strcmp (osect.the_bfd_section->name, ".dynamic") == 0)
            {
-             CORE_ADDR addr = osect->addr ();
-             CORE_ADDR endaddr = osect->endaddr ();
+             CORE_ADDR addr = osect.addr ();
+             CORE_ADDR endaddr = osect.endaddr ();
 
              while (addr < endaddr)
                {
@@ -3513,12 +3513,12 @@ find_extant_func_descr (struct gdbarch *gdbarch, CORE_ADDR faddr)
 
   if (faddr_sect != NULL)
     {
-      for (obj_section *osect : faddr_sect->objfile->sections ())
+      for (obj_section &osect : faddr_sect->objfile->sections ())
        {
-         if (strcmp (osect->the_bfd_section->name, ".opd") == 0)
+         if (strcmp (osect.the_bfd_section->name, ".opd") == 0)
            {
-             CORE_ADDR addr = osect->addr ();
-             CORE_ADDR endaddr = osect->endaddr ();
+             CORE_ADDR addr = osect.addr ();
+             CORE_ADDR endaddr = osect.endaddr ();
 
              while (addr < endaddr)
                {
index ffee18171563e0b349fca0a43d2636b8a87bc5d6..30d376c7675479120e73eb198a45817bc6b3b55d 100644 (file)
@@ -901,13 +901,13 @@ macho_symfile_offsets (struct objfile *objfile,
 
   for (i = 0; i < addrs.size (); i++)
     {
-      for (obj_section *osect : objfile->sections ())
+      for (obj_section &osect : objfile->sections ())
        {
-         const char *bfd_sect_name = osect->the_bfd_section->name;
+         const char *bfd_sect_name = osect.the_bfd_section->name;
 
          if (bfd_sect_name == addrs[i].name)
            {
-             osect->set_offset (addrs[i].addr);
+             osect.set_offset (addrs[i].addr);
              break;
            }
        }
@@ -915,10 +915,10 @@ macho_symfile_offsets (struct objfile *objfile,
 
   objfile->sect_index_text = 0;
 
-  for (obj_section *osect : objfile->sections ())
+  for (obj_section &osect : objfile->sections ())
     {
-      const char *bfd_sect_name = osect->the_bfd_section->name;
-      int sect_index = osect - objfile->sections_start;
+      const char *bfd_sect_name = osect.the_bfd_section->name;
+      int sect_index = &osect - objfile->sections_start;
 
       if (startswith (bfd_sect_name, "LC_SEGMENT."))
        bfd_sect_name += 11;
index 78dea22541f1e3753eeeedf254ea66ccdedbfc88..d76d957b6e66d2ab6e2f00c1047a33f7f8944103 100644 (file)
@@ -582,9 +582,9 @@ maintenance_translate_address (const char *arg, int from_tty)
       p = skip_spaces (p + 1);
 
       for (objfile *objfile : current_program_space->objfiles ())
-       for (obj_section *iter : objfile->sections ())
+       for (obj_section &iter : objfile->sections ())
          {
-           if (strncmp (iter->the_bfd_section->name, arg, arg_len) == 0)
+           if (strncmp (iter.the_bfd_section->name, arg, arg_len) == 0)
              goto found;
          }
 
index 4a6459a6f2d2f5543c511c4e01788a6e7b430b41..16befa7782073101bebeefc78a8b678ee8fb04d0 100644 (file)
@@ -712,11 +712,11 @@ static int
 frob_address (struct objfile *objfile, CORE_ADDR pc,
              unrelocated_addr *unrel_addr)
 {
-  for (obj_section *iter : objfile->sections ())
+  for (obj_section &iter : objfile->sections ())
     {
-      if (iter->contains (pc))
+      if (iter.contains (pc))
        {
-         *unrel_addr = unrelocated_addr (pc - iter->offset ());
+         *unrel_addr = unrelocated_addr (pc - iter.offset ());
          return 1;
        }
     }
index 9ea07cbaa66ee6e739e7ca73cce4576219b50631..d0eb678f4512873d8c7bfd7172b8d92c443b5b83 100644 (file)
@@ -587,12 +587,12 @@ objfile_relocate1 (struct objfile *objfile,
   get_objfile_pspace_data (objfile->pspace ())->section_map_dirty = 1;
 
   /* Update the table in exec_ops, used to read memory.  */
-  for (obj_section *s : objfile->sections ())
+  for (obj_section &s : objfile->sections ())
     {
-      int idx = s - objfile->sections_start;
+      int idx = &s - objfile->sections_start;
 
       exec_set_section_address (bfd_get_filename (objfile->obfd.get ()), idx,
-                               s->addr ());
+                               s.addr ());
     }
 
   /* Data changed.  */
@@ -790,10 +790,10 @@ sort_cmp (const struct obj_section *sect1, const obj_section *sect2)
             second case shouldn't occur during normal use, but std::sort
             does check that '!(a < a)' when compiled in debug mode.  */
 
-         for (const obj_section *osect : objfile1->sections ())
-           if (osect == sect2)
+         for (const obj_section &osect : objfile1->sections ())
+           if (&osect == sect2)
              return false;
-           else if (osect == sect1)
+           else if (&osect == sect1)
              return true;
 
          /* We should have found one of the sections before getting here.  */
@@ -994,8 +994,8 @@ update_section_map (struct program_space *pspace,
 
   alloc_size = 0;
   for (objfile *objfile : pspace->objfiles ())
-    for (obj_section *s : objfile->sections ())
-      if (insert_section_p (objfile->obfd.get (), s->the_bfd_section))
+    for (obj_section &s : objfile->sections ())
+      if (insert_section_p (objfile->obfd.get (), s.the_bfd_section))
        alloc_size += 1;
 
   /* This happens on detach/attach (e.g. in gdb.base/attach.exp).  */
@@ -1010,9 +1010,9 @@ update_section_map (struct program_space *pspace,
 
   i = 0;
   for (objfile *objfile : pspace->objfiles ())
-    for (obj_section *s : objfile->sections ())
-      if (insert_section_p (objfile->obfd.get (), s->the_bfd_section))
-       map[i++] = s;
+    for (obj_section &s : objfile->sections ())
+      if (insert_section_p (objfile->obfd.get (), s.the_bfd_section))
+       map[i++] = &s;
 
   std::sort (map, map + alloc_size, sort_cmp);
   map_size = filter_debuginfo_sections(map, alloc_size);
@@ -1127,12 +1127,12 @@ is_addr_in_objfile (CORE_ADDR addr, const struct objfile *objfile)
   if (objfile == NULL)
     return false;
 
-  for (obj_section *osect : objfile->sections ())
+  for (obj_section &osect : objfile->sections ())
     {
-      if (section_is_overlay (osect) && !section_is_mapped (osect))
+      if (section_is_overlay (&osect) && !section_is_mapped (&osect))
        continue;
 
-      if (osect->contains (addr))
+      if (osect.contains (addr))
        return true;
     }
   return false;
index da9d2f3f9389afd111cfe958ea61f7960783f380..fe7a2ac91fda72a8ae5b6e6462c711e3d9b2a815 100644 (file)
@@ -665,11 +665,11 @@ public:
     section_iterator &operator= (const section_iterator &) = default;
     section_iterator &operator= (section_iterator &&) = default;
 
-    typedef section_iterator self_type;
-    typedef obj_section *value_type;
+    using self_type = section_iterator;
+    using reference = obj_section &;
 
-    value_type operator* ()
-    { return m_iter; }
+    reference operator* ()
+    { return *m_iter; }
 
     section_iterator &operator++ ()
     {
@@ -701,8 +701,8 @@ public:
        ++m_iter;
     }
 
-    value_type m_iter;
-    value_type m_end;
+    obj_section *m_iter;
+    obj_section *m_end;
   };
 
   iterator_range<section_iterator> sections ()
index 1c50b6cbae8d52bdda4ab1fe8fcf04d8e1f2cdb2..210cf79a537baddd0a10d770cf50796b8bf288d5 100644 (file)
@@ -1494,27 +1494,27 @@ info_symbol_command (const char *arg, int from_tty)
 
   addr = parse_and_eval_address (arg);
   for (objfile *objfile : current_program_space->objfiles ())
-    for (obj_section *osect : objfile->sections ())
+    for (obj_section &osect : objfile->sections ())
       {
        /* Only process each object file once, even if there's a separate
           debug file.  */
        if (objfile->separate_debug_objfile_backlink)
          continue;
 
-       sect_addr = overlay_mapped_address (addr, osect);
+       sect_addr = overlay_mapped_address (addr, &osect);
 
-       if (osect->contains (sect_addr)
+       if (osect.contains (sect_addr)
            && (msymbol
                = lookup_minimal_symbol_by_pc_section (sect_addr,
-                                                      osect).minsym))
+                                                      &osect).minsym))
          {
            const char *obj_name, *mapped, *sec_name, *msym_name;
            const char *loc_string;
 
            matches = 1;
            offset = sect_addr - msymbol->value_address (objfile);
-           mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
-           sec_name = osect->the_bfd_section->name;
+           mapped = section_is_mapped (&osect) ? _("mapped") : _("unmapped");
+           sec_name = osect.the_bfd_section->name;
            msym_name = msymbol->print_name ();
 
            /* Don't print the offset if it is zero.
@@ -1528,12 +1528,12 @@ info_symbol_command (const char *arg, int from_tty)
            else
              loc_string = msym_name;
 
-           gdb_assert (osect->objfile && objfile_name (osect->objfile));
-           obj_name = objfile_name (osect->objfile);
+           gdb_assert (osect.objfile && objfile_name (osect.objfile));
+           obj_name = objfile_name (osect.objfile);
 
            if (current_program_space->multi_objfile_p ())
-             if (pc_in_unmapped_range (addr, osect))
-               if (section_is_overlay (osect))
+             if (pc_in_unmapped_range (addr, &osect))
+               if (section_is_overlay (&osect))
                  gdb_printf (_("%s in load address range of "
                                "%s overlay section %s of %s\n"),
                              loc_string, mapped, sec_name, obj_name);
@@ -1542,15 +1542,15 @@ info_symbol_command (const char *arg, int from_tty)
                                "section %s of %s\n"),
                              loc_string, sec_name, obj_name);
              else
-               if (section_is_overlay (osect))
+               if (section_is_overlay (&osect))
                  gdb_printf (_("%s in %s overlay section %s of %s\n"),
                              loc_string, mapped, sec_name, obj_name);
                else
                  gdb_printf (_("%s in section %s of %s\n"),
                              loc_string, sec_name, obj_name);
            else
-             if (pc_in_unmapped_range (addr, osect))
-               if (section_is_overlay (osect))
+             if (pc_in_unmapped_range (addr, &osect))
+               if (section_is_overlay (&osect))
                  gdb_printf (_("%s in load address range of %s overlay "
                                "section %s\n"),
                              loc_string, mapped, sec_name);
@@ -1559,7 +1559,7 @@ info_symbol_command (const char *arg, int from_tty)
                    (_("%s in load address range of section %s\n"),
                     loc_string, sec_name);
              else
-               if (section_is_overlay (osect))
+               if (section_is_overlay (&osect))
                  gdb_printf (_("%s in %s overlay section %s\n"),
                              loc_string, mapped, sec_name);
                else
index fb81a56ca190c3d668716cd57b44e510487a290b..6859092a78360643e2e3c28e33a1737d3bc12a46 100644 (file)
@@ -622,9 +622,9 @@ aix_solib_ops::bfd_open (const char *pathname) const
 static struct obj_section *
 data_obj_section_from_objfile (struct objfile *objfile)
 {
-  for (obj_section *osect : objfile->sections ())
-    if (strcmp (bfd_section_name (osect->the_bfd_section), ".data") == 0)
-      return osect;
+  for (obj_section &osect : objfile->sections ())
+    if (strcmp (bfd_section_name (osect.the_bfd_section), ".data") == 0)
+      return &osect;
 
   return NULL;
 }
index 4f2c918c11b92cc15a3b4ec7b009624aefd4e565..6b5b646480e609985289b45ca0a8de2a8c11d345 100644 (file)
@@ -816,16 +816,16 @@ dsbt_relocate_main_executable (void)
   section_offsets new_offsets (objf->section_offsets.size ());
   changed = 0;
 
-  for (obj_section *osect : objf->sections ())
+  for (obj_section &osect : objf->sections ())
     {
       CORE_ADDR orig_addr, addr, offset;
       int osect_idx;
       int seg;
 
-      osect_idx = osect - objf->sections_start;
+      osect_idx = &osect - objf->sections_start;
 
       /* Current address of section.  */
-      addr = osect->addr ();
+      addr = osect.addr ();
       /* Offset from where this section started.  */
       offset = objf->section_offsets[osect_idx];
       /* Original address prior to any past relocations.  */
index 9a9b65d29646539fe552d3da0f06a0af7c7cf94a..e6499f46937829d94079ffb0f94768601ccddac2 100644 (file)
@@ -750,16 +750,16 @@ frv_relocate_main_executable (void)
   section_offsets new_offsets (objf->section_offsets.size ());
   changed = 0;
 
-  for (obj_section *osect : objf->sections ())
+  for (obj_section &osect : objf->sections ())
     {
       CORE_ADDR orig_addr, addr, offset;
       int osect_idx;
       int seg;
-      
-      osect_idx = osect - objf->sections_start;
+
+      osect_idx = &osect - objf->sections_start;
 
       /* Current address of section.  */
-      addr = osect->addr ();
+      addr = osect.addr ();
       /* Offset from where this section started.  */
       offset = objf->section_offsets[osect_idx];
       /* Original address prior to any past relocations.  */
index 66409e7e239a92ff1c6652965757663bbf764572..635e52a198777cc3e230ad5d223bd98e63223bb2 100644 (file)
@@ -1622,8 +1622,8 @@ is_thread_local_section (struct bfd_section *bfd_sect)
 static bool
 has_thread_local_section (const objfile *objf)
 {
-  for (obj_section *objsec : objf->sections ())
-    if (is_thread_local_section (objsec->the_bfd_section))
+  for (obj_section &objsec : objf->sections ())
+    if (is_thread_local_section (objsec.the_bfd_section))
       return true;
   return false;
 }
index 0e47f5099943b9ceecbb5da5a287a5116e1373ed..8e4888fe0087b144b90f82bd00a7bb8269424ba9 100644 (file)
@@ -835,9 +835,9 @@ init_entry_point_info (struct objfile *objfile)
        = gdbarch_addr_bits_remove (objfile->arch (), entry_point);
 
       found = 0;
-      for (obj_section *osect : objfile->sections ())
+      for (obj_section &osect : objfile->sections ())
        {
-         struct bfd_section *sect = osect->the_bfd_section;
+         struct bfd_section *sect = osect.the_bfd_section;
 
          if (entry_point >= bfd_section_vma (sect)
              && entry_point < (bfd_section_vma (sect)
@@ -3007,9 +3007,9 @@ static void
 overlay_invalidate_all (program_space *pspace)
 {
   for (objfile *objfile : pspace->objfiles ())
-    for (obj_section *sect : objfile->sections ())
-      if (section_is_overlay (sect))
-       sect->ovly_mapped = -1;
+    for (obj_section &sect : objfile->sections ())
+      if (section_is_overlay (&sect))
+       sect.ovly_mapped = -1;
 }
 
 /* Function: section_is_mapped (SECTION)
@@ -3183,18 +3183,18 @@ find_pc_overlay (CORE_ADDR pc)
   if (overlay_debugging)
     {
       for (objfile *objfile : current_program_space->objfiles ())
-       for (obj_section *osect : objfile->sections ())
-         if (section_is_overlay (osect))
+       for (obj_section &osect : objfile->sections ())
+         if (section_is_overlay (&osect))
            {
-             if (pc_in_mapped_range (pc, osect))
+             if (pc_in_mapped_range (pc, &osect))
                {
-                 if (section_is_mapped (osect))
-                   return osect;
+                 if (section_is_mapped (&osect))
+                   return &osect;
                  else
-                   best_match = osect;
+                   best_match = &osect;
                }
-             else if (pc_in_unmapped_range (pc, osect))
-               best_match = osect;
+             else if (pc_in_unmapped_range (pc, &osect))
+               best_match = &osect;
            }
     }
   return best_match;
@@ -3210,9 +3210,9 @@ find_pc_mapped_section (CORE_ADDR pc)
   if (overlay_debugging)
     {
       for (objfile *objfile : current_program_space->objfiles ())
-       for (obj_section *osect : objfile->sections ())
-         if (pc_in_mapped_range (pc, osect) && section_is_mapped (osect))
-           return osect;
+       for (obj_section &osect : objfile->sections ())
+         if (pc_in_mapped_range (pc, &osect) && section_is_mapped (&osect))
+           return &osect;
     }
 
   return NULL;
@@ -3229,18 +3229,18 @@ list_overlays_command (const char *args, int from_tty)
   if (overlay_debugging)
     {
       for (objfile *objfile : current_program_space->objfiles ())
-       for (obj_section *osect : objfile->sections ())
-         if (section_is_mapped (osect))
+       for (obj_section &osect : objfile->sections ())
+         if (section_is_mapped (&osect))
            {
              struct gdbarch *gdbarch = objfile->arch ();
              const char *name;
              bfd_vma lma, vma;
              int size;
 
-             vma = bfd_section_vma (osect->the_bfd_section);
-             lma = bfd_section_lma (osect->the_bfd_section);
-             size = bfd_section_size (osect->the_bfd_section);
-             name = bfd_section_name (osect->the_bfd_section);
+             vma = bfd_section_vma (osect.the_bfd_section);
+             lma = bfd_section_lma (osect.the_bfd_section);
+             size = bfd_section_size (osect.the_bfd_section);
+             name = bfd_section_name (osect.the_bfd_section);
 
              gdb_printf ("Section %s, loaded at ", name);
              gdb_puts (paddress (gdbarch, lma));
@@ -3275,27 +3275,27 @@ map_overlay_command (const char *args, int from_tty)
 
   /* First, find a section matching the user supplied argument.  */
   for (objfile *obj_file : current_program_space->objfiles ())
-    for (obj_section *sec : obj_file->sections ())
-      if (!strcmp (bfd_section_name (sec->the_bfd_section), args))
+    for (obj_section &sec : obj_file->sections ())
+      if (!strcmp (bfd_section_name (sec.the_bfd_section), args))
        {
          /* Now, check to see if the section is an overlay.  */
-         if (!section_is_overlay (sec))
+         if (!section_is_overlay (&sec))
            continue;           /* not an overlay section */
 
          /* Mark the overlay as "mapped".  */
-         sec->ovly_mapped = 1;
+         sec.ovly_mapped = 1;
 
          /* Next, make a pass and unmap any sections that are
             overlapped by this new section: */
          for (objfile *objfile2 : current_program_space->objfiles ())
-           for (obj_section *sec2 : objfile2->sections ())
-             if (sec2->ovly_mapped && sec != sec2 && sections_overlap (sec,
-                                                                       sec2))
+           for (obj_section &sec2 : objfile2->sections ())
+             if (sec2.ovly_mapped && &sec != &sec2 && sections_overlap (&sec,
+                                                                        &sec2))
                {
                  if (info_verbose)
                    gdb_printf (_("Note: section %s unmapped by overlap\n"),
-                               bfd_section_name (sec2->the_bfd_section));
-                 sec2->ovly_mapped = 0; /* sec2 overlaps sec: unmap sec2.  */
+                               bfd_section_name (sec2.the_bfd_section));
+                 sec2.ovly_mapped = 0; /* sec2 overlaps sec: unmap sec2.  */
                }
          return;
        }
@@ -3319,12 +3319,12 @@ unmap_overlay_command (const char *args, int from_tty)
 
   /* First, find a section matching the user supplied argument.  */
   for (objfile *objfile : current_program_space->objfiles ())
-    for (obj_section *sec : objfile->sections ())
-      if (!strcmp (bfd_section_name (sec->the_bfd_section), args))
+    for (obj_section &sec : objfile->sections ())
+      if (!strcmp (bfd_section_name (sec.the_bfd_section), args))
        {
-         if (!sec->ovly_mapped)
+         if (!sec.ovly_mapped)
            error (_("Section %s is not mapped"), args);
-         sec->ovly_mapped = 0;
+         sec.ovly_mapped = 0;
          return;
        }
   error (_("No overlay section called %s"), args);
@@ -3578,17 +3578,17 @@ simple_overlay_update (struct obj_section *osect)
 
   /* Now may as well update all sections, even if only one was requested.  */
   for (objfile *objfile : current_program_space->objfiles ())
-    for (obj_section *sect : objfile->sections ())
-      if (section_is_overlay (sect))
+    for (obj_section &sect : objfile->sections ())
+      if (section_is_overlay (&sect))
        {
          int i;
-         asection *bsect = sect->the_bfd_section;
+         asection *bsect = sect.the_bfd_section;
 
          for (i = 0; i < cache_novlys; i++)
            if (cache_ovly_table[i][VMA] == bfd_section_vma (bsect)
                && cache_ovly_table[i][LMA] == bfd_section_lma (bsect))
              { /* obj_section matches i'th entry in ovly_table.  */
-               sect->ovly_mapped = cache_ovly_table[i][MAPPED];
+               sect.ovly_mapped = cache_ovly_table[i][MAPPED];
                break;          /* finished with inner for loop: break out.  */
              }
        }
index b6bd0a4817130e0b8e36d45fcd90e4697cf5256c..245eab20cfeeae6b23cc2ec45e5b81e60f0f06f0 100644 (file)
@@ -1846,18 +1846,18 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
         this reason, we still attempt a lookup by name prior to doing
         a search of the section table.  */
 
-      for (obj_section *s : objfile->sections ())
+      for (obj_section &s : objfile->sections ())
        {
-         if ((bfd_section_flags (s->the_bfd_section) & SEC_ALLOC) == 0)
+         if ((bfd_section_flags (s.the_bfd_section) & SEC_ALLOC) == 0)
            continue;
 
-         int idx = s - objfile->sections_start;
+         int idx = &s - objfile->sections_start;
          CORE_ADDR offset = objfile->section_offsets[idx];
 
          if (fallback == -1)
            fallback = idx;
 
-         if (s->addr () - offset <= addr && addr < s->endaddr () - offset)
+         if (s.addr () - offset <= addr && addr < s.endaddr () - offset)
            {
              sym->set_section_index (idx);
              return;
index b4042f1498c52918489ba98a59da7762af1836f9..b63dfa04be00a72ec2ec3b78e28618caf6ed98e2 100644 (file)
@@ -546,14 +546,14 @@ xstormy16_find_jmp_table_entry (struct gdbarch *gdbarch, CORE_ADDR faddr)
       if (!strcmp (faddr_sect->the_bfd_section->name, ".plt"))
        return faddr;
 
-      for (obj_section *osect : faddr_sect->objfile->sections ())
+      for (obj_section &osect : faddr_sect->objfile->sections ())
        {
-         if (!strcmp (osect->the_bfd_section->name, ".plt"))
+         if (!strcmp (osect.the_bfd_section->name, ".plt"))
            {
              CORE_ADDR addr, endaddr;
 
-             addr = osect->addr ();
-             endaddr = osect->endaddr ();
+             addr = osect.addr ();
+             endaddr = osect.endaddr ();
 
              for (; addr < endaddr; addr += 2 * xstormy16_inst_size)
                {
index 8f3924d5cad33e81243bda35a9b6ad836a464b9a..c8f0038e31d3d6f4b5a872a3ce7f7b243e1b20af 100644 (file)
@@ -962,11 +962,11 @@ z80_overlay_update_1 (struct obj_section *osect)
 
   /* we have interest for sections with same VMA */
   for (objfile *objfile : current_program_space->objfiles ())
-    for (obj_section *sect : objfile->sections ())
-      if (section_is_overlay (sect))
+    for (obj_section &sect : objfile->sections ())
+      if (section_is_overlay (&sect))
        {
-         sect->ovly_mapped = (lma == bfd_section_lma (sect->the_bfd_section));
-         i |= sect->ovly_mapped; /* true, if at least one section is mapped */
+         sect.ovly_mapped = (lma == bfd_section_lma (sect.the_bfd_section));
+         i |= sect.ovly_mapped; /* true, if at least one section is mapped */
        }
   return i;
 }
@@ -985,18 +985,18 @@ z80_overlay_update (struct obj_section *osect)
 
   /* Update all sections, even if only one was requested.  */
   for (objfile *objfile : current_program_space->objfiles ())
-    for (obj_section *sect : objfile->sections ())
+    for (obj_section &sect : objfile->sections ())
       {
-       if (!section_is_overlay (sect))
+       if (!section_is_overlay (&sect))
          continue;
 
-       asection *bsect = sect->the_bfd_section;
+       asection *bsect = sect.the_bfd_section;
        bfd_vma lma = bfd_section_lma (bsect);
        bfd_vma vma = bfd_section_vma (bsect);
 
        for (int i = 0; i < cache_novly_regions; ++i)
          if (cache_ovly_region_table[i][Z80_VMA] == vma)
-           sect->ovly_mapped =
+           sect.ovly_mapped =
              (cache_ovly_region_table[i][Z80_MAPPED_TO_LMA] == lma);
       }
 }