From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id jRk2NNnfBmsStzwAWB0awg (envelope-from ) for ; Wed, 25 Nov 2026 08:17:13 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KW2alKMj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id BC5C81E09B; Wed, 25 Nov 2026 08:17:13 -0500 (EST) 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 [IPv6:2620:52:6:3111::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 B86321E09B for ; Wed, 25 Nov 2026 08:17:12 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 06F58452C532 for ; Wed, 25 Nov 2026 13:17:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06F58452C532 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KW2alKMj Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by sourceware.org (Postfix) with ESMTPS id 6E6244614463 for ; Wed, 25 Nov 2026 13:16:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E6244614463 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6E6244614463 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795612604; cv=none; b=DOz71K+Wo5zaaFdlF+HN9qNjOHybbemBpscYm1LdpESmKPUgFPmQ50+/aPuhbi+mbyg11oDdi7WA+tXv306YJ1zgVkkYXQo5KaXDcYVCjMWQFnIkyXqx4a8qxYIPKB9jqFhC+r9vqJMzsSoz3pGXb4bKmmGc911Ku6vh5wz3bJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795612604; c=relaxed/simple; bh=bpyLIm+Q8AOJ17XaPTy0F43fsJrWup6dL5TP0t6IgxU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GjpzE9KOEDfzrp5uciRFSI9hcScHVdMcXrB2220ogNZyG8afaYTklAUXuyageLVXEf+bU+/+fs25MvvUe3N/qIi1ptmGGl1KSdHUuURhtbsOq8cOUZhAlwZPFX6GNhWSebGKgihEbtWynzykrk3gmTbJpDNLw7Zf1cCAjSZ1VNs= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KW2alKMj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E6244614463 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1795612604; x=1827148604; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=bpyLIm+Q8AOJ17XaPTy0F43fsJrWup6dL5TP0t6IgxU=; b=KW2alKMjPaR4AdO42W0byGB4kJTMjPKvXeTq10OQyXhiz46IgIE/1GR9 eRAGK0TeNkHxq7pO0euHjpvlcD4woXY0EWDHoRIz/O2qyduS05Yf9vPkZ ZLOoAeewKra2klDal7nSS3rKrQsmjpI4z+vm4twKKGI/aTyRgEGmuaU8c yKhyLJsUWvmATZkpXbi71IO99uSKBoY7Ows/jLrjJFOeWuqELHvYIW73z y7PYhqsnS7sY8vNou1yUfdjQC3oqw/kp2ZsI55+G0Ojv4juHek2vpDUrp ipmACxgkKn+vlEsjEg5SP42VaDpDbmIEOgnRp1YkUptDoGCK61rUvc51U g==; X-CSE-ConnectionGUID: 7REkT/jlQ/ambl3DyK9WeQ== X-CSE-MsgGUID: UQ5P3Ha2QWqFsDtHYBUHxQ== X-IronPort-AV: E=McAfee;i="6800,10657,11977"; a="4402679" X-IronPort-AV: E=Sophos;i="6.27,232,1787036400"; d="scan'208";a="4402679" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2026 05:16:43 -0800 X-CSE-ConnectionGUID: 4PEtMMG1SLWaX1+/R9xQcQ== X-CSE-MsgGUID: 6kk350sqRZi7Ln/3IFBi/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,232,1787036400"; d="scan'208";a="12455071" Received: from dut1048pvc.igk.intel.com (HELO localhost) ([10.211.177.228]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2026 05:16:43 -0800 From: Stephan Rohr To: gdb-patches@sourceware.org Subject: [PATCH] gdb: fix location number after a breakpoint is re-set Date: Wed, 25 Nov 2026 13:16:34 +0000 Message-ID: <20261125131634.117460-1-stephan.rohr@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 If a thread stops at a breakpoint location and the breakpoint is then re-set, e.g., because of a shared library load event, its locations are replaced. The bpstat of the stop still refers to the old location, and bpstat_locno does not find it. GDB then outputs a warning: warning: location number not found for breakpoint [..] Also, the convenience variable $_hit_locno is set to 1, which may not be the location the thread stopped at. Fix this by looking up the new location based on the program space and address of the old location. --- gdb/breakpoint.c | 18 +++++ .../gdb.base/breakpoint-reset-location.exp | 81 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 gdb/testsuite/gdb.base/breakpoint-reset-location.exp diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index ca8ae98a7b7..a3f69037b8d 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -5102,6 +5102,24 @@ bpstat_locno (const bpstat *bs) ++locno; } + /* Breakpoint B may be re-set after BS is created, e.g., if symbols are + loaded while the program is stopped at BL. In this case, BL is no + longer a location of B and the check above does not work. Instead, + use the location that replaced it, if available. */ + if (bl->owner != b) + { + locno = 1; + for (bp_location &loc : b->locations ()) + { + if (loc.pspace == bl->pspace && loc.address == bl->address) + return locno; + + ++locno; + } + + return 0; + } + warning (_("location number not found for breakpoint %d address %s."), b->number, paddress (bl->gdbarch, bl->address)); } diff --git a/gdb/testsuite/gdb.base/breakpoint-reset-location.exp b/gdb/testsuite/gdb.base/breakpoint-reset-location.exp new file mode 100644 index 00000000000..a44958b38bb --- /dev/null +++ b/gdb/testsuite/gdb.base/breakpoint-reset-location.exp @@ -0,0 +1,81 @@ +# Copyright 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 . + +# Re-set a breakpoint with two locations while the program is stopped +# at one of them, e.g., because symbols are loaded. Test that GDB still finds +# the number of that location and does not warn that it cannot find it. + +require allow_shlib_tests + +standard_testfile ctxobj-m.c ctxobj-f.c ctxobj-v.c + +# Include ctxobj-f.c in both the executable and the shared library to get +# two breakpoint locations. +set libsrc [list "${srcdir}/${subdir}/${srcfile3}" \ + "${srcdir}/${subdir}/${srcfile2}"] +set libobj [standard_output_file libctxobj.so] +set libobj_opts { debug + additional_flags=-DVERSION=203 + additional_flags=-DGET_VERSION=get_version_2 } + +if { [gdb_compile_shlib $libsrc $libobj $libobj_opts] != "" } { + untested "failed to compile shared library" + return +} + +if { [build_executable "failed to build" $testfile \ + [list $srcfile $srcfile2 $srcfile3] \ + [list debug shlib=$libobj \ + additional_flags=-DVERSION=104 \ + additional_flags=-DGET_VERSION=get_version_1]] } { + return +} + +clean_restart $testfile +gdb_load_shlib $libobj + +if {![runto_main]} { + return +} + +set bp_line [gdb_get_line_number "STOP" "ctxobj-f.c"] +gdb_test "break ctxobj-f.c:$bp_line" \ + "Breakpoint $decimal at $hex: ctxobj-f.c:$bp_line. \\(2 locations\\)" + +# Continue to the breakpoint location in the executable. The order is not +# fixed, so record the location's number. +set hit "unknown" +gdb_test_multiple "continue" "continue to get_version_1" { + -re -wrap "Breakpoint ($decimal\\.$decimal), get_version_1 \\(\\).*" { + set hit $expect_out(1,string) + pass $gdb_test_name + } +} + +# Reloading the symbols of the shared libraries re-sets the breakpoints. +gdb_test_no_output "nosharedlibrary" +gdb_test "sharedlibrary" ".*" "reload the shared libraries" + +# Test that the breakpoint location is still found. GDB used to warn +# about the old location after every command and set $_hit_locno to 1. +gdb_test_multiple "printf \"%d.%d\\n\", \$_hit_bpnum, \$_hit_locno" \ + "\$_hit_bpnum.\$_hit_locno after re-set" { + -re -wrap "warning: location number not found.*" { + fail $gdb_test_name + } + -re -wrap "\r\n[string_to_regexp $hit]" { + pass $gdb_test_name + } +} -- 2.43.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.