From a6862c3322ca7575a251ab7e89a00d67e7580035 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 23 Jan 2025 18:56:51 -0700 Subject: Restore "ingestion" of .debug_str when writing .debug_names 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 --- gdb/dwarf2/index-write.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index bd14cb9..37e66a5 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -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 (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; -- cgit v1.1