From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E02553858C66 for ; Wed, 8 Nov 2023 14:24:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E02553858C66 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 E02553858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699453473; cv=none; b=bhqH3QcLJkW0oG2RgmWWWfmiLU8rerCvo5XPBbbBSK2QisJbFBvHJJQCniFEyFbRApk1kcBfMYoWBgZGNvhg1v3CBOnlZ8nLB3EXquMoYT+8pFg/gOh6evsM5Y/Ok/GqWpEoBOsNkRbz1Jdv01C0IvKm7IR+12pOjLbj2b/6Ots= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699453473; c=relaxed/simple; bh=9/xiEmMGqkEKcYngIRK6Kdhm/OEnYeQaL6Oh+n5lcUc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fr5Wwh4pS5MRghjLsPsNI56u01MhV/P88SfZ9NaGi0Ftu6CMt+dj0BZKjSdZWCeZjo4n58E65IDHqiWw+/1OBRxJ73ruPTkkROu4Xzkr8zAL1PDilGOl5YjEBK11Zg4U7XYhelmuZCDp2sNG+1LjSwZgOP3nZzljzkQ7JVjt3iQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699453471; 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=2beOEoQTYQDN3FT2Swvssoktt8wpqMS492rQQtohOOo=; b=NPJkUvWEsVXU7uuu5fTZ+a6YFXFZqa4NQgwpDZFInLo2AD4eN9FvLmvbgQtc9Hoj4+sJLZ /n0Tfq21kgB0/BTcYwmJIEiWWPTlflKDPndjitwynsXtV1GDwi26s2EWb/DmClhKXgN9OE jANb5//OrIxKL8IVbM7tFkPrjj0GtfU= 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-608-6aZKZiBlPl2R3gdUgkIe9A-1; Wed, 08 Nov 2023 09:24:30 -0500 X-MC-Unique: 6aZKZiBlPl2R3gdUgkIe9A-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 F3F2A802E65 for ; Wed, 8 Nov 2023 14:24:29 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D619492BE7; Wed, 8 Nov 2023 14:24:29 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen , Andrew Burgess Subject: [PATCH v3] gdb: register frame_destroyed function for amd64 gdbarch Date: Wed, 8 Nov 2023 15:24:22 +0100 Message-ID: <20231108142422.1209851-1-blarsen@redhat.com> In-Reply-To: <20231102095005.3650126-1-blarsen@redhat.com> References: <20231102095005.3650126-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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.5 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_H3,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 List-Id: 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. The logic that identifies the epilogue has been factored out into the new function amd64_stack_frame_destroyed_p_1, so the frame sniffer can call it directly, and its behavior isn't changed. 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 | 32 ++++++++++++++++------ gdb/testsuite/gdb.python/py-watchpoint.exp | 17 +----------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index e6feee677b3..2e101b4fca1 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -2886,6 +2886,22 @@ static const struct frame_base amd64_frame_base = amd64_frame_base_address }; +/* Implement core of the stack_frame_destroyed_p gdbarch method. */ + +static int +amd64_stack_frame_destroyed_p_1 (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + gdb_byte insn; + + if (target_read_memory (pc, &insn, 1)) + return 0; /* Can't read memory at pc. */ + + if (insn != 0xc3) /* 'ret' instruction. */ + return 0; + + return 1; +} + /* Normal frames, but in a function epilogue. */ /* Implement the stack_frame_destroyed_p gdbarch method. @@ -2897,15 +2913,13 @@ static const struct frame_base amd64_frame_base = static int amd64_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc) { - gdb_byte insn; + struct compunit_symtab *cust = find_pc_compunit_symtab (pc); - if (target_read_memory (pc, &insn, 1)) - return 0; /* Can't read memory at pc. */ + if (cust != nullptr && cust->producer () != nullptr + && producer_is_llvm (cust->producer ())) + return amd64_stack_frame_destroyed_p_1 (gdbarch, pc); - if (insn != 0xc3) /* 'ret' instruction. */ - return 0; - - return 1; + return 0; } static int @@ -2938,7 +2952,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 +3324,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); + /* 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" -- 2.41.0