diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2023-01-27 14:46:50 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2023-01-30 10:22:42 -0500 |
commit | 5867ab870b8aa36ae490ec6e4e8e4c55be11ccf1 (patch) | |
tree | c5049320fa15c17055ef6bf20935118170545080 /gdb/addrmap.c | |
parent | 8d31d08fe61059fb94c02ae30c2b7cd0ea738df0 (diff) | |
download | gdb-5867ab870b8aa36ae490ec6e4e8e4c55be11ccf1.zip gdb-5867ab870b8aa36ae490ec6e4e8e4c55be11ccf1.tar.gz gdb-5867ab870b8aa36ae490ec6e4e8e4c55be11ccf1.tar.bz2 |
gdb: provide const-correct versions of addrmap::find and addrmap::foreach
Users of addrmap::find and addrmap::foreach that have a const addrmap
should ideally receive const pointers to objects, to indicate they
should not be modified. However, users that have a non-const addrmap
should still receive a non-const pointer.
To achieve this, without adding more virtual methods, make the existing
find and foreach virtual methods private and prefix them with "do_".
Add small non-const and const wrappers for find and foreach.
Obviously, the const can be cast away, but if using static_cast
instead of C-style casts, then the compiler won't let you cast
the const away. I changed all the callers of addrmap::find and
addrmap::foreach I could find to make them use static_cast.
Change-Id: Ia8e69d022564f80d961413658fe6068edc71a094
Diffstat (limited to 'gdb/addrmap.c')
-rw-r--r-- | gdb/addrmap.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/gdb/addrmap.c b/gdb/addrmap.c index 0a6b2e5..33dc776 100644 --- a/gdb/addrmap.c +++ b/gdb/addrmap.c @@ -40,7 +40,7 @@ addrmap_fixed::set_empty (CORE_ADDR start, CORE_ADDR end_inclusive, void * -addrmap_fixed::find (CORE_ADDR addr) const +addrmap_fixed::do_find (CORE_ADDR addr) const { const struct addrmap_transition *bottom = &transitions[0]; const struct addrmap_transition *top = &transitions[num_transitions - 1]; @@ -82,7 +82,7 @@ addrmap_fixed::relocate (CORE_ADDR offset) int -addrmap_fixed::foreach (addrmap_foreach_fn fn) +addrmap_fixed::do_foreach (addrmap_foreach_fn fn) const { size_t i; @@ -240,7 +240,7 @@ addrmap_mutable::set_empty (CORE_ADDR start, CORE_ADDR end_inclusive, void * -addrmap_mutable::find (CORE_ADDR addr) const +addrmap_mutable::do_find (CORE_ADDR addr) const { splay_tree_node n = splay_tree_lookup (addr); if (n != nullptr) @@ -317,7 +317,7 @@ addrmap_mutable_foreach_worker (splay_tree_node node, void *data) int -addrmap_mutable::foreach (addrmap_foreach_fn fn) +addrmap_mutable::do_foreach (addrmap_foreach_fn fn) const { return splay_tree_foreach (tree, addrmap_mutable_foreach_worker, &fn); } @@ -368,7 +368,7 @@ addrmap_dump (struct addrmap *map, struct ui_file *outfile, void *payload) addrmap entry defines the end of the range). */ bool previous_matched = false; - auto callback = [&] (CORE_ADDR start_addr, void *obj) + auto callback = [&] (CORE_ADDR start_addr, const void *obj) { QUIT; |