Add support for catching exec events on FreeBSD.
authorJohn Baldwin <jhb@FreeBSD.org>
Sat, 18 Apr 2015 05:00:06 +0000 (01:00 -0400)
committerJohn Baldwin <jhb@FreeBSD.org>
Mon, 27 Apr 2015 23:27:04 +0000 (19:27 -0400)
FreeBSD kernels that support fork tracing always stop a process to
report events for exec.  Such a process will have the PL_FLAG_EXEC
flag set in the pl_flags field of the ptrace_lwpinfo struct returned
by PT_LWPINFO.  The structure does not include the pathname passed to
exec, so use fbsd_pid_to_exec_file to query the pathname of the
process' executable.

gdb/ChangeLog:

* fbsd-nat.c: (fbsd_wait) [PL_FLAG_EXEC]: Report TARGET_WAITKIND_EXECD
event if PL_FLAG_EXEC is set.
[PL_FLAG_EXEC] (fbsd_insert_exec_catchpoint): New function.
[PL_FLAG_EXEC] (fbsd_remove_exec_catchpoint): New function.
(fbsd_nat_add_target) [PL_FLAG_EXEC]: Set
"to_insert_exec_catchpoint" to "fbsd_insert_exec_catchpoint".
Set "to_remove_exec_catchpoint" to "fbsd_remove_exec_catchpoint".

gdb/ChangeLog
gdb/fbsd-nat.c

index 220bc36da83b098418b126e90024421e8034046e..f21b3585f66bdb5c61ff12724c495f530a26ded4 100644 (file)
@@ -1,3 +1,13 @@
+2015-04-27  John Baldwin  <jhb@FreeBSD.org>
+
+       * fbsd-nat.c: (fbsd_wait) [PL_FLAG_EXEC]: Report TARGET_WAITKIND_EXECD
+       event if PL_FLAG_EXEC is set.
+       [PL_FLAG_EXEC] (fbsd_insert_exec_catchpoint): New function.
+       [PL_FLAG_EXEC] (fbsd_remove_exec_catchpoint): New function.
+       (fbsd_nat_add_target) [PL_FLAG_EXEC]: Set
+       "to_insert_exec_catchpoint" to "fbsd_insert_exec_catchpoint".
+       Set "to_remove_exec_catchpoint" to "fbsd_remove_exec_catchpoint".
+
 2015-04-27  John Baldwin  <jhb@FreeBSD.org>
 
        * fbsd-nat.c: [PT_LWPINFO] New variable super_wait.
index 214f411c82c9695937ddcc9d14be6fb3b04923b0..066e2881837d8a033c8448413c392b3581a4538c 100644 (file)
@@ -376,6 +376,16 @@ fbsd_wait (struct target_ops *ops,
              continue;
            }
 #endif
+
+#ifdef PL_FLAG_EXEC
+         if (pl.pl_flags & PL_FLAG_EXEC)
+           {
+             ourstatus->kind = TARGET_WAITKIND_EXECD;
+             ourstatus->value.execd_pathname
+               = xstrdup (fbsd_pid_to_exec_file (NULL, pid));
+             return wptid;
+           }
+#endif
        }
       return wptid;
     }
@@ -458,6 +468,23 @@ fbsd_post_attach (struct target_ops *self, int pid)
   fbsd_enable_follow_fork (pid);
 }
 #endif
+
+#ifdef PL_FLAG_EXEC
+/* If the FreeBSD kernel supports PL_FLAG_EXEC, then traced processes
+   will always stop after exec.  */
+
+static int
+fbsd_insert_exec_catchpoint (struct target_ops *self, int pid)
+{
+  return 0;
+}
+
+static int
+fbsd_remove_exec_catchpoint (struct target_ops *self, int pid)
+{
+  return 0;
+}
+#endif
 #endif
 
 void
@@ -477,6 +504,10 @@ fbsd_nat_add_target (struct target_ops *t)
   t->to_post_startup_inferior = fbsd_post_startup_inferior;
   t->to_post_attach = fbsd_post_attach;
 #endif
+#ifdef PL_FLAG_EXEC
+  t->to_insert_exec_catchpoint = fbsd_insert_exec_catchpoint;
+  t->to_remove_exec_catchpoint = fbsd_remove_exec_catchpoint;
+#endif
 #endif
   add_target (t);
 }
This page took 0.032204 seconds and 4 git commands to generate.