public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix sporadic XFAILs in, gdb.threads/attach-many-short-lived-threads.exp
@ 2024-03-31 10:47 Bernd Edlinger
  2024-04-04  1:41 ` Thiago Jung Bauermann
  0 siblings, 1 reply; 5+ messages in thread
From: Bernd Edlinger @ 2024-03-31 10:47 UTC (permalink / raw)
  To: gdb-patches

This is about random test failures like those:

XFAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 6: attach (EPERM)
XFAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 7: attach (EPERM)
XFAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: attach (EPERM)
XFAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 9: attach (EPERM)
XFAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 10: attach (EPERM)

The reason for this effect is apparently as follows:

There is a race condition when gdb tries to attach a thread but the
thread exits at the same time.  Normally when that happens the return
code of ptrace(PTRACE_ATTACH, x) is EPERM, which could also have other
reasons.  To detect the true reason, we try to open /proc/<pid>/status
which normally fails in that situation, but it may happen that the
fopen succeeds, and the thread disappears while reading the content,
then the read has the errno=ESRCH, use that as an indication that the
thread has exited between fopen and reading of the status file.
---
 gdb/nat/linux-procfs.c | 3 +++
 1 file changed, 3 insertions(+)

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;
     }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-06  3:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-31 10:47 [PATCH] Fix sporadic XFAILs in, gdb.threads/attach-many-short-lived-threads.exp 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
2024-04-06  3:40       ` Thiago Jung Bauermann

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).