From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Z2LZEEypbGqWmTcAWB0awg (envelope-from ) for ; Fri, 31 Jul 2026 09:55:24 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TCjN4mDi; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 33EF31E099; Fri, 31 Jul 2026 09:55:24 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7821A1E099 for ; Fri, 31 Jul 2026 09:55:23 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EFD9F4BB588E for ; Fri, 31 Jul 2026 13:55:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFD9F4BB588E Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TCjN4mDi Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 260394BB3BA9 for ; Fri, 31 Jul 2026 13:54:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 260394BB3BA9 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 260394BB3BA9 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785506098; cv=none; b=w38bvNLc/VI5mhCO2eAvvJEfFHt/gJvmYhGUM40rORlgID+qyVudVUMJ0+WeqxPcnWydO5nxxhXS8j7j7SC+M6zIHk6iPUyatpDeFRfCEjOQEtV3Cmf40eP1urzW6aGiIRn/QMgv5aYOiz6LQSw0AThm+nHhaV/HJpcSorm9W20= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785506098; c=relaxed/simple; bh=P23igIruckZqB6oUsgDJWAF/AfFP6jekEbCptAVv4LE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=V7G6m02571YTI+IuVLQSdzc3abMLqfbydi54FCEtpDl+pknVfta1PGVlbcXbFkYcalgwJH7HhaaMmxGry4DUwdBZt5a1HFJlHHEI6s+U5w3cTRqXL2welVw+pVUpBY3192gqCSYB5xt9WsmpPlsn8dX3S1kUcURQM+YTcnivmvI= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TCjN4mDi DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 260394BB3BA9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785506097; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cImHgu3AkLYss/Ku7hlY4udNnw8b4Mhf6l42IY3bdUo=; b=TCjN4mDidJbuyhUhu2xuy3Zy03fPu//2yU3xAvdj1+QQ1eSDV+BFjJUMDXWgmZMt9UTb56 ZgATQsZkebbY5PhT5Aywaqx4GuAfweDO3QBB01S38uxR45CAY4yB42llUIzGdgmoDN8NlB Re/8b1/v77DzpBEq2aUD78boMDux/ng= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-465-h7pyOE2rMrGNiReQpAUJhg-1; Fri, 31 Jul 2026 09:54:56 -0400 X-MC-Unique: h7pyOE2rMrGNiReQpAUJhg-1 X-Mimecast-MFC-AGG-ID: h7pyOE2rMrGNiReQpAUJhg_1785506095 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-47fd4ee0ac0so479402f8f.2 for ; Fri, 31 Jul 2026 06:54:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785506095; x=1786110895; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=cImHgu3AkLYss/Ku7hlY4udNnw8b4Mhf6l42IY3bdUo=; b=hf44KwAUPzalqQhkcLToQv5i+axoSbwwLPwJ9zS9URUmYSdBq4DYERx7NH9bdE4D09 2OC7YFvtnEGKuPwuHT8UflT+9skAZqBSzJAAi7H7a1r9VaGI/WS9ic8PacqL8AmC9MQa iArKrxNBy2Hrd9qhq5qNDZsrK77FWvUzv35iGPlZVPSDwKRhfvE585G396QinhB7I3ug xHiKYL1qcJx+g24H9++krlUSqBb4/R6im2jyvh34uaKr9K40gkJYCsNto+33ABFL1n6P Arkffb2eW8qVq3YKs8nQ7Kev+jNn07kRn84KlSz8DJ9+ix7R92GLcPJl80Iq1kwrFb2r Q9qw== X-Forwarded-Encrypted: i=1; AHgh+Rqmp9PQZMmCp+0wkN8aXUbsPWWbKFMpQxpCTku72z6ulOIt4l8GRdECeOpLBRa3XzGz0tBNQiYN+DqZeA==@sourceware.org X-Gm-Message-State: AOJu0YybOl6m6jxEomFsRlyZFlreDQq+VJEDZbVQqr4j9CL17xdvr4y+ bJ5UnGFd1GSicBOPcdigAbNRJH9ylOSTvqqrgxMxglghNdHeeVFv0hU9KZ1nf3CXEWs9sRizEb6 IHU9vtF1B+yyiopG0tYpwdt4720SEHZzkDlAYZ1B78gnW+jRPDtsD9icjQWsMcl3qYg1p+Zk= X-Gm-Gg: AR+sD132whC+kOVODv/bmb6swlWngn0EikkIvhov2qxcWc6sw0Jyg0gSgzUinH/07d/ fh9I4mVhsFlMAGwLNI6c6T6TTut7KrAe66muxjXrLP51ad22saS3Or/gzAY4B0ZSf2FpP/TNMxp Bt+etSPcmAemMxsjHgrlu321WhP1AXWJf3vkN5NLWSUG2th+8y9lnpMdXVsCrdTOpqjHGBeKqgb KxaHTpn6XD7jA+h23ps3S3Wl/JGNab+UP9X3u7sfXMwJ4NTov6kZdY9Et5RuMvj8y4eO5MqT4YM ccYHXMTb8yRtrWSPfOIyGDntG/Vb8CJ7WnaVB8cPlQRYHYmx9Ym71YAdvVxn4axDjj5rax3frSQ xnQHKhilJZ9HZgERA X-Received: by 2002:a05:6000:4a0d:b0:47f:8558:8ff4 with SMTP id ffacd0b85a97d-47fd2b6652bmr5148098f8f.54.1785506095110; Fri, 31 Jul 2026 06:54:55 -0700 (PDT) X-Received: by 2002:a05:6000:4a0d:b0:47f:8558:8ff4 with SMTP id ffacd0b85a97d-47fd2b6652bmr5148028f8f.54.1785506094640; Fri, 31 Jul 2026 06:54:54 -0700 (PDT) Received: from localhost (92.6.93.209.dyn.plus.net. [209.93.6.92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47fd458ab61sm5132534f8f.25.2026.07.31.06.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 06:54:54 -0700 (PDT) From: Andrew Burgess To: Craig Blackmore , gdb-patches@sourceware.org Cc: Craig Blackmore , Simon Cook Subject: Re: [PATCH] Add missing null pointer check in get_sal_arch In-Reply-To: <20260729150617.3502554-1-craig.blackmore@embecosm.com> References: <20260729150617.3502554-1-craig.blackmore@embecosm.com> Date: Fri, 31 Jul 2026 14:54:53 +0100 Message-ID: <87ldarmfgy.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: NhE5Abet8oLMeHKS5G0cu8L0PSkPRISJuYB_7Cd-bQc_1785506095 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Craig Blackmore writes: > This fixes a GDB crash when trying to set a breakpoint on a function in > an ELF where there is both no .text section and the first section within > the ELF is not allocatable. > > Co-authored-by: Simon Cook > --- > gdb/breakpoint.c | 2 +- > gdb/testsuite/gdb.base/bp-non-alloc.c | 21 +++++++++++++++ > gdb/testsuite/gdb.base/bp-non-alloc.exp | 36 +++++++++++++++++++++++++ > gdb/testsuite/gdb.base/bp-non-alloc.ld | 35 ++++++++++++++++++++++++ > 4 files changed, 93 insertions(+), 1 deletion(-) > create mode 100644 gdb/testsuite/gdb.base/bp-non-alloc.c > create mode 100644 gdb/testsuite/gdb.base/bp-non-alloc.exp > create mode 100644 gdb/testsuite/gdb.base/bp-non-alloc.ld > > diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c > index ca600a845e5..7df63856278 100644 > --- a/gdb/breakpoint.c > +++ b/gdb/breakpoint.c > @@ -7764,7 +7764,7 @@ set_breakpoint_location_function (struct bp_location *loc) > struct gdbarch * > get_sal_arch (struct symtab_and_line sal) > { > - if (sal.section != nullptr) > + if (sal.section != nullptr && sal.section->objfile != nullptr) > return sal.section->objfile->arch (); > if (sal.symtab != nullptr) > return sal.symtab->compunit ().objfile ()->arch (); > diff --git a/gdb/testsuite/gdb.base/bp-non-alloc.c b/gdb/testsuite/gdb.base/bp-non-alloc.c > new file mode 100644 > index 00000000000..2eb9f523887 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/bp-non-alloc.c > @@ -0,0 +1,21 @@ > +/* Copyright (C) 2026 Free Software Foundation, Inc. > + > + This file is part of GDB. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +int main () > +{ > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/bp-non-alloc.exp b/gdb/testsuite/gdb.base/bp-non-alloc.exp > new file mode 100644 > index 00000000000..7758a591fa7 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/bp-non-alloc.exp > @@ -0,0 +1,36 @@ > +# Copyright (C) 2026 Free Software Foundation, Inc. > +# > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# For an ELF that has no section called ".text" and the first section is > +# non-alloc, test that a breakpoint can be set on a function. This previously > +# caused GDB to crash due to a missing null pointer check. > + > +require is_elf_target > + > +global srcdir > +global subdir > + > +standard_testfile > + > +set linker_script $srcdir/$subdir/$testfile.ld Isn't a test with a custom linker script, especially one that's placing text sections going to be architecture specific? I would have expected this to be a gdb.arch/ test? If this does work more widely then maybe a list of the targets it has been confirmed to work on would be good. You can push a `try` branch to sourceware into your username namespace, e.g. I could push to 'aburgess/try-my-awesome-fix' and the sourceware CI will spot this branch, run its tests, and email you the results. The key is the 'try-' part of the branch name. Though thinking about it, I'm not sure if it runs all tests, or just a subset, I guess you'd have to "try" it and find out. Thanks, Andrew > + > +set options "debug ldscript=-Wl,-T${linker_script}" > +if {[build_executable "failed to prepare" $testfile $srcfile $options]} { > + return -1 > +} > + > +clean_restart $testfile > + > +gdb_test "break main" "Breakpoint .* at .*" > diff --git a/gdb/testsuite/gdb.base/bp-non-alloc.ld b/gdb/testsuite/gdb.base/bp-non-alloc.ld > new file mode 100644 > index 00000000000..6a8ad57af18 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/bp-non-alloc.ld > @@ -0,0 +1,35 @@ > +/* Copyright (C) 2026 Free Software Foundation, Inc. > + > + This file is part of GDB. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . > + > + This linker script is used to produce an executable that starts with a > + non-allocatable section and does not contain a `.text` section. */ > + > +MEMORY > +{ > + DATA (rw) : ORIGIN = 0x8000000, LENGTH = 0x10000 > + TEXT (rx) : ORIGIN = LENGTH (DATA), LENGTH = 0x10000 > +} > + > +SECTIONS > +{ > + .my_non_alloc_sec (INFO) : { . = . + 0x10; } > + .text.all : { *(.text) } > TEXT > + .data : { *(.data) } > DATA > + _edata = .; > + .bss : { *(.bss) } > DATA > + _end = .; > +} > -- > 2.43.0