From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2087) id 5949D3858D28; Wed, 18 Jan 2023 11:35:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5949D3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674041716; bh=nxA0ss1DbbwJxhlkEyH4pq+g2xBUeM6N9YG4/bEGm+U=; h=From:To:Subject:Date:From; b=aqeHAeMCMaooAC1J4w4SnNIb1ZD36vqA7c0uob7aHU2UvzoemFk09VBmIzKO0Epai p6gpUlPeCbya1ZyN+DujZrEcEtCBpjLqfdCXkiL5142myQE1MC41O8D67W8Mccr5TY lUl0AOxhO2t5AWzVL79Jne9UGknjZICOHK5OA3ok= 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: care for dynamic objfiles in build_id_bfd_get () X-Act-Checkin: binutils-gdb X-Git-Author: Jan Vrany X-Git-Refname: refs/heads/master X-Git-Oldrev: 94e76498c3790d90c383621b88268abf9acdd5bf X-Git-Newrev: 722e0dd9e4f03d66666c5b62e162da31cafe6d9f Message-Id: <20230118113516.5949D3858D28@sourceware.org> Date: Wed, 18 Jan 2023 11:35:16 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D722e0dd9e4f0= 3d66666c5b62e162da31cafe6d9f commit 722e0dd9e4f03d66666c5b62e162da31cafe6d9f Author: Jan Vrany Date: Wed Jan 18 11:34:37 2023 +0000 gdb: care for dynamic objfiles in build_id_bfd_get () =20 Accessing gdb.Objfile.build_id caused GDB to crash when objfile is dynamic, that is created by JIT reader API. =20 The issue was NULL-pointer dereferencing in build_id_bfd_get () because dynamic objfiles have no underlaying BFD structure. This commit fixes the problem by a NULL-check in build_id_bfd_get (). Diff: --- gdb/build-id.c | 6 ++++++ gdb/testsuite/gdb.base/jit-reader.exp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/gdb/build-id.c b/gdb/build-id.c index c82f96402c8..801eb004ad7 100644 --- a/gdb/build-id.c +++ b/gdb/build-id.c @@ -32,6 +32,12 @@ const struct bfd_build_id * build_id_bfd_get (bfd *abfd) { + /* Dynamic objfiles such as ones created by JIT reader API + have no underlaying bfd structure (that is, objfile->obfd + is NULL). */ + if (abfd =3D=3D nullptr) + return nullptr; + if (!bfd_check_format (abfd, bfd_object) && !bfd_check_format (abfd, bfd_core)) return NULL; diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base= /jit-reader.exp index fd0c5f56d6e..399cb67dcce 100644 --- a/gdb/testsuite/gdb.base/jit-reader.exp +++ b/gdb/testsuite/gdb.base/jit-reader.exp @@ -227,6 +227,10 @@ proc jit_reader_test {} { gdb_test "python print(list(map(lambda objf : objf.filename, gdb.objfile= s())))" \ "$any'<< JIT compiled code at $hex >>'$any" \ "python gdb.Objfile.filename" + + gdb_test "python print( \[o for o in gdb.objfiles() if o.filename.starts= with('<< JIT compiled code')\]\[0\].build_id )" \ + "None" \ + "python gdb.Objfile.build_id" } } }