diff options
author | Simon Ser <contact@emersion.fr> | 2018-09-06 15:03:19 -0700 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2018-09-06 15:07:59 -0700 |
commit | 739ab2e92e1840c9285f3cfce1f1236c0fa68730 (patch) | |
tree | c73a69f78dcdbc8f709727803a395c1d27402425 /gdb/fbsd-nat.c | |
parent | d82b3862f1218134f5301ed990c6db48fcb82b2f (diff) | |
download | gdb-739ab2e92e1840c9285f3cfce1f1236c0fa68730.zip gdb-739ab2e92e1840c9285f3cfce1f1236c0fa68730.tar.gz gdb-739ab2e92e1840c9285f3cfce1f1236c0fa68730.tar.bz2 |
Generate NT_PROCSTAT_{AUXV,VMMAP,PS_STRINGS} in FreeBSD coredumps
gcore generates NT_AUXV and NT_FILE notes for Linux targets. On
FreeBSD auxv is stored in a NT_PROCSTAT_AUXV section, virtual memory
mappings are stored in a NT_PROCSTAT_VMMAP, and both are prefixed with
the struct size. In addition, store a NT_PROCSTAT_PS_STRINGS note
saving the initial location of the argv[] and environment[] arrays.
gdb/ChangeLog:
PR gdb/23105
* 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_note_desc): New.
(fbsd_make_corefile_notes): Write NT_PROCSTAT_AUXV,
NT_PROCSTAT_VMMAP and NT_PROCSTAT_PS_STRINGS notes.
* target.h (enum target_object) Add FreeBSD-specific
TARGET_OBJECT_FREEBSD_VMMAP and TARGET_OBJECT_FREEBSD_PS_STRINGS.
Diffstat (limited to 'gdb/fbsd-nat.c')
-rw-r--r-- | gdb/fbsd-nat.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index 115deac..a255318 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -751,6 +751,61 @@ fbsd_nat_target::xfer_partial (enum target_object object, } return TARGET_XFER_E_IO; } + 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; + uint32_t struct_size; + switch (object) + { + case TARGET_OBJECT_FREEBSD_VMMAP: + proc_target = KERN_PROC_VMMAP; + struct_size = sizeof (struct kinfo_vmentry); + break; + case TARGET_OBJECT_FREEBSD_PS_STRINGS: + proc_target = KERN_PROC_PS_STRINGS; + struct_size = sizeof (void *); + break; + } + + if (writebuf != NULL) + return TARGET_XFER_E_IO; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = proc_target; + mib[3] = pid; + + if (sysctl (mib, 4, NULL, &buflen, NULL, 0) != 0) + return TARGET_XFER_E_IO; + buflen += sizeof (struct_size); + + if (offset >= buflen) + { + *xfered_len = 0; + return TARGET_XFER_EOF; + } + + buf_storage.resize (buflen); + buf = buf_storage.data (); + + memcpy (buf, &struct_size, sizeof (struct_size)); + buflen -= sizeof (struct_size); + if (sysctl (mib, 4, buf + sizeof (struct_size), &buflen, NULL, 0) != 0) + return TARGET_XFER_E_IO; + buflen += sizeof (struct_size); + + if (buflen - offset < len) + len = buflen - offset; + memcpy (readbuf, buf + offset, len); + *xfered_len = len; + return TARGET_XFER_OK; + } default: return inf_ptrace_target::xfer_partial (object, annex, readbuf, writebuf, offset, |