From patchwork Sun Apr 26 01:24:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 6432 Received: (qmail 68226 invoked by alias); 26 Apr 2015 01:25:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 68211 invoked by uid 89); 26 Apr 2015 01:25:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.1 required=5.0 tests=AWL, BAYES_50, SPF_HELO_PASS, SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: bigwig.baldwin.cx Received: from bigwig.baldwin.cx (HELO bigwig.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Sun, 26 Apr 2015 01:25:08 +0000 Received: from ralph.baldwin.cx (pool-173-54-116-245.nwrknj.fios.verizon.net [173.54.116.245]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id CA176B923 for ; Sat, 25 Apr 2015 21:25:05 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH 3/3] Add support for catching exec events on FreeBSD. Date: Sat, 25 Apr 2015 21:24:59 -0400 Message-ID: <3266059.AhJIoIbZRa@ralph.baldwin.cx> User-Agent: KMail/4.14.2 (FreeBSD/10.1-STABLE; KDE/4.14.2; amd64; ; ) In-Reply-To: <4db7ab8c84be14f3c18e4d1431e8e1d9c6f92efe.1430009921.git.jhb@FreeBSD.org> References: <4db7ab8c84be14f3c18e4d1431e8e1d9c6f92efe.1430009921.git.jhb@FreeBSD.org> MIME-Version: 1.0 X-IsSubscribed: yes 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". diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index 214f411..066e288 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -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); }