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 1C8933858C5E for ; Thu, 7 Dec 2023 17:36:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C8933858C5E 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 1C8933858C5E 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=1701970584; cv=none; b=x3jqgm1fvAR2JYHRl3dfULoqMyfDbCisonk2aUi5ZtgtB1TadKts5Fsu0ibgjNEeORRiMlAsBLaLVU33GwhZ9404atNscB8+1kZder6aYRDGb86Dq1RNG4W/3Cs9gTTmnkK6dY3Zx+bex81KD3ad5yd3Zd4TZUzEItFDOFgJ3I8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701970584; c=relaxed/simple; bh=bpc9fwOWwnXO+m54xThfaGA0m4v+mBYBapbz5qKTKdE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=lSl73o4492K2K96QForTFfeNwzkr9H/LjUq9Di2Q/LKNRqMj1APdI3DCwDFbR/N5D6ygjAStTtrNYbvJ41GPhXY/Lx4mGqjRSmWmDg2LJZFIvxTWl5suT5yP0uWUdjHmXxZ4nftbE3WO/hYWsovZGJJQWJJRtKZoOqXTp+97T8o= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701970582; 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=TbkjhYRPnYyAr0HZD+yvlFopj58o8wdnZF8+opqbr1Y=; b=UIb8/vsmBHguilMWJr2wENaPCDObU0jXxltmq12Abvl00pfk7PjYNkb8dsaV1H0ktjDvEA eAZWz/Rh2ift7Z7XAKjgRN2zWYyiwIcGMrG6zgzP77cZ+OAN6QIUaqSOkJHWDIWfzFSJMS GdvfDMFgXxcmyo9o0YNbd3YSxaWI0jE= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-526-2vXl9a9UPYihUekzl6UcJA-1; Thu, 07 Dec 2023 12:36:21 -0500 X-MC-Unique: 2vXl9a9UPYihUekzl6UcJA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a1b06d1bea7so66891566b.0 for ; Thu, 07 Dec 2023 09:36:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701970580; x=1702575380; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TbkjhYRPnYyAr0HZD+yvlFopj58o8wdnZF8+opqbr1Y=; b=tiHGS1A+PKogL25hg2dzunMnQlVfibuk1zyzQAKLgDMs3x9qfy+INnGaEIOEF/kjWc C2DES8u3mN7Fypa8dpbpeUY2tBnGwS8CeRDRBDQrqUbioqVEm594DGCSeenyRvY+iDEz 8FHfB5vrs4nhOLZeDpUIMOnB/cIFs0iZhMKmyg9tOkURA7HiISklOmuqPAF2QOIqOZXk yVeDjpBgB5UGS73jyLTT8CTkVBU1BlmmH6iNza68SwnTVmIGkduoKbSlynrorItXFsSo wkP3/YO+E88n9h2Znng3Er5m12Wc2y0lDh0ukAAw4UK0FrgcWSjqwaOgebAhwTezlcyL muQA== X-Gm-Message-State: AOJu0YxpIcr3TyGYAIPaobpCD60H5Ha1HaweFhdid/Q1Ga5FrVtY7pXX /P8dN+VwtkMaVWYMahlu4WMql8mbN47kKpx6HtCzF6DaOJWneBjDa54G+2eW3Z0nZ68gsn1vrT3 u0VrgU2njcITjc+5rsy64WagZpHaJtLbPbA5gL/75UHlZQMuZ7vLNTJAzH/450Y0PYmNbyh20Rb yo9KhV X-Received: by 2002:a17:906:535e:b0:a19:a19b:c70a with SMTP id j30-20020a170906535e00b00a19a19bc70amr1640306ejo.90.1701970579944; Thu, 07 Dec 2023 09:36:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZsht74YiPZSmNEN3oOTS3GXbCb/JwWLKYDK3Gt1oSwOeESs2MefBmfqh4Au7dzXN2z6m8+g== X-Received: by 2002:a17:906:535e:b0:a19:a19b:c70a with SMTP id j30-20020a170906535e00b00a19a19bc70amr1640296ejo.90.1701970579486; Thu, 07 Dec 2023 09:36:19 -0800 (PST) Received: from [192.168.0.129] (ip-94-112-227-180.bb.vodafone.cz. [94.112.227.180]) by smtp.gmail.com with ESMTPSA id hw18-20020a170907a0d200b00a1cbe52300csm13006ejc.56.2023.12.07.09.36.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Dec 2023 09:36:19 -0800 (PST) Message-ID: <1acf9fad-d739-68e8-4090-c70572937eab@redhat.com> Date: Thu, 7 Dec 2023 18:36:18 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: [PING][PATCH v3] gdb: register frame_destroyed function for amd64 gdbarch To: gdb-patches@sourceware.org, Guinevere Larsen Cc: Andrew Burgess References: <20231102095005.3650126-1-blarsen@redhat.com> <20231108142422.1209851-1-blarsen@redhat.com> From: Guinevere Larsen In-Reply-To: <20231108142422.1209851-1-blarsen@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_BARRACUDACENTRAL,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: Ping! -- Cheers, Guinevere Larsen She/Her/Hers On 08/11/2023 15:24, Guinevere Larsen wrote: > 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"