From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16802 invoked by alias); 1 Aug 2018 16:33:32 -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 16304 invoked by uid 89); 1 Aug 2018 16:33:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 spammy=H*R:D*fr, H*R:U*contact, fbsdtdepc, fbsd-tdep.c X-HELO: mail4.protonmail.ch Received: from mail4.protonmail.ch (HELO mail4.protonmail.ch) (185.70.40.27) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 01 Aug 2018 16:33:28 +0000 Date: Wed, 01 Aug 2018 16:33:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emersion.fr; s=protonmail; t=1533141204; bh=gTlIQKzToWNqlgUpW/vzmsCbusoJpGlXBLBwFpOBU6c=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References: Feedback-ID:From; b=iwyXvFEtJnXJp+McyNqy329Tp6m8DJ44929/8Av6oJyYjqNpq1/94IAl4a/3VP3aD G1I8SSSvpjtY/zXPf6qPwjsFH8XUsFCgE72Xgvqhmdn7GZxmGF7zLLCl/aND5fGwG7 ICXV8zdLTTRVQHGOQwFwZ/knYr9u4Uy0wvlGEM3E= To: "gdb-patches@sourceware.org" From: Simon Ser Cc: Simon Ser , "jhb@FreeBSD.org" Reply-To: Simon Ser Subject: Re: [PATCH v2] Generate NT_PROCSTAT_{AUXV,VMMAP,PS_STRINGS} in FreeBSD coredumps Message-ID: In-Reply-To: References: <_LRTDYZchE3m5uYvETytJBLgsrWRhqIDAXHnzDsU6kJBhItMetbpfxGe8OJD9a4K4b9brDxF9YvXWOzdDfTRBRfrZI-4XLl8mWwlrEpqmm0=@emersion.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2018-08/txt/msg00015.txt.bz2 Hi John, What do you think of this patch? Thanks! Simon Ser On July 24, 2018 8:17 AM, Simon Ser wrote: > Hi John, > > Do you think this approach is acceptable? > > Thanks, > > Simon Ser > > On July 16, 2018 2:38 PM, 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-16 Simon Ser > > * target.h (enum target_object): add FreeBSD-specific > > TARGET_OBJECT_FREEBSD_VMMAP and TARGET_OBJECT_FREEBSD_PS_STRINGS > > * fbsd-nat.c (fbsd_nat_target::xfer_partial): add support for > > TARGET_OBJECT_FREEBSD_VMMAP and TARGET_OBJECT_FREEBSD_PS_STRINGS > > * fbsd-tdep.c (fbsd_make_corefile_notes): write NT_PROCSTAT_AUX= V, > > NT_PROCSTAT_VMMAP and NT_PROCSTAT_PS_STRINGS notes > > --- > > > > This patch uses a different approach than the previous one: it adds two > > FreeBSD-specific target objects. I chose this approach because there > > were already some platform-specific target objects (e.g. for Darwin). > > This should fix the issue John pointed out. > > > > gdb/fbsd-nat.c | 17 ++++++++++++++- > > gdb/fbsd-tdep.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ > > gdb/target.h | 4 ++++ > > 3 files changed, 77 insertions(+), 1 deletion(-) > > > > diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c > > index 115deac0..2d056676 100644 > > --- a/gdb/fbsd-nat.c > > +++ b/gdb/fbsd-nat.c > > @@ -711,17 +711,32 @@ fbsd_nat_target::xfer_partial (enum target_object= object, > > } > > #endif > > case TARGET_OBJECT_AUXV: > > + case TARGET_OBJECT_FREEBSD_VMMAP: > > + case TARGET_OBJECT_FREEBSD_PS_STRINGS: > > { > > gdb::byte_vector buf_storage; > > gdb_byte *buf; > > size_t buflen; > > int mib[4]; > > > > + int proc_target; > > + switch (object) { > > + case TARGET_OBJECT_AUXV: > > + proc_target =3D KERN_PROC_AUXV; > > + break; > > + case TARGET_OBJECT_FREEBSD_VMMAP: > > + proc_target =3D KERN_PROC_VMMAP; > > + break; > > + case TARGET_OBJECT_FREEBSD_PS_STRINGS: > > + proc_target =3D KERN_PROC_PS_STRINGS; > > + break; > > + } > > + > > if (writebuf !=3D NULL) > > return TARGET_XFER_E_IO; > > mib[0] =3D CTL_KERN; > > mib[1] =3D KERN_PROC; > > - mib[2] =3D KERN_PROC_AUXV; > > + mib[2] =3D proc_target; > > mib[3] =3D pid; > > if (offset =3D=3D 0) > > { > > diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c > > index 9cea0098..2ea76e66 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,20 @@ fbsd_corefile_thread (struct thread_info *info, > > args->note_size, args->stop_signal); > > } > > > > +static gdb::optional > > +fbsd_make_note_desc (enum target_object object, uint32_t structsize) > > +{ > > + gdb::optional buf =3D > > + target_read_alloc (current_top_target (), object, NULL); > > + if (!buf || buf->empty ()) > > + return {}; > > + > > + gdb::byte_vector desc (sizeof (structsize) + buf->size ()); > > + memcpy (desc.data (), &structsize, sizeof (structsize)); > > + memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size = ()); > > + return desc; > > +} > > + > > /* Create appropriate note sections for a corefile, returning them in > > allocated memory. */ > > > > @@ -586,6 +603,46 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch,= bfd *obfd, int *note_size) > > > > note_data =3D thread_args.note_data; > > > > + pid_t pid =3D inferior_ptid.pid (); > > + > > + /* Auxillary vector. */ > > + uint32_t structsize =3D gdbarch_addr_bit (gdbarch) / 4; /* Elf_Auxin= fo */ > > + gdb::optional note_desc =3D > > + fbsd_make_note_desc (TARGET_OBJECT_AUXV, structsize); > > + if (note_desc && !note_desc->empty ()) > > + { > > + note_data =3D elfcore_write_note (obfd, note_data, note_size, > > + "FreeBSD", NT_FREEBSD_PROCSTAT_A= UXV, > > + note_desc->data (), note_desc->s= ize ()); > > + if (!note_data) > > + return NULL; > > + } > > + > > + /* File mappings */ > > + structsize =3D 0x488; /* struct kinfo_vmentry */ > > + note_desc =3D fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP, stru= ctsize); > > + if (note_desc && !note_desc->empty ()) > > + { > > + note_data =3D elfcore_write_note (obfd, note_data, note_size, > > + "FreeBSD", NT_FREEBSD_PROCSTAT_V= MMAP, > > + note_desc->data (), note_desc->s= ize ()); > > + if (!note_data) > > + return NULL; > > + } > > + > > + structsize =3D gdbarch_addr_bit (gdbarch) / 8; /* void * */ > > + note_desc =3D > > + fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS, structsize); > > + if (note_desc && !note_desc->empty ()) > > + { > > + note_data =3D elfcore_write_note (obfd, note_data, note_size, > > + "FreeBSD", > > + NT_FREEBSD_PROCSTAT_PSSTRINGS, > > + note_desc->data (), note_desc->s= ize ()); > > + if (!note_data) > > + return NULL; > > + } > > + > > return note_data; > > } > > > > diff --git a/gdb/target.h b/gdb/target.h > > index 18c4a84c..83f1172c 100644 > > --- a/gdb/target.h > > +++ b/gdb/target.h > > @@ -203,6 +203,10 @@ enum target_object > > of the process ID of the process in question, in hexadecimal > > format. */ > > TARGET_OBJECT_EXEC_FILE, > > + /* FreeBSD file mappings */ > > + TARGET_OBJECT_FREEBSD_VMMAP, > > + /* FreeBSD process strings */ > > + TARGET_OBJECT_FREEBSD_PS_STRINGS, > > /* Possible future objects: TARGET_OBJECT_FILE, ... */ > > }; > > > > -- > > 2.18.0