public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix sporadic XFAILs in, gdb.threads/attach-many-short-lived-threads.exp
Date: Fri, 5 Apr 2024 07:00:11 +0200	[thread overview]
Message-ID: <AS8P193MB12854050D97B2114298F63C6E4032@AS8P193MB1285.EURP193.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <87sf01nli5.fsf@linaro.org>

On 4/4/24 18:25, Thiago Jung Bauermann wrote:
> 
> Hello again,
> 
> Sorry, one more comment that occurred to me today.
> 
> Thiago Jung Bauermann <thiago.bauermann@linaro.org> writes:
> 
>> Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
>>
>>> diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c
>>> index e2086952ce6..36e0f5bf16a 100644
>>> --- a/gdb/nat/linux-procfs.c
>>> +++ b/gdb/nat/linux-procfs.c
>>> @@ -165,6 +165,9 @@ linux_proc_pid_is_gone (pid_t pid)
>>>      }
>>>    else if (have_state == 0)
>>>      {
>>> +      /* errno is ESRCH "No such process": assume thread has disappeared.  */
>>> +      if (errno == ESRCH)
>>> +	return 1;
>>>        /* No "State:" line, assume thread is alive.  */
>>>        return 0;
>>>      }
>>
>> With this patch applied on top of my patch series fixing attach to
>> zombie threads¹, I don't see these XFAILs anymore on an aarch64-linux
>> machine where previously I saw them on every run of this testcase. Nice!
>>
>> I would even suggest removing the XFAIL from the testcase, if other
>> people can confirm similar results.
>>
>> In any case:
>>
>> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
> 
> Actually, thinking more about it I think it would be better if
> linux_proc_pid_get_state checked for errno == ESRCH itself and returned
> -1 in that case (and also warn if that parameter is true), instead of
> making its caller do that check.
> 
> The function documentation says:
> 
> /* Fill in STATE, a buffer with BUFFER_SIZE bytes with the 'State'
>    line of /proc/PID/status.  Returns -1 on failure to open the /proc
>    file, 1 if the line is found, and 0 if not found.  If WARN, warn on
>    failure to open the /proc file.  */
> 
> I think that getting the ESRCH error while reading is semantically
> equivalent to failing to open the /proc file. Returning 0 when the line
> wasn't found because of the ESRCH error adheres to the letter of that
> comment but not to its spirit. :-)
> 

The patch only works because linux_proc_pid_is_gone is just called
on two places, where errno == EPERM:

gdb/linux-nat.c:	      || (err == EPERM && linux_proc_pid_is_gone (lwpid)))
gdbserver/linux-low.cc:	  || (err == EPERM && linux_proc_pid_is_gone (lwpid)))

so when errno is changed from EPERM->ESRCH and there was no Status line
found, then it is pretty clear what happened.

But linux_proc_pid_get_state is called from other places where errno may
be by chance already ESRCH.

I've spent some time reading the kernel sources, where the ESRCH return code
was first introduced with v2.6.18, but unless the ESRCH is returned, all
linux versions seem to always return the "Name:" followed by "State:" 
etc.

So actually I don't see under which condition a thread can be alive
when no "State:" line is found, as the comment here is probably
just wrong:

      /* No "State:" line, assume thread is alive.  */
      return 0;


Bernd.

> --
> Thiago

  reply	other threads:[~2024-04-05  4:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-31 10:47 Bernd Edlinger
2024-04-04  1:41 ` Thiago Jung Bauermann
2024-04-04 16:25   ` Thiago Jung Bauermann
2024-04-05  5:00     ` Bernd Edlinger [this message]
2024-04-06  3:40       ` Thiago Jung Bauermann

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=AS8P193MB12854050D97B2114298F63C6E4032@AS8P193MB1285.EURP193.PROD.OUTLOOK.COM \
    --to=bernd.edlinger@hotmail.de \
    --cc=gdb-patches@sourceware.org \
    --cc=thiago.bauermann@linaro.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).