From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 46aLJgkXamokUTMAWB0awg (envelope-from ) for ; Wed, 29 Jul 2026 11:06:49 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=VesdMZ+L; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8BCB51E099; Wed, 29 Jul 2026 11:06:49 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 D5D511E099 for ; Wed, 29 Jul 2026 11:06:48 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62BD74BB58FE for ; Wed, 29 Jul 2026 15:06:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62BD74BB58FE Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=VesdMZ+L Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 5F5A04BB58B0 for ; Wed, 29 Jul 2026 15:06:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F5A04BB58B0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5F5A04BB58B0 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785337584; cv=none; b=ozUBn033zMcSu9nrErmlEy2Hzh6bsGKzYz04aUVAXdLbpSx8bfMhX7dq5wLvqMDI9RxzbblY4koD2gPhHZTYppMBkE6O5FZQILNPHZRzHGDTS3ys9WF04cuXgn6upTwrmEENBCC9bXlGbSqjG+ZP6+9vW8968xwRknltNqxJpVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785337584; c=relaxed/simple; bh=v1gXc7zW+NJFn0bw5G+KLDTcBeWniq925CgKRjVk3p8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=IIB8g2JmH6QCMd4KtR4ISWsgRyuVJwFn8/EPPsPvRPVh8i7zFI5rj5KC4z5OUYXIYH5Mpnob969F8CFGjJmBCnJ3Va6Kb81mEIbadpnEUEmtupoalcyQLsNj8U/W3RBnqcShI3ZbVgccdhttFvOkIlWEmctZjSs1jUa6mhlqbyo= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=VesdMZ+L DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F5A04BB58B0 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4954df200ddso6385495e9.0 for ; Wed, 29 Jul 2026 08:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1785337583; x=1785942383; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Gp2LXRkSnqR1MrVBy8XSX8HWj89ZIM+6b3UjH39T4ts=; b=VesdMZ+LSi3RPBy4qKRMXAtuLQ19ky7yZ8Qe+g1hd2iRdx/AcZh+y0Q1dmHVd3Y24k tSOn5P++yUNM6lcHC4eotQ12Q6RHCSnQQEwT1qth4KCZzu7d5HHK8xTliU6hzqGWLvtV tXrllU4eCfc3KK5EkJ8bqgr94k0WQ67IesDMjVejH4QenhhMGHw25LjZdufC/LxWr8Yj a0jro5ofEvO9xcuuR7NDjLjZvXcauC3fqxIgZlDHFmcingYsaaWXcp1jf8j2BA/BiITY Vel/Q5fsYIsprD4esMB708NdhdmOUqkaQno4A2XU6KVkLZRiO1PJeWxfPN4blpPfQIpg dxiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785337583; x=1785942383; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Gp2LXRkSnqR1MrVBy8XSX8HWj89ZIM+6b3UjH39T4ts=; b=VOMV8sJXgRwIdyEXxEis62NNJX6y31xAqUady32X0G1+No8mssE2Fets3Xe9eDKF7d yeGDdp/Kuh0cDl8kknKwRzcVHi0V/Yt0kKDHnpt15Za9f1Y3PaFuRgjtpkkJHsqx0Xvw ZSdkRFNkB217SGTy3rtnVPxVW/Th0yfBnoCF/Q2t7mnyhmunDTgov1EkP2O96zFhJnHz oBGdM7Slovejgy0eopubccgq/1GLtUKvWij4c6/h5NY/BwPqYHtsryjJP72MzjwEtOvj 4XH9oeITQ3X+jschr320Z+mw2T+pwKr9OV2GcV6xbTQwwC+/0qhXgwkNuRj9TYKXdQC2 LPcg== X-Gm-Message-State: AOJu0YxVa3x5zeVsna/2jnxjnxrsj7iS09ZzhS0oHjlg3YvtlW9ntZHH kuDOZ002tlBQXi2ntTPmCmq4zrGKkXv3knirja/hl4DwqADnYLevZioZSWhbBGAMFr9iynpwqTl UWFFY X-Gm-Gg: AR+sD12G1Z+fkAWbvq0U6W6C6nPwWxkhUQxl0Xg4r/q2i+WjDP80HQPnpo0f0yGyiMO gkZ1shr/j0bonL30BJN8mcIRygYtzbVakLwOYp0IE93sl39u68rXsA9KqZfBYDRSg06brEYqeb7 nJaN+rIcgosl4WOolibfeEUC4l1l8PGSbFOWL3LZu3Wv97RE2YvcXB38HWH4n3m2UxlYxpTQau9 sTmBYuE92F49W1nLXFBjVBtlig8PVzvazzmHjImjFZy/reIZhwTXztrLpA5vd+2bYnU2nZ/0n1C eShF6OJs4y1sMBWrUSxNFRE5IEalTayZgaI7SwIHrYJPYExcUXa4o79mbYV+2idpK3qTIa2osvd wEBaEsS3csx4aUdZmw7k84p870exZJJyB1WbvO9K+Gm3//LBs69xpJG/oz3qLcpgsbaIEm7VivK obmQV4gIbw7vuT2vrm+Z0btNLE738aXLiAQaDBJ1zFW08K1VXZdMEP9xdYKF5GNrC8ShAJIAhKH +V7Kv8UKTba3KWLhCTM X-Received: by 2002:a05:600c:820a:b0:495:409e:bc80 with SMTP id 5b1f17b1804b1-496c6586d21mr76911635e9.37.1785337582910; Wed, 29 Jul 2026 08:06:22 -0700 (PDT) Received: from dorian.sou.embecosm-corp.com ([212.69.42.53]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49764d8e81asm64277175e9.7.2026.07.29.08.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jul 2026 08:06:22 -0700 (PDT) From: Craig Blackmore To: gdb-patches@sourceware.org Cc: Craig Blackmore , Simon Cook Subject: [PATCH] Add missing null pointer check in get_sal_arch Date: Wed, 29 Jul 2026 16:06:17 +0100 Message-ID: <20260729150617.3502554-1-craig.blackmore@embecosm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 + +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