gdb: generate NT_PROCSTAT_AUXV in FreeBSD coredumps
Commit Message
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(+)
@@ -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<gdb::byte_vector> 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;
}