From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id E675B3858CDA; Tue, 31 Jan 2023 18:22:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E675B3858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675189328; bh=aPgrbrKT7sbtUZDJJS3H0lTIQFgguXRVxsyeHv2ZnJs=; h=From:To:Subject:Date:From; b=KjZaQ4NfCARKgJoKGW8NsMkRgfF1NceHb6s2Iyp5UzkqgSijVAKLJuR2h1s2mYSCp 3g1UTtiuZABKwRCB7eHr6R5cd6tyjhPUnpZBo5iRJHkWnufDJrTK6rdrTi+XsJ4dhB nL3HGo8kLK/eun+QHsE8WDdO/j5e3MutWBpfcNYQ= 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: add nullptr check to cooked_index_functions::dump X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: d7789889b1839c3c0f64c6738b0d8517ccead049 X-Git-Newrev: cd07187f238b4d0135f2e331810cc5995a8be8f3 Message-Id: <20230131182208.E675B3858CDA@sourceware.org> Date: Tue, 31 Jan 2023 18:22:08 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dcd07187f238b= 4d0135f2e331810cc5995a8be8f3 commit cd07187f238b4d0135f2e331810cc5995a8be8f3 Author: Simon Marchi Date: Tue Jan 31 10:57:21 2023 -0500 gdb: add nullptr check to cooked_index_functions::dump =20 Since commit 7d82b08e9e0a ("gdb/dwarf: dump cooked index contents in cooked_index_functions::dump"), we see: =20 maint print objfiles /home/smarchi/build/binutils-gdb/gdb/testsuite= /outputs/gdb.dwarf2/dw2-error/dw2-error^M ^M Object file /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/= gdb.dwarf2/dw2-error/dw2-error: Objfile at 0x614000005040, bfd at 0x612000= 0e08c0, 15 minsyms^M ^M Cooked index in use:^M ^M /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb-checked-static= -cast.h:58: internal-error: checked_static_cast: Assertion `result !=3D nul= lptr' failed.^M A problem internal to GDB has been detected,^M further debugging may prove unreliable.^M ----- Backtrace -----^M FAIL: gdb.dwarf2/dw2-error.exp: maint print objfiles /home/smarchi/= build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error (GD= B internal error) =20 The problem is that when cooked_index_functions fails to build an index, per_objfile->index_table is nullptr. Therefore, add a nullptr check, like other methods of cooked_index_functions already do. =20 Print the "Cooked index in use" message after the nullptr check, such that if the cooked index failed to build, that message is not printed. =20 Change-Id: Id67aef592e76c41b1e3bde9838a4e36cef873253 Diff: --- gdb/dwarf2/read.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e8a3e359ada..6cee22a3faa 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -18589,14 +18589,15 @@ struct cooked_index_functions : public dwarf2_bas= e_index_functions =20 void dump (struct objfile *objfile) override { - gdb_printf ("Cooked index in use:\n"); - gdb_printf ("\n"); - dwarf2_per_objfile *per_objfile =3D get_dwarf2_per_objfile (objfile); cooked_index_vector *index =3D (gdb::checked_static_cast - (per_objfile->per_bfd->index_table.get ())); + (per_objfile->per_bfd->index_table.get ())); + if (index =3D=3D nullptr) + return; =20 + gdb_printf ("Cooked index in use:\n"); + gdb_printf ("\n"); index->dump (objfile->arch ()); }