From patchwork Thu Nov 2 09:50:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinevere Larsen X-Patchwork-Id: 78918 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 65C623858D37 for ; Thu, 2 Nov 2023 09:50:30 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 243FA3858D37 for ; Thu, 2 Nov 2023 09:50:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 243FA3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 243FA3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698918617; cv=none; b=hJgekh6av+sPT71WMPwIj34zaBa4fZIQW+lx+o3bv/hpE+e7/sPuewFWERVcc7aVE0T8n5YEUD5WcYZXhyfith2H4FSv2XNuUpG1U2U9jEjm88lnOshfSi6L6iLLJT4k29LY4fCsnA8LrpsIHgktCp9oL0uOjHFeONfpgZXerug= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698918617; c=relaxed/simple; bh=CY6M6M5JfIsw5MMw3JU/Yypcb8/RlrxHbn/YHNH3p8I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Dgv7HZ3x1NUUx/qIZUk2xwK78IS29AYI1mH/VpHwyaAD3fwcgSNGWjSAjUodVTU/2MdOpjiKPAP3OYUFC5/0u+QCItvPlTYd9glMXoMw3KRkq4PJuJI6M7iU5qW2X5T7s+tmvB8Qd7udHSUrLKC2XQNNOOH3HuW7Fs65p0VUMHE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698918615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QxhlWutO7Hp5ncfSPBbB//VKRlPUjHwDKE2pCTa0ITc=; b=ZafZoJtzOw9upX2XD18T9hL9Abdq5Mu/RuLeyFCijCcJd0P8/mottCTHNasvENBeG8dJFe l9HrWGeV5KXVQY3ppysar3+KbeySsNtAEjteio6UUmKh0UbWCbhNGpSguCUrQIwqzbrjP6 D9ewfAfwZHxgkbnGnE1EibXx5HzKqdo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-V796r_WNN1GPbLutlLRUnw-1; Thu, 02 Nov 2023 05:50:14 -0400 X-MC-Unique: V796r_WNN1GPbLutlLRUnw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4977E185A780 for ; Thu, 2 Nov 2023 09:50:14 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A1DAB492BE0; Thu, 2 Nov 2023 09:50:13 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen , Andrew Burgess Subject: [PATCH v2] gdb: register frame_destroyed function for amd64 gdbarch Date: Thu, 2 Nov 2023 10:50:05 +0100 Message-ID: <20231102095005.3650126-1-blarsen@redhat.com> In-Reply-To: <20231026090448.1182959-1-blarsen@redhat.com> References: <20231026090448.1182959-1-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 gdbarches usually register functions to check when a frame is destroyed which is used with software watchpoints, since the expression of the watchpoint is no longer vlaid at this point. On amd64, this wasn't done anymore because GCC started using CFA for variable locations instead. However, clang doesn't use the CFA and instead relies on specifying when an epilogue has started, meaning software watchpoints get a spurious hit when a frame is destroyed. This patch re-adds the code to register the function that detects when a frame is destroyed, but only uses this when the producer is LLVM, so gcc code isn't affected. This can also remove the XFAIL added to gdb.python/pq-watchpoint tests that handled this exact flaw in clang Co-Authored-By: Andrew Burgess --- gdb/amd64-tdep.c | 16 +++++++++++++++- gdb/testsuite/gdb.python/py-watchpoint.exp | 17 +---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index e6feee677b3..362151f227c 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -2908,6 +2908,18 @@ amd64_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc) return 1; } +static int +amd64_stack_frame_destroyed_p_1 (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + struct compunit_symtab *cust = find_pc_compunit_symtab (pc); + + if (cust != nullptr && cust->producer () != nullptr + && producer_is_llvm (cust->producer ())) + return amd64_stack_frame_destroyed_p (gdbarch, pc); + + return 0; +} + static int amd64_epilogue_frame_sniffer_1 (const struct frame_unwind *self, frame_info_ptr this_frame, @@ -2938,7 +2950,7 @@ amd64_epilogue_frame_sniffer_1 (const struct frame_unwind *self, } /* Check whether we're in an epilogue. */ - return amd64_stack_frame_destroyed_p (gdbarch, pc); + return amd64_stack_frame_destroyed_p_1 (gdbarch, pc); } static int @@ -3310,6 +3322,8 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch, set_gdbarch_gen_return_address (gdbarch, amd64_gen_return_address); + set_gdbarch_stack_frame_destroyed_p (gdbarch, amd64_stack_frame_destroyed_p_1); + /* SystemTap variables and functions. */ set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes); set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes); diff --git a/gdb/testsuite/gdb.python/py-watchpoint.exp b/gdb/testsuite/gdb.python/py-watchpoint.exp index 5ff61285979..9a6ef447572 100644 --- a/gdb/testsuite/gdb.python/py-watchpoint.exp +++ b/gdb/testsuite/gdb.python/py-watchpoint.exp @@ -42,20 +42,5 @@ gdb_test "source $pyfile" ".*Python script imported.*" \ "import python scripts" gdb_test "python print(len(gdb.breakpoints()))" "2" "check modified BP count" gdb_test "continue" ".*" "run until program stops" -# Clang doesn't use CFA location information for variables (despite generating -# them), meaning when the instruction "pop rbp" happens, we get a false hit -# on the watchpoint. for more details, see: -# https://github.com/llvm/llvm-project/issues/64390 -gdb_test_multiple "python print(bpt.n)" "check watchpoint hits" { - -re -wrap "5" { - pass $gdb_test_name - } - -re -wrap "6" { - if {[test_compiler_info "clang-*"]} { - xfail "$gdb_test_name (clang issue 64390)" - } else { - fail $gdb_test_name - } - } -} +gdb_test "python print(bpt.n)" "5" "check watchpoint hits" gdb_test "python print(len(gdb.breakpoints()))" "1" "check BP count"