From patchwork Tue Jul 10 11:07:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Ser X-Patchwork-Id: 28289 Received: (qmail 35497 invoked by alias); 10 Jul 2018 11:07:55 -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 35328 invoked by uid 89); 10 Jul 2018 11:07:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_05, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=H*F:U*contact, HX-Envelope-From:sk:contact, H*Ad:U*contact, H*R:U*contact X-HELO: mail2.protonmail.ch Received: from mail2.protonmail.ch (HELO mail2.protonmail.ch) (185.70.40.22) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Jul 2018 11:07:38 +0000 Date: Tue, 10 Jul 2018 07:07:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emersion.fr; s=protonmail; t=1531220856; bh=/AVJzqGUarHfY+yt8pdBPlr79gjx73UQrekrfnGKrAI=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=Y1qv6gqUqvjI/o1e6qHUIrjOfX3MBS8B4S2GZhPluK/zD1lWiprzvK/eQzcsGHExa OJKoTEkvjogN6ifgobzhkbaUFfawi+Ve7KFa1+Ml3rR+0qcAbIzYsFxOyYtpuPMUiA HNehOeOGBXQQsEdRxV82Raa/WXV/aoINHcXh3ucE= To: gdb-patches@sourceware.org From: Simon Ser Cc: Simon Ser Reply-To: Simon Ser Subject: [PATCH] gdb: generate NT_PROCSTAT_AUXV in FreeBSD coredumps Message-ID: MIME-Version: 1.0 gcore generates NT_AUXV notes for Linux targets. On FreeBSD the auxv is stored in a NT_PROCSTAT_AUXV section. --- I'm not sure where to define those NT_PROCSTAT_* constants. These seem to be pretty FreeBSD-specific. They come from elf.h on a FreeBSD system, and aren't defined on Linux. As this is my first patch to GDB, I'm not sure I've done everything right. In particular, I don't know if/how the ChangeLog should be updated. Let me know if something needs to be changed. gdb/fbsd-tdep.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index 9cea0098..598efe66 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -29,6 +29,15 @@ #include "elf-bfd.h" #include "fbsd-tdep.h" +#define NT_PROCSTAT_PROC 8 /* Procstat proc data. */ +#define NT_PROCSTAT_FILES 9 /* Procstat files data. */ +#define NT_PROCSTAT_VMMAP 10 /* Procstat vmmap data. */ +#define NT_PROCSTAT_GROUPS 11 /* Procstat groups data. */ +#define NT_PROCSTAT_UMASK 12 /* Procstat umask data. */ +#define NT_PROCSTAT_RLIMIT 13 /* Procstat rlimit data. */ +#define NT_PROCSTAT_OSREL 14 /* Procstat osreldate data. */ +#define NT_PROCSTAT_PSSTRINGS 15 /* Procstat ps_strings data. */ +#define NT_PROCSTAT_AUXV 16 /* Procstat auxv data. */ /* FreeBSD kernels 12.0 and later include a copy of the 'ptrace_lwpinfo' structure returned by the PT_LWPINFO ptrace @@ -586,6 +595,19 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) note_data = thread_args.note_data; + /* Auxillary vector. */ + gdb::optional auxv = + target_read_alloc (current_top_target (), TARGET_OBJECT_AUXV, NULL); + if (auxv && !auxv->empty ()) + { + note_data = elfcore_write_note (obfd, note_data, note_size, + "FreeBSD", NT_PROCSTAT_AUXV, + auxv->data (), auxv->size ()); + + if (!note_data) + return NULL; + } + return note_data; }