]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Restore "ingestion" of .debug_str when writing .debug_names
authorTom Tromey <tom@tromey.com>
Fri, 24 Jan 2025 01:56:51 +0000 (18:56 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 10 Sep 2025 22:05:27 +0000 (16:05 -0600)
When I rewrote the .debug_names writer (commit 91a42a61), I changed
the writer to not import .debug_str into the debug_str_lookup object.

However, a later patch in this series needed this again.  The issue
here was that if a name occurs in the DWARF, and is also allocated,
then there is a race, where the created index depends on which DIE is
read first.  This can cause index-file.exp failures.

This patch restores the old approach, avoiding this problem.  I also
applied a couple of small cleanups to the class.  And, I removed the
old complaint from the "ingestion" function, as this was not
necessary.

Acked-By: Simon Marchi <simon.marchi@efficios.com>
gdb/dwarf2/index-write.c

index bd14cb9eace0bdca8f9fe635aef0979a661ffd79..37e66a59c16defff696e588030792f39b5f074d4 100644 (file)
@@ -757,7 +757,7 @@ public:
                   });
 
        m_name_table_string_offs.push_back_reorder
-         (m_debugstrlookup.lookup (name.c_str ())); /* ??? */
+         (m_debugstrlookup.lookup (name.c_str ()));
        m_name_table_entry_offs.push_back_reorder (m_entry_pool.size ());
 
        for (const cooked_index_entry *entry : these_entries)
@@ -922,10 +922,21 @@ private:
   {
   public:
 
-    /* Object constructor to be called for current DWARF2_PER_BFD.  */
-    debug_str_lookup (dwarf2_per_bfd *per_bfd)
+    /* Object constructor to be called for current DWARF2_PER_BFD.
+       All .debug_str section strings are automatically stored.  */
+    explicit debug_str_lookup (dwarf2_per_bfd *per_bfd)
       : m_per_bfd (per_bfd)
     {
+      gdb_assert (per_bfd->str.readin);
+      const gdb_byte *data = per_bfd->str.buffer;
+      if (data == nullptr)
+       return;
+      while (data < per_bfd->str.buffer + per_bfd->str.size)
+       {
+         const char *const s = reinterpret_cast<const char *> (data);
+         m_str_table.emplace (c_str_view (s), data - per_bfd->str.buffer);
+         data += strlen (s) + 1;
+       }
     }
 
     /* Return offset of symbol name S in the .debug_str section.  Add
@@ -933,13 +944,6 @@ private:
        yet.  */
     size_t lookup (const char *s)
     {
-      /* Most strings will have come from the string table
-        already.  */
-      const gdb_byte *b = (const gdb_byte *) s;
-      if (b >= m_per_bfd->str.buffer
-         && b < m_per_bfd->str.buffer + m_per_bfd->str.size)
-       return b - m_per_bfd->str.buffer;
-
       const auto it = m_str_table.find (c_str_view (s));
       if (it != m_str_table.end ())
        return it->second;