aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2022-07-13 12:20:53 +0200
committerTom de Vries <tdevries@suse.de>2022-07-13 12:20:53 +0200
commit52c0a455466aa437e4b8d6967e44767c8f3fa260 (patch)
tree8bc1c87e84046736a961239650478b4f3b1793f9
parentdd4c046506cd4da46b439a2b4f8b6d933ecbb961 (diff)
downloadgdb-52c0a455466aa437e4b8d6967e44767c8f3fa260.zip
gdb-52c0a455466aa437e4b8d6967e44767c8f3fa260.tar.gz
gdb-52c0a455466aa437e4b8d6967e44767c8f3fa260.tar.bz2
[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.
-rw-r--r--gdb/dwarf2/read.c38
-rw-r--r--gdb/dwarf2/read.h11
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp4
3 files changed, 28 insertions, 25 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 2aac991..5ca787c 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -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. */
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 707dca9..fcf0cd7 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -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. */
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp b/gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp
index 3ac94c3..3d2890a 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp
@@ -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" {