From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68674 invoked by alias); 11 Jul 2018 16:16:30 -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 68662 invoked by uid 89); 11 Jul 2018 16:16:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=HTo:U*contact, HTo:D*fr, Changes X-HELO: mail.baldwin.cx Received: from bigwig.baldwin.cx (HELO mail.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Jul 2018 16:16:25 +0000 Received: from John-Baldwins-MacBook-Pro-2.local (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 8AD7C10AFCD; Wed, 11 Jul 2018 12:16:23 -0400 (EDT) Subject: Re: [PATCH] Generate NT_PROCSTAT_{AUXV,VMMAP} in FreeBSD coredumps To: Simon Ser , gdb-patches@sourceware.org References: From: John Baldwin Message-ID: <95fcaebb-d260-bff6-ac4b-5e052c3787bb@FreeBSD.org> Date: Wed, 11 Jul 2018 16:16:00 -0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-07/txt/msg00315.txt.bz2 On 7/11/18 5:35 AM, Simon Ser wrote: > gcore generates NT_AUXV and NT_FILE notes for Linux targets. On > FreeBSD auxv is stored in a NT_PROCSTAT_AUXV section, file mappings > are stored in a NT_PROCSTAT_VMMAP and both are prefixed with the > struct size. > > 2018-07-11 Simon Ser > * fbsd-tdep.c (fbsd_make_corefile_notes): write NT_PROCSTAT_AUXV > and NT_PROCSTAT_VMMAP notes > > --- > > This is an improvement of my v2 patch [1]. Thanks John for your review! > > Changes from v2 to v3: > - Use NT_FREEBSD_PROCSTAT_* enums instead or re-defining these > - Simplify Elf_Auxinfo struct size expression > - Also write NT_PROCSTAT_VMMAP notes > - Directly use sysctl as this will allow to support more notes in > the future (all of these work in the same way) > - Use gdb::unique_xmalloc_ptr() > > [1]: https://sourceware.org/ml/gdb-patches/2018-07/msg00267.html > > gdb/fbsd-tdep.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 58 insertions(+) > > diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c > index 9cea0098..e335ee6f 100644 > --- a/gdb/fbsd-tdep.c > +++ b/gdb/fbsd-tdep.c > @@ -25,6 +25,9 @@ > #include "regset.h" > #include "gdbthread.h" > #include "xml-syscall.h" > +#include > +#include > +#include > > #include "elf-bfd.h" > #include "fbsd-tdep.h" > @@ -512,6 +515,32 @@ fbsd_corefile_thread (struct thread_info *info, > args->note_size, args->stop_signal); > } > > +static gdb::unique_xmalloc_ptr > +procstat_sysctl (pid_t pid, int what, size_t structsz, size_t *sizep) > +{ > + int name[4]; > + name[0] = CTL_KERN; > + name[1] = KERN_PROC; > + name[2] = what; > + name[3] = pid; > + size_t len = 0; > + if (sysctl (name, 4, NULL, &len, NULL, 0) == -1) > + return NULL; > + > + int structsize = structsz; > + gdb::unique_xmalloc_ptr buf > + ((char *) xmalloc (sizeof (structsize) + len)); > + if (buf == NULL) > + return NULL; > + memcpy (buf.get (), &structsize, sizeof (structsize)); > + void *p = buf.get () + sizeof (structsize); > + if (sysctl (name, 4, p, &len, NULL, 0) == -1) > + return NULL; > + > + *sizep = sizeof (structsize) + len; > + return buf; > +} > + You can't use a sysctl like this in a tdep.c file. fbsd-tdep.c runs on any OS, (so for example you could be running gdb with a FreeBSD binary on Linux or OS X against a debug server (gdbserver or lldb-server or some such) running on a remote FreeBSD host (or VM) and use 'gcore' on the debugging host to generate a local core file. Native code that would only run on a FreeBSD host would live in fbsd-nat.c, and when I have thought about handling other procstat notes in FreeBSD cores I've mostly thought about adding some kind of hook that fbsd-tdep.c would invoke to write extra core notes and setting that hook only for native targets in fbsd-nat.c for the native gdbarchs. Your previous patch for AUXV still works because the target_foo function you called previously will talk to either the debug server or the native target to fetch the AUXV data, so I think your previous patch for NT_PROCSTAT_AUXV is a better approach for that note. -- John Baldwin