From: Simon Ser <contact@emersion.fr>
To: gdb-patches@sourceware.org
Cc: Simon Ser <contact@emersion.fr>, jhb@FreeBSD.org
Subject: [PATCH] Generate NT_PROCSTAT_{AUXV,VMMAP} in FreeBSD coredumps
Date: Wed, 11 Jul 2018 12:35:00 -0000 [thread overview]
Message-ID: <iz0c1bAaNjgAACgCF3B9wWvubTieWo_FAMspoBDj72Th_JjQgzLhxnkAApDxTVICOTRuGk3F1EFNJDl96yeYU6oFRqZToAbjqKR-b61opzQ=@emersion.fr> (raw)
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 <contact@emersion.fr>
* 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 <sys/user.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
#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<char>
+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<char> 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;
+}
+
/* Create appropriate note sections for a corefile, returning them in
allocated memory. */
@@ -586,6 +615,35 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
note_data = thread_args.note_data;
+ pid_t pid = inferior_ptid.pid ();
+
+ /* Auxillary vector. */
+ size_t auxinfo_size = gdbarch_addr_bit (gdbarch) / 4; /* Elf_Auxinfo */
+ size_t note_desc_size;
+ gdb::unique_xmalloc_ptr<char> note_desc;
+ note_desc = procstat_sysctl (pid, KERN_PROC_AUXV, auxinfo_size,
+ ¬e_desc_size);
+ if (note_desc != NULL)
+ {
+ note_data = elfcore_write_note (obfd, note_data, note_size,
+ "FreeBSD", NT_FREEBSD_PROCSTAT_AUXV,
+ note_desc.get (), note_desc_size);
+ if (!note_data)
+ return NULL;
+ }
+
+ /* File mappings */
+ note_desc = procstat_sysctl (pid, KERN_PROC_VMMAP,
+ sizeof(struct kinfo_vmentry), ¬e_desc_size);
+ if (note_desc != NULL)
+ {
+ note_data = elfcore_write_note (obfd, note_data, note_size,
+ "FreeBSD", NT_FREEBSD_PROCSTAT_VMMAP,
+ note_desc.get (), note_desc_size);
+ if (!note_data)
+ return NULL;
+ }
+
return note_data;
}
--
2.18.0
next reply other threads:[~2018-07-11 12:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-11 12:35 Simon Ser [this message]
2018-07-11 16:16 ` John Baldwin
2018-07-11 16:40 ` Simon Ser
2018-07-16 13:39 ` [PATCH v2] Generate NT_PROCSTAT_{AUXV,VMMAP,PS_STRINGS} " Simon Ser
2018-07-24 7:53 ` Simon Ser
2018-08-01 16:33 ` Simon Ser
2018-08-01 18:16 ` John Baldwin
2018-08-21 14:45 ` [PATCH v3] " Simon Ser
2018-08-23 10:40 ` John Baldwin
2018-08-23 14:02 ` [PATCH v4] " Simon Ser
2018-08-23 16:16 ` John Baldwin
2018-08-23 17:11 ` [PATCH v5] " Simon Ser
2018-09-02 20:02 ` Simon Ser
2018-09-06 22:12 ` John Baldwin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='iz0c1bAaNjgAACgCF3B9wWvubTieWo_FAMspoBDj72Th_JjQgzLhxnkAApDxTVICOTRuGk3F1EFNJDl96yeYU6oFRqZToAbjqKR-b61opzQ=@emersion.fr' \
--to=contact@emersion.fr \
--cc=gdb-patches@sourceware.org \
--cc=jhb@FreeBSD.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox