From: Simon Marchi Date: Sun, 9 Feb 2025 05:51:02 +0000 (-0500) Subject: gdb/dwarf: allow for cooked_index_shard::m_addrmap to be nullptr X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=de33cf88daf58cf8322867389afa9bcf3e377696;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf: allow for cooked_index_shard::m_addrmap to be nullptr The following patch makes the .debug_names reader create multiple cooked index shards, only one of them having an address map. The others will have a nullptr address map. Change the code using cooked_index_shard::m_addrmap to account for the fact that it can be nullptr. Change-Id: Id05b974e661d901dd43bb5ecb3a8fcfc15abc7ed Approved-By: Tom Tromey --- diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 2d9f6e904ca..e09be98ea8e 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -841,12 +841,15 @@ cooked_index::dump (gdbarch *arch) std::vector addrmaps = this->get_addrmaps (); for (i = 0; i < addrmaps.size (); ++i) { - const addrmap &addrmap = *addrmaps[i]; + const addrmap *addrmap = addrmaps[i]; - gdb_printf (" [%zu] ((addrmap *) %p)\n", i, &addrmap); + gdb_printf (" [%zu] ((addrmap *) %p)\n", i, addrmap); gdb_printf ("\n"); - addrmap.foreach ([arch] (CORE_ADDR start_addr, const void *obj) + if (addrmap == nullptr) + continue; + + addrmap->foreach ([arch] (CORE_ADDR start_addr, const void *obj) { QUIT; diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index fc29bfdec62..191e8243c2c 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -319,6 +319,9 @@ private: found. */ dwarf2_per_cu_data *lookup (unrelocated_addr addr) { + if (m_addrmap == nullptr) + return nullptr; + return (static_cast (m_addrmap->find ((CORE_ADDR) addr))); } @@ -669,7 +672,9 @@ public: dwarf2_per_cu_data *lookup (unrelocated_addr addr) override; /* Return a new vector of all the addrmaps used by all the indexes - held by this object. */ + held by this object. + + Elements of the vector may be nullptr. */ std::vector get_addrmaps (); /* Return the entry that is believed to represent the program's diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 9087adde4f2..f36f388cfa4 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1358,7 +1358,8 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table, /* Dump the address map. */ data_buf addr_vec; for (auto map : table->get_addrmaps ()) - write_address_map (map, addr_vec, cu_index_htab); + if (map != nullptr) + write_address_map (map, addr_vec, cu_index_htab); /* Ensure symbol hash is built domestically. */ symtab.sort ();