Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [pushed] gdb: update blockvector::lookup
@ 2025-11-28 13:49 Jan Vrany
  2025-11-28 13:49 ` [pushed] gdb: change blockvector::contains() to handle blockvectors with "holes" Jan Vrany
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jan Vrany @ 2025-11-28 13:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany, Simon Marchi

This commit changes blockvector::lookup() to improve style and
readability. It also adds quick range check to see if given address
falls into global block.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
---
 gdb/block.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/gdb/block.c b/gdb/block.c
index 98088aa3807..e21580bcf63 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -810,12 +810,17 @@ blockvector::append_block (struct block *block)
 const struct block *
 blockvector::lookup (CORE_ADDR addr) const
 {
-  const struct block *b;
-  int bot, top, half;
+  const CORE_ADDR start = global_block ()->start ();
+  const CORE_ADDR end = global_block ()->end ();
+
+  /* Check if the given address falls into the global block.  If not, this
+     blockvector definitely does not contain any block at ADDR.  */
+  if (addr < start || end <= addr)
+    return nullptr;
 
   /* If we have an addrmap mapping code addresses to blocks, then use
      that.  */
-  if (map ())
+  if (map () != nullptr)
     return (const struct block *) map ()->find (addr);
 
   /* Otherwise, use binary search to find the last block that starts
@@ -824,14 +829,15 @@ blockvector::lookup (CORE_ADDR addr) const
      They both have the same START,END values.
      Historically this code would choose STATIC_BLOCK over GLOBAL_BLOCK but the
      fact that this choice was made was subtle, now we make it explicit.  */
-  gdb_assert (blocks ().size () >= 2);
-  bot = STATIC_BLOCK;
-  top = blocks ().size ();
+  gdb_assert (num_blocks () >= 2);
+
+  int bot = STATIC_BLOCK;
+  int top = num_blocks ();
 
   while (top - bot > 1)
     {
-      half = (top - bot + 1) >> 1;
-      b = block (bot + half);
+      auto half = (top - bot + 1) >> 1;
+      auto b = block (bot + half);
       if (b->start () <= addr)
 	bot += half;
       else
@@ -842,15 +848,15 @@ blockvector::lookup (CORE_ADDR addr) const
 
   while (bot >= STATIC_BLOCK)
     {
-      b = block (bot);
-      if (!(b->start () <= addr))
-	return NULL;
+      auto b = block (bot);
+      if (b->start () > addr)
+	return nullptr;
       if (b->end () > addr)
 	return b;
       bot--;
     }
 
-  return NULL;
+  return nullptr;
 }
 
 /* See block.h.  */
-- 
2.51.0


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

end of thread, other threads:[~2025-12-04 15:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-28 13:49 [pushed] gdb: update blockvector::lookup Jan Vrany
2025-11-28 13:49 ` [pushed] gdb: change blockvector::contains() to handle blockvectors with "holes" Jan Vrany
2025-12-02 17:41   ` Tom Tromey
2025-12-02 21:58     ` Jan Vraný
2025-12-03 19:36       ` Tom Tromey
2025-12-03 21:31         ` Jan Vraný
2025-12-04 11:42           ` Tom de Vries
2025-12-04 15:03             ` Jan Vraný
2025-11-28 13:49 ` [pushed] gdb: add unittests for blockvector lookup functions Jan Vrany
2025-11-28 13:49 ` [pushed] gdb: update is_addr_in_objfile to support "dynamic" objfiles Jan Vrany

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox