From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 8F1293858C20; Thu, 10 Mar 2022 11:42:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F1293858C20 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdbserver: Reorganize linux_process_target::filter_event X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: 1abeb1e90d708c1d94867957f90607eaa63dfad7 X-Git-Newrev: 5406bc3f1b3a8b9a653b80bae25253b1841adb46 Message-Id: <20220310114202.8F1293858C20@sourceware.org> Date: Thu, 10 Mar 2022 11:42:02 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Mar 2022 11:42:02 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D5406bc3f1b3a= 8b9a653b80bae25253b1841adb46 commit 5406bc3f1b3a8b9a653b80bae25253b1841adb46 Author: Pedro Alves Date: Tue Feb 22 10:15:07 2022 +0000 gdbserver: Reorganize linux_process_target::filter_event =20 Reorganize linux-low.cc:linux_process_target::filter_event such that all the handling for events for LWPs not in the LWP list is together. This helps make a following patch clearer. The comments and debug messages have also been tweaked to have them synchronized with the GDB counterpart. =20 Change-Id: If9019635f63a846607cfda44b454b4254a404019 Diff: --- gdbserver/linux-low.cc | 76 ++++++++++++++++++++++++++--------------------= ---- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index db482b2f48e..f7731864c1b 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -2148,46 +2148,50 @@ linux_process_target::filter_event (int lwpid, int = wstat) =20 child =3D find_lwp_pid (ptid_t (lwpid)); =20 - /* Check for stop events reported by a process we didn't already - know about - anything not already in our LWP list. - - If we're expecting to receive stopped processes after - fork, vfork, and clone events, then we'll just add the - new one to our list and go back to waiting for the event - to be reported - the stopped process might be returned - from waitpid before or after the event is. - - But note the case of a non-leader thread exec'ing after the - leader having exited, and gone from our lists (because - check_zombie_leaders deleted it). The non-leader thread - changes its tid to the tgid. */ - - if (WIFSTOPPED (wstat) && child =3D=3D NULL && WSTOPSIG (wstat) =3D=3D S= IGTRAP - && linux_ptrace_get_extended_event (wstat) =3D=3D PTRACE_EVENT_EXEC) + /* Check for events reported by anything not in our LWP list. */ + if (child =3D=3D nullptr) { - ptid_t child_ptid; - - /* A multi-thread exec after we had seen the leader exiting. */ - threads_debug_printf ("Re-adding thread group leader LWP %d after ex= ec.", - lwpid); + if (WIFSTOPPED (wstat)) + { + if (WSTOPSIG (wstat) =3D=3D SIGTRAP + && linux_ptrace_get_extended_event (wstat) =3D=3D PTRACE_EVENT_EXEC) + { + /* A non-leader thread exec'ed after we've seen the + leader zombie, and removed it from our lists (in + check_zombie_leaders). The non-leader thread changes + its tid to the tgid. */ + threads_debug_printf + ("Re-adding thread group leader LWP %d after exec.", + lwpid); =20 - child_ptid =3D ptid_t (lwpid, lwpid); - child =3D add_lwp (child_ptid); - child->stopped =3D 1; - switch_to_thread (child->thread); - } + child =3D add_lwp (ptid_t (lwpid, lwpid)); + child->stopped =3D 1; + switch_to_thread (child->thread); + } + else + { + /* A process we are controlling has forked and the new + child's stop was reported to us by the kernel. Save + its PID and go back to waiting for the fork event to + be reported - the stopped process might be returned + from waitpid before or after the fork event is. */ + threads_debug_printf + ("Saving LWP %d status %s in stopped_pids list", + lwpid, status_to_str (wstat).c_str ()); + add_to_pid_list (&stopped_pids, lwpid, wstat); + } + } + else + { + /* Don't report an event for the exit of an LWP not in our + list, i.e. not part of any inferior we're debugging. + This can happen if we detach from a program we originally + forked and then it exits. */ + } =20 - /* If we didn't find a process, one of two things presumably happened: - - A process we started and then detached from has exited. Ignore it. - - A process we are controlling has forked and the new child's stop - was reported to us by the kernel. Save its PID. */ - if (child =3D=3D NULL && WIFSTOPPED (wstat)) - { - add_to_pid_list (&stopped_pids, lwpid, wstat); - return; + if (child =3D=3D nullptr) + return; } - else if (child =3D=3D NULL) - return; =20 thread =3D get_lwp_thread (child);