From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2087) id 5346A38362D7; Thu, 8 Dec 2022 11:50:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5346A38362D7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670500233; bh=KegiGqThBrC92E3+F/adXhs9SdHncwGBieHdS4B53wE=; h=From:To:Subject:Date:From; b=gps7S5ndN1274lz+dIobDLIb3tnTIJAbXf7QuKmddnTPkCDhXr1nRyq4U1m1cylmO Ke6J0CCchTkxDFQzvDi4r9CIkAGuiq0CimvTCJ87Ah4/oscikJ2XjiyRygHQ10kdmG ukNiftMXr5Qbzj4VkHjfSkGALS+TbLZa02fBE8S4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jan Vrany To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: skip objfiles with no BFD in DWARF unwinder X-Act-Checkin: binutils-gdb X-Git-Author: Jan Vrany X-Git-Refname: refs/heads/master X-Git-Oldrev: 57336e2e4d05eaac6367400e6ce3aed24f838f2c X-Git-Newrev: 05a1f6468ea806239f0cd5605732a09023a90e0a Message-Id: <20221208115033.5346A38362D7@sourceware.org> Date: Thu, 8 Dec 2022 11:50:33 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D05a1f6468ea8= 06239f0cd5605732a09023a90e0a commit 05a1f6468ea806239f0cd5605732a09023a90e0a Author: Jan Vrany Date: Thu Dec 8 11:30:25 2022 +0000 gdb: skip objfiles with no BFD in DWARF unwinder =20 While playing with JIT reader I experienced GDB to crash on null-pointer dereference when stepping through non-jitted code. =20 The problem was that dwarf2_frame_find_fde () assumed that all objfiles have BFD but that's not always true. To address this problem, this commit skips such objfiles. =20 To test the fix we put breakpoint in jit_function_add (). The JIT reader does not know how unwind this function so unwinding eventually falls back to DWARF unwinder which in turn iterates over objfiles. Since the the code is jitted, it is guaranteed it would eventually process JIT objfile. =20 Approved-By: Simon Marchi Diff: --- gdb/dwarf2/frame.c | 3 +++ gdb/objfiles.h | 4 +++- gdb/testsuite/gdb.base/jit-reader.exp | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c index 3f884abe1d5..54a0912ebc6 100644 --- a/gdb/dwarf2/frame.c +++ b/gdb/dwarf2/frame.c @@ -1560,6 +1560,9 @@ dwarf2_frame_find_fde (CORE_ADDR *pc, dwarf2_per_objf= ile **out_per_objfile) CORE_ADDR offset; CORE_ADDR seek_pc; =20 + if (objfile->obfd =3D=3D nullptr) + continue; + comp_unit *unit =3D find_comp_unit (objfile); if (unit =3D=3D NULL) { diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 9a152cbc387..0d887ce112f 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -646,7 +646,9 @@ public: struct compunit_symtab *compunit_symtabs =3D nullptr; =20 /* The object file's BFD. Can be null if the objfile contains only - minimal symbols, e.g. the run time common symbols for SunOS4. */ + minimal symbols (e.g. the run time common symbols for SunOS4) or + if the objfile is a dynamic objfile (e.g. created by JIT reader + API). */ =20 gdb_bfd_ref_ptr obfd; =20 diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base= /jit-reader.exp index 69bf721d90a..a66896dda67 100644 --- a/gdb/testsuite/gdb.base/jit-reader.exp +++ b/gdb/testsuite/gdb.base/jit-reader.exp @@ -277,6 +277,19 @@ proc jit_reader_test {} { "True" \ "at least one file-based objfile" } + + with_test_prefix "test dwarf unwinder" { + # Check that the DWARF unwinder does not crash in presence of + # JIT objfiles. + gdb_test "up" + gdb_breakpoint "*function_add" temporary + gdb_test "cont" ".*Temporary breakpoint ${any} in jit_function_add .*" + gdb_test "bt" \ + [multi_line \ + "#0 ${any} in jit_function_add ${any}" \ + "#1 ${any} in main ${any}" \ + ] + } } =20 jit_reader_test