From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 108653 invoked by alias); 20 Jun 2016 22:56:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 108644 invoked by uid 89); 20 Jun 2016 22:56:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1526,6, 15266, UD:sig, sticky X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 20 Jun 2016 22:56:43 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31718D47B9; Mon, 20 Jun 2016 22:56:42 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5KMuejV014406; Mon, 20 Jun 2016 18:56:41 -0400 Subject: Re: [PATCH] Add support for catching system calls to native FreeBSD targets. To: John Baldwin , gdb-patches@sourceware.org References: <20160614205751.11566-1-jhb@FreeBSD.org> From: Pedro Alves Message-ID: <53d24aec-5588-ea4f-7d6d-085aca553457@redhat.com> Date: Mon, 20 Jun 2016 22:56:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <20160614205751.11566-1-jhb@FreeBSD.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-06/txt/msg00340.txt.bz2 Hi John, This looks good to me. Just some minor nits below. On 06/14/2016 09:57 PM, John Baldwin wrote: > All platforms on FreeBSD use a shared system call table, so use a > single XML file to describe the system calls available on each FreeBSD > platform. > > xRecent typo. > versions of FreeBSD include the identifier of the current > system call when reporting a system call entry or exit event in the > ptrace_lwpinfo structure obtained via PT_LWPINFO in fbsd_wait. As > such, FreeBSD native targets do not use the gdbarch method to fetch > the system call code. In addition, FreeBSD register sets fetched via > ptrace do not include an equivalent of 'orig_rax' (on amd64 for > example), so the system call code cannot be extracted from the > available registers during a system call exit. However, GDB assumes > that system call catch points are not supported if the gdbarch method > is not present. As a workaround, FreeBSD ABIs install a dummy gdbarch > method that throws an internal_error if it is ever invoked. > We should probably get rid of this gdbarch method, by making linux-nat.c (the only caller) call an arch-specific target_ops override instead of a gdbarch method, like gdbserver's equivalent code does. To replace the break-catch-syscall.c error, I think that it'd be reasonable to remove it altogether, and for Linux targets that don't implement the gdbarch hook yet, instead just always intercept all syscalls, reporting an syscall number. But what you did seems like a reasonable thing to do as long as do have the gdbarch hook. > diff --git a/gdb/configure.ac b/gdb/configure.ac > index 6a72f72..4ed706a 100644 > --- a/gdb/configure.ac > +++ b/gdb/configure.ac > @@ -1526,6 +1526,11 @@ fi > AC_CHECK_MEMBERS([struct ptrace_lwpinfo.pl_tdname], [], [], > [#include ]) > > +# See if supports syscall fields on FreeBSD Missing period. > +# Older FreeBSD versions don't have the pl_syscall_code member of > +# `struct ptrace_lwpinfo'. Can you replace "Older" with a non-relative version reference? > +AC_CHECK_MEMBERS([struct ptrace_lwpinfo.pl_syscall_code], [], [], > + [#include ]) > > diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c > index b582abe..741a96d 100644 > --- a/gdb/fbsd-nat.c > +++ b/gdb/fbsd-nat.c > @@ -707,6 +707,40 @@ fbsd_wait (struct target_ops *ops, > 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 > + entriy/exit events. */ Typo "entriy". > + 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; > + else > + ourstatus->kind = TARGET_WAITKIND_SYSCALL_RETURN; > + ourstatus->value.syscall_number = pl.pl_syscall_code; > + return wptid; > + } > + } > +#endif > + /* If the core isn't interested in this event, just > + continue the process explicitly and wait for another > + event. Note that PT_SYSCALL is "sticky" on FreeBSD > + and once system call stops are enabled on a process > + it stops for all system call entries and exits. */ > + if (ptrace (PT_CONTINUE, pid, (caddr_t) 1, 0) == -1) > + perror_with_name (("ptrace")); > + continue; > + } > } > return wptid; > } > #include "elf-bfd.h" > #include "fbsd-tdep.h" > @@ -283,6 +284,20 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) > return note_data; > } > > +static LONGEST > +fbsd_get_syscall_number (struct gdbarch *gdbarch, > + ptid_t ptid) Add the usual "implement foo gdbarch method" or some such comment. > +{ Thanks, Pedro Alves