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.129.124]) by sourceware.org (Postfix) with ESMTPS id 5F46A3858C42 for ; Tue, 19 Dec 2023 11:51:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F46A3858C42 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 5F46A3858C42 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=1702986674; cv=none; b=iUUcug3MT6KRQGvuhU6TpQgXHhtVfV5sT+fCVOOYx8ZRL+7K7BzKXNVU4upMouNsmgN6b/hvVHUpmuubKeklw/+29qdVVYBDjZePpUWSD4ylUXTsnbNDt7nW5pLLMOK8NQx8zVGV7x+wtzgQMLUMKkkXCm619i0QtwOnCwT5wxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702986674; c=relaxed/simple; bh=7L+RN5AM3I6Kzac7s4d0Uoz9lpiExXf0B4G+jGkeUIY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ESRfbsaVmaJN+meluTDKQ3S1iiypyzN3ig2w6VqoJRhTy/h+GBVM4cSCQtIWuuzDgLBLGyLBtlr/KzNgRQEVpiepHP2C8yyQEYryiZ0KAv+irAmvri1arHxCxNdaml1ngce5Fn44dJgtPNanonljZEoXbQUuhHo0seOSfWTMS5U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702986670; 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: in-reply-to:in-reply-to:references:references; bh=/VwceZd6oVBj5Y96g/A6aeJAxVmJNLTKugLAfpJuSUw=; b=Lq71GXeHnTrmunQvU8Yy1vDMax6KPBtTL7JrHElZfKIPLblQwALFmdfTEKeVqAhLPtmMYh M+CtPYwWnagElMS9BOrUIMkPGbOoKQ7465I63lR/iPTK3zitWA8t7ElOOhK+/NYXT6dQ6V MNcnQ2dImJ70AozwK+FJZNgGCxnCNWM= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-207-bvVt76pNMgOhgPZa4nxrBw-1; Tue, 19 Dec 2023 06:51:08 -0500 X-MC-Unique: bvVt76pNMgOhgPZa4nxrBw-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-9fd0a58549bso436431566b.0 for ; Tue, 19 Dec 2023 03:51:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702986667; x=1703591467; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/VwceZd6oVBj5Y96g/A6aeJAxVmJNLTKugLAfpJuSUw=; b=r93/oCdOlLe/vtgf92R5LGOpmfrWiRSMCmyv4GoPz+UE2BqcQYwJ95uBtpd9sWaete Hq9GZB2It3ic/zrIpkxsNaHPBCyE5wr/+hpA8aHRVG6DkM5eooWirQEmQYwQnFK9Ju+T qCmfJCH6yvO9Ho39RZz675qxwI9Q+ymmOdgwe9VYVojPUouwU48fzUoiYg8MNKAsQ5xm laavOlCp56kLGpP9F+oe2P01wuWDQRQ70smm3FPnuocSQsDA+xm1yeeONhAejhIKKO57 3BDqLTnypEQVApfY8uSdUrfjoPWq/8yqCQFgyetcrj6Ii05l/tnCrPIEDIQXmVNMM4B5 Vmzw== X-Gm-Message-State: AOJu0Yz1LkHDAXKmr+NKUFg1e4HtKVHjGoOE4WNkg49yTpzmbLudUyb1 7DMGQ1nBOEVkE+Te5yPTDI0a8WeUWWzr80QdI+0+Yp/HQZH6AQJegpRlPnv11k8+rWg1tuvWXEo 9DoMnqd0uZIAcusbk+5jAYl8nVTrtZP8f3hL/6A== X-Received: by 2002:a17:906:1392:b0:a23:671c:2284 with SMTP id f18-20020a170906139200b00a23671c2284mr988479ejc.29.1702986667050; Tue, 19 Dec 2023 03:51:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGDRZL/JmJyD14iSSLVh4cfdFcGV16x10M/y8nzsT6uTR6jHz1+/cvGzd4coUf+mjgBKbrEg== X-Received: by 2002:a17:906:1392:b0:a23:671c:2284 with SMTP id f18-20020a170906139200b00a23671c2284mr988473ejc.29.1702986666740; Tue, 19 Dec 2023 03:51:06 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id y22-20020a170906071600b00a2686db1e81sm89537ejb.26.2023.12.19.03.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 03:51:06 -0800 (PST) From: Andrew Burgess To: Guinevere Larsen , gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: Re: [PATCH v3] gdb: register frame_destroyed function for amd64 gdbarch In-Reply-To: <20231108142422.1209851-1-blarsen@redhat.com> References: <20231102095005.3650126-1-blarsen@redhat.com> <20231108142422.1209851-1-blarsen@redhat.com> Date: Tue, 19 Dec 2023 11:51:05 +0000 Message-ID: <87o7emz9zq.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 List-Id: Guinevere Larsen writes: > 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 Missing a '.' on the last sentence of your commit message :) Approved-By: Andrew Burgess Thanks for fixing this. Andrew > > 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