Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/gpl3/gdb/dist/gdb Fix thread debugging.
details: https://anonhg.NetBSD.org/src/rev/6c8083c07bc4
branches: trunk
changeset: 320100:6c8083c07bc4
user: christos <christos%NetBSD.org@localhost>
date: Sat Jun 23 03:15:55 2018 +0000
description:
Fix thread debugging.
diffstat:
external/gpl3/gdb/dist/gdb/inf-ptrace.c | 2 +-
external/gpl3/gdb/dist/gdb/nbsd-nat.c | 308 ++-----------------------------
2 files changed, 29 insertions(+), 281 deletions(-)
diffs (truncated from 360 to 300 lines):
diff -r 4992c250d89b -r 6c8083c07bc4 external/gpl3/gdb/dist/gdb/inf-ptrace.c
--- a/external/gpl3/gdb/dist/gdb/inf-ptrace.c Sat Jun 23 01:51:03 2018 +0000
+++ b/external/gpl3/gdb/dist/gdb/inf-ptrace.c Sat Jun 23 03:15:55 2018 +0000
@@ -353,7 +353,7 @@
all possible successor instructions), so we don't have to
worry about that here. */
request = PT_STEP;
-#if 0
+#if __NetBSD__
/*
* On NetBSD the data field of PT_STEP contains the thread
* to be stepped; all other threads are continued if this value is > 0
diff -r 4992c250d89b -r 6c8083c07bc4 external/gpl3/gdb/dist/gdb/nbsd-nat.c
--- a/external/gpl3/gdb/dist/gdb/nbsd-nat.c Sat Jun 23 01:51:03 2018 +0000
+++ b/external/gpl3/gdb/dist/gdb/nbsd-nat.c Sat Jun 23 03:15:55 2018 +0000
@@ -371,7 +371,7 @@
int val;
struct ptrace_lwpinfo pl;
- gdb_assert (!in_thread_list (pid_to_ptid (pid)));
+// gdb_assert (!in_thread_list (pid_to_ptid (pid)));
pl.pl_lwpid = 0;
while ((val = ptrace (PT_LWPINFO, pid, (void *)&pl, sizeof(pl))) != -1
&& pl.pl_lwpid != 0)
@@ -537,68 +537,13 @@
nbsd_resume (struct target_ops *ops,
ptid_t ptid, int step, enum gdb_signal signo)
{
-#if defined(TDP_RFPPWAIT) && !defined(PTRACE_VFORK)
- pid_t pid;
-
- /* Don't PT_CONTINUE a process which has a pending vfork done event. */
- if (ptid_equal (minus_one_ptid, ptid))
- pid = ptid_get_pid (inferior_ptid);
- else
- pid = ptid_get_pid (ptid);
- if (nbsd_is_vfork_done_pending (pid))
- return;
-#endif
-
if (debug_nbsd_lwp)
fprintf_unfiltered (gdb_stdlog,
"NLWP: nbsd_resume for ptid (%d, %ld, %ld)\n",
ptid_get_pid (ptid), ptid_get_lwp (ptid),
ptid_get_tid (ptid));
- if (ptid_lwp_p (ptid))
- {
- /* FreeBSD: If ptid is a specific LWP, suspend all other LWPs in the
- * process.
- */
- /* NetBSD, this function is about resuming so we only deal with
- * the thread we've been asked to work with
- */
- struct thread_info *tp;
- int request;
-
- ALL_NON_EXITED_THREADS (tp)
- {
- if (ptid_get_pid (tp->ptid) != ptid_get_pid (ptid))
- continue;
-
- if (ptid_get_lwp (tp->ptid) == ptid_get_lwp (ptid))
- request = PT_RESUME;
-#ifndef __NetBSD__
- else
- request = PT_SUSPEND;
-#endif
-
- if (ptrace (request, ptid_get_pid (tp->ptid), NULL,
- ptid_get_lwp (tp->ptid)) == -1)
- perror_with_name (("ptrace"));
- }
- }
- else
- {
- /* If ptid is a wildcard, resume all matching threads (they won't run
- until the process is continued however). */
- struct thread_info *tp;
-
- ALL_NON_EXITED_THREADS (tp)
- {
- if (!ptid_match (tp->ptid, ptid))
- continue;
-
- if (ptrace (PT_RESUME, ptid_get_pid (tp->ptid), NULL,
- ptid_get_lwp (tp->ptid)) == -1)
- perror_with_name (("ptrace"));
- }
- ptid = inferior_ptid;
- }
+ if (ptid_get_pid(ptid) == -1)
+ ptid = inferior_ptid;
super_resume (ops, ptid, step, signo);
}
@@ -613,203 +558,35 @@
{
ptid_t wptid;
- while (1)
+ wptid = super_wait (ops, ptid, ourstatus, target_options);
+ if (ourstatus->kind == TARGET_WAITKIND_STOPPED)
{
-#ifndef PTRACE_VFORK
- wptid = nbsd_next_vfork_done ();
- if (!ptid_equal (wptid, null_ptid))
- {
- ourstatus->kind = TARGET_WAITKIND_VFORK_DONE;
- return wptid;
- }
-#endif
- wptid = super_wait (ops, ptid, ourstatus, target_options);
- if (ourstatus->kind == TARGET_WAITKIND_STOPPED)
- {
- struct ptrace_lwpinfo pl;
- pid_t pid;
- int status;
-
- pid = ptid_get_pid (wptid);
- pl.pl_lwpid = 0;
- if (ptrace (PT_LWPINFO, pid, (caddr_t) &pl, sizeof pl) == -1)
- perror_with_name (("ptrace"));
-
- wptid = ptid_build (pid, pl.pl_lwpid, 0);
-
-#ifdef PT_LWP_EVENTS
- if (pl.pl_flags & PL_FLAG_EXITED)
- {
- /* If GDB attaches to a multi-threaded process, exiting
- threads might be skipped during nbsd_post_attach that
- have not yet reported their PL_FLAG_EXITED event.
- Ignore EXITED events for an unknown LWP. */
- if (in_thread_list (wptid))
- {
- if (debug_nbsd_lwp)
- fprintf_unfiltered (gdb_stdlog,
- "NLWP: deleting thread for LWP %u\n",
- pl.pl_lwpid);
- if (print_thread_events)
- printf_unfiltered (_("[%s exited]\n"), target_pid_to_str
- (wptid));
- delete_thread (wptid);
- }
- if (ptrace (PT_CONTINUE, pid, (caddr_t) 1, 0) == -1)
- perror_with_name (("ptrace"));
- continue;
- }
-#endif
-
- /* Switch to an LWP PTID on the first stop in a new process.
- This is done after handling PL_FLAG_EXITED to avoid
- switching to an exited LWP. It is done before checking
- PL_FLAG_BORN in case the first stop reported after
- attaching to an existing process is a PL_FLAG_BORN
- event. */
- if (in_thread_list (pid_to_ptid (pid)))
- {
- if (debug_nbsd_lwp)
- fprintf_unfiltered (gdb_stdlog,
- "NLWP: using LWP %u for first thread\n",
- pl.pl_lwpid);
- thread_change_ptid (pid_to_ptid (pid), wptid);
- }
-
-#ifdef PT_LWP_EVENTS
- if (pl.pl_flags & PL_FLAG_BORN)
- {
- /* If GDB attaches to a multi-threaded process, newborn
- threads might be added by nbsd_add_threads that have
- not yet reported their PL_FLAG_BORN event. Ignore
- BORN events for an already-known LWP. */
- if (!in_thread_list (wptid))
- {
- if (debug_nbsd_lwp)
- fprintf_unfiltered (gdb_stdlog,
- "NLWP: adding thread for LWP %u\n",
- pl.pl_lwpid);
- add_thread (wptid);
- }
- ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
- return wptid;
- }
-#endif
-
-#ifdef TDP_RFPPWAIT
- if (pl.pl_flags & PL_FLAG_FORKED)
- {
-#ifndef PTRACE_VFORK
- struct kinfo_proc kp;
-#endif
- ptid_t child_ptid;
- pid_t child;
-
- child = pl.pl_child_pid;
- ourstatus->kind = TARGET_WAITKIND_FORKED;
-#ifdef PTRACE_VFORK
- if (pl.pl_flags & PL_FLAG_VFORKED)
- ourstatus->kind = TARGET_WAITKIND_VFORKED;
-#endif
+ struct ptrace_lwpinfo pl;
+ pid_t pid;
+ int status;
+ pid = ptid_get_pid (wptid);
+ // Find the lwp that caused the wait status change
+ pl.pl_lwpid = 0;
+ do {
+ if (ptrace (PT_LWPINFO, pid, (caddr_t) &pl, sizeof pl) == -1)
+ perror_with_name (("ptrace"));
+ if (pl.pl_event == PL_EVENT_SIGNAL)
+ break;
+ } while (pl.pl_lwpid != 0);
+ if (pl.pl_lwpid != 0)
+ wptid = ptid_build (pid, pl.pl_lwpid, 0);
+ if (!in_thread_list (wptid))
+ add_thread (wptid);
- /* Make sure the other end of the fork is stopped too. */
- child_ptid = nbsd_is_child_pending (child);
- if (ptid_equal (child_ptid, null_ptid))
- {
- pid = waitpid (child, &status, 0);
- if (pid == -1)
- perror_with_name (("waitpid"));
-
- gdb_assert (pid == child);
- pl.pl_lwpid = 0;
- if (ptrace (PT_LWPINFO, child, (caddr_t)&pl, sizeof pl) == -1)
- perror_with_name (("ptrace"));
-
- gdb_assert (pl.pl_flags & PL_FLAG_CHILD);
- child_ptid = ptid_build (child, pl.pl_lwpid, 0);
- }
-
- /* Enable additional events on the child process. */
- nbsd_enable_proc_events (ptid_get_pid (child_ptid));
-
-#ifndef PTRACE_VFORK
- /* For vfork, the child process will have the P_PPWAIT
- flag set. */
- nbsd_fetch_kinfo_proc (child, &kp);
- if (kp.ki_flag & P_PPWAIT)
- ourstatus->kind = TARGET_WAITKIND_VFORKED;
-#endif
- ourstatus->value.related_pid = child_ptid;
-
- return wptid;
- }
-
- if (pl.pl_flags & PL_FLAG_CHILD)
- {
- /* Remember that this child forked, but do not report it
- until the parent reports its corresponding fork
- event. */
- nbsd_remember_child (wptid);
- continue;
- }
+ if (debug_nbsd_lwp)
+ fprintf_unfiltered (gdb_stdlog,
+ "NLWP: nbsd_wait returned (%d, %ld, %ld)\n",
+ ptid_get_pid (wptid), ptid_get_lwp (wptid),
+ ptid_get_tid (wptid));
+ inferior_ptid = wptid;
-#ifdef PTRACE_VFORK
- if (pl.pl_flags & PL_FLAG_VFORK_DONE)
- {
- ourstatus->kind = TARGET_WAITKIND_VFORK_DONE;
- return wptid;
- }
-#endif
-#endif
-
-#ifdef PL_FLAG_EXEC
- if (pl.pl_flags & PL_FLAG_EXEC)
- {
- ourstatus->kind = TARGET_WAITKIND_EXECD;
- ourstatus->value.execd_pathname
- = xstrdup (nbsd_pid_to_exec_file (NULL, pid));
- return wptid;
- }
-#endif
-
- /* Note that PL_FLAG_SCE is set for any event reported while
- a thread is executing a system call in the kernel. In
- particular, signals that interrupt a sleep in a system
- call will report this flag as part of their event. Stops
- explicitly for system call entry and exit always use
- SIGTRAP, so only treat SIGTRAP events as system call
- entry/exit events. */
-#ifdef PL_FLAG_SCE
- if (pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX)
- && ourstatus->value.sig == SIGTRAP)
- {
-#ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_SYSCALL_CODE
- if (catch_syscall_enabled ())
- {
- if (catching_syscall_number (pl.pl_syscall_code))
- {
- if (pl.pl_flags & PL_FLAG_SCE)
- ourstatus->kind = TARGET_WAITKIND_SYSCALL_ENTRY;
Home |
Main Index |
Thread Index |
Old Index