[gdb/symtab] Make per_cu->set_lang more strict

We have in per_cu->set_lang this comment:
...
  void set_lang (enum language lang)
  {
    /* We'd like to be more strict here, similar to what is done in
       set_unit_type,  but currently a partial unit can go from unknown to
       minimal to ada to c.  */
...

Fix this by not setting m_lang for partial units.

This requires us to move the m_unit_type initialization to ensure that
m_unit_type is initialized before per_cu->m_lang.

Tested on x86_64-linux, with native and target board cc-with-dwz-m.
This commit is contained in:
Tom de Vries
2022-07-13 12:20:53 +02:00
parent dd4c046506
commit 52c0a45546
3 changed files with 28 additions and 25 deletions

View File

@@ -6777,24 +6777,6 @@ process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu,
if (reader.comp_unit_die == nullptr)
return;
switch (reader.comp_unit_die->tag)
{
case DW_TAG_compile_unit:
this_cu->set_unit_type (DW_UT_compile);
break;
case DW_TAG_partial_unit:
this_cu->set_unit_type (DW_UT_partial);
break;
case DW_TAG_type_unit:
this_cu->set_unit_type (DW_UT_type);
break;
default:
error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
dwarf_tag_name (reader.comp_unit_die->tag),
sect_offset_str (reader.cu->per_cu->sect_off),
objfile_name (per_objfile->objfile));
}
if (reader.dummy_p)
{
/* Nothing. */
@@ -23587,8 +23569,26 @@ prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die,
else
lang = pretend_language;
cu->per_cu->set_lang (lang);
cu->language_defn = language_def (lang);
switch (comp_unit_die->tag)
{
case DW_TAG_compile_unit:
cu->per_cu->set_unit_type (DW_UT_compile);
break;
case DW_TAG_partial_unit:
cu->per_cu->set_unit_type (DW_UT_partial);
break;
case DW_TAG_type_unit:
cu->per_cu->set_unit_type (DW_UT_type);
break;
default:
error (_("Dwarf Error: unexpected tag '%s' at offset %s"),
dwarf_tag_name (comp_unit_die->tag),
sect_offset_str (cu->per_cu->sect_off));
}
cu->per_cu->set_lang (lang);
}
/* See read.h. */

View File

@@ -353,11 +353,14 @@ public:
void set_lang (enum language lang)
{
/* We'd like to be more strict here, similar to what is done in
set_unit_type, but currently a partial unit can go from unknown to
minimal to ada to c. */
if (m_lang != lang)
if (unit_type () == DW_UT_partial)
return;
if (m_lang == language_unknown)
/* Set if not set already. */
m_lang = lang;
else
/* If already set, verify that it's the same value. */
gdb_assert (m_lang == lang);
}
/* Free any cached file names. */

View File

@@ -54,7 +54,7 @@ clean_restart
set pattern1 \
[multi_line \
"Reading symbols from \[^\r\n\]+" \
"Dwarf Error: unexpected tag 'DW_TAG_subprogram' at offset $hex \\\[\[^\r\n\]+\\\]"]
"Dwarf Error: unexpected tag 'DW_TAG_subprogram' at offset $hex"]
# This pattern is hit when GDB does use -readnow (e.g. running with
# --target_board=readnow).
@@ -62,7 +62,7 @@ set pattern2 \
[multi_line \
"Reading symbols from \[^\r\n\]+" \
"Expanding full symbols from \[^\r\n\]+" \
"Dwarf Error: unexpected tag 'DW_TAG_subprogram' at offset $hex \\\[\[^\r\n\]+\\\]"]
"Dwarf Error: unexpected tag 'DW_TAG_subprogram' at offset $hex"]
# Load the executable, we expect an error from the DWARF parser.
gdb_test_multiple "file $binfile" "file $testfile" {