Module Name:    src
Committed By:   kamil
Date:           Fri May  3 07:05:28 UTC 2019

Modified Files:
        src/external/gpl3/gdb/dist/gdb: infrun.c nbsd-nat.c

Log Message:
Quick clean up the NetBSD support in GDB

Changes:

 - always perform polling on inferior_ptid, never -1
   -1 can cause catching fork/vfork events in random order
   polling on pid will guarantee to report events in expected order

 - assume availability of KERN_PROC_PATHNAME

 - drop dead code for KERN_PROC_AUXV (FreeBSD-specific sysctl)
   AUXV on NetBSD is handled with PIOD_READ_AUXV

 - drop unused nbsd_fetch_kinfo_proc

 - drop unneeded hacks for fork/vfork code

 - drop support for FreeBSD specific flags returned for PT_LWPINFO
   NetBSD uses PT_GET_SIGINFO / PT_GET_PROCESS_STATE for most pieces of
   information

 - port nbsd_thread_name to NetBSD

 - enable LWP and FORK events in nbsd_enable_proc_events

 - use NetBSD new batteries for distinguishing event type in to_wait
   map most events into GDB types
   breakpoint, single step, hw breakpoint/watchpoint ones are still not
   used with the full power here

 - add support for EXEC events

 - clean up

This change makes GDB functional with threaded code and it is good enough
to pass t_regress / threads test.

It's possible to execute and step processes with multiple threads, use
scheduler-lock, follow-fork etc features.

What does not work:

 - the LWP EXIT event and wait() are not synchronized and can deadlock
   this has been observed with exiting go applications

 - GDB VFORK code is still disabled and awaits kernel fixing

Short term goal is to correct LWP EXIT and follow up with VFORK fixes.

Long term goal is to rewrite NetBSD GDB support and write new support in
the remote process plugin (gdb-server) framework.

PR kern/53120
PR port-arm/51677
PR bin/54060
PR bin/49662
PR kern/52548


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.7 -r1.2 src/external/gpl3/gdb/dist/gdb/infrun.c
cvs rdiff -u -r1.6 -r1.7 src/external/gpl3/gdb/dist/gdb/nbsd-nat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/gdb/dist/gdb/infrun.c
diff -u src/external/gpl3/gdb/dist/gdb/infrun.c:1.1.1.7 src/external/gpl3/gdb/dist/gdb/infrun.c:1.2
--- src/external/gpl3/gdb/dist/gdb/infrun.c:1.1.1.7	Tue Nov 28 18:18:23 2017
+++ src/external/gpl3/gdb/dist/gdb/infrun.c	Fri May  3 07:05:28 2019
@@ -3874,7 +3874,11 @@ fetch_inferior_event (void *client_data)
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   struct cleanup *ts_old_chain;
   int cmd_done = 0;
+#if defined(__NetBSD__)
+  ptid_t waiton_ptid = inferior_ptid;
+#else
   ptid_t waiton_ptid = minus_one_ptid;
+#endif
 
   memset (ecs, 0, sizeof (*ecs));
 

Index: src/external/gpl3/gdb/dist/gdb/nbsd-nat.c
diff -u src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.6 src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.7
--- src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.6	Sat Jun 23 03:15:55 2018
+++ src/external/gpl3/gdb/dist/gdb/nbsd-nat.c	Fri May  3 07:05:28 2019
@@ -45,7 +45,6 @@ nbsd_pid_to_exec_file (struct target_ops
   static char buf[PATH_MAX];
   char name[PATH_MAX];
 
-#ifdef KERN_PROC_PATHNAME
   size_t buflen;
   int mib[4];
 
@@ -56,7 +55,6 @@ nbsd_pid_to_exec_file (struct target_ops
   buflen = sizeof buf;
   if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0)
     return buf;
-#endif
 
   xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
   len = readlink (name, buf, PATH_MAX - 1);
@@ -131,79 +129,6 @@ nbsd_find_memory_regions (struct target_
   return 0;
 }
 
-#ifdef KERN_PROC_AUXV
-static enum target_xfer_status (*super_xfer_partial) (struct target_ops *ops,
-						      enum target_object object,
-						      const char *annex,
-						      gdb_byte *readbuf,
-						      const gdb_byte *writebuf,
-						      ULONGEST offset,
-						      ULONGEST len,
-						      ULONGEST *xfered_len);
-
-/* Implement the "to_xfer_partial target_ops" method.  */
-
-static enum target_xfer_status
-nbsd_xfer_partial (struct target_ops *ops, enum target_object object,
-		   const char *annex, gdb_byte *readbuf,
-		   const gdb_byte *writebuf,
-		   ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
-{
-  pid_t pid = ptid_get_pid (inferior_ptid);
-
-  switch (object)
-    {
-    case TARGET_OBJECT_AUXV:
-      {
-	struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
-	unsigned char *buf;
-	size_t buflen;
-	int mib[4];
-
-	if (writebuf != NULL)
-	  return TARGET_XFER_E_IO;
-	mib[0] = CTL_KERN;
-	mib[1] = KERN_PROC;
-	mib[2] = KERN_PROC_AUXV;
-	mib[3] = pid;
-	if (offset == 0)
-	  {
-	    buf = readbuf;
-	    buflen = len;
-	  }
-	else
-	  {
-	    buflen = offset + len;
-	    buf = XCNEWVEC (unsigned char, buflen);
-	    cleanup = make_cleanup (xfree, buf);
-	  }
-	if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0)
-	  {
-	    if (offset != 0)
-	      {
-		if (buflen > offset)
-		  {
-		    buflen -= offset;
-		    memcpy (readbuf, buf + offset, buflen);
-		  }
-		else
-		  buflen = 0;
-	      }
-	    do_cleanups (cleanup);
-	    *xfered_len = buflen;
-	    return (buflen == 0) ? TARGET_XFER_EOF : TARGET_XFER_OK;
-	  }
-	do_cleanups (cleanup);
-	return TARGET_XFER_E_IO;
-      }
-    default:
-      return super_xfer_partial (ops, object, annex, readbuf, writebuf, offset,
-				 len, xfered_len);
-    }
-}
-#endif
-
-#ifdef PT_LWPINFO
 static int debug_nbsd_lwp;
 
 static void (*super_resume) (struct target_ops *,
@@ -222,27 +147,6 @@ show_nbsd_lwp_debug (struct ui_file *fil
   fprintf_filtered (file, _("Debugging of NetBSD lwp module is %s.\n"), value);
 }
 
-#if defined(TDP_RFPPWAIT) || defined(HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME)
-/* Fetch the external variant of the kernel's internal process
-   structure for the process PID into KP.  */
-
-static void
-nbsd_fetch_kinfo_proc (pid_t pid, struct kinfo_proc *kp)
-{
-  size_t len;
-  int mib[4];
-
-  len = sizeof *kp;
-  mib[0] = CTL_KERN;
-  mib[1] = KERN_PROC;
-  mib[2] = KERN_PROC_PID;
-  mib[3] = pid;
-  if (sysctl (mib, 4, kp, &len, NULL, 0) == -1)
-    perror_with_name (("sysctl"));
-}
-#endif
-
-
 /* Return true if PTID is still active in the inferior.  */
 
 static int
@@ -256,10 +160,6 @@ nbsd_thread_alive (struct target_ops *op
       if (ptrace (PT_LWPINFO, ptid_get_pid (ptid), (caddr_t) &pl, sizeof pl)
 	  == -1)
 	return 0;
-#ifdef PL_FLAG_EXITED
-      if (pl.pl_flags & PL_FLAG_EXITED)
-	return 0;
-#endif
     }
 
   return 1;
@@ -286,77 +186,71 @@ nbsd_pid_to_str (struct target_ops *ops,
   return normal_pid_to_str (ptid);
 }
 
-#ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME
 /* Return the name assigned to a thread by an application.  Returns
    the string in a static buffer.  */
 
 static const char *
 nbsd_thread_name (struct target_ops *self, struct thread_info *thr)
 {
-  struct ptrace_lwpinfo pl;
-  struct kinfo_proc kp;
+  struct kinfo_lwp *kl;
   pid_t pid = ptid_get_pid (thr->ptid);
   lwpid_t lwp = ptid_get_lwp (thr->ptid);
-  static char buf[sizeof pl.pl_tdname + 1];
+  static char buf[KI_LNAMELEN];
+  int mib[5];
+  size_t i, nlwps;
+  size_t size;
+
+  mib[0] = CTL_KERN;
+  mib[1] = KERN_LWP;
+  mib[2] = pid;
+  mib[3] = sizeof(struct kinfo_lwp);
+  mib[4] = 0;
+
+  if (sysctl(mib, 5, NULL, &size, NULL, 0) == -1 || size == 0)
+    perror_with_name (("sysctl"));
+
+  mib[4] = size / sizeof(size_t);
+
+  kl = (struct kinfo_lwp *) xmalloc (size);
+  if (kl == NULL)
+    perror_with_name (("malloc"));
+
+  if (sysctl(mib, 5, kl, &size, NULL, 0) == -1 || size == 0)
+    perror_with_name (("sysctl"));
+
+  nlwps = size / sizeof(struct kinfo_lwp);
+  buf[0] = '\0';
+  for (i = 0; i < nlwps; i++) {
+    if (kl[i].l_lid == lwp) {
+      xsnprintf (buf, sizeof buf, "%s", kl[i].l_name);
+      break;
+    }
+  }
+  xfree(kl);
 
-  /* Note that ptrace_lwpinfo returns the process command in pl_tdname
-     if a name has not been set explicitly.  Return a NULL name in
-     that case.  */
-  nbsd_fetch_kinfo_proc (pid, &kp);
-  pl.pl_lwpid = lwp;
-  if (ptrace (PT_LWPINFO, pid, (caddr_t) &pl, sizeof pl) == -1)
-    perror_with_name (("ptrace"));
-  if (strcmp (kp.ki_comm, pl.pl_tdname) == 0)
-    return NULL;
-  xsnprintf (buf, sizeof buf, "%s", pl.pl_tdname);
   return buf;
 }
-#endif
 
-/* Enable additional event reporting on new processes.
-
-   To catch fork events, PTRACE_FORK is set on every traced process
-   to enable stops on returns from fork or vfork.  Note that both the
-   parent and child will always stop, even if system call stops are
-   not enabled.
-
-   To catch LWP events, PTRACE_EVENTS is set on every traced process.
-   This enables stops on the birth for new LWPs (excluding the "main" LWP)
-   and the death of LWPs (excluding the last LWP in a process).  Note
-   that unlike fork events, the LWP that creates a new LWP does not
-   report an event.  */
+/* Enable additional event reporting on new processes. */
 
 static void
 nbsd_enable_proc_events (pid_t pid)
 {
-#ifdef PT_GET_EVENT_MASK
   int events;
 
   if (ptrace (PT_GET_EVENT_MASK, pid, (PTRACE_TYPE_ARG3)&events,
 	      sizeof (events)) == -1)
     perror_with_name (("ptrace"));
   events |= PTRACE_FORK;
-#ifdef PTRACE_LWP
-  events |= PTRACE_LWP;
-#endif
 #ifdef notyet
-#ifdef PTRACE_VFORK
   events |= PTRACE_VFORK;
+  events |= PTRACE_VFORK_DONE;
 #endif
-#endif
+  events |= PTRACE_LWP_CREATE;
+  events |= PTRACE_LWP_EXIT;
   if (ptrace (PT_SET_EVENT_MASK, pid, (PTRACE_TYPE_ARG3)&events,
 	      sizeof (events)) == -1)
     perror_with_name (("ptrace"));
-#else
-#ifdef TDP_RFPPWAIT
-  if (ptrace (PT_FOLLOW_FORK, pid, (PTRACE_TYPE_ARG3)0, 1) == -1)
-    perror_with_name (("ptrace"));
-#endif
-#ifdef PT_LWP_EVENTS
-  if (ptrace (PT_LWP_EVENTS, pid, (PTRACE_TYPE_ARG3)0, 1) == -1)
-    perror_with_name (("ptrace"));
-#endif
-#endif
 }
 
 /* Add threads for any new LWPs in a process.
@@ -371,7 +265,6 @@ nbsd_add_threads (pid_t pid)
   int val;
   struct ptrace_lwpinfo pl;
 
-//  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)
@@ -387,50 +280,11 @@ nbsd_add_threads (pid_t pid)
 static void
 nbsd_update_thread_list (struct target_ops *ops)
 {
-#ifdef PT_LWP_EVENTS
-  /* With support for thread events, threads are added/deleted from the
-     list as events are reported, so just try deleting exited threads.  */
-  delete_exited_threads ();
-#else
   prune_threads ();
 
   nbsd_add_threads (ptid_get_pid (inferior_ptid));
-#endif
 }
 
-#ifdef TDP_RFPPWAIT
-/*
-  To catch fork events, PT_FOLLOW_FORK is set on every traced process
-  to enable stops on returns from fork or vfork.  Note that both the
-  parent and child will always stop, even if system call stops are not
-  enabled.
-
-  After a fork, both the child and parent process will stop and report
-  an event.  However, there is no guarantee of order.  If the parent
-  reports its stop first, then nbsd_wait explicitly waits for the new
-  child before returning.  If the child reports its stop first, then
-  the event is saved on a list and ignored until the parent's stop is
-  reported.  nbsd_wait could have been changed to fetch the parent PID
-  of the new child and used that to wait for the parent explicitly.
-  However, if two threads in the parent fork at the same time, then
-  the wait on the parent might return the "wrong" fork event.
-
-  The initial version of PT_FOLLOW_FORK did not set PL_FLAG_CHILD for
-  the new child process.  This flag could be inferred by treating any
-  events for an unknown pid as a new child.
-
-  In addition, the initial version of PT_FOLLOW_FORK did not report a
-  stop event for the parent process of a vfork until after the child
-  process executed a new program or exited.  The kernel was changed to
-  defer the wait for exit or exec of the child until after posting the
-  stop event shortly after the change to introduce PL_FLAG_CHILD.
-  This could be worked around by reporting a vfork event when the
-  child event posted and ignoring the subsequent event from the
-  parent.
-
-  This implementation requires both of these fixes for simplicity's
-  sake.  FreeBSD versions newer than 9.1 contain both fixes.
-*/
 
 struct nbsd_fork_info
 {
@@ -479,58 +333,6 @@ nbsd_is_child_pending (pid_t pid)
   return null_ptid;
 }
 
-#ifndef PTRACE_VFORK
-static struct nbsd_fork_info *nbsd_pending_vfork_done;
-
-/* Record a pending vfork done event.  */
-
-static void
-nbsd_add_vfork_done (ptid_t pid)
-{
-  struct nbsd_fork_info *info = XCNEW (struct nbsd_fork_info);
-
-  info->ptid = pid;
-  info->next = nbsd_pending_vfork_done;
-  nbsd_pending_vfork_done = info;
-}
-
-/* Check for a pending vfork done event for a specific PID.  */
-
-static int
-nbsd_is_vfork_done_pending (pid_t pid)
-{
-  struct nbsd_fork_info *info;
-
-  for (info = nbsd_pending_vfork_done; info != NULL; info = info->next)
-    {
-      if (ptid_get_pid (info->ptid) == pid)
-	return 1;
-    }
-  return 0;
-}
-
-/* Check for a pending vfork done event.  If one is found, remove it
-   from the list and return the PTID.  */
-
-static ptid_t
-nbsd_next_vfork_done (void)
-{
-  struct nbsd_fork_info *info;
-  ptid_t ptid;
-
-  if (nbsd_pending_vfork_done != NULL)
-    {
-      info = nbsd_pending_vfork_done;
-      nbsd_pending_vfork_done = info->next;
-      ptid = info->ptid;
-      xfree (info);
-      return ptid;
-    }
-  return null_ptid;
-}
-#endif
-#endif
-
 /* Implement the "to_resume" target_ops method.  */
 
 static void
@@ -558,25 +360,170 @@ nbsd_wait (struct target_ops *ops,
 {
   ptid_t wptid;
 
+  if (debug_nbsd_lwp)
+    fprintf_unfiltered (gdb_stdlog, "NLWP: calling super_wait (%d, %ld, %ld) target_options=%#x\n",
+                        ptid_get_pid (ptid), ptid_get_lwp (ptid),
+                        ptid_get_tid (ptid), target_options);
+
   wptid = super_wait (ops, ptid, ourstatus, target_options);
+
+  if (debug_nbsd_lwp)
+    fprintf_unfiltered (gdb_stdlog, "NLWP: returned from super_wait (%d, %ld, %ld) target_options=%#x with ourstatus->kind=%d\n",
+                        ptid_get_pid (ptid), ptid_get_lwp (ptid),
+                        ptid_get_tid (ptid), target_options, ourstatus->kind);
+
   if (ourstatus->kind == TARGET_WAITKIND_STOPPED)
     {
-      struct ptrace_lwpinfo pl;
-      pid_t pid;
+      ptrace_state_t pst, child_pst;
+      ptrace_siginfo_t psi, child_psi;
       int status;
+      pid_t pid, child, wchild;
+      ptid_t child_ptid;
+      lwpid_t lwp;
+      struct ptrace_lwpinfo pl;
+
       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);
+      if (ptrace(PT_GET_SIGINFO, pid, &psi, sizeof(psi)) == -1)
+        perror_with_name (("ptrace"));
+
+      /* For whole-process signals pick random thread */
+      if (psi.psi_lwpid == 0) {
+        // XXX: Is this always valid?
+        lwp = ptid_get_lwp (inferior_ptid);
+      } else {
+        lwp = psi.psi_lwpid;
+      }
+
+      wptid = ptid_build (pid, lwp, 0);
+
+      /* Set LWP in the process */
+      if (in_thread_list (pid_to_ptid (pid))) {
+          if (debug_nbsd_lwp)
+            fprintf_unfiltered (gdb_stdlog,
+                                "NLWP: using LWP %d for first thread\n",
+                                lwp);
+          thread_change_ptid (pid_to_ptid (pid), wptid);                                                                                                 
+      }
+
+      if (debug_nbsd_lwp)
+         fprintf_unfiltered (gdb_stdlog,
+                             "NLWP: received signal=%d si_code=%d in process=%d lwp=%d\n",
+                             psi.psi_siginfo.si_signo, psi.psi_siginfo.si_code, pid, lwp);
+
+      switch (psi.psi_siginfo.si_signo) {
+      case SIGTRAP:
+        switch (psi.psi_siginfo.si_code) {
+        case TRAP_BRKPT:
+//          lp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
+          break;
+        case TRAP_DBREG:
+//          if (hardware_breakpoint_inserted_here_p (get_regcache_aspace (regcache), pc))
+//            lp->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
+//          else
+//            lp->stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
+          break;
+        case TRAP_TRACE:
+//          lp->stop_reason = TARGET_STOPPED_BY_SINGLE_STEP;
+          break;
+        case TRAP_SCE:
+          ourstatus->kind = TARGET_WAITKIND_SYSCALL_ENTRY;
+//          ourstatus->value.syscall_number = 0;
+          break;
+        case TRAP_SCX:
+          ourstatus->kind = TARGET_WAITKIND_SYSCALL_RETURN;
+//          ourstatus->value.syscall_number = 0;
+          break;
+        case TRAP_EXEC:
+          ourstatus->kind = TARGET_WAITKIND_EXECD;
+          ourstatus->value.execd_pathname = xstrdup(nbsd_pid_to_exec_file (NULL, pid));
+          break;
+        case TRAP_LWP:
+        case TRAP_CHLD:
+          if (ptrace(PT_GET_PROCESS_STATE, pid, &pst, sizeof(pst)) == -1)
+            perror_with_name (("ptrace"));
+          switch (pst.pe_report_event) {
+          case PTRACE_FORK:
+          case PTRACE_VFORK:
+            if (pst.pe_report_event == PTRACE_FORK)
+              ourstatus->kind = TARGET_WAITKIND_FORKED;
+            else
+              ourstatus->kind = TARGET_WAITKIND_VFORKED;
+            child = pst.pe_other_pid;
+
+            if (debug_nbsd_lwp)
+              fprintf_unfiltered (gdb_stdlog,
+                                  "NLWP: registered %s event for PID %d\n",
+                                  (pst.pe_report_event == PTRACE_FORK) ? "FORK" : "VFORK", child);
+
+            wchild = waitpid (child, &status, 0);
+
+            if (wchild == -1)
+              perror_with_name (("waitpid"));
+
+            gdb_assert (wchild == child);
+
+            if (!WIFSTOPPED(status)) {
+              /* Abnormal situation (SIGKILLed?).. bail out */
+              ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
+              return wptid;
+            }
+
+            if (ptrace(PT_GET_SIGINFO, child, &child_psi, sizeof(child_psi)) == -1)
+              perror_with_name (("ptrace"));
+
+            if (child_psi.psi_siginfo.si_signo != SIGTRAP) {
+              /* Abnormal situation.. bail out */
+              ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
+              return wptid;
+            }
+
+            if (child_psi.psi_siginfo.si_code != TRAP_CHLD) {
+              /* Abnormal situation.. bail out */
+              ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
+              return wptid;
+            }
+
+            child_ptid = ptid_build(child, child_psi.psi_lwpid, 0);
+            nbsd_enable_proc_events (ptid_get_pid (child_ptid));
+            ourstatus->value.related_pid = child_ptid;
+            break;
+          case PTRACE_VFORK_DONE:
+            ourstatus->kind = TARGET_WAITKIND_VFORK_DONE;
+            if (debug_nbsd_lwp)
+              fprintf_unfiltered (gdb_stdlog, "NLWP: reported VFORK_DONE parent=%d child=%d\n", pid, pst.pe_other_pid);
+            break;
+          case PTRACE_LWP_CREATE:
+            wptid = ptid_build (pid, pst.pe_lwp, 0);
+            if (in_thread_list (wptid)) {
+              /* Newborn reported after attach? */
+              ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
+              return wptid;
+            }
+            add_thread (wptid);
+            ourstatus->kind = TARGET_WAITKIND_THREAD_CREATED;
+            if (debug_nbsd_lwp)
+              fprintf_unfiltered (gdb_stdlog, "NLWP: created LWP %d\n", pst.pe_lwp);
+            break;
+          case PTRACE_LWP_EXIT:
+            wptid = ptid_build (pid, pst.pe_lwp, 0);
+            if (!in_thread_list (wptid)) {
+              /* Dead child reported after attach? */
+              ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
+              return wptid;
+            }
+            delete_thread (wptid);
+            ourstatus->kind = TARGET_WAITKIND_THREAD_EXITED;
+            if (debug_nbsd_lwp)
+              fprintf_unfiltered (gdb_stdlog, "NLWP: exited LWP %d\n", pst.pe_lwp);
+            if (ptrace (PT_CONTINUE, pid, (void *)1, 0) == -1)
+              perror_with_name (("ptrace"));
+            break;
+          }
+          break;
+        }
+        break;
+      }
 
       if (debug_nbsd_lwp)
 	fprintf_unfiltered (gdb_stdlog,
@@ -589,7 +536,6 @@ nbsd_wait (struct target_ops *ops,
     return wptid;
 }
 
-#ifdef TDP_RFPPWAIT
 /* Target hook for follow_fork.  On entry and at return inferior_ptid is
    the ptid of the followed inferior.  */
 
@@ -635,7 +581,6 @@ nbsd_remove_vfork_catchpoint (struct tar
 {
   return 0;
 }
-#endif
 
 /* Implement the "to_post_startup_inferior" target_ops method.  */
 
@@ -654,10 +599,6 @@ nbsd_post_attach (struct target_ops *sel
   nbsd_add_threads (pid);
 }
 
-#ifdef PL_FLAG_EXEC
-/* If the FreeBSD kernel supports PL_FLAG_EXEC, then traced processes
-   will always stop after exec.  */
-
 static int
 nbsd_insert_exec_catchpoint (struct target_ops *self, int pid)
 {
@@ -669,9 +610,7 @@ nbsd_remove_exec_catchpoint (struct targ
 {
   return 0;
 }
-#endif
 
-#ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_SYSCALL_CODE
 static int
 nbsd_set_syscall_catchpoint (struct target_ops *self, int pid, int needed,
 			     int any_count, int table_size, int *table)
@@ -682,24 +621,15 @@ nbsd_set_syscall_catchpoint (struct targ
      are filtered by GDB rather than the kernel.  */
   return 0;
 }
-#endif
-#endif
 
 void
 nbsd_nat_add_target (struct target_ops *t)
 {
   t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
   t->to_find_memory_regions = nbsd_find_memory_regions;
-#ifdef KERN_PROC_AUXV
-  super_xfer_partial = t->to_xfer_partial;
-  t->to_xfer_partial = nbsd_xfer_partial;
-#endif
-#ifdef PT_LWPINFO
   t->to_thread_alive = nbsd_thread_alive;
   t->to_pid_to_str = nbsd_pid_to_str;
-#ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME
   t->to_thread_name = nbsd_thread_name;
-#endif
   t->to_update_thread_list = nbsd_update_thread_list;
   t->to_has_thread_control = tc_schedlock;
   super_resume = t->to_resume;
@@ -708,21 +638,14 @@ nbsd_nat_add_target (struct target_ops *
   t->to_wait = nbsd_wait;
   t->to_post_startup_inferior = nbsd_post_startup_inferior;
   t->to_post_attach = nbsd_post_attach;
-#ifdef TDP_RFPPWAIT
   t->to_follow_fork = nbsd_follow_fork;
   t->to_insert_fork_catchpoint = nbsd_insert_fork_catchpoint;
   t->to_remove_fork_catchpoint = nbsd_remove_fork_catchpoint;
   t->to_insert_vfork_catchpoint = nbsd_insert_vfork_catchpoint;
   t->to_remove_vfork_catchpoint = nbsd_remove_vfork_catchpoint;
-#endif
-#ifdef PL_FLAG_EXEC
   t->to_insert_exec_catchpoint = nbsd_insert_exec_catchpoint;
   t->to_remove_exec_catchpoint = nbsd_remove_exec_catchpoint;
-#endif
-#ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_SYSCALL_CODE
   t->to_set_syscall_catchpoint = nbsd_set_syscall_catchpoint;
-#endif
-#endif
   add_target (t);
 }
 
@@ -732,7 +655,6 @@ extern initialize_file_ftype _initialize
 void
 _initialize_nbsd_nat (void)
 {
-#ifdef PT_LWPINFO
   add_setshow_boolean_cmd ("nbsd-lwp", class_maintenance,
 			   &debug_nbsd_lwp, _("\
 Set debugging of NetBSD lwp module."), _("\
@@ -741,5 +663,4 @@ Enables printf debugging output."),
 			   NULL,
 			   &show_nbsd_lwp_debug,
 			   &setdebuglist, &showdebuglist);
-#endif
 }

Reply via email to