From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id DF38A3858D37; Mon, 4 Apr 2022 21:50:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF38A3858D37 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: remove assertion in psymbol_functions::expand_symtabs_matching X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 7b01c1cc1d111ba0afa51e60fa9842d3b971e2d1 X-Git-Newrev: cb25fdbb76e41d9c02fe86009fc8a3ecf8737c9a Message-Id: <20220404215000.DF38A3858D37@sourceware.org> Date: Mon, 4 Apr 2022 21:50:00 +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: Mon, 04 Apr 2022 21:50:01 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dcb25fdbb76e4= 1d9c02fe86009fc8a3ecf8737c9a commit cb25fdbb76e41d9c02fe86009fc8a3ecf8737c9a Author: Simon Marchi Date: Thu Mar 31 16:38:33 2022 -0400 gdb: remove assertion in psymbol_functions::expand_symtabs_matching =20 psymtab_to_symtab is documented as possibly returning nullptr, if the primary symtab of the partial symtab has no symbols. However, psymbol_functions::expand_symtabs_matching asserts that the result of psymtab_to_symtab as non-nullptr. =20 I caught this assert by trying the CTF symbol reader on a library I built with -gctf: =20 $ ./gdb --data-directory=3Ddata-directory /tmp/babeltrace-ctf/src/l= ib/.libs/libbabeltrace2.so.0.0.0 ... Reading symbols from /tmp/babeltrace-ctf/src/lib/.libs/libbabeltrac= e2.so.0.0.0... (gdb) maintenance expand-symtabs /home/simark/src/binutils-gdb/gdb/psymtab.c:1142: internal-error: e= xpand_symtabs_matching: Assertion `symtab !=3D nullptr' failed. =20 The "symtab" in question is: =20 $ readelf --ctf=3D.ctf /tmp/babeltrace-ctf/src/lib/.libs/libbabelt= race2.so.0.0.0 ... CTF archive member: /home/simark/src/babeltrace/src/lib/graph/compo= nent-descriptor-set.c: =20 Header: Magic number: 0xdff2 Version: 4 (CTF_VERSION_3) Flags: 0xe (CTF_F_NEWFUNCINFO, CTF_F_IDXSORTED, CTF_F_DYNSTR) Parent name: .ctf Compilation unit name: /home/simark/src/babeltrace/src/lib/grap= h/component-descriptor-set.c Type section: 0x0 -- 0x13 (0x14 bytes) String section: 0x14 -- 0x5f (0x4c bytes) =20 Labels: =20 Data objects: =20 Function objects: =20 Variables: =20 Types: 0x80000001: (kind 5) bt_bool (*) (const bt_value *) (aligned at= 0x8) =20 Strings: 0x0: 0x1: .ctf 0x6: /home/simark/src/babeltrace/src/lib/graph/component-descri= ptor-set.c =20 It contains a single type, and it is skipped by ctf_add_type_cb, because an identical type was already seen earlier in this objfile. As a result, no compunit_symtab is created. =20 Change psymbol_functions::expand_symtabs_matching to expect that psymtab_to_symtab can return nullptr. =20 Another possibility would be to make the CTF symbol reader always create a compunit_symtab, even if there are no symbols in it (like the DWARF parser does), but so far I don't see any advantage in doing so. =20 Change-Id: Ic43c38202c838a5eb87630ed1fd61d33528164f4 Diff: --- gdb/psymtab.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/gdb/psymtab.c b/gdb/psymtab.c index b31ce877b62..a26ecd0b4e5 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1136,13 +1136,10 @@ psymbol_functions::expand_symtabs_matching *psym_lookup_name, symbol_matcher)) { - struct compunit_symtab *symtab =3D - psymtab_to_symtab (objfile, ps); + compunit_symtab *cust =3D psymtab_to_symtab (objfile, ps); =20 - gdb_assert (symtab !=3D nullptr); - - if (expansion_notify !=3D NULL) - if (!expansion_notify (symtab)) + if (cust !=3D nullptr && expansion_notify !=3D nullptr) + if (!expansion_notify (cust)) return false; } }