From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 7E5943858429; Thu, 10 Mar 2022 11:41:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E5943858429 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] gdb: Reorganize linux_nat_filter_event X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: b7b1008c0b1af5379656bd8e3063d01daf2bd764 X-Git-Newrev: 1abeb1e90d708c1d94867957f90607eaa63dfad7 Message-Id: <20220310114157.7E5943858429@sourceware.org> Date: Thu, 10 Mar 2022 11:41:57 +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:41:57 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D1abeb1e90d70= 8c1d94867957f90607eaa63dfad7 commit 1abeb1e90d708c1d94867957f90607eaa63dfad7 Author: Pedro Alves Date: Mon Feb 21 20:07:20 2022 +0000 gdb: Reorganize linux_nat_filter_event =20 Reorganize linux-nat.c:linux_nat_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 - the end goal is to have them synchronized with the gdbserver counterpart. =20 Change-Id: I8586d8dcd76d8bd3795145e3056fc660e3b2cd22 Diff: --- gdb/linux-nat.c | 75 ++++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 13682fcff43..1555d3a79e3 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -2776,46 +2776,51 @@ linux_nat_filter_event (int lwpid, int status) =20 lp =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. The non-leader - thread changes its tid to the tgid. */ - - if (WIFSTOPPED (status) && lp =3D=3D NULL - && (WSTOPSIG (status) =3D=3D SIGTRAP && event =3D=3D PTRACE_EVENT_EX= EC)) + /* Check for events reported by anything not in our LWP list. */ + if (lp =3D=3D nullptr) { - /* A multi-thread exec after we had seen the leader exiting. */ - linux_nat_debug_printf ("Re-adding thread group leader LWP %d.", lwp= id); + if (WIFSTOPPED (status)) + { + if (WSTOPSIG (status) =3D=3D SIGTRAP && event =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. */ + linux_nat_debug_printf + ("Re-adding thread group leader LWP %d after exec.", + lwpid); =20 - lp =3D add_lwp (ptid_t (lwpid, lwpid)); - lp->stopped =3D 1; - lp->resumed =3D 1; - add_thread (linux_target, lp->ptid); - } + lp =3D add_lwp (ptid_t (lwpid, lwpid)); + lp->stopped =3D 1; + lp->resumed =3D 1; + add_thread (linux_target, lp->ptid); + } + 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. */ + linux_nat_debug_printf + ("Saving LWP %d status %s in stopped_pids list", + lwpid, status_to_str (status).c_str ()); + add_to_pid_list (&stopped_pids, lwpid, status); + } + } + 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 (WIFSTOPPED (status) && !lp) - { - linux_nat_debug_printf ("saving LWP %ld status %s in stopped_pids li= st", - (long) lwpid, status_to_str (status).c_str ()); - add_to_pid_list (&stopped_pids, lwpid, status); - return; + if (lp =3D=3D nullptr) + return; } =20 - /* Make sure we don't report an event for the exit of an LWP not in - our list, i.e. not part of the current process. This can happen - if we detach from a program we originally forked and then it - exits. */ - if (!WIFSTOPPED (status) && !lp) - return; - /* This LWP is stopped now. (And if dead, this prevents it from ever being continued.) */ lp->stopped =3D 1;