]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add obj_section::contains method
authorTom Tromey <tom@tromey.com>
Sat, 10 Feb 2024 22:03:18 +0000 (15:03 -0700)
committerTom Tromey <tom@tromey.com>
Tue, 20 Feb 2024 15:52:33 +0000 (08:52 -0700)
I noticed a number of spots checking whether an address is in an
obj_section.  This patch introduces a new method for this and changes
some code to use it.

Regression tested on x86-64 Fedora 38.

Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/minsyms.c
gdb/objfiles.c
gdb/objfiles.h
gdb/printcmd.c
gdb/symfile.c

index 2a43175a170d8e34b9aae8ce13867287d11ce924..6aa2010fb0142f5824a5200bec378da307bdb60f 100644 (file)
@@ -716,7 +716,7 @@ frob_address (struct objfile *objfile, CORE_ADDR pc,
 {
   for (obj_section *iter : objfile->sections ())
     {
-      if (pc >= iter->addr () && pc < iter->endaddr ())
+      if (iter->contains (pc))
        {
          *unrel_addr = unrelocated_addr (pc - iter->offset ());
          return 1;
index bcaae42a30f39bec589eccd08e7da05b5d88207b..d880b9304d27101cdbbbb83f0841422e51809b62 100644 (file)
@@ -1213,7 +1213,7 @@ is_addr_in_objfile (CORE_ADDR addr, const struct objfile *objfile)
       if (section_is_overlay (osect) && !section_is_mapped (osect))
        continue;
 
-      if (osect->addr () <= addr && addr < osect->endaddr ())
+      if (osect->contains (addr))
        return true;
     }
   return false;
index 7ed23224ba808c4831fe0752dc4a8e7e83956ba7..8b8b7182e8716a4dc8ca9e5fcbde67b749d6fcf7 100644 (file)
@@ -394,6 +394,12 @@ struct obj_section
     return this->addr () + bfd_section_size (this->the_bfd_section);
   }
 
+  /* True if ADDR is in this obj_section, false otherwise.  */
+  bool contains (CORE_ADDR addr) const
+  {
+    return addr >= this->addr () && addr < endaddr ();
+  }
+
   /* BFD section pointer */
   struct bfd_section *the_bfd_section;
 
index 43c0f447fa8a6a8671f602c07adf3ea53b6f2eed..63e530e612e20ef760618a9cef0d4ec6a507dc8b 100644 (file)
@@ -1499,7 +1499,7 @@ info_symbol_command (const char *arg, int from_tty)
 
        sect_addr = overlay_mapped_address (addr, osect);
 
-       if (osect->addr () <= sect_addr && sect_addr < osect->endaddr ()
+       if (osect->contains (sect_addr)
            && (msymbol
                = lookup_minimal_symbol_by_pc_section (sect_addr,
                                                       osect).minsym))
index 9d5ce7f6ad293d37896489222af752885f1adb5b..db6d76e78bf58773d599725ec8fff7df914fa778 100644 (file)
@@ -3085,8 +3085,7 @@ pc_in_mapped_range (CORE_ADDR pc, struct obj_section *section)
 {
   if (section_is_overlay (section))
     {
-      if (section->addr () <= pc
-         && pc < section->endaddr ())
+      if (section->contains (pc))
        return true;
     }