Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>, Tom Tromey <tom@tromey.com>
Subject: [RFC v5 02/18] gdb: introduce compunit_symtab::maybe_contains
Date: Mon, 23 Jun 2025 17:09:57 +0100	[thread overview]
Message-ID: <20250623161013.650814-3-jan.vrany@labware.com> (raw)
In-Reply-To: <20250623161013.650814-1-jan.vrany@labware.com>

This commit introduces new method - compunit_symtab::maybe_contains -
returning true if a compunit_symtab may contain given address or false
if it definitely cannot. This means, compunit_symtab::maybe_contains
may return true even if in fact the compunit does not contain the
address.

This may happen for native ecoff format, as described in a comment in
find_pc_sect_compunit_symtab (symtab.c).

The second case described in that command (when objfiles that have their
functions reordered) should be handled, in that DWARF reader sets
blockvector's map accordingly and maybe_contains consults that map.

Approved-By: Tom Tromey <tom@tromey.com>
---
 gdb/block.c  | 23 +++++++++++++++++++++++
 gdb/block.h  |  4 ++++
 gdb/symtab.c | 26 ++++++++++++--------------
 gdb/symtab.h |  4 ++++
 4 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/gdb/block.c b/gdb/block.c
index fdf209c86a2..54d768d7255 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -821,6 +821,29 @@ make_blockranges (struct objfile *objfile,
   return blr;
 }
 
+/* See block.h.  */
+
+bool blockvector::maybe_contains (CORE_ADDR addr) const
+{
+  const CORE_ADDR start = global_block ()->start ();
+  const CORE_ADDR end = global_block ()->end ();
+
+  /* Check if given address falls into global block.  If not, this compunit
+     definitely does not contain ADDR.  */
+  if (addr < start || end <= addr)
+    return false;
+
+  /* A compunit may span over multiple disjoint regions (see comment in
+     find_pc_sect_compunit_symtab).  DWARF reader sets address map mapping
+     addresses to blocks.  So if the map is set and there is no block
+     mapped at ADDR, this compunit definitely does not contain ADDR.  */
+  if (map () != nullptr && map ()->find (addr) == nullptr)
+    return false;
+
+  /* Otherwise, this compunit may or may not contain ADDR.  */
+  return true;
+}
+
 /* Implement 'maint info blocks' command.  If passed an argument then
    print a list of all blocks at the given address.  With no arguments
    then list all blocks at the current address of the current inferior.  */
diff --git a/gdb/block.h b/gdb/block.h
index 76fa203697c..4a962eff30e 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -483,6 +483,10 @@ struct blockvector
   void set_map (addrmap_fixed *map)
   { m_map = map; }
 
+  /* True if this blockvector contains block at ADDR, false if
+     it definitely does not.  */
+  bool maybe_contains (CORE_ADDR addr) const;
+
 private:
   /* An address map mapping addresses to blocks in this blockvector.
      This pointer is zero if the blocks' start and end addresses are
diff --git a/gdb/symtab.c b/gdb/symtab.c
index b2de990143d..506e21eeac4 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -529,6 +529,14 @@ compunit_symtab::forget_cached_source_info ()
 
 /* See symtab.h.  */
 
+bool
+compunit_symtab::maybe_contains (CORE_ADDR addr) const
+{
+  return this->blockvector ()->maybe_contains (addr);
+}
+
+/* See symtab.h.  */
+
 void
 compunit_symtab::finalize ()
 {
@@ -2931,23 +2939,13 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
     {
       for (compunit_symtab *cust : obj_file->compunits ())
 	{
-	  const struct blockvector *bv = cust->blockvector ();
-	  const struct block *global_block = bv->global_block ();
-	  CORE_ADDR start = global_block->start ();
-	  CORE_ADDR end = global_block->end ();
-	  bool in_range_p = start <= pc && pc < end;
-	  if (!in_range_p)
+	  if (!cust->maybe_contains (pc))
 	    continue;
 
-	  if (bv->map () != nullptr)
-	    {
-	      if (bv->map ()->find (pc) == nullptr)
-		continue;
-
-	      return cust;
-	    }
+	  const struct blockvector *bv = cust->blockvector ();
+	  CORE_ADDR range =
+	    bv->global_block ()->end () - bv->global_block ()->start ();
 
-	  CORE_ADDR range = end - start;
 	  if (best_cust != nullptr
 	      && range >= best_cust_range)
 	    /* Cust doesn't have a smaller range than best_cust, skip it.  */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 0a57be5ed80..7f084cef691 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1963,6 +1963,10 @@ struct compunit_symtab
      compunit_symtab objects are allocated on an obstack.  */
   void finalize ();
 
+  /* True if ADDR may be in this compunit_symtab, false if
+     definitely is not.  */
+  bool maybe_contains (CORE_ADDR addr) const;
+
   /* Unordered chain of all compunit symtabs of this objfile.  */
   struct compunit_symtab *next;
 
-- 
2.47.2


  parent reply	other threads:[~2025-06-23 16:13 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-23 16:09 [RFC v5 00/19] Add Python "JIT" API Jan Vrany
2025-06-23 16:09 ` [RFC v5 01/18] gdb: introduce expand_symtabs_maybe_overlapping Jan Vrany
2025-06-24 15:22   ` Tom Tromey
2025-06-26 15:05     ` Jan Vraný
2025-06-23 16:09 ` Jan Vrany [this message]
2025-06-23 16:09 ` [RFC v5 03/18] gdb: update is_addr_in_objfile to support "dynamic" objfiles Jan Vrany
2025-06-23 16:09 ` [RFC v5 04/18] gdb: introduce new function create_function_type Jan Vrany
2025-06-24 15:29   ` Tom Tromey
2025-06-26 11:12     ` Jan Vraný
2025-06-27 14:21       ` Tom Tromey
2025-06-27 14:30         ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 05/18] gdb/python: add function () method to gdb.Type object Jan Vrany
2025-06-24 16:11   ` Tom Tromey
2025-06-26 11:13     ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 06/18] gdb: use std::vector<> to hold on blocks in struct blockvector Jan Vrany
2025-06-23 16:10 ` [RFC v5 07/18] gdb/python: add gdb.Compunit Jan Vrany
2025-06-23 16:10 ` [RFC v5 08/18] gdb/python: allow instantiation of gdb.Objfile from Python Jan Vrany
2025-06-23 16:10 ` [RFC v5 09/18] gdb/python: add unlink () method to gdb.Objfile object Jan Vrany
2025-06-23 16:10 ` [RFC v5 10/18] gdb/python: allow instantiation of gdb.Compunit from Python Jan Vrany
2025-06-23 16:10 ` [RFC v5 11/18] gdb/python: allow instantiation of gdb.Symtab " Jan Vrany
2025-06-23 16:10 ` [RFC v5 12/18] gdb/python: allow instantiation of gdb.Block " Jan Vrany
2025-06-23 16:10 ` [RFC v5 13/18] gdb/python: allow instantiation of gdb.Symbol " Jan Vrany
2025-06-23 16:10 ` [RFC v5 14/18] gdb/python: add add_symbol () method to gdb.Block Jan Vrany
2025-08-29 14:10   ` Andrew Burgess
2025-08-29 14:14     ` Andrew Burgess
2025-06-23 16:10 ` [RFC v5 15/18] gdb/python: add more attributes to gdb.LinetableEntry objects Jan Vrany
2025-08-29 14:00   ` Andrew Burgess
2025-09-02 11:03     ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 16/18] gdb/python: allow instantiation of gdb.LineTableEntry objects Jan Vrany
2025-06-23 16:10 ` [RFC v5 17/18] gdb/python: allow instantiation of gdb.LineTable objects Jan Vrany
2025-06-23 16:10 ` [RFC v5 18/18] gdb/python: add section in documentation on implementing JIT interface Jan Vrany

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250623161013.650814-3-jan.vrany@labware.com \
    --to=jan.vrany@labware.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox