]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: allow for cooked_index_shard::m_addrmap to be nullptr
authorSimon Marchi <simon.marchi@polymtl.ca>
Sun, 9 Feb 2025 05:51:02 +0000 (00:51 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 10 Feb 2025 16:28:56 +0000 (11:28 -0500)
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 <tom@tromey.com>
gdb/dwarf2/cooked-index.c
gdb/dwarf2/cooked-index.h
gdb/dwarf2/index-write.c

index 2d9f6e904ca72d5241bdcabdaea4b06955034ffc..e09be98ea8e62c23ab49865c20c2898ed58b4c6e 100644 (file)
@@ -841,12 +841,15 @@ cooked_index::dump (gdbarch *arch)
   std::vector<const addrmap *> 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;
 
index fc29bfdec620d27bc1288641badd3feffc1517d4..191e8243c2c6bb238bd61363a2e011843b717e77 100644 (file)
@@ -319,6 +319,9 @@ private:
      found.  */
   dwarf2_per_cu_data *lookup (unrelocated_addr addr)
   {
+    if (m_addrmap == nullptr)
+      return nullptr;
+
     return (static_cast<dwarf2_per_cu_data *>
            (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<const addrmap *> get_addrmaps ();
 
   /* Return the entry that is believed to represent the program's
index 9087adde4f2c70d352a2bf1b12ff18c81ef5e0ec..f36f388cfa47466e5f03bb037a9f29128e00f142 100644 (file)
@@ -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 ();