public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/hurd: handle inferiors exiting
@ 2022-01-06 15:41 Andrew Burgess
  2022-01-06 17:35 ` John Baldwin
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Burgess @ 2022-01-06 15:41 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

While testing on GNU/Hurd (i386) I noticed that GDB crashes when an
inferior exits, with this error:

  inferior.c:293: internal-error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.

The problem appears to be in gnu_nat_target::wait.

When GDB is waiting for any active inferior to do something
interesting, we pass in the null_ptid to indicate that the target
should wait on all inferiors.

In gnu_nat_target::wait, when we get an exit event, we currently
return the passed in ptid (null_ptid) and there's a comment in the
code "let wait_for_inferior handle exit case".

This may have been the case once upon a time, when GDB could only
handle one inferior at a time, but is certainly not the case any more,
we expect ::wait to return a valid ptid if it saw an event.

I believe that the fix for this issue is pretty easy, when we see the
exit event, just return a ptid containing the process-id only.

For testing, running something like gdb.base/break.exp is enough to
show the original problem, and this test now fully passes with this
patch applied.

I've not run the full testsuite on GNU/Hurd as there appear to be lots
of other issues with this target that makes running the full testsuite
very painful, but I think this looks like a small easy improvement.

Feedback welcome.
---
 gdb/gnu-nat.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index b7b486904e8..4086aeb4569 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -1603,7 +1603,10 @@ gnu_nat_target::wait (ptid_t ptid, struct target_waitstatus *status,
 							       available
 							       thread.  */
       else
-	ptid = inferior_ptid;	/* let wait_for_inferior handle exit case */
+	{
+	  /* The process exited. */
+	  ptid = ptid_t (inf->pid);
+	}
     }
 
   if (thread
-- 
2.25.4


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

end of thread, other threads:[~2022-01-08 22:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06 15:41 [PATCH] gdb/hurd: handle inferiors exiting Andrew Burgess
2022-01-06 17:35 ` John Baldwin
2022-01-07 10:46   ` Andrew Burgess
2022-01-07 17:13   ` Pedro Alves
2022-01-08 22:14     ` Andrew Burgess

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