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.*"