From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>,
Simon Marchi <simon.marchi@efficios.com>
Subject: [pushed] gdb: update blockvector::lookup
Date: Fri, 28 Nov 2025 13:49:47 +0000 [thread overview]
Message-ID: <20251128134950.1763596-1-jan.vrany@labware.com> (raw)
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
next reply other threads:[~2025-11-28 13:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-28 13:49 Jan Vrany [this message]
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
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=20251128134950.1763596-1-jan.vrany@labware.com \
--to=jan.vrany@labware.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.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