From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sun, 20 Feb 2022 00:44:08 -0800 Subject: [PATCH] serenity: Implement mourn_inferior override for the serenity_nat_target We need to pass `WNOHANG` to our `waitpid(..)` call on SerenityOS, otherwise we will wait forever. --- gdb/serenity-nat.c | 14 ++++++++++++++ gdb/serenity-nat.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/gdb/serenity-nat.c b/gdb/serenity-nat.c index b1d39d4..7789950 100644 --- a/gdb/serenity-nat.c +++ b/gdb/serenity-nat.c @@ -71,3 +71,17 @@ ptid_t serenity_nat_target::wait (ptid_t ptid, struct target_waitstatus* ourstat return ptid_t (pid); } + +void serenity_nat_target::mourn_inferior () +{ + int status; + + /* Wait just one more time to collect the inferior's exit status. + * Do not check whether this succeeds though, since we may be + * dealing with a process that we attached to. Such a process will + * only report its exit status to its original parent. + */ + waitpid (inferior_ptid.pid (), &status, WNOHANG); + + inf_child_target::mourn_inferior (); +} diff --git a/gdb/serenity-nat.h b/gdb/serenity-nat.h index 9ae3b87..35d7ffc 100644 --- a/gdb/serenity-nat.h +++ b/gdb/serenity-nat.h @@ -13,6 +13,8 @@ class serenity_nat_target : public inf_ptrace_target { ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override; + void mourn_inferior (); + private: bool m_attach_before_continue_called { false }; };