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 AAA8D3858424 for ; Mon, 18 Dec 2023 10:24:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AAA8D3858424 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 AAA8D3858424 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=1702895077; cv=none; b=eLhVdIlO34XNvNAIYxbU+1txsUjwuRowxR3NX39t7vN4fz8fj9wksJmTnhPaeUT9CDglNYYSQ8L5v3fqBB0sva1jtWaFGqlpEq0vF4NKEkcOoGh7OgfTa0Hfmd5RHrAgd8fdszQmPH4a1YAARfmA7QdHcZbi6rmFYZtgQ2gz2zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702895077; c=relaxed/simple; bh=wznOHRhpRio0+O7IOugLc4cF8hMgRwz+U+EH0l2UPSo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=H1QaYpfyKiMgtrZp5CoVzN118zCFTtxwA3tjhXuS8BI1xHRO73dBfMB75dPh8/RnbpKXDzjvt9G/TRNvtUe8urDn4RbHwzCME88Pqp/GA9+tyw6mA7D9iGaj4HMyxwGQemJR3/79b+2Y9HpwU+0HQG+XicFWewfqLXGpbjGCWv0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702895075; 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=JRFmYk6uJSqtx19Ct88U/g9SWEfDq5urBV1QRJRyhuw=; b=d0drTHZ4MD8r3dIIMbZMIvfO4kjMPaG6fjYw5GclbQNw2sPIowd/FytwJ3sGvCqmJT3uLJ JaVwIxnmCGElEpK85EERQyBwZAy7jlEkpo/VxAJXHsQ0zoZP/6yOWBPFxxJy7Vyf3I79J7 MkCo00bO1WUjh0S76E9pCRS7OoXubzs= 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-222-KRcfqjaKM2ifdQbTVzs6EA-1; Mon, 18 Dec 2023 05:24:34 -0500 X-MC-Unique: KRcfqjaKM2ifdQbTVzs6EA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a2359549fc0so20158566b.0 for ; Mon, 18 Dec 2023 02:24:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702895072; x=1703499872; 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=JRFmYk6uJSqtx19Ct88U/g9SWEfDq5urBV1QRJRyhuw=; b=iNrVopQyVYXSSwGAHAqDd17F1UXnI2iMx/TZGdsaNqSytGsj/AOC6G+GykcWfQ+X/U aS8ZfyOUOYgptP6l7UJj7yZCd9Gq0EooAcCkX5SFT5n5Tya9+CvrHQ5Lr8slqz6pknPN Oh1uXb9zb8kWjBRUbBNhIPNV0/NWND7Xqa6DVMfjgidEg+MWsAXcwe3gz8MYBN2VZyyM fIAK8kpabzj7NFtU+/Z9C9JBdCvywqybdror8sCgo2lE/rVed2huOgGuA5UsEr5LxuFv ASIcIjCqI+yB3SBpok76uHAV+1RJeH0yTrr3u8WX65xMlfgc29tbydznOi3I8AVdOCqk ZeIg== X-Gm-Message-State: AOJu0YzCBIw4g+fX7jCfUtrrbJkQslb9MO7B52C6cySxH5DIl8JUUDO7 +GLjHlH9Srol+IXtcAkX7swXgOIHAUhuM/XZ5q651sCztrBldAGkDKJOBWq7q5278jIGrflklCk KewgwXXva7UpaBfo2Qfmeja1n82cy/1f+s/5x6AaAUN0nki9YgKOl6vyUUbB9G43UXM9nfBiiaH xGnt7a X-Received: by 2002:a17:906:106:b0:a10:ef07:fa9e with SMTP id 6-20020a170906010600b00a10ef07fa9emr10423897eje.6.1702895072601; Mon, 18 Dec 2023 02:24:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCoD/Ego7Dtq3gQmOYecYd0TM3az17z/GNwdwySanA/LqmquH51XgH3YBDm6UAKDKkafT1tg== X-Received: by 2002:a17:906:106:b0:a10:ef07:fa9e with SMTP id 6-20020a170906010600b00a10ef07fa9emr10423888eje.6.1702895072172; Mon, 18 Dec 2023 02:24:32 -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 sk26-20020a170906631a00b00a1f7852c877sm13302679ejc.142.2023.12.18.02.24.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Dec 2023 02:24:31 -0800 (PST) Message-ID: <391b21b5-91ef-d395-10a1-bc01ba2901f4@redhat.com> Date: Mon, 18 Dec 2023 11:24:29 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: [PINGv2][PATCH v3] gdb: register frame_destroyed function for amd64 gdbarch To: gdb-patches@sourceware.org Cc: Andrew Burgess References: <20231102095005.3650126-1-blarsen@redhat.com> <20231108142422.1209851-1-blarsen@redhat.com> <1acf9fad-d739-68e8-4090-c70572937eab@redhat.com> From: Guinevere Larsen In-Reply-To: <1acf9fad-d739-68e8-4090-c70572937eab@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: 8bit X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,BODY_8BITS,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! On 07/12/2023 18:36, Guinevere Larsen wrote: > 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" -- Cheers, Guinevere Larsen She/Her/Hers