From patchwork Fri Oct 18 10:21:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Gerlicher X-Patchwork-Id: 99155 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CFE9A3857C6C for ; Fri, 18 Oct 2024 10:23:13 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by sourceware.org (Postfix) with ESMTPS id 6A15B3858D37 for ; Fri, 18 Oct 2024 10:22:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A15B3858D37 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 6A15B3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729246961; cv=none; b=PET/GNzQQPzBB345Hw0fRzvDrOlaqFdZP9dEv23SdjCRtY6yPbpa9zukL/Ka4jvoWZqqxvm97N2yQd9Ss19SHrGxCqkRlbtVdFZOKw4fQhh9EXzGFjY76umBSdu5SRjhnyG6Cjh9UjJAxK+M4qy3UMRouOJz3ecLZ9+wUNFRvX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729246961; c=relaxed/simple; bh=+vK7HHcPdleS/SoK+rl1Y8GnSXLBROVotNmUMLjRB9o=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=nXRp80xl9nz4FT/aCFtToZwABv0bslRCPUgf6OOgJyEhn3JuKS17L5CLTgLxSn+/POlE0SPQy8Lbg/qfsitacS3Im0N0eBtPGYDZherM2VYjmFhGDuL/JBu3Jx5cUIavKmQoVWSZPntx1UYGXvhw3NbBz7PCeSRiChERED0YBfg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729246954; x=1760782954; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=+vK7HHcPdleS/SoK+rl1Y8GnSXLBROVotNmUMLjRB9o=; b=OBdsxt+qeD5g5Y/Z8q0YwbBv5Cho+ZIDkHga50vxJZz5qV1wQr2CK7ZX PnLfs2wCNs6EGqhChoyXwHRMqSW+z8aEIz+zNCfGqv2A+lAiaeFoU13oJ UjlB9Bf1P2J2h1AyP2KtqxyjUPer0krrcB81xXOdnykhGoTI3qmSoBMbX /y1xnx4/fRLR3WUyLQ8iK6Fcpbkc+JbXcMmbJJl44UQ22a2maty6e+CyS H0s5VWdCV5nPLqJwztAd9zCzzF7pg/0KKyHYgE3gq0IFQVuzsZztTFtqC BWLeOWRaF/clmR2D+uGb06n8mT9SPD0jBYb3Sud/8AQFsFpF3brLQxzDb g==; X-CSE-ConnectionGUID: p0iniw76R9abV0qPpIpiWw== X-CSE-MsgGUID: hcDkzyf4SFm03ensYbGPfA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="39901552" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="39901552" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2024 03:22:33 -0700 X-CSE-ConnectionGUID: UvBcJ7adR/yLcDPdHcwsOA== X-CSE-MsgGUID: wNQNw7XnR+Wl3IZvfsHzqg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,213,1725346800"; d="scan'208";a="78843291" Received: from dut1016pvc.igk.intel.com (HELO localhost) ([10.211.177.46]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2024 03:22:31 -0700 From: Klaus Gerlicher To: gdb-patches@sourceware.org Subject: [PATCH 1/2] gdb, linespec: avoid multiple locations with same PC Date: Fri, 18 Oct 2024 10:21:55 +0000 Message-Id: <20241018102156.350310-2-klaus.gerlicher@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241018102156.350310-1-klaus.gerlicher@intel.com> References: <20241018102156.350310-1-klaus.gerlicher@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org From: "Gerlicher, Klaus" Setting a BP on a line like this would incorrectly yield two BP locations: 01 void two () { {int var = 0;} } (gdb) break 1 Breakpoint 1 at 0x1164: main.cpp:1. (2 locations) (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 1.1 y 0x0000000000001164 in two() at main.cpp:1 1.2 y 0x0000000000001164 in two() at main.cpp:1 In this case decode_digits_ordinary () returns two SALs, exactly matching the requested line. One for the entry PC and one for the prologue end PC. This was tested with GCC, CLANG and ICPX. Subsequent code tries to skip the prologue on these PCs, which in turn makes them the same. To fix this, ignore SALs with the same PC and program space when adding to the list of SALs. This will then properly set only one location: (gdb) break 1 Breakpoint 1 at 0x1164: file main.cpp, line 1 (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x0000000000001164 in two() at main.cpp:1 Reviewed-By: Alexandra Petlanova Hajkova --- gdb/linespec.c | 6 ++++++ gdb/testsuite/gdb.linespec/linespec.exp | 6 ++++++ gdb/testsuite/gdb.linespec/lspec.cc | 2 ++ 3 files changed, 14 insertions(+) diff --git a/gdb/linespec.c b/gdb/linespec.c index d5256261eff..a2723e1c06a 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -1047,6 +1047,12 @@ add_sal_to_sals (struct linespec_state *self, struct symtab_and_line *sal, const char *symname, int literal_canonical) { + /* We don't want two SALs with the same PC from the + same program space. */ + for (const auto &s : *sals) + if (sal->pc == s.pc && sal->pspace == s.pspace) + return; + sals->push_back (*sal); if (self->canonical) diff --git a/gdb/testsuite/gdb.linespec/linespec.exp b/gdb/testsuite/gdb.linespec/linespec.exp index 576d788cae0..789f1287b07 100644 --- a/gdb/testsuite/gdb.linespec/linespec.exp +++ b/gdb/testsuite/gdb.linespec/linespec.exp @@ -194,6 +194,12 @@ gdb_test "break lspec.h:$line" \ "Breakpoint \[0-9\]+ at $hex: file .*lspec.h, line $line." \ "set breakpoint in f1" +# This should only have a single location -- in no_multi_locs. +set line [gdb_get_line_number no_multi_locs] +gdb_test "break $line" \ + "Breakpoint \[0-9\]+ at $hex: file .*$srcfile, line $line." \ + "set breakpoint at no_multi_locs" + # # Multi-inferior tests. # diff --git a/gdb/testsuite/gdb.linespec/lspec.cc b/gdb/testsuite/gdb.linespec/lspec.cc index bb660fbc79e..ab0a193da89 100644 --- a/gdb/testsuite/gdb.linespec/lspec.cc +++ b/gdb/testsuite/gdb.linespec/lspec.cc @@ -13,6 +13,8 @@ int body_elsewhere() #include "body.h" } +void no_multi_locs () { {int var = 0;} } + int main() { return dupname(0) + m(0) + n(0) + f1() + f2() + body_elsewhere(); From patchwork Fri Oct 18 10:21:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Gerlicher X-Patchwork-Id: 99156 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 86BB03858420 for ; Fri, 18 Oct 2024 10:23:18 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by sourceware.org (Postfix) with ESMTPS id 7884C3858C39 for ; Fri, 18 Oct 2024 10:22:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7884C3858C39 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 7884C3858C39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729246967; cv=none; b=eZpUdhMelUZoF+eSkjEvvpIQBOxZcK97nljc7rZbECXYcGUp6g8EkuV1hyEmBhrHHuEsxI+DP8orBuYUpV0kHL4C0wJXbd6JjNw7Qep75zfKYnNMf/93g04zNshewztVnqrdIYjeIZ24i3kWu3jwq7ob5zv1FiM10jT4fSjZf8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729246967; c=relaxed/simple; bh=nRon109FswdSj4AZ/PdaTw/VFXR0cwZBULxFgfH4j2I=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=GorZdo4YBeLT8kWkGQPG1J8UlursjXEmh/2zzJ2qSLp9Jd1vFy5heOli3FJtRpLzbAdqpTLq7o5y2VxMhcEMF6/6V1V0TGJ6b+jgVGBJHVcVv2NsHq/USxxmhy2INRiDlRg23cC7dwnyIJ3qcAJmqu9FBkzdGU63ZBVff9bNiac= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729246965; x=1760782965; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=nRon109FswdSj4AZ/PdaTw/VFXR0cwZBULxFgfH4j2I=; b=RP6GRgIfJSafuMqdZxZ9lFMA3kYKnLyoOewtGdbMzFPg83uEWPivK0NL d+cQflExsLBV3uMx3hkz2/TTLsnn0xfpz+v47ikYu+MF9nIV65bxfX8+A 8rc6fcYm1j/2lxpi+CksIQdGqL2dYC1qHsjX7rzje/ntGfVS0+pcyRxTc kMOeTkWijy2WgobFJYiEEMQJDykkRa2Q75JJ7KNFebrvi5bMYXyAJRX9c RlG8+sZLZr6uOdqPjxj2vRpx7KrqIqi39yiujIh6Uo33YJvEFhTa16iNh cQt+4vhIP0CWd5NBOP48SRVPLyb1rEz4ADpytCxB0igOtvUnjI6zSHIKn w==; X-CSE-ConnectionGUID: Ci8P7A6+RVeETF893boPQA== X-CSE-MsgGUID: 6BznPBYjQxqI8a7RncpqXQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="39901575" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="39901575" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2024 03:22:43 -0700 X-CSE-ConnectionGUID: AM66f4e3SGGT2zHB9bnOmg== X-CSE-MsgGUID: SZ+TrgGWSGq5LM5Ih+CEgQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,213,1725346800"; d="scan'208";a="78843297" Received: from dut1016pvc.igk.intel.com (HELO localhost) ([10.211.177.46]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2024 03:22:42 -0700 From: Klaus Gerlicher To: gdb-patches@sourceware.org Subject: [PATCH 2/2] gdb, linespec: reject inserting breakpoints for both entry and prologue end PC Date: Fri, 18 Oct 2024 10:21:56 +0000 Message-Id: <20241018102156.350310-3-klaus.gerlicher@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241018102156.350310-1-klaus.gerlicher@intel.com> References: <20241018102156.350310-1-klaus.gerlicher@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org From: "Gerlicher, Klaus" This patch extends "gdb: reject inserting breakpoints between functions". We are keeping BPs from sliding into non-related blocks when they would slide into a line with an entry PC. However this is not enough to prevent all BP slides into non-related blocks since the compiler can also generate a prologue end PC that would be used. To avoid this also treat the prologue end PC the same as the entry PC. --- gdb/linespec.c | 41 ++++++++++++++++-- gdb/testsuite/gdb.linespec/bad-slide.c | 41 ++++++++++++++++++ gdb/testsuite/gdb.linespec/bad-slide.exp | 54 ++++++++++++++++++++++++ 3 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.linespec/bad-slide.c create mode 100644 gdb/testsuite/gdb.linespec/bad-slide.exp diff --git a/gdb/linespec.c b/gdb/linespec.c index a2723e1c06a..bb262b180b1 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -2154,13 +2154,48 @@ create_sals_line_offset (struct linespec_state *self, The intent of this heuristic is that a breakpoint requested on line 11 and 12 will not result in a breakpoint on main, but a breakpoint on line 13 will. A breakpoint requested on the empty - line 16 will also result in a breakpoint in main, at line 17. */ + line 16 will also result in a breakpoint in main, at line 17. + + Also consider that there may be a separate line table entry + for the same line at the prologue end. Treat this the + same as the entry PC. + + 01 + 02 int + 03 main () { { int i = 1; } + 04 return 0; + 05 } + + will generate linetable entries like this where line 3 has two + entries because of the extra code block. The first one is + the entry pc, the second one is the end of the prologue. + + INDEX LINE REL-ADDRESS UNREL-ADDRESS IS-STMT P-END + 0 3 0x0000555555555130 0x0000000000001130 Y + 1 3 0x000055555555513b 0x000000000000113b Y Y + 2 4 0x0000555555555142 0x0000000000001142 Y + 3 END 0x0000555555555146 0x0000000000001146 Y + + The second entry would still be considered a valid location, + therefore this should also be skipped in the same way as + the entry pc. */ + if (!was_exact && sym != nullptr && sym->aclass () == LOC_BLOCK - && sal.pc == sym->value_block ()->entry_pc () && val.line < sym->line ()) - continue; + { + std::optional prologue_end; + + if (self->funfirstline) + prologue_end = skip_prologue_using_sal ( + sym->arch (), sym->value_block ()->entry_pc ()); + + if (sal.pc == sym->value_block ()->entry_pc () + || (self->funfirstline && prologue_end.has_value () + && sal.pc == *prologue_end)) + continue; + } if (self->funfirstline) skip_prologue_sal (&sal); diff --git a/gdb/testsuite/gdb.linespec/bad-slide.c b/gdb/testsuite/gdb.linespec/bad-slide.c new file mode 100644 index 00000000000..49d842c037d --- /dev/null +++ b/gdb/testsuite/gdb.linespec/bad-slide.c @@ -0,0 +1,41 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024 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 . + + Source code has intentionally been formatted not according to GNU style + to show issues with breakpoint propagation/sliding. */ + +/* break here one. */ +void one () { int var = 0; +} + +/* break here two. */ +void two () { {int var = 0;} } /* func line two. */ + +/* break here three. */ +void three () { /* func line three. */ + {int var = 0;} /* func body three. */ +} + +int +main (void) +{ + one (); + two (); + three (); + + return 0; +} diff --git a/gdb/testsuite/gdb.linespec/bad-slide.exp b/gdb/testsuite/gdb.linespec/bad-slide.exp new file mode 100644 index 00000000000..aa01da2b1f4 --- /dev/null +++ b/gdb/testsuite/gdb.linespec/bad-slide.exp @@ -0,0 +1,54 @@ +# Copyright (C) 2024 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 . +# +# Test the breakpoint rejection for breakpoints between functions. + +standard_testfile + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \ + { debug }] } { + return -1 +} + +if {![runto_main]} { + return -1 +} + +gdb_test_no_output "set breakpoint pending off" + +set bp_line [gdb_get_line_number "break here one"] +gdb_test "break $bp_line" \ + ".*No compiled code for line $bp_line in the current file." + +set bp_line [gdb_get_line_number "break here two"] +gdb_test "break $bp_line" \ + ".*No compiled code for line $bp_line in the current file." + +set bp_line [gdb_get_line_number "func line two"] +gdb_test "break $bp_line" \ + ".*Breakpoint $decimal at .*$srcfile,.*line $bp_line.*" + +set bp_line [gdb_get_line_number "break here three"] +gdb_test "break $bp_line" \ + ".*No compiled code for line $bp_line in the current file." + +set bp_line [gdb_get_line_number "func line three"] +set bp_line_prop [expr $bp_line + 1] +gdb_test "break $bp_line" \ + ".*Breakpoint $decimal at .*$srcfile,.*line $bp_line_prop.*" + +set bp_line [gdb_get_line_number "func body three"] +gdb_test "break $bp_line" \ + ".*Breakpoint $decimal at .*$srcfile,.*line $bp_line.*"