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();