Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Luis Machado <luis.machado@arm.com>,
	gdb-patches@sourceware.org, Pedro Alves <pedro@palves.net>
Subject: Re: [PATCH] [gdb/tdep] Fix gdb.base/watchpoint-running on {arm, ppc64le}-linux
Date: Thu, 13 Jun 2024 11:07:54 +0200	[thread overview]
Message-ID: <9939e750-5ab9-4703-be6b-ff544d4d09d1@suse.de> (raw)
In-Reply-To: <93d12a77-ad21-4e67-ba82-3205ba923c01@suse.de>

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 <luis.machado@arm.com>
>> Tested-By: Luis Machado <luis.machado@arm.com>
> 
> 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


  reply	other threads:[~2024-06-13  9:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-07  6:35 Tom de Vries
2024-06-07 10:18 ` Luis Machado
2024-06-07 12:05   ` Tom de Vries
2024-06-13  9:07     ` Tom de Vries [this message]
2024-06-13  9:08       ` Luis Machado
2024-06-14 16:49 ` Pedro Alves
2024-06-17 18:22   ` Tom de Vries
2024-06-20 13:49     ` Tom de Vries
2024-06-20 18:15     ` Pedro Alves
2024-06-21  9:43       ` Tom de Vries
2024-06-21 12:44         ` Pedro Alves
2024-06-21 14:51           ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9939e750-5ab9-4703-be6b-ff544d4d09d1@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado@arm.com \
    --cc=pedro@palves.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox