Fix .debug_names regression with new indexer

At AdaCore, we run the internal gdb test suite in several modes,
including one using the .debug_names index.  This caught a regression
caused by the new DWARF indexer.

First, the psymtabs-based .debug_names generator was completely wrong.
However, to avoid making the rewrite series even bigger (fixing the
writer will also require rewriting the .debug_names reader), it
attempted to preserve the weirdness.

However, this was not done properly.  For example the old writer did
this:

-      case STRUCT_DOMAIN:
-	return DW_TAG_structure_type;

The new code, instead, simply preserves the actual DWARF tag -- but
this makes future lookups fail, because the .debug_names reader only
looks for DW_TAG_structure_type.

This patch attempts to revert to the old behavior in the writer.
This commit is contained in:
Tom Tromey
2022-04-21 07:28:56 -06:00
parent 225170409b
commit 446fcb446f
3 changed files with 85 additions and 3 deletions

View File

@@ -37,6 +37,7 @@
#include "gdbcmd.h"
#include "objfiles.h"
#include "ada-lang.h"
#include "dwarf2/tag.h"
#include <algorithm>
#include <cmath>
@@ -569,7 +570,18 @@ public:
const auto it = m_cu_index_htab.find (entry->per_cu);
gdb_assert (it != m_cu_index_htab.cend ());
const char *name = entry->full_name (&m_string_obstack);
insert (entry->tag, name, it->second, (entry->flags & IS_STATIC) != 0,
/* This is incorrect but it mirrors gdb's historical behavior; and
because the current .debug_names generation is also incorrect,
it seems better to follow what was done before, rather than
introduce a mismatch between the newer and older gdb. */
dwarf_tag tag = entry->tag;
if (tag != DW_TAG_typedef && tag_is_type (tag))
tag = DW_TAG_structure_type;
else if (tag == DW_TAG_enumerator || tag == DW_TAG_constant)
tag = DW_TAG_variable;
insert (tag, name, it->second, (entry->flags & IS_STATIC) != 0,
entry->per_cu->is_debug_types ? unit_kind::tu : unit_kind::cu,
entry->per_cu->lang);
}