From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id RVYDB+vroGZhWDAAWB0awg (envelope-from ) for ; Wed, 24 Jul 2024 07:56:27 -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=qKcaBmMi; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=0tbzGoTv; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=R92Qzeae; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=9bA50O2J; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 065A11E0C3; Wed, 24 Jul 2024 07:56:27 -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 C0D691E097 for ; Wed, 24 Jul 2024 07:56:24 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2883E3858D26 for ; Wed, 24 Jul 2024 11:56:24 +0000 (GMT) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 0C9853858D26 for ; Wed, 24 Jul 2024 11:55:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C9853858D26 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 0C9853858D26 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=1721822162; cv=none; b=bhqSv1eBcUzIFryVxNFsa+kVydw1/Lz3YdGp8OTwaQqSCLwKS5vLjJeiCiVDacwh6z6ldb0PHapTy/VGRJhjCmeyP+YkP1xj+Erey7l/7wZFrsEi99PHdgzy+vNPcb1Bz/DlNOGk3z5m/Yd8Lg6P4aNH4QseS1R0J42GVOedx8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721822162; c=relaxed/simple; bh=PnGl9kbSMgEIZ/3LvogXuVSc5BaZwbVAAkEzHZljzf0=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=Alo++81ncpdNHn3Hx4NEQbx4Sh+IyZc4pddYeQcyc4ub5R7WVjt5bfOc2P589SSTgnKpx6mpH6ZN5ynbcKEA3xM9qOg6pgUJs9ALGKp6TyvASbYpjW5s2w8yBzdxm/9zYsHoklqBBnkKvsx2g4je1H3oqlleWM/EUI+khBRE4Rk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 F007021AF6; Wed, 24 Jul 2024 11:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721822158; 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=t/u8wvApAgFlqvPgdrA6KzHq3KZsZLvA69Kwq9GDQtg=; b=qKcaBmMiFMn6AkidqfsCY9bTlzpOTnb9RHK153yiilNxrn69M5IEchzT7epS5ZuJBbK0VM B8ER+cYGfCsXj5emFaYimbeIWHaw696J8ZGSR7CzaMrcVsCKZoi0zwRQHO5pzycCod1yx7 vPf0ZWDfiw5b6N+M4Tn/QcX3ZGyers0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721822158; 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=t/u8wvApAgFlqvPgdrA6KzHq3KZsZLvA69Kwq9GDQtg=; b=0tbzGoTvrRCTURWwq7CyA5Rr8Q5+yVqvakvpocWSJtuGfgAHtIa/827H9kXyamPSrkOnmS uYorsY55FXIdgwAA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=R92Qzeae; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=9bA50O2J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721822157; 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=t/u8wvApAgFlqvPgdrA6KzHq3KZsZLvA69Kwq9GDQtg=; b=R92QzeaeMKW/y61OS/DMlt/APuBKIMKUyO62ZTGGuQxyni9I+1bJp6rhoUIq7NsPDKlWD9 3K46aKABFye4HWP0YoWitYqJhQAfpL/F8GSroPiva+FpWLq3jRMzTKBzRflhqrNDU3b0Yu qVa5HloGkRGZkaRshKFRHnn3xwsD5RI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721822157; 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=t/u8wvApAgFlqvPgdrA6KzHq3KZsZLvA69Kwq9GDQtg=; b=9bA50O2JTgP7KoQr+BaNOfJG3at027nc0T4QR+9SlrNEHO4cCbYQ6RrOI66C2JogjonVg8 CS05j8BYIaeE6SBA== 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 D9D4513AF8; Wed, 24 Jul 2024 11:55:57 +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 N7DZM83roGbpewAAD6G6ig (envelope-from ); Wed, 24 Jul 2024 11:55:57 +0000 Message-ID: Date: Wed, 24 Jul 2024 13:56:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC] [gdb/testsuite] Add xfail in gdb.base/hbreak.exp To: Luis Machado , gdb-patches@sourceware.org References: <20240717151055.21480-1-tdevries@suse.de> <6ad9fbd8-1977-4688-9534-00d1271bba99@arm.com> <6d4a4345-0247-4c1f-9db3-e0347b475e4b@suse.de> <4e82e0bc-3e3a-4461-be2d-7b8d4785e1a5@arm.com> <0f4d0d87-458f-482d-af49-fc6a65b15daa@suse.de> <678c782d-a7c6-43d7-a454-2d6f21967c78@arm.com> Content-Language: en-US From: Tom de Vries In-Reply-To: <678c782d-a7c6-43d7-a454-2d6f21967c78@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.30 / 50.00]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; XM_UA_NO_VERSION(0.01)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Spam-Score: -3.30 X-Rspamd-Queue-Id: F007021AF6 X-Spam-Status: No, score=-10.9 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 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 7/24/24 12:45, Luis Machado wrote: > On 7/24/24 10:28, Tom de Vries wrote: >> On 7/24/24 08:53, Luis Machado wrote: >>> On 7/24/24 06:25, Tom de Vries wrote: >>>> On 7/23/24 12:02, Luis Machado wrote: >>>>> On 7/17/24 16:14, Luis Machado wrote: >>>>>> On 7/17/24 16:10, Tom de Vries wrote: >>>>>>> On an aarch64-linux system with 32-bit userland running in a chroot, and using >>>>>>> target board unix/mthumb I get: >>>>>>> ... >>>>>>> (gdb) hbreak hbreak.c:27^M >>>>>>> Hardware assisted breakpoint 2 at 0x4004e2: file hbreak.c, line 27.^M >>>>>> >>>>>> That is a bit odd, but it goes through the compat layer, which is not exercised >>>>>> as often as the 32-bit code. >>>>>> >>>>>> Let me see if I can reproduce this one on my end. >>>>> >>>>> I managed to reproduce this. I checked with the kernel folks and this should >>>>> work, but I'm not sure where the error is coming from. >>>>> >>>> >>>> Hi Luis, >>>> >>>> thanks for looking into this, and the approval, committed. >>>> >>>> Are you or the kernel folks following up on this, in terms of a linux kernel PR or some such?  It would be nice to add some sort of reference to the xfail. >>> >>> It's in my TODO. I'm still investigating to understand where the error is coming from. Once located, I plan to check with them for their thoughts and a possible >>> fix. I don't think the kernel folks use the PR process much. We could probably ammend this commit later on once we have more information though. >>> >> >> Ok, I spent some more time debugging this issue this morning. >> >> After reading kernel sources for a while, I tried out reversing the order in which the Breakpoint Register Pair is written in arm_linux_nat_target::low_prepare_to_resume, and ... the test-case passes. >> > > But what would change with reversing writing to the control registers, from gdb's perspective? > Well, from gdb's perspective, the only difference is that both ptrace calls succeed, while with the original order the first one fails (and consequently there's no second call). >> My theory at this point is that the following happens in the failing case: >> - PTRACE_SETHBPREGS with address 0x4004e2 >> - compat_arch_ptrace >> - compat_ptrace_sethbpregs >> - compat_ptrace_hbp_set >> - ptrace_hbp_set_addr >> - ptrace_hbp_get_initialised_bp >> - ptrace_hbp_create >> - /* Initialise fields to sane defaults >>      (i.e. values that will pass validation).  */ >>   attr.bp_len = HW_BREAKPOINT_LEN_4; > > > The default starts as a 4-byte breakpoint, but is supposed to be adjusted later on to 2 bytes. If this isn't happening, I think we have a bug somewhere. > Agreed, you could frame that as a kernel bug. It would be good to known whether the kernel developers agree with that assessment. >> - attr.bp_addr = 0x4004e2; >> - modify_user_hw_breakpoint >> - modify_user_hw_breakpoint_check >> - hw_breakpoint_parse >> - hw_breakpoint_arch_parse >> - case is_compat_bp(bp) >> - offset = 2; >> - fallthrough to default >> - return -EINVAL >> >> In short, we try to validate: >> - attr.bp_len == HW_BREAKPOINT_LEN_4 && attr.bp_addr == 0x4004e2 >> and fail. >> >> By reversing the order, we validate: >> - attr.bp_len == HW_BREAKPOINT_LEN_2 && attr.bp_addr == 0, and then >> - attr.bp_len == HW_BREAKPOINT_LEN_2 && attr.bp_addr == 0x4004e2 >> which both succeed. > > Why do we have HW_BREAKPOINT_LEN_2 above while the first case has HW_BREAKPOINT_LEN_4? > Well, because we reversed the order of the two ptrace calls. So, in the original case, the first call to ptrace uses the default bp_len (HW_BREAKPOINT_LEN_4) and the actual address (0x4004e2), which fails. And in the reversed order case, the first call to ptrace uses the default address (0x0) and the actual bp_len (HW_BREAKPOINT_LEN_2). [ With "default" meaning, as set by ptrace_hbp_create, and "actual", as set by the ptrace calls. ] >> >> So, my questions at this point are: >> - is this a problem limited to aarch64 32-bit mode, or does it also >>   occur for native 32-bit arm? > > I'm not sure at this point. They are two separate code bases, but it is probably reasonable to assume the compat layer of aarch64 was based on the > original 32-bit arm code. Checking hw_breakpoint_arch_parse for arm, it does seem fairly similar. > I also observed that they're very similar. >> - is this a kernel bug? > > Potentially, if it is assuming a length that is not correct. > >> - if this is a kernel bug, is there a workaround we can use? >> - if this is not a kernel bug, is this because gdb is writing the >>   Breakpoint Register Pair in the wrong order? > > I don't think we have a specific order to write things, but if it is a bug that arises from a specific order of commands, we could potentially > work around it. > OK, I'm currently testing that approach. Thanks, - Tom >> >> Thanks, >> - Tom >> >>>> >>>> Thanks, >>>> - Tom >>>> >>>>>> >>>>>> >>>>>>> (gdb) PASS: gdb.base/hbreak.exp: hbreak >>>>>>> continue^M >>>>>>> Continuing.^M >>>>>>> Unexpected error setting breakpoint: Invalid argument.^M >>>>>>> (gdb) FAIL: gdb.base/hbreak.exp: continue to break-at-exit after hbreak >>>>>>> ... >>>>>>> due to this call in arm_linux_nat_target::low_prepare_to_resume: >>>>>>> ... >>>>>>>             if (ptrace (PTRACE_SETHBPREGS, pid, >>>>>>>                 (PTRACE_TYPE_ARG3) ((i << 1) + 1), &bpts[i].address) < 0) >>>>>>>               perror_with_name (_("Unexpected error setting breakpoint")); >>>>>>> ... >>>>>>> >>>>>>> This problem does not happen if instead we use a 4-byte aligned address. >>>>>>> >>>>>>> I'm not sure if this is simply unsupported or if there's a kernel bug of some >>>>>>> sort, but I don't see what gdb can do about this. >>>>>>> >>>>>>> Tentatively mark this as xfail. >>>>>>> >>>>>>> Tested on aarch64-linux. >>>>>>> --- >>>>>>>    gdb/testsuite/gdb.base/hbreak.exp | 40 ++++++++++++++++++++++++++----- >>>>>>>    1 file changed, 34 insertions(+), 6 deletions(-) >>>>>>> >>>>>>> diff --git a/gdb/testsuite/gdb.base/hbreak.exp b/gdb/testsuite/gdb.base/hbreak.exp >>>>>>> index 73a3e2afb67..b140257a23e 100644 >>>>>>> --- a/gdb/testsuite/gdb.base/hbreak.exp >>>>>>> +++ b/gdb/testsuite/gdb.base/hbreak.exp >>>>>>> @@ -27,10 +27,38 @@ if ![runto_main] { >>>>>>>      set breakline [gdb_get_line_number "break-at-exit"] >>>>>>>    -gdb_test "hbreak ${srcfile}:${breakline}" \ >>>>>>> -     "Hardware assisted breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*${srcfile}, line ${breakline}\\." \ >>>>>>> -     "hbreak" >>>>>>> +set re_loc "file \[^\r\n\]*$srcfile, line $breakline" >>>>>>> +set re_dot [string_to_regexp .] >>>>>>>    -gdb_test "continue" \ >>>>>>> -     "Continuing\\.\[ \r\n\]+Breakpoint \[0-9\]+, .*break-at-exit.*" \ >>>>>>> -     "continue to break-at-exit after hbreak" >>>>>>> +set addr 0x0 >>>>>>> +gdb_test_multiple "hbreak ${srcfile}:${breakline}" "hbreak" { >>>>>>> +    -re -wrap "Hardware assisted breakpoint $decimal at ($hex): $re_loc$re_dot" { >>>>>>> +    set addr $expect_out(1,string) >>>>>>> +    pass $gdb_test_name >>>>>>> +    } >>>>>>> +} >>>>>>> + >>>>>>> +set have_xfail 0 >>>>>>> +if { [istarget arm*-*-*] } { >>>>>>> +    # When running 32-bit userland on aarch64 kernel, thumb instructions that >>>>>>> +    # are not 4-byte aligned may not be supported for setting a hardware >>>>>>> +    # breakpoint on. >>>>>>> +    set have_xfail [expr ($addr & 0x2) == 2] >>>>>>> +} >>>>>>> + >>>>>>> +set re_xfail \ >>>>>>> +    [string_to_regexp \ >>>>>>> +     "Unexpected error setting breakpoint: Invalid argument."] >>>>>>> + >>>>>>> +gdb_test_multiple "continue" "continue to break-at-exit after hbreak" { >>>>>>> +    -re -wrap "Continuing\\.\[ \r\n\]+Breakpoint \[0-9\]+, .*break-at-exit.*" { >>>>>>> +    pass $gdb_test_name >>>>>>> +    } >>>>>>> +    -re -wrap $re_xfail { >>>>>>> +    if { $have_xfail } { >>>>>>> +        xfail $gdb_test_name >>>>>>> +    } else { >>>>>>> +        fail $gdb_test_name >>>>>>> +    } >>>>>>> +    } >>>>>>> +} >>>>>>> >>>>>>> base-commit: 0ed152c5c6b3c72fc505b331ed77e08b438d643a >>>>>> >>>>> >>>>> In any case, I agree gdb doesn't have a better way to deal with it. >>>>> >>>>> Approved-By: Luis Machado >>>> >>> >> >