public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add obj_section::contains method
@ 2024-02-16  4:12 Tom Tromey
  2024-02-20 12:21 ` Andrew Burgess
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2024-02-16  4:12 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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.
---
 gdb/minsyms.c  | 2 +-
 gdb/objfiles.c | 2 +-
 gdb/objfiles.h | 6 ++++++
 gdb/printcmd.c | 2 +-
 gdb/symfile.c  | 3 +--
 5 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 1b85424586f..543003f3bb9 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -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;
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index bcaae42a30f..d880b9304d2 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -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;
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 98e2355f7a9..13cc78e17e3 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -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;
 
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 7f47f489a94..679323c61cb 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -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))
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 9d5ce7f6ad2..db6d76e78bf 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -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;
     }
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Add obj_section::contains method
  2024-02-16  4:12 [PATCH] Add obj_section::contains method Tom Tromey
@ 2024-02-20 12:21 ` Andrew Burgess
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Burgess @ 2024-02-20 12:21 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches; +Cc: Tom Tromey

Tom Tromey <tom@tromey.com> writes:

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

LGTM.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew


>
> Regression tested on x86-64 Fedora 38.
> ---
>  gdb/minsyms.c  | 2 +-
>  gdb/objfiles.c | 2 +-
>  gdb/objfiles.h | 6 ++++++
>  gdb/printcmd.c | 2 +-
>  gdb/symfile.c  | 3 +--
>  5 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/gdb/minsyms.c b/gdb/minsyms.c
> index 1b85424586f..543003f3bb9 100644
> --- a/gdb/minsyms.c
> +++ b/gdb/minsyms.c
> @@ -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;
> diff --git a/gdb/objfiles.c b/gdb/objfiles.c
> index bcaae42a30f..d880b9304d2 100644
> --- a/gdb/objfiles.c
> +++ b/gdb/objfiles.c
> @@ -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;
> diff --git a/gdb/objfiles.h b/gdb/objfiles.h
> index 98e2355f7a9..13cc78e17e3 100644
> --- a/gdb/objfiles.h
> +++ b/gdb/objfiles.h
> @@ -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;
>  
> diff --git a/gdb/printcmd.c b/gdb/printcmd.c
> index 7f47f489a94..679323c61cb 100644
> --- a/gdb/printcmd.c
> +++ b/gdb/printcmd.c
> @@ -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))
> diff --git a/gdb/symfile.c b/gdb/symfile.c
> index 9d5ce7f6ad2..db6d76e78bf 100644
> --- a/gdb/symfile.c
> +++ b/gdb/symfile.c
> @@ -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;
>      }
>  
> -- 
> 2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-20 12:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-16  4:12 [PATCH] Add obj_section::contains method Tom Tromey
2024-02-20 12:21 ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).