From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 8E08F38515F6 for ; Tue, 5 Apr 2022 14:46:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8E08F38515F6 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [172.16.0.95] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 320521E150; Tue, 5 Apr 2022 10:46:17 -0400 (EDT) Message-ID: <22e6f3e9-e065-e90d-7d98-9cf20aa30144@simark.ca> Date: Tue, 5 Apr 2022 10:46:16 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] gdb: skip objfiles with no BFD in DWARF unwinder Content-Language: tl To: Jan Vrany , gdb-patches@sourceware.org References: <20220405100429.188136-1-jan.vrany@labware.com> From: Simon Marchi In-Reply-To: <20220405100429.188136-1-jan.vrany@labware.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3645.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Apr 2022 14:46:18 -0000 On 2022-04-05 06:04, Jan Vrany via Gdb-patches wrote: > While playing with JIT reader I experienced GDB to crash on null-pointer > dereference when stepping through non-jitted code. > > 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. > > As for the test, I initially tried to use temporary breakpoint and then > 'continue' to get out of the jitted code but this for some reason did > not trigger the crash. Using 'finish' to get out of jitted code followed > by 'next' triggered it. > --- > gdb/dwarf2/frame.c | 3 +++ > gdb/objfiles.h | 4 +++- > gdb/testsuite/gdb.base/jit-reader.exp | 10 ++++++++++ > 3 files changed, 16 insertions(+), 1 deletion(-) > > diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c > index 5878d72f922..514ae8c694f 100644 > --- a/gdb/dwarf2/frame.c > +++ b/gdb/dwarf2/frame.c > @@ -1565,6 +1565,9 @@ dwarf2_frame_find_fde (CORE_ADDR *pc, dwarf2_per_objfile **out_per_objfile) > CORE_ADDR offset; > CORE_ADDR seek_pc; > > + if (objfile->obfd == nullptr) > + continue; Ok, I presume that this is the case only for JIT-ed objfiles whose debuginfo was created using the JIT debug info reader API. If the JIT engine produced an executable file in memory with DWARF in it and we consumed it, then I suppose that objfile will have a bfd, since it was opened and parsed using bfd. > + > comp_unit *unit = find_comp_unit (objfile); > if (unit == NULL) > { > diff --git a/gdb/objfiles.h b/gdb/objfiles.h > index 8bd76705688..429dea1da4c 100644 > --- a/gdb/objfiles.h > +++ b/gdb/objfiles.h > @@ -636,7 +636,9 @@ struct objfile > struct compunit_symtab *compunit_symtabs = nullptr; > > /* 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). */ > > bfd *obfd; > > diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp > index d94360cd7d9..0de552b1ce5 100644 > --- a/gdb/testsuite/gdb.base/jit-reader.exp > +++ b/gdb/testsuite/gdb.base/jit-reader.exp > @@ -271,6 +271,16 @@ proc jit_reader_test {} { > "#1 ${any} in main ${any}" \ > ] > } > + > + # check that the DWARF unwinder does not crash in presence of Capital C to "check". > + # JIT objfiles. > + gdb_test "fin" \ > + [multi_line \ > + "Run till exit from ${any} jit_function_stack_mangle ${any}" \ > + "main ${any} at ${any}.*" \ > + ] > + gdb_test "bt" "#0 main ${any} at ${any}" > + gdb_test "next" Please take in consideration Lancelot's comment, the patch LGTM with that feedback addressed. Simon