Home | History | Annotate | Line # | Download | only in gdb
fbsd-nat.c revision 1.5
      1  1.1  christos /* Native-dependent code for FreeBSD.
      2  1.1  christos 
      3  1.3  christos    Copyright (C) 2002-2015 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos    This file is part of GDB.
      6  1.1  christos 
      7  1.1  christos    This program is free software; you can redistribute it and/or modify
      8  1.1  christos    it under the terms of the GNU General Public License as published by
      9  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10  1.1  christos    (at your option) any later version.
     11  1.1  christos 
     12  1.1  christos    This program is distributed in the hope that it will be useful,
     13  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  1.1  christos    GNU General Public License for more details.
     16  1.1  christos 
     17  1.1  christos    You should have received a copy of the GNU General Public License
     18  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19  1.1  christos 
     20  1.1  christos #include "defs.h"
     21  1.1  christos #include "gdbcore.h"
     22  1.1  christos #include "inferior.h"
     23  1.1  christos #include "regcache.h"
     24  1.1  christos #include "regset.h"
     25  1.1  christos #include "gdbthread.h"
     26  1.5  christos #include "gdb_wait.h"
     27  1.1  christos #include <sys/types.h>
     28  1.1  christos #include <sys/procfs.h>
     29  1.5  christos #include <sys/ptrace.h>
     30  1.1  christos #include <sys/sysctl.h>
     31  1.5  christos #ifdef HAVE_KINFO_GETVMMAP
     32  1.5  christos #include <sys/user.h>
     33  1.5  christos #include <libutil.h>
     34  1.5  christos #endif
     35  1.1  christos 
     36  1.1  christos #include "elf-bfd.h"
     37  1.1  christos #include "fbsd-nat.h"
     38  1.1  christos 
     39  1.1  christos /* Return the name of a file that can be opened to get the symbols for
     40  1.1  christos    the child process identified by PID.  */
     41  1.1  christos 
     42  1.5  christos static char *
     43  1.3  christos fbsd_pid_to_exec_file (struct target_ops *self, int pid)
     44  1.1  christos {
     45  1.3  christos   ssize_t len = PATH_MAX;
     46  1.3  christos   static char buf[PATH_MAX];
     47  1.3  christos   char name[PATH_MAX];
     48  1.1  christos 
     49  1.1  christos #ifdef KERN_PROC_PATHNAME
     50  1.1  christos   int mib[4];
     51  1.1  christos 
     52  1.1  christos   mib[0] = CTL_KERN;
     53  1.1  christos   mib[1] = KERN_PROC;
     54  1.1  christos   mib[2] = KERN_PROC_PATHNAME;
     55  1.1  christos   mib[3] = pid;
     56  1.1  christos   if (sysctl (mib, 4, buf, &len, NULL, 0) == 0)
     57  1.1  christos     return buf;
     58  1.1  christos #endif
     59  1.1  christos 
     60  1.3  christos   xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
     61  1.3  christos   len = readlink (name, buf, PATH_MAX - 1);
     62  1.3  christos   if (len != -1)
     63  1.1  christos     {
     64  1.3  christos       buf[len] = '\0';
     65  1.3  christos       return buf;
     66  1.1  christos     }
     67  1.1  christos 
     68  1.3  christos   return NULL;
     69  1.1  christos }
     70  1.1  christos 
     71  1.5  christos #ifdef HAVE_KINFO_GETVMMAP
     72  1.5  christos /* Iterate over all the memory regions in the current inferior,
     73  1.5  christos    calling FUNC for each memory region.  OBFD is passed as the last
     74  1.5  christos    argument to FUNC.  */
     75  1.5  christos 
     76  1.5  christos static int
     77  1.5  christos fbsd_find_memory_regions (struct target_ops *self,
     78  1.5  christos 			  find_memory_region_ftype func, void *obfd)
     79  1.5  christos {
     80  1.5  christos   pid_t pid = ptid_get_pid (inferior_ptid);
     81  1.5  christos   struct kinfo_vmentry *vmentl, *kve;
     82  1.5  christos   uint64_t size;
     83  1.5  christos   struct cleanup *cleanup;
     84  1.5  christos   int i, nitems;
     85  1.5  christos 
     86  1.5  christos   vmentl = kinfo_getvmmap (pid, &nitems);
     87  1.5  christos   if (vmentl == NULL)
     88  1.5  christos     perror_with_name (_("Couldn't fetch VM map entries."));
     89  1.5  christos   cleanup = make_cleanup (free, vmentl);
     90  1.5  christos 
     91  1.5  christos   for (i = 0; i < nitems; i++)
     92  1.5  christos     {
     93  1.5  christos       kve = &vmentl[i];
     94  1.5  christos 
     95  1.5  christos       /* Skip unreadable segments and those where MAP_NOCORE has been set.  */
     96  1.5  christos       if (!(kve->kve_protection & KVME_PROT_READ)
     97  1.5  christos 	  || kve->kve_flags & KVME_FLAG_NOCOREDUMP)
     98  1.5  christos 	continue;
     99  1.5  christos 
    100  1.5  christos       /* Skip segments with an invalid type.  */
    101  1.5  christos       if (kve->kve_type != KVME_TYPE_DEFAULT
    102  1.5  christos 	  && kve->kve_type != KVME_TYPE_VNODE
    103  1.5  christos 	  && kve->kve_type != KVME_TYPE_SWAP
    104  1.5  christos 	  && kve->kve_type != KVME_TYPE_PHYS)
    105  1.5  christos 	continue;
    106  1.5  christos 
    107  1.5  christos       size = kve->kve_end - kve->kve_start;
    108  1.5  christos       if (info_verbose)
    109  1.5  christos 	{
    110  1.5  christos 	  fprintf_filtered (gdb_stdout,
    111  1.5  christos 			    "Save segment, %ld bytes at %s (%c%c%c)\n",
    112  1.5  christos 			    (long) size,
    113  1.5  christos 			    paddress (target_gdbarch (), kve->kve_start),
    114  1.5  christos 			    kve->kve_protection & KVME_PROT_READ ? 'r' : '-',
    115  1.5  christos 			    kve->kve_protection & KVME_PROT_WRITE ? 'w' : '-',
    116  1.5  christos 			    kve->kve_protection & KVME_PROT_EXEC ? 'x' : '-');
    117  1.5  christos 	}
    118  1.5  christos 
    119  1.5  christos       /* Invoke the callback function to create the corefile segment.
    120  1.5  christos 	 Pass MODIFIED as true, we do not know the real modification state.  */
    121  1.5  christos       func (kve->kve_start, size, kve->kve_protection & KVME_PROT_READ,
    122  1.5  christos 	    kve->kve_protection & KVME_PROT_WRITE,
    123  1.5  christos 	    kve->kve_protection & KVME_PROT_EXEC, 1, obfd);
    124  1.5  christos     }
    125  1.5  christos   do_cleanups (cleanup);
    126  1.5  christos   return 0;
    127  1.5  christos }
    128  1.5  christos #else
    129  1.1  christos static int
    130  1.1  christos fbsd_read_mapping (FILE *mapfile, unsigned long *start, unsigned long *end,
    131  1.1  christos 		   char *protection)
    132  1.1  christos {
    133  1.1  christos   /* FreeBSD 5.1-RELEASE uses a 256-byte buffer.  */
    134  1.1  christos   char buf[256];
    135  1.1  christos   int resident, privateresident;
    136  1.1  christos   unsigned long obj;
    137  1.1  christos   int ret = EOF;
    138  1.1  christos 
    139  1.1  christos   /* As of FreeBSD 5.0-RELEASE, the layout is described in
    140  1.1  christos      /usr/src/sys/fs/procfs/procfs_map.c.  Somewhere in 5.1-CURRENT a
    141  1.1  christos      new column was added to the procfs map.  Therefore we can't use
    142  1.1  christos      fscanf since we need to support older releases too.  */
    143  1.1  christos   if (fgets (buf, sizeof buf, mapfile) != NULL)
    144  1.1  christos     ret = sscanf (buf, "%lx %lx %d %d %lx %s", start, end,
    145  1.1  christos 		  &resident, &privateresident, &obj, protection);
    146  1.1  christos 
    147  1.1  christos   return (ret != 0 && ret != EOF);
    148  1.1  christos }
    149  1.1  christos 
    150  1.1  christos /* Iterate over all the memory regions in the current inferior,
    151  1.1  christos    calling FUNC for each memory region.  OBFD is passed as the last
    152  1.1  christos    argument to FUNC.  */
    153  1.1  christos 
    154  1.5  christos static int
    155  1.3  christos fbsd_find_memory_regions (struct target_ops *self,
    156  1.3  christos 			  find_memory_region_ftype func, void *obfd)
    157  1.1  christos {
    158  1.1  christos   pid_t pid = ptid_get_pid (inferior_ptid);
    159  1.1  christos   char *mapfilename;
    160  1.1  christos   FILE *mapfile;
    161  1.1  christos   unsigned long start, end, size;
    162  1.1  christos   char protection[4];
    163  1.1  christos   int read, write, exec;
    164  1.1  christos   struct cleanup *cleanup;
    165  1.1  christos 
    166  1.1  christos   mapfilename = xstrprintf ("/proc/%ld/map", (long) pid);
    167  1.1  christos   cleanup = make_cleanup (xfree, mapfilename);
    168  1.1  christos   mapfile = fopen (mapfilename, "r");
    169  1.1  christos   if (mapfile == NULL)
    170  1.1  christos     error (_("Couldn't open %s."), mapfilename);
    171  1.1  christos   make_cleanup_fclose (mapfile);
    172  1.1  christos 
    173  1.1  christos   if (info_verbose)
    174  1.1  christos     fprintf_filtered (gdb_stdout,
    175  1.1  christos 		      "Reading memory regions from %s\n", mapfilename);
    176  1.1  christos 
    177  1.1  christos   /* Now iterate until end-of-file.  */
    178  1.1  christos   while (fbsd_read_mapping (mapfile, &start, &end, &protection[0]))
    179  1.1  christos     {
    180  1.1  christos       size = end - start;
    181  1.1  christos 
    182  1.1  christos       read = (strchr (protection, 'r') != 0);
    183  1.1  christos       write = (strchr (protection, 'w') != 0);
    184  1.1  christos       exec = (strchr (protection, 'x') != 0);
    185  1.1  christos 
    186  1.1  christos       if (info_verbose)
    187  1.1  christos 	{
    188  1.1  christos 	  fprintf_filtered (gdb_stdout,
    189  1.1  christos 			    "Save segment, %ld bytes at %s (%c%c%c)\n",
    190  1.1  christos 			    size, paddress (target_gdbarch (), start),
    191  1.1  christos 			    read ? 'r' : '-',
    192  1.1  christos 			    write ? 'w' : '-',
    193  1.1  christos 			    exec ? 'x' : '-');
    194  1.1  christos 	}
    195  1.1  christos 
    196  1.1  christos       /* Invoke the callback function to create the corefile segment.
    197  1.1  christos 	 Pass MODIFIED as true, we do not know the real modification state.  */
    198  1.1  christos       func (start, size, read, write, exec, 1, obfd);
    199  1.1  christos     }
    200  1.1  christos 
    201  1.1  christos   do_cleanups (cleanup);
    202  1.1  christos   return 0;
    203  1.1  christos }
    204  1.5  christos #endif
    205  1.5  christos 
    206  1.5  christos #ifdef PT_LWPINFO
    207  1.5  christos static ptid_t (*super_wait) (struct target_ops *,
    208  1.5  christos 			     ptid_t,
    209  1.5  christos 			     struct target_waitstatus *,
    210  1.5  christos 			     int);
    211  1.5  christos 
    212  1.5  christos #ifdef TDP_RFPPWAIT
    213  1.5  christos /*
    214  1.5  christos   To catch fork events, PT_FOLLOW_FORK is set on every traced process
    215  1.5  christos   to enable stops on returns from fork or vfork.  Note that both the
    216  1.5  christos   parent and child will always stop, even if system call stops are not
    217  1.5  christos   enabled.
    218  1.5  christos 
    219  1.5  christos   After a fork, both the child and parent process will stop and report
    220  1.5  christos   an event.  However, there is no guarantee of order.  If the parent
    221  1.5  christos   reports its stop first, then fbsd_wait explicitly waits for the new
    222  1.5  christos   child before returning.  If the child reports its stop first, then
    223  1.5  christos   the event is saved on a list and ignored until the parent's stop is
    224  1.5  christos   reported.  fbsd_wait could have been changed to fetch the parent PID
    225  1.5  christos   of the new child and used that to wait for the parent explicitly.
    226  1.5  christos   However, if two threads in the parent fork at the same time, then
    227  1.5  christos   the wait on the parent might return the "wrong" fork event.
    228  1.5  christos 
    229  1.5  christos   The initial version of PT_FOLLOW_FORK did not set PL_FLAG_CHILD for
    230  1.5  christos   the new child process.  This flag could be inferred by treating any
    231  1.5  christos   events for an unknown pid as a new child.
    232  1.5  christos 
    233  1.5  christos   In addition, the initial version of PT_FOLLOW_FORK did not report a
    234  1.5  christos   stop event for the parent process of a vfork until after the child
    235  1.5  christos   process executed a new program or exited.  The kernel was changed to
    236  1.5  christos   defer the wait for exit or exec of the child until after posting the
    237  1.5  christos   stop event shortly after the change to introduce PL_FLAG_CHILD.
    238  1.5  christos   This could be worked around by reporting a vfork event when the
    239  1.5  christos   child event posted and ignoring the subsequent event from the
    240  1.5  christos   parent.
    241  1.5  christos 
    242  1.5  christos   This implementation requires both of these fixes for simplicity's
    243  1.5  christos   sake.  FreeBSD versions newer than 9.1 contain both fixes.
    244  1.5  christos */
    245  1.5  christos 
    246  1.5  christos struct fbsd_fork_child_info
    247  1.5  christos {
    248  1.5  christos   struct fbsd_fork_child_info *next;
    249  1.5  christos   pid_t child;			/* Pid of new child.  */
    250  1.5  christos };
    251  1.5  christos 
    252  1.5  christos static struct fbsd_fork_child_info *fbsd_pending_children;
    253  1.5  christos 
    254  1.5  christos /* Record a new child process event that is reported before the
    255  1.5  christos    corresponding fork event in the parent.  */
    256  1.5  christos 
    257  1.5  christos static void
    258  1.5  christos fbsd_remember_child (pid_t pid)
    259  1.5  christos {
    260  1.5  christos   struct fbsd_fork_child_info *info;
    261  1.5  christos 
    262  1.5  christos   info = xcalloc (1, sizeof *info);
    263  1.5  christos 
    264  1.5  christos   info->child = pid;
    265  1.5  christos   info->next = fbsd_pending_children;
    266  1.5  christos   fbsd_pending_children = info;
    267  1.5  christos }
    268  1.5  christos 
    269  1.5  christos /* Check for a previously-recorded new child process event for PID.
    270  1.5  christos    If one is found, remove it from the list.  */
    271  1.5  christos 
    272  1.5  christos static int
    273  1.5  christos fbsd_is_child_pending (pid_t pid)
    274  1.5  christos {
    275  1.5  christos   struct fbsd_fork_child_info *info, *prev;
    276  1.5  christos 
    277  1.5  christos   prev = NULL;
    278  1.5  christos   for (info = fbsd_pending_children; info; prev = info, info = info->next)
    279  1.5  christos     {
    280  1.5  christos       if (info->child == pid)
    281  1.5  christos 	{
    282  1.5  christos 	  if (prev == NULL)
    283  1.5  christos 	    fbsd_pending_children = info->next;
    284  1.5  christos 	  else
    285  1.5  christos 	    prev->next = info->next;
    286  1.5  christos 	  xfree (info);
    287  1.5  christos 	  return 1;
    288  1.5  christos 	}
    289  1.5  christos     }
    290  1.5  christos   return 0;
    291  1.5  christos }
    292  1.5  christos 
    293  1.5  christos /* Fetch the external variant of the kernel's internal process
    294  1.5  christos    structure for the process PID into KP.  */
    295  1.5  christos 
    296  1.5  christos static void
    297  1.5  christos fbsd_fetch_kinfo_proc (pid_t pid, struct kinfo_proc *kp)
    298  1.5  christos {
    299  1.5  christos   size_t len;
    300  1.5  christos   int mib[4];
    301  1.5  christos 
    302  1.5  christos   len = sizeof *kp;
    303  1.5  christos   mib[0] = CTL_KERN;
    304  1.5  christos   mib[1] = KERN_PROC;
    305  1.5  christos   mib[2] = KERN_PROC_PID;
    306  1.5  christos   mib[3] = pid;
    307  1.5  christos   if (sysctl (mib, 4, kp, &len, NULL, 0) == -1)
    308  1.5  christos     perror_with_name (("sysctl"));
    309  1.5  christos }
    310  1.5  christos #endif
    311  1.5  christos 
    312  1.5  christos /* Wait for the child specified by PTID to do something.  Return the
    313  1.5  christos    process ID of the child, or MINUS_ONE_PTID in case of error; store
    314  1.5  christos    the status in *OURSTATUS.  */
    315  1.5  christos 
    316  1.5  christos static ptid_t
    317  1.5  christos fbsd_wait (struct target_ops *ops,
    318  1.5  christos 	   ptid_t ptid, struct target_waitstatus *ourstatus,
    319  1.5  christos 	   int target_options)
    320  1.5  christos {
    321  1.5  christos   ptid_t wptid;
    322  1.5  christos 
    323  1.5  christos   while (1)
    324  1.5  christos     {
    325  1.5  christos       wptid = super_wait (ops, ptid, ourstatus, target_options);
    326  1.5  christos       if (ourstatus->kind == TARGET_WAITKIND_STOPPED)
    327  1.5  christos 	{
    328  1.5  christos 	  struct ptrace_lwpinfo pl;
    329  1.5  christos 	  pid_t pid;
    330  1.5  christos 	  int status;
    331  1.5  christos 
    332  1.5  christos 	  pid = ptid_get_pid (wptid);
    333  1.5  christos 	  if (ptrace (PT_LWPINFO, pid, (caddr_t)&pl, sizeof pl) == -1)
    334  1.5  christos 	    perror_with_name (("ptrace"));
    335  1.5  christos 
    336  1.5  christos #ifdef TDP_RFPPWAIT
    337  1.5  christos 	  if (pl.pl_flags & PL_FLAG_FORKED)
    338  1.5  christos 	    {
    339  1.5  christos 	      struct kinfo_proc kp;
    340  1.5  christos 	      pid_t child;
    341  1.5  christos 
    342  1.5  christos 	      child = pl.pl_child_pid;
    343  1.5  christos 	      ourstatus->kind = TARGET_WAITKIND_FORKED;
    344  1.5  christos 	      ourstatus->value.related_pid = pid_to_ptid (child);
    345  1.5  christos 
    346  1.5  christos 	      /* Make sure the other end of the fork is stopped too.  */
    347  1.5  christos 	      if (!fbsd_is_child_pending (child))
    348  1.5  christos 		{
    349  1.5  christos 		  pid = waitpid (child, &status, 0);
    350  1.5  christos 		  if (pid == -1)
    351  1.5  christos 		    perror_with_name (("waitpid"));
    352  1.5  christos 
    353  1.5  christos 		  gdb_assert (pid == child);
    354  1.5  christos 
    355  1.5  christos 		  if (ptrace (PT_LWPINFO, child, (caddr_t)&pl, sizeof pl) == -1)
    356  1.5  christos 		    perror_with_name (("ptrace"));
    357  1.5  christos 
    358  1.5  christos 		  gdb_assert (pl.pl_flags & PL_FLAG_CHILD);
    359  1.5  christos 		}
    360  1.5  christos 
    361  1.5  christos 	      /* For vfork, the child process will have the P_PPWAIT
    362  1.5  christos 		 flag set.  */
    363  1.5  christos 	      fbsd_fetch_kinfo_proc (child, &kp);
    364  1.5  christos 	      if (kp.ki_flag & P_PPWAIT)
    365  1.5  christos 		ourstatus->kind = TARGET_WAITKIND_VFORKED;
    366  1.5  christos 
    367  1.5  christos 	      return wptid;
    368  1.5  christos 	    }
    369  1.5  christos 
    370  1.5  christos 	  if (pl.pl_flags & PL_FLAG_CHILD)
    371  1.5  christos 	    {
    372  1.5  christos 	      /* Remember that this child forked, but do not report it
    373  1.5  christos 		 until the parent reports its corresponding fork
    374  1.5  christos 		 event.  */
    375  1.5  christos 	      fbsd_remember_child (ptid_get_pid (wptid));
    376  1.5  christos 	      continue;
    377  1.5  christos 	    }
    378  1.5  christos #endif
    379  1.5  christos 
    380  1.5  christos #ifdef PL_FLAG_EXEC
    381  1.5  christos 	  if (pl.pl_flags & PL_FLAG_EXEC)
    382  1.5  christos 	    {
    383  1.5  christos 	      ourstatus->kind = TARGET_WAITKIND_EXECD;
    384  1.5  christos 	      ourstatus->value.execd_pathname
    385  1.5  christos 		= xstrdup (fbsd_pid_to_exec_file (NULL, pid));
    386  1.5  christos 	      return wptid;
    387  1.5  christos 	    }
    388  1.5  christos #endif
    389  1.5  christos 	}
    390  1.5  christos       return wptid;
    391  1.5  christos     }
    392  1.5  christos }
    393  1.5  christos 
    394  1.5  christos #ifdef TDP_RFPPWAIT
    395  1.5  christos /* Target hook for follow_fork.  On entry and at return inferior_ptid is
    396  1.5  christos    the ptid of the followed inferior.  */
    397  1.5  christos 
    398  1.5  christos static int
    399  1.5  christos fbsd_follow_fork (struct target_ops *ops, int follow_child,
    400  1.5  christos 			int detach_fork)
    401  1.5  christos {
    402  1.5  christos   if (!follow_child)
    403  1.5  christos     {
    404  1.5  christos       struct thread_info *tp = inferior_thread ();
    405  1.5  christos       pid_t child_pid = ptid_get_pid (tp->pending_follow.value.related_pid);
    406  1.5  christos 
    407  1.5  christos       /* Breakpoints have already been detached from the child by
    408  1.5  christos 	 infrun.c.  */
    409  1.5  christos 
    410  1.5  christos       if (ptrace (PT_DETACH, child_pid, (PTRACE_TYPE_ARG3)1, 0) == -1)
    411  1.5  christos 	perror_with_name (("ptrace"));
    412  1.5  christos     }
    413  1.5  christos 
    414  1.5  christos   return 0;
    415  1.5  christos }
    416  1.5  christos 
    417  1.5  christos static int
    418  1.5  christos fbsd_insert_fork_catchpoint (struct target_ops *self, int pid)
    419  1.5  christos {
    420  1.5  christos   return 0;
    421  1.5  christos }
    422  1.5  christos 
    423  1.5  christos static int
    424  1.5  christos fbsd_remove_fork_catchpoint (struct target_ops *self, int pid)
    425  1.5  christos {
    426  1.5  christos   return 0;
    427  1.5  christos }
    428  1.5  christos 
    429  1.5  christos static int
    430  1.5  christos fbsd_insert_vfork_catchpoint (struct target_ops *self, int pid)
    431  1.5  christos {
    432  1.5  christos   return 0;
    433  1.5  christos }
    434  1.5  christos 
    435  1.5  christos static int
    436  1.5  christos fbsd_remove_vfork_catchpoint (struct target_ops *self, int pid)
    437  1.5  christos {
    438  1.5  christos   return 0;
    439  1.5  christos }
    440  1.5  christos 
    441  1.5  christos /* Enable fork tracing for a specific process.
    442  1.5  christos 
    443  1.5  christos    To catch fork events, PT_FOLLOW_FORK is set on every traced process
    444  1.5  christos    to enable stops on returns from fork or vfork.  Note that both the
    445  1.5  christos    parent and child will always stop, even if system call stops are
    446  1.5  christos    not enabled.  */
    447  1.5  christos 
    448  1.5  christos static void
    449  1.5  christos fbsd_enable_follow_fork (pid_t pid)
    450  1.5  christos {
    451  1.5  christos   if (ptrace (PT_FOLLOW_FORK, pid, (PTRACE_TYPE_ARG3)0, 1) == -1)
    452  1.5  christos     perror_with_name (("ptrace"));
    453  1.5  christos }
    454  1.5  christos 
    455  1.5  christos /* Implement the "to_post_startup_inferior" target_ops method.  */
    456  1.5  christos 
    457  1.5  christos static void
    458  1.5  christos fbsd_post_startup_inferior (struct target_ops *self, ptid_t pid)
    459  1.5  christos {
    460  1.5  christos   fbsd_enable_follow_fork (ptid_get_pid (pid));
    461  1.5  christos }
    462  1.5  christos 
    463  1.5  christos /* Implement the "to_post_attach" target_ops method.  */
    464  1.5  christos 
    465  1.5  christos static void
    466  1.5  christos fbsd_post_attach (struct target_ops *self, int pid)
    467  1.5  christos {
    468  1.5  christos   fbsd_enable_follow_fork (pid);
    469  1.5  christos }
    470  1.5  christos #endif
    471  1.5  christos 
    472  1.5  christos #ifdef PL_FLAG_EXEC
    473  1.5  christos /* If the FreeBSD kernel supports PL_FLAG_EXEC, then traced processes
    474  1.5  christos    will always stop after exec.  */
    475  1.5  christos 
    476  1.5  christos static int
    477  1.5  christos fbsd_insert_exec_catchpoint (struct target_ops *self, int pid)
    478  1.5  christos {
    479  1.5  christos   return 0;
    480  1.5  christos }
    481  1.5  christos 
    482  1.5  christos static int
    483  1.5  christos fbsd_remove_exec_catchpoint (struct target_ops *self, int pid)
    484  1.5  christos {
    485  1.5  christos   return 0;
    486  1.5  christos }
    487  1.5  christos #endif
    488  1.5  christos #endif
    489  1.5  christos 
    490  1.5  christos void
    491  1.5  christos fbsd_nat_add_target (struct target_ops *t)
    492  1.5  christos {
    493  1.5  christos   t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
    494  1.5  christos   t->to_find_memory_regions = fbsd_find_memory_regions;
    495  1.5  christos #ifdef PT_LWPINFO
    496  1.5  christos   super_wait = t->to_wait;
    497  1.5  christos   t->to_wait = fbsd_wait;
    498  1.5  christos #ifdef TDP_RFPPWAIT
    499  1.5  christos   t->to_follow_fork = fbsd_follow_fork;
    500  1.5  christos   t->to_insert_fork_catchpoint = fbsd_insert_fork_catchpoint;
    501  1.5  christos   t->to_remove_fork_catchpoint = fbsd_remove_fork_catchpoint;
    502  1.5  christos   t->to_insert_vfork_catchpoint = fbsd_insert_vfork_catchpoint;
    503  1.5  christos   t->to_remove_vfork_catchpoint = fbsd_remove_vfork_catchpoint;
    504  1.5  christos   t->to_post_startup_inferior = fbsd_post_startup_inferior;
    505  1.5  christos   t->to_post_attach = fbsd_post_attach;
    506  1.5  christos #endif
    507  1.5  christos #ifdef PL_FLAG_EXEC
    508  1.5  christos   t->to_insert_exec_catchpoint = fbsd_insert_exec_catchpoint;
    509  1.5  christos   t->to_remove_exec_catchpoint = fbsd_remove_exec_catchpoint;
    510  1.5  christos #endif
    511  1.5  christos #endif
    512  1.5  christos   add_target (t);
    513  1.5  christos }
    514