From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 0F42D385AE43; Sun, 12 Jun 2022 16:55:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F42D385AE43 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Remove addrmap wrapper functions X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 1b3261edfb7b0c66f538c778a07f0bf2547c906d X-Git-Newrev: 769520b7e5c3a6a941969b3b3c52fa04edf73295 Message-Id: <20220612165546.0F42D385AE43@sourceware.org> Date: Sun, 12 Jun 2022 16:55:46 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Jun 2022 16:55:46 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D769520b7e5c3= a6a941969b3b3c52fa04edf73295 commit 769520b7e5c3a6a941969b3b3c52fa04edf73295 Author: Tom Tromey Date: Sat Apr 16 09:30:53 2022 -0600 Remove addrmap wrapper functions =20 This removes the various addrmap wrapper functions in favor of simple method calls on the objects themselves. Diff: --- gdb/addrmap.c | 60 +++++-------------------- gdb/addrmap.h | 109 +++++++++++++++++++++---------------------= ---- gdb/block.c | 4 +- gdb/buildsym.c | 4 +- gdb/dwarf2/cooked-index.h | 4 +- gdb/dwarf2/index-write.c | 2 +- gdb/dwarf2/read.c | 31 ++++++------- gdb/inline-frame.c | 2 +- gdb/objfiles.c | 2 +- gdb/psymtab.c | 3 +- gdb/symtab.c | 2 +- 11 files changed, 84 insertions(+), 139 deletions(-) diff --git a/gdb/addrmap.c b/gdb/addrmap.c index eddf084d822..b9a787135b8 100644 --- a/gdb/addrmap.c +++ b/gdb/addrmap.c @@ -27,44 +27,6 @@ gdb_static_assert (sizeof (splay_tree_key) >=3D sizeof (CORE_ADDR *)); gdb_static_assert (sizeof (splay_tree_value) >=3D sizeof (void *)); =20 -=0C -void -addrmap_set_empty (struct addrmap *map, - CORE_ADDR start, CORE_ADDR end_inclusive, - void *obj) -{ - map->set_empty (start, end_inclusive, obj); -} - - -void * -addrmap_find (const addrmap *map, CORE_ADDR addr) -{ - return map->find (addr); -} - - -struct addrmap * -addrmap_create_fixed (struct addrmap *original, struct obstack *obstack) -{ - return original->create_fixed (obstack); -} - - -/* Relocate all the addresses in MAP by OFFSET. (This can be applied - to either mutable or immutable maps.) */ -void -addrmap_relocate (struct addrmap *map, CORE_ADDR offset) -{ - map->relocate (offset); -} - - -int -addrmap_foreach (struct addrmap *map, addrmap_foreach_fn fn) -{ - return map->foreach (fn); -} =0C /* Fixed address maps. */ =20 @@ -313,7 +275,7 @@ addrmap_fixed::addrmap_fixed (struct obstack *obstack, = addrmap_mutable *mut) size_t transition_count =3D 0; =20 /* Count the number of transitions in the tree. */ - addrmap_foreach (mut, [&] (CORE_ADDR start, void *obj) + mut->foreach ([&] (CORE_ADDR start, void *obj) { ++transition_count; return 0; @@ -331,7 +293,7 @@ addrmap_fixed::addrmap_fixed (struct obstack *obstack, = addrmap_mutable *mut) =20 /* Copy all entries from the splay tree to the array, in order=20 of increasing address. */ - addrmap_foreach (mut, [&] (CORE_ADDR start, void *obj) + mut->foreach ([&] (CORE_ADDR start, void *obj) { transitions[num_transitions].addr =3D start; transitions[num_transitions].value =3D obj; @@ -482,7 +444,7 @@ addrmap_dump (struct addrmap *map, struct ui_file *outf= ile, void *payload) return 0; }; =20 - addrmap_foreach (map, callback); + map->foreach (callback); } =20 #if GDB_SELF_TEST @@ -502,7 +464,7 @@ core_addr (void *p) do \ { \ for (unsigned i =3D LOW; i <=3D HIGH; ++i) \ - SELF_CHECK (addrmap_find (MAP, core_addr (&ARRAY[i])) =3D=3D VAL); \ + SELF_CHECK (MAP->find (core_addr (&ARRAY[i])) =3D=3D VAL); \ } \ while (0) =20 @@ -528,14 +490,13 @@ test_addrmap () CHECK_ADDRMAP_FIND (map, array, 0, 19, nullptr); =20 /* Insert address range into mutable addrmap. */ - addrmap_set_empty (map, core_addr (&array[10]), core_addr (&array[12]), - val1); + map->set_empty (core_addr (&array[10]), core_addr (&array[12]), val1); CHECK_ADDRMAP_FIND (map, array, 0, 9, nullptr); CHECK_ADDRMAP_FIND (map, array, 10, 12, val1); CHECK_ADDRMAP_FIND (map, array, 13, 19, nullptr); =20 /* Create corresponding fixed addrmap. */ - struct addrmap *map2 =3D addrmap_create_fixed (map, &temp_obstack); + struct addrmap *map2 =3D map->create_fixed (&temp_obstack); SELF_CHECK (map2 !=3D nullptr); CHECK_ADDRMAP_FIND (map2, array, 0, 9, nullptr); CHECK_ADDRMAP_FIND (map2, array, 10, 12, val1); @@ -554,18 +515,17 @@ test_addrmap () SELF_CHECK (false); return 0; }; - SELF_CHECK (addrmap_foreach (map, callback) =3D=3D 0); - SELF_CHECK (addrmap_foreach (map2, callback) =3D=3D 0); + SELF_CHECK (map->foreach (callback) =3D=3D 0); + SELF_CHECK (map2->foreach (callback) =3D=3D 0); =20 /* Relocate fixed addrmap. */ - addrmap_relocate (map2, 1); + map2->relocate (1); CHECK_ADDRMAP_FIND (map2, array, 0, 10, nullptr); CHECK_ADDRMAP_FIND (map2, array, 11, 13, val1); CHECK_ADDRMAP_FIND (map2, array, 14, 19, nullptr); =20 /* Insert partially overlapping address range into mutable addrmap. */ - addrmap_set_empty (map, core_addr (&array[11]), core_addr (&array[13]), - val2); + map->set_empty (core_addr (&array[11]), core_addr (&array[13]), val2); CHECK_ADDRMAP_FIND (map, array, 0, 9, nullptr); CHECK_ADDRMAP_FIND (map, array, 10, 12, val1); CHECK_ADDRMAP_FIND (map, array, 13, 13, val2); diff --git a/gdb/addrmap.h b/gdb/addrmap.h index c530200e4a9..01569d3fa0a 100644 --- a/gdb/addrmap.h +++ b/gdb/addrmap.h @@ -44,11 +44,61 @@ struct addrmap : public allocate_on_obstack { virtual ~addrmap () =3D default; =20 + /* In the mutable address map MAP, associate the addresses from START + to END_INCLUSIVE that are currently associated with NULL with OBJ + instead. Addresses mapped to an object other than NULL are left + unchanged. + + As the name suggests, END_INCLUSIVE is also mapped to OBJ. This + convention is unusual, but it allows callers to accurately specify + ranges that abut the top of the address space, and ranges that + cover the entire address space. + + This operation seems a bit complicated for a primitive: if it's + needed, why not just have a simpler primitive operation that sets a + range to a value, wiping out whatever was there before, and then + let the caller construct more complicated operations from that, + along with some others for traversal? + + It turns out this is the mutation operation we want to use all the + time, at least for now. Our immediate use for address maps is to + represent lexical blocks whose address ranges are not contiguous. + We walk the tree of lexical blocks present in the debug info, and + only create 'struct block' objects after we've traversed all a + block's children. If a lexical block declares no local variables + (and isn't the lexical block for a function's body), we omit it + from GDB's data structures entirely. + + However, this means that we don't decide to create a block (and + thus record it in the address map) until after we've traversed its + children. If we do decide to create the block, we do so at a time + when all its children have already been recorded in the map. So + this operation --- change only those addresses left unset --- is + actually the operation we want to use every time. + + It seems simpler to let the code which operates on the + representation directly deal with the hair of implementing these + semantics than to provide an interface which allows it to be + implemented efficiently, but doesn't reveal too much of the + representation. */ virtual void set_empty (CORE_ADDR start, CORE_ADDR end_inclusive, void *obj) =3D 0; + + /* Return the object associated with ADDR in MAP. */ virtual void *find (CORE_ADDR addr) const =3D 0; + + /* Create a fixed address map which is a copy of this mutable + address map. Allocate entries in OBSTACK. */ virtual struct addrmap *create_fixed (struct obstack *obstack) =3D 0; + + /* Relocate all the addresses in MAP by OFFSET. (This can be applied + to either mutable or immutable maps.) */ virtual void relocate (CORE_ADDR offset) =3D 0; + + /* Call FN for every address in MAP, following an in-order traversal. + If FN ever returns a non-zero value, the iteration ceases + immediately, and the value is returned. Otherwise, this function + returns 0. */ virtual int foreach (addrmap_foreach_fn fn) =3D 0; }; =20 @@ -156,65 +206,6 @@ private: Allocate entries in OBSTACK. */ struct addrmap *addrmap_create_mutable (struct obstack *obstack); =20 -/* In the mutable address map MAP, associate the addresses from START - to END_INCLUSIVE that are currently associated with NULL with OBJ - instead. Addresses mapped to an object other than NULL are left - unchanged. - - As the name suggests, END_INCLUSIVE is also mapped to OBJ. This - convention is unusual, but it allows callers to accurately specify - ranges that abut the top of the address space, and ranges that - cover the entire address space. - - This operation seems a bit complicated for a primitive: if it's - needed, why not just have a simpler primitive operation that sets a - range to a value, wiping out whatever was there before, and then - let the caller construct more complicated operations from that, - along with some others for traversal? - - It turns out this is the mutation operation we want to use all the - time, at least for now. Our immediate use for address maps is to - represent lexical blocks whose address ranges are not contiguous. - We walk the tree of lexical blocks present in the debug info, and - only create 'struct block' objects after we've traversed all a - block's children. If a lexical block declares no local variables - (and isn't the lexical block for a function's body), we omit it - from GDB's data structures entirely. - - However, this means that we don't decide to create a block (and - thus record it in the address map) until after we've traversed its - children. If we do decide to create the block, we do so at a time - when all its children have already been recorded in the map. So - this operation --- change only those addresses left unset --- is - actually the operation we want to use every time. - - It seems simpler to let the code which operates on the - representation directly deal with the hair of implementing these - semantics than to provide an interface which allows it to be - implemented efficiently, but doesn't reveal too much of the - representation. */ -void addrmap_set_empty (struct addrmap *map, - CORE_ADDR start, CORE_ADDR end_inclusive, - void *obj); - -/* Return the object associated with ADDR in MAP. */ -void *addrmap_find (const addrmap *map, CORE_ADDR addr); - -/* Create a fixed address map which is a copy of the mutable address - map ORIGINAL. Allocate entries in OBSTACK. */ -struct addrmap *addrmap_create_fixed (struct addrmap *original, - struct obstack *obstack); - -/* Relocate all the addresses in MAP by OFFSET. (This can be applied - to either mutable or immutable maps.) */ -void addrmap_relocate (struct addrmap *map, CORE_ADDR offset); - -/* Call FN for every address in MAP, following an in-order traversal. - If FN ever returns a non-zero value, the iteration ceases - immediately, and the value is returned. Otherwise, this function - returns 0. */ -int addrmap_foreach (struct addrmap *map, addrmap_foreach_fn fn); - /* Dump the addrmap to OUTFILE. If PAYLOAD is non-NULL, only dump any components that map to PAYLOAD. (If PAYLOAD is NULL, the entire map is dumped.) */ diff --git a/gdb/block.c b/gdb/block.c index 39a39df9454..26126f5b76f 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -138,8 +138,8 @@ find_block_in_blockvector (const struct blockvector *bl= , CORE_ADDR pc) =20 /* If we have an addrmap mapping code addresses to blocks, then use that. */ - if (bl->map () !=3D nullptr) - return (const struct block *) addrmap_find (bl->map (), pc); + if (bl->map ()) + return (const struct block *) bl->map ()->find (pc); =20 /* Otherwise, use binary search to find the last block that starts before PC. diff --git a/gdb/buildsym.c b/gdb/buildsym.c index c54e6586ced..f057f5c4b3f 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -421,7 +421,7 @@ buildsym_compunit::record_block_range (struct block *bl= ock, if (m_pending_addrmap =3D=3D nullptr) m_pending_addrmap =3D addrmap_create_mutable (&m_pending_addrmap_obsta= ck); =20 - addrmap_set_empty (m_pending_addrmap, start, end_inclusive, block); + m_pending_addrmap->set_empty (start, end_inclusive, block); } =20 struct blockvector * @@ -458,7 +458,7 @@ buildsym_compunit::make_blockvector () blockvector. */ if (m_pending_addrmap !=3D nullptr && m_pending_addrmap_interesting) blockvector->set_map - (addrmap_create_fixed (m_pending_addrmap, &m_objfile->objfile_obstac= k)); + (m_pending_addrmap->create_fixed (&m_objfile->objfile_obstack)); else blockvector->set_map (nullptr); =20 diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 4e65e9d0c61..4fc2a9411d4 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -188,7 +188,7 @@ public: void install_addrmap (addrmap *map) { gdb_assert (m_addrmap =3D=3D nullptr); - m_addrmap =3D addrmap_create_fixed (map, &m_storage); + m_addrmap =3D map->create_fixed (&m_storage); } =20 /* Finalize the index. This should be called a single time, when @@ -233,7 +233,7 @@ private: found. */ dwarf2_per_cu_data *lookup (CORE_ADDR addr) { - return (dwarf2_per_cu_data *) addrmap_find (m_addrmap, addr); + return (dwarf2_per_cu_data *) m_addrmap->find (addr); } =20 /* Create a new cooked_index_entry and register it with this object. diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index dfa74ddad8e..7f8df0ba8a1 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -479,7 +479,7 @@ write_address_map (struct addrmap *addrmap, data_buf &a= ddr_vec, { struct addrmap_index_data addrmap_index_data (addr_vec, cu_index_htab); =20 - addrmap_foreach (addrmap, addrmap_index_data); + addrmap->foreach (addrmap_index_data); =20 /* It's highly unlikely the last entry (end address =3D 0xff...ff) is valid, but we should still handle it. diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 696277d931a..2af1a49f45d 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2305,12 +2305,10 @@ create_addrmap_from_index (dwarf2_per_objfile *per_= objfile, =20 lo =3D gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr) - baseadd= r; hi =3D gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr) - baseadd= r; - addrmap_set_empty (mutable_map, lo, hi - 1, - per_bfd->get_cu (cu_index)); + mutable_map->set_empty (lo, hi - 1, per_bfd->get_cu (cu_index)); } =20 - per_bfd->index_addrmap =3D addrmap_create_fixed (mutable_map, - &per_bfd->obstack); + per_bfd->index_addrmap =3D mutable_map->create_fixed (&per_bfd->obstack); } =20 /* Read the address map data from DWARF-5 .debug_aranges, and use it @@ -2479,7 +2477,7 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_ob= jfile, - baseaddr); end =3D (gdbarch_adjust_dwarf2_addr (gdbarch, end + baseaddr) - baseaddr); - addrmap_set_empty (mutable_map, start, end - 1, per_cu); + mutable_map->set_empty (start, end - 1, per_cu); } =20 per_cu->addresses_seen =3D true; @@ -2501,8 +2499,7 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_= objfile, addrmap *mutable_map =3D addrmap_create_mutable (&temp_obstack); =20 if (read_addrmap_from_aranges (per_objfile, section, mutable_map)) - per_bfd->index_addrmap =3D addrmap_create_fixed (mutable_map, - &per_bfd->obstack); + per_bfd->index_addrmap =3D mutable_map->create_fixed (&per_bfd->obstac= k); } =20 /* A helper function that reads the .gdb_index from BUFFER and fills @@ -4254,8 +4251,8 @@ dwarf2_base_index_functions::find_per_cu (dwarf2_per_= bfd *per_bfd, { if (per_bfd->index_addrmap =3D=3D nullptr) return nullptr; - return (struct dwarf2_per_cu_data *) addrmap_find (per_bfd->index_addrma= p, - adjusted_pc); + return ((struct dwarf2_per_cu_data *) + per_bfd->index_addrmap->find (adjusted_pc)); } =20 struct compunit_symtab * @@ -12931,7 +12928,7 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low= _return, highpc =3D (gdbarch_adjust_dwarf2_addr (gdbarch, range_end + baseaddr) - baseaddr); - addrmap_set_empty (map, lowpc, highpc - 1, datum); + map->set_empty (lowpc, highpc - 1, datum); } =20 /* FIXME: This is recording everything as a low-high @@ -17893,8 +17890,7 @@ cooked_indexer::check_bounds (cutu_reader *reader) - baseaddr - 1); /* Store the contiguous range if it is not empty; it can be empty for CUs with no code. */ - addrmap_set_empty (m_index_storage->get_addrmap (), low, high, - cu->per_cu); + m_index_storage->get_addrmap ()->set_empty (low, high, cu->per_cu); =20 cu->per_cu->addresses_seen =3D true; } @@ -18146,8 +18142,7 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data= *scanning_per_cu, { CORE_ADDR lookup =3D form_addr (origin_offset, origin_is_dwz); *parent_entry - =3D (cooked_index_entry *) addrmap_find (m_die_range_map, - lookup); + =3D (cooked_index_entry *) m_die_range_map->find (lookup); } =20 unsigned int bytes_read; @@ -18187,8 +18182,8 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data= *scanning_per_cu, CORE_ADDR hi =3D (gdbarch_adjust_dwarf2_addr (gdbarch, *high_pc + baseaddr) - baseaddr); - addrmap_set_empty (m_index_storage->get_addrmap (), lo, hi - 1, - scanning_per_cu); + m_index_storage->get_addrmap ()->set_empty (lo, hi - 1, + scanning_per_cu); } } =20 @@ -18264,7 +18259,7 @@ cooked_indexer::recurse (cutu_reader *reader, reader->cu->per_cu->is_dwz); CORE_ADDR end =3D form_addr (sect_offset (info_ptr - 1 - reader->buf= fer), reader->cu->per_cu->is_dwz); - addrmap_set_empty (m_die_range_map, start, end, (void *) parent_entr= y); + m_die_range_map->set_empty (start, end, (void *) parent_entry); } =20 return info_ptr; @@ -18437,7 +18432,7 @@ cooked_indexer::make_index (cutu_reader *reader) { CORE_ADDR key =3D form_addr (entry.die_offset, m_per_cu->is_dwz); cooked_index_entry *parent - =3D (cooked_index_entry *) addrmap_find (m_die_range_map, key); + =3D (cooked_index_entry *) m_die_range_map->find (key); m_index_storage->add (entry.die_offset, entry.tag, entry.flags, entry.name, parent, m_per_cu); } diff --git a/gdb/inline-frame.c b/gdb/inline-frame.c index 57b58f38c22..5cb6776aaff 100644 --- a/gdb/inline-frame.c +++ b/gdb/inline-frame.c @@ -289,7 +289,7 @@ block_starting_point_at (CORE_ADDR pc, const struct blo= ck *block) if (bv->map () =3D=3D nullptr) return 0; =20 - new_block =3D (const struct block *) addrmap_find (bv->map (), pc - 1); + new_block =3D (const struct block *) bv->map ()->find (pc - 1); if (new_block =3D=3D NULL) return 1; =20 diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 4fc859f185a..f4625575473 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -666,7 +666,7 @@ objfile_relocate1 (struct objfile *objfile, int block_line_section =3D cust->block_line_section (); =20 if (bv->map () !=3D nullptr) - addrmap_relocate (bv->map (), delta[block_line_section]); + bv->map ()->relocate (delta[block_line_section]); =20 for (block *b : bv->blocks ()) { diff --git a/gdb/psymtab.c b/gdb/psymtab.c index e6c9526cc4f..bf8a7432186 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -190,8 +190,7 @@ psymbol_functions::find_pc_sect_psymtab (struct objfile= *objfile, =20 struct partial_symtab *pst =3D ((struct partial_symtab *) - addrmap_find (m_partial_symtabs->psymtabs_addrmap, - pc - baseaddr)); + m_partial_symtabs->psymtabs_addrmap->find (pc - baseaddr)); if (pst !=3D NULL) { /* FIXME: addrmaps currently do not handle overlayed sections, diff --git a/gdb/symtab.c b/gdb/symtab.c index 8564986f66d..03aa2a96b87 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2946,7 +2946,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct ob= j_section *section) =20 if (bv->map () !=3D nullptr) { - if (addrmap_find (bv->map (), pc) =3D=3D nullptr) + if (bv->map ()->find (pc) =3D=3D nullptr) continue; =20 return cust;