From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 1F79738560B9; Wed, 13 Jul 2022 10:20:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F79738560B9 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/symtab] Make per_cu->set_lang more strict X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: dd4c046506cd4da46b439a2b4f8b6d933ecbb961 X-Git-Newrev: 52c0a455466aa437e4b8d6967e44767c8f3fa260 Message-Id: <20220713102057.1F79738560B9@sourceware.org> Date: Wed, 13 Jul 2022 10:20:57 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jul 2022 10:20:57 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D52c0a455466a= a437e4b8d6967e44767c8f3fa260 commit 52c0a455466aa437e4b8d6967e44767c8f3fa260 Author: Tom de Vries Date: Wed Jul 13 12:20:53 2022 +0200 [gdb/symtab] Make per_cu->set_lang more strict =20 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. */ ... =20 Fix this by not setting m_lang for partial units. =20 This requires us to move the m_unit_type initialization to ensure that m_unit_type is initialized before per_cu->m_lang. =20 Tested on x86_64-linux, with native and target board cc-with-dwz-m. Diff: --- gdb/dwarf2/read.c | 38 ++++++++++++---------= ---- gdb/dwarf2/read.h | 11 ++++--- gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp | 4 +-- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 2aac9912ef1..5ca787cc095 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 =3D=3D nullptr) return; =20 - 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, struc= t die_info *comp_unit_die, else lang =3D pretend_language; =20 - cu->per_cu->set_lang (lang); cu->language_defn =3D 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); } =20 /* See read.h. */ diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 707dca9ee57..fcf0cd70530 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -353,11 +353,14 @@ public: =20 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 !=3D lang) + if (unit_type () =3D=3D DW_UT_partial) + return; + if (m_lang =3D=3D language_unknown) + /* Set if not set already. */ m_lang =3D lang; + else + /* If already set, verify that it's the same value. */ + gdb_assert (m_lang =3D=3D lang); } =20 /* Free any cached file names. */ diff --git a/gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp b/gdb/testsuit= e/gdb.dwarf2/dw2-missing-cu-tag.exp index 3ac94c31689..3d2890a56b2 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"] =20 # This pattern is hit when GDB does use -readnow (e.g. running with # --target_board=3Dreadnow). @@ -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"] =20 # Load the executable, we expect an error from the DWARF parser. gdb_test_multiple "file $binfile" "file $testfile" {