From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 348D23857B8D; Fri, 8 Jul 2022 13:56:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 348D23857B8D 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] Fix assert in process_imported_unit_die X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 3fa23bb5a5320dd82d32455036d59a026929fc2f X-Git-Newrev: 8728fb3385c136b05dc16fb6664a57028acd0d73 Message-Id: <20220708135615.348D23857B8D@sourceware.org> Date: Fri, 8 Jul 2022 13:56:15 +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: Fri, 08 Jul 2022 13:56:15 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8728fb3385c1= 36b05dc16fb6664a57028acd0d73 commit 8728fb3385c136b05dc16fb6664a57028acd0d73 Author: Tom de Vries Date: Fri Jul 8 15:56:06 2022 +0200 [gdb/symtab] Fix assert in process_imported_unit_die =20 When running test-case gdb.dwarf2/dw2-symtab-includes.exp with target b= oard cc-with-debug-names, I run into: ... (gdb) maint expand-symtab dw2-symtab-includes.h^M src/gdb/dwarf2/read.h:311: internal-error: unit_type: \ Assertion `m_unit_type !=3D 0' failed.^M A problem internal to GDB has been detected,^M further debugging may prove unreliable.^M ----- Backtrace -----^M FAIL: gdb.dwarf2/dw2-symtab-includes.exp: maint expand-symtab \ dw2-symtab-includes.h (GDB internal error) ... =20 The assert was recently added in commit 2c474c46943 ("[gdb/symtab] Add = get/set functions for per_cu->lang/unit_type"). =20 The assert is triggered here: ... /* We're importing a C++ compilation unit with tag DW_TAG_compile_u= nit into another compilation unit, at root level. Regard this as a = hint, and ignore it. */ if (die->parent && die->parent->parent =3D=3D NULL && per_cu->unit_type () =3D=3D DW_UT_compile && per_cu->lang () =3D=3D language_cplus) return; ... =20 We're trying to access unit_type / lang which hasn't been set yet. =20 Normally, these are set during cooked index creation, but that's not th= e case when using an index (or using -readnow). =20 In other words, this lto binary reading speed optimization only works i= n the normal use case. =20 IWBN to have this working in all use cases, but for now, allow lang () = and unit_type () to return language_unknown and 0 here. =20 Tested on x86_64-linux. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29321 Diff: --- gdb/dwarf2/read.c | 7 ++++--- gdb/dwarf2/read.h | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 9f92b420645..55e61b882a9 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -8538,10 +8538,11 @@ process_imported_unit_die (struct die_info *die, st= ruct dwarf2_cu *cu) =20 /* We're importing a C++ compilation unit with tag DW_TAG_compile_un= it into another compilation unit, at root level. Regard this as a hint, - and ignore it. */ + and ignore it. This is a best effort, it only works if unit_type and + lang are already set. */ if (die->parent && die->parent->parent =3D=3D NULL - && per_cu->unit_type () =3D=3D DW_UT_compile - && per_cu->lang () =3D=3D language_cplus) + && per_cu->unit_type (false) =3D=3D DW_UT_compile + && per_cu->lang (false) =3D=3D language_cplus) return; =20 /* If necessary, add it to the queue and load its DIEs. */ diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 1d9c66aafad..c9afa074ae9 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -306,9 +306,10 @@ public: gdb_assert (m_dwarf_version =3D=3D version); } =20 - dwarf_unit_type unit_type () const + dwarf_unit_type unit_type (bool strict_p =3D true) const { - gdb_assert (m_unit_type !=3D 0); + if (strict_p) + gdb_assert (m_unit_type !=3D 0); return m_unit_type; } =20 @@ -322,9 +323,10 @@ public: gdb_assert (m_unit_type =3D=3D unit_type); } =20 - enum language lang () const + enum language lang (bool strict_p =3D true) const { - gdb_assert (m_lang !=3D language_unknown); + if (strict_p) + gdb_assert (m_lang !=3D language_unknown); return m_lang; }