From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 3/5] [gdb] Extend addrmap::find with low/high results
Date: Mon, 21 Sep 2026 22:55:55 +0200 [thread overview]
Message-ID: <20260921205557.2706300-4-tdevries@suse.de> (raw)
In-Reply-To: <20260921205557.2706300-1-tdevries@suse.de>
An addrmap contains a mapping from CORE_ADDR to void *.
The function addrmap::find:
...
void *find (CORE_ADDR addr)
...
returns a void * for a given addr, but doesn't gives us an answer about the
range of addresses containing addr for which it would return the same value.
Add a alternative using parameters low/high:
...
void *find (CORE_ADDR addr, CORE_ADDR *low, CORE_ADDR *high)
...
---
gdb/addrmap.c | 78 +++++++++++++++++++++++++++++++++++++++++++++------
gdb/addrmap.h | 23 ++++++++++-----
2 files changed, 86 insertions(+), 15 deletions(-)
diff --git a/gdb/addrmap.c b/gdb/addrmap.c
index a311592c3bb..cc98ece6f3f 100644
--- a/gdb/addrmap.c
+++ b/gdb/addrmap.c
@@ -31,7 +31,7 @@ static_assert (sizeof (splay_tree_value) >= sizeof (void *));
/* Fixed address maps. */
void *
-addrmap_fixed::do_find (CORE_ADDR addr) const
+addrmap_fixed::do_find (CORE_ADDR addr, CORE_ADDR *low, CORE_ADDR *high) const
{
const struct addrmap_transition *bottom = &transitions[0];
const struct addrmap_transition *top = &transitions[num_transitions - 1];
@@ -58,6 +58,12 @@ addrmap_fixed::do_find (CORE_ADDR addr) const
top = mid - 1;
}
+ if (low != nullptr)
+ *low = bottom->addr;
+ if (high != nullptr)
+ *high = (bottom == &transitions[num_transitions - 1]
+ ? (CORE_ADDR)-1
+ : (bottom + 1)->addr - 1);
return bottom->value;
}
@@ -119,7 +125,7 @@ addrmap_mutable::splay_tree_predecessor (CORE_ADDR addr) const
splay_tree_node
-addrmap_mutable::splay_tree_successor (CORE_ADDR addr)
+addrmap_mutable::splay_tree_successor (CORE_ADDR addr) const
{
return ::splay_tree_successor (tree, (splay_tree_key) &addr);
}
@@ -266,25 +272,54 @@ addrmap_mutable::set_empty (CORE_ADDR start, CORE_ADDR end_inclusive,
void *
-addrmap_mutable::do_find (CORE_ADDR addr) const
+addrmap_mutable::do_find (CORE_ADDR addr, CORE_ADDR *low, CORE_ADDR *high) const
{
if (tree == nullptr)
- return nullptr;
+ {
+ if (low)
+ *low = 0;
+ if (high)
+ *high = (CORE_ADDR)-1;
+ return nullptr;
+ }
+
+ auto return_value = [this, &low, &high] (splay_tree_node &n)
+ {
+ if (low)
+ *low = addrmap_node_key (n);
+ if (high)
+ {
+ splay_tree_node succ = splay_tree_successor (addrmap_node_key (n));
+ if (succ != nullptr)
+ *high = addrmap_node_key (succ) - 1;
+ else
+ *high = (CORE_ADDR)-1;
+ }
+ return addrmap_node_value (n);
+ };
splay_tree_node n = splay_tree_lookup (addr);
if (n != nullptr)
{
gdb_assert (addrmap_node_key (n) == addr);
- return addrmap_node_value (n);
+ return return_value (n);
}
n = splay_tree_predecessor (addr);
if (n != nullptr)
{
gdb_assert (addrmap_node_key (n) < addr);
- return addrmap_node_value (n);
+ return return_value (n);
}
+ if (low != nullptr)
+ *low = 0;
+ if (high != nullptr)
+ {
+ splay_tree_node succ = splay_tree_successor (addr);
+ gdb_assert (succ != nullptr);
+ *high = addrmap_node_key (succ) - 1;
+ }
return nullptr;
}
@@ -436,10 +471,22 @@ test_addrmap ()
/* Create mutable addrmap. */
auto_obstack temp_obstack;
addrmap_mutable map;
+ addrmap_fixed *map2;
/* Check initial state. */
check_addrmap_find (map, array, 0, 19, nullptr);
+ CORE_ADDR low, high;
+ {
+ map2 = new (&temp_obstack) addrmap_fixed (&temp_obstack, &map);
+ for (addrmap *m : {(addrmap *)&map, (addrmap *)map2})
+ {
+ SELF_CHECK (m->find (core_addr (&array[0]), &low, &high) == nullptr);
+ SELF_CHECK (low == 0 && high == (CORE_ADDR)-1);
+ }
+ delete map2;
+ }
+
/* Insert address range into mutable addrmap. */
bool full_range_p
= map.set_empty (core_addr (&array[10]), core_addr (&array[12]), val1);
@@ -449,8 +496,7 @@ test_addrmap ()
check_addrmap_find (map, array, 13, 19, nullptr);
/* Create corresponding fixed addrmap. */
- addrmap_fixed *map2
- = new (&temp_obstack) addrmap_fixed (&temp_obstack, &map);
+ map2 = new (&temp_obstack) addrmap_fixed (&temp_obstack, &map);
SELF_CHECK (map2 != nullptr);
check_addrmap_find (*map2, array, 0, 9, nullptr);
check_addrmap_find (*map2, array, 10, 12, val1);
@@ -472,6 +518,22 @@ test_addrmap ()
SELF_CHECK (map.foreach (callback) == 0);
SELF_CHECK (map2->foreach (callback) == 0);
+ for (addrmap *m : {(addrmap *)&map, (addrmap *)map2})
+ {
+ SELF_CHECK (m->find (core_addr (&array[0]), &low, &high) == nullptr);
+ SELF_CHECK (low == 0 && high == core_addr (&array[9]));
+
+ for (int i = 10; i <= 12; i++)
+ {
+ m->find (core_addr (&array[i]), &low, &high);
+ SELF_CHECK (low == core_addr (&array[10])
+ && high == core_addr (&array[12]));
+ }
+
+ SELF_CHECK (m->find (core_addr (&array[19]), &low, &high) == nullptr);
+ SELF_CHECK (low == core_addr (&array[13]) && high == (CORE_ADDR)-1);
+ }
+
/* Relocate fixed addrmap. */
map2->relocate (1);
check_addrmap_find (*map2, array, 0, 10, nullptr);
diff --git a/gdb/addrmap.h b/gdb/addrmap.h
index a702341ef8f..029f58133c3 100644
--- a/gdb/addrmap.h
+++ b/gdb/addrmap.h
@@ -45,12 +45,18 @@ using addrmap_foreach_const_fn
/* The base class for addrmaps. */
struct addrmap
{
- /* Return the object associated with ADDR in MAP. */
+ /* Return the object associated with ADDR in MAP. If LOW and HIGH are
+ non-nullptr, use them to return the range associated with ADDR. */
+ const void *find (CORE_ADDR addr, CORE_ADDR *low,
+ CORE_ADDR *high) const
+ { return this->do_find (addr, low, high); }
const void *find (CORE_ADDR addr) const
- { return this->do_find (addr); }
+ { return this->do_find (addr, nullptr, nullptr); }
+ void *find (CORE_ADDR addr, CORE_ADDR *low, CORE_ADDR *high)
+ { return this->do_find (addr, low, high); }
void *find (CORE_ADDR addr)
- { return this->do_find (addr); }
+ { return this->do_find (addr, nullptr, nullptr); }
/* Call FN for every address in MAP, following an in-order traversal.
If FN ever returns a non-zero value, the iteration ceases
@@ -68,7 +74,8 @@ struct addrmap
private:
/* Worker for find, implemented by sub-classes. */
- virtual void *do_find (CORE_ADDR addr) const = 0;
+ virtual void *do_find (CORE_ADDR addr, CORE_ADDR *low,
+ CORE_ADDR *high) const = 0;
/* Worker for foreach, implemented by sub-classes. */
virtual int do_foreach (addrmap_foreach_fn fn) const = 0;
@@ -94,7 +101,8 @@ struct addrmap_fixed final : public addrmap,
void relocate (CORE_ADDR offset);
private:
- void *do_find (CORE_ADDR addr) const override;
+ void *do_find (CORE_ADDR addr, CORE_ADDR *low,
+ CORE_ADDR *high) const override;
int do_foreach (addrmap_foreach_fn fn) const override;
/* A transition: a point in an address map where the value changes.
@@ -193,7 +201,8 @@ struct addrmap_mutable final : public addrmap
void clear ();
private:
- void *do_find (CORE_ADDR addr) const override;
+ void *do_find (CORE_ADDR addr, CORE_ADDR *low,
+ CORE_ADDR *high) const override;
int do_foreach (addrmap_foreach_fn fn) const override;
/* A splay tree, with a node for each transition; there is a
@@ -220,7 +229,7 @@ struct addrmap_mutable final : public addrmap
void force_transition (CORE_ADDR addr);
splay_tree_node splay_tree_lookup (CORE_ADDR addr) const;
splay_tree_node splay_tree_predecessor (CORE_ADDR addr) const;
- splay_tree_node splay_tree_successor (CORE_ADDR addr);
+ splay_tree_node splay_tree_successor (CORE_ADDR addr) const;
void splay_tree_remove (CORE_ADDR addr);
void splay_tree_insert (CORE_ADDR key, void *value);
};
--
2.51.0
next prev parent reply other threads:[~2026-09-21 20:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 20:55 [PATCH v3 0/5] [gdb/tui] Some section hole handling fixes Tom de Vries
2026-09-21 20:55 ` [PATCH v3 1/5] [gdb] Factor out update_section_map Tom de Vries
2026-09-21 20:55 ` [PATCH v3 2/5] [gdb] Add section_addrmap Tom de Vries
2026-09-21 20:55 ` Tom de Vries [this message]
2026-09-21 20:55 ` [PATCH v3 4/5] [gdb] Handle sections when disassembling Tom de Vries
2026-09-21 20:55 ` [PATCH v3 5/5] [gdb] Don't stop disassembly at section hole Tom de Vries
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=20260921205557.2706300-4-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/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