From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 59Y/Mdm2ambObjMAWB0awg (envelope-from ) for ; Thu, 13 Jun 2024 05:07:37 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=LYEJPT20; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=octfhdFK; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=oXf/Z5RW; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=tckVLC4Y; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B4C471E0C1; Thu, 13 Jun 2024 05:07:37 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5BDB31E030 for ; Thu, 13 Jun 2024 05:07:35 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE9BD388215B for ; Thu, 13 Jun 2024 09:07:34 +0000 (GMT) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 1746A3882049 for ; Thu, 13 Jun 2024 09:07:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1746A3882049 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1746A3882049 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718269635; cv=none; b=j8xJhjfb+RkPosNSogqWFl3CljdtXycUV+jmz01CD8GIcT3UIQtgzY3sD7EI/dZwMgGDFKQJTPJ1W02vsQ6MEVIj/i6hkh8re7gsKHZS9ELXSQBIT2Soct6TP5FR4S52WlGRfMcCMQLL4+CJD44Kr8AKFh1kKjzbZ9Y4oNRlZEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718269635; c=relaxed/simple; bh=2lezdYhKwauKhQcmUjsRlsar+kWy0NGjKENzdv/QQB0=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:From:To; b=PuHHkV57F/Sw4iiiJuUk2EEz4xh07S2zaO/6W0om4UB5nrOWowLtm/NdaKD73Y6jDtKGq3IUQwCfOUKH/sDFbN6hbmSb4c3rC6DTnwuYmtdQaFSCVYHiy719+qQyhAfbf+mEdX4XMibxs5aTP3UBu5xhinzTuL1aGLlQy3sFVBk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E905035170; Thu, 13 Jun 2024 09:07:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718269632; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5SqrWzklKiMBi1Hy6ZOaoBuKICxv32zsojyvdQdzZJ0=; b=LYEJPT20lZ9vaPz4xoRvVhTS5BgN4qT+6+826BSk7P/w2abSO48bcwqpzbVWkdSLwdiZkI 8dc/EIOsDJrX0rV8kG2a2D/9IZMo5UcVwGxpeGwl/nblfJkn7WGDy7JUD57YUNBSWxpHCM 78CU4St73R7fgEMsAyqCw0HXt9fiIg8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718269632; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5SqrWzklKiMBi1Hy6ZOaoBuKICxv32zsojyvdQdzZJ0=; b=octfhdFKO0wrbl1ZUQAI6G8tNWVCx3pkOQo8bRlizDnL76DXUR7jlpgIkj6SXDRgotZzM+ QSDeCMUlu/89geCw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718269631; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5SqrWzklKiMBi1Hy6ZOaoBuKICxv32zsojyvdQdzZJ0=; b=oXf/Z5RW64hKFLGFzF16DElk6b2ITkLh0AWgR1DNIhFD0SBGndOvYrQU3NSGcsdGYRVefE hFvgQD+/1wmvshiITkMYuGyy3Nl/Y+PMODbJaQRL2xJWL9/BBi4YkZSKauaYwPAglpcpa1 AwqiqJLDN1sIqDMXTMAKbrcDm0MCaOE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718269631; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5SqrWzklKiMBi1Hy6ZOaoBuKICxv32zsojyvdQdzZJ0=; b=tckVLC4YWbY4JaUdV0oRZJHxKK6pylrSnA4cZLPSRa1mycO+WRmx7iaANC3vHFhcZf0v7T BflLmHG++LvXA2Dg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C894A13A7F; Thu, 13 Jun 2024 09:07:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id adZ5L7+2amYfaAAAD6G6ig (envelope-from ); Thu, 13 Jun 2024 09:07:11 +0000 Message-ID: <9939e750-5ab9-4703-be6b-ff544d4d09d1@suse.de> Date: Thu, 13 Jun 2024 11:07:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] [gdb/tdep] Fix gdb.base/watchpoint-running on {arm, ppc64le}-linux From: Tom de Vries To: Luis Machado , gdb-patches@sourceware.org, Pedro Alves References: <20240607063525.9887-1-tdevries@suse.de> <702876d8-e2e4-4962-83fe-2cce2195b4a0@arm.com> <93d12a77-ad21-4e67-ba82-3205ba923c01@suse.de> Content-Language: en-US In-Reply-To: <93d12a77-ad21-4e67-ba82-3205ba923c01@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-4.28 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.19)[-0.947]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[arm.com:email,imap1.dmz-prg2.suse.org:helo] X-Spam-Score: -4.28 X-Spam-Level: X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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+public-inbox=simark.ca@sourceware.org On 6/7/24 14:05, Tom de Vries wrote: > On 6/7/24 12:18, Luis Machado wrote: >> On 6/7/24 07:35, Tom de Vries wrote: >>> When running test-case gdb.base/watchpoint-running on ppc64le-linux, >>> we get: >>> ... >>> (gdb) watch global_var^M >>> warning: Error when detecting the debug register interface. \ >>>    Debug registers will be unavailable.^M >>> Watchpoint 2: global_var^M >>> (gdb) FAIL: $exp: all-stop: hardware: watch global_var >>> FAIL: $exp: all-stop: hardware: watchpoint hit (timeout) >>> ... >>> >>> The problem is that ppc_linux_dreg_interface::detect fails to detect the >>> hardware watchpoint interface, because the calls to ptrace return >>> with errno >>> set to ESRCH. >>> >>> This is a feature of ptrace: if a call is done while the tracee is not >>> ptrace-stopped, it returns ESRCH. >>> >>> Indeed, in the test-case "watch global_var" is executed while the >>> inferior is >>> running, and that triggers the first call to >>> ppc_linux_dreg_interface::detect. >>> >>> And because the detection failure is cached, subsequent attempts at >>> setting >>> hardware watchpoints will also fail, even if the tracee is >>> ptrace-stopped. >>> >>> Fix this by calling target_can_use_hardware_watchpoint from >>> linux_init_ptrace_procfs, which is called from both: >>> - linux_nat_target::post_attach, and >>> - linux_nat_target::post_startup_inferior. >>> >>> By fixing this here, we also fix the same problem for arm-linux. >>> >>> Tested on ppc64le-linux and arm-linux. >>> >>> PR tdep/31834 >>> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31834 >>> PR tdep/31705 >>> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31705 >>> --- >>>   gdb/linux-nat.c | 12 ++++++++++++ >>>   1 file changed, 12 insertions(+) >>> >>> diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c >>> index c95d420d416..d8b5a99269b 100644 >>> --- a/gdb/linux-nat.c >>> +++ b/gdb/linux-nat.c >>> @@ -454,6 +454,18 @@ linux_init_ptrace_procfs (pid_t pid, int attached) >>>     linux_ptrace_init_warnings (); >>>     linux_proc_init_warnings (); >>>     proc_mem_file_is_writable (); >>> + >>> +  /* Some targets (for instance ppc and arm) may call ptrace to >>> answer a >>> +     target_can_use_hardware_watchpoint query, and cache the >>> result.  However, >>> +     the ptrace call will fail with errno ESRCH if the tracee is not >>> +     ptrace-stopped, making the query fail.  And if the caching >>> mechanism does >>> +     not disregard an ESRCH result, all subsequent queries will also >>> fail. >>> +     Call it now, where we known the tracee is ptrace-stopped. >>> + >>> +     Other targets (for instance aarch64) do the relevant ptrace >>> call and >>> +     caching in their implementation of post_attach and >>> post_startup_inferior, >>> +     in which case this call is expected to have no effect.  */ >>> +  target_can_use_hardware_watchpoint (bp_hardware_watchpoint, 1, 0); >>>   } >>>   linux_nat_target::~linux_nat_target () >>> >>> base-commit: f9478936896ada7786e8d68622f6e6ff78b97b0d >> >> Looks good from arm-linux's side. Thanks! >> >> Reviewed-By: Luis Machado >> Tested-By: Luis Machado > > Luis, thanks for the review and the testing. > > Pedro, since you reviewed a target-specific patch for the arm PR, any > comments? And just to mention this, I'd like to backport this fix to the gdb-15-branch. Thanks, - Tom