* [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD @ 2016-06-16 6:02 John Baldwin 2016-06-16 6:02 ` [PATCH 6/6] Add a gdbarch 'print_auxv' method for FreeBSD ABIs John Baldwin ` (6 more replies) 0 siblings, 7 replies; 16+ messages in thread From: John Baldwin @ 2016-06-16 6:02 UTC (permalink / raw) To: gdb-patches, binutils This patch series fixes 'info auxv' to work on live binaries and cores for FreeBSD. I believe most of these patches are straightforward. I broke out parsing of FreeBSD-specific ELF core notes to avoid a collision with duplicate NT_* values (NT_FREEBSD_PROCSTAT_AUXV conflicts with NT_LWPSTATUS). The biggest change is adding a new gdbarch method to handle formatting individual auxv vectors. FreeBSD uses AT_* constants that overlap with existing AT_* constants but with different meanings. One result of making the interpretation of AT_* constants a gdbarch method is that 'info auxv' shows the correct output (Linux values) when gdb inspects a Linux binary executing on FreeBSD via FreeBSD's Linux ABI support. John Baldwin (6): Add constants for FreeBSD-specific auxiliary vector entry types. Add elfcore_grok_freebsd_note to parse FreeBSD ELF core notes. Fetch the ELF auxiliary vector from live processes on FreeBSD. Create a psuedo section for the ELF AUXV core dump note on FreeBSD. Add a new gdbarch method to print a single AUXV entry. Add a gdbarch 'print_auxv' method for FreeBSD ABIs. bfd/ChangeLog | 15 ++++ bfd/elf.c | 152 +++++++++++++++++++++++++++++++++++++--- gdb/ChangeLog | 23 +++++++ gdb/auxv.c | 191 ++++++++++++++++++++++++++++----------------------- gdb/auxv.h | 8 +++ gdb/fbsd-nat.c | 74 ++++++++++++++++++++ gdb/fbsd-tdep.c | 33 +++++++++ gdb/gdbarch.c | 32 +++++++++ gdb/gdbarch.h | 11 +++ gdb/gdbarch.sh | 6 ++ include/ChangeLog | 7 ++ include/elf/common.h | 10 +++ 12 files changed, 467 insertions(+), 95 deletions(-) -- 2.8.4 ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 6/6] Add a gdbarch 'print_auxv' method for FreeBSD ABIs. 2016-06-16 6:02 [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin @ 2016-06-16 6:02 ` John Baldwin 2016-06-20 23:43 ` Pedro Alves 2016-06-16 6:02 ` [PATCH 3/6] Fetch the ELF auxiliary vector from live processes on FreeBSD John Baldwin ` (5 subsequent siblings) 6 siblings, 1 reply; 16+ messages in thread From: John Baldwin @ 2016-06-16 6:02 UTC (permalink / raw) To: gdb-patches, binutils Add a 'print_auxv' method for FreeBSD ABIs that parses FreeBSD-specific auxiliary vector entries and outputs a suitable description using fprint_single_auxv. gdb/ChangeLog: * fbsd-tdep.c: Include "auxv.h". (fbsd_print_auxv): New function. (fbsd_init_abi): Install gdbarch "print_auxv" method. --- gdb/ChangeLog | 6 ++++++ gdb/fbsd-tdep.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2426a2f..27d4620 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2016-06-15 John Baldwin <jhb@FreeBSD.org> + * fbsd-tdep.c: Include "auxv.h". + (fbsd_print_auxv): New function. + (fbsd_init_abi): Install gdbarch "print_auxv" method. + +2016-06-15 John Baldwin <jhb@FreeBSD.org> + * auxv.c (fprint_single_auxv): New function. (default_print_auxv): New function. (fprint_target_auxv): Use gdbarch_print_auxv and default_print_auxv. diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index 7310ea0..8aca570 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "defs.h" +#include "auxv.h" #include "gdbcore.h" #include "inferior.h" #include "regcache.h" @@ -283,6 +284,37 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) return note_data; } +static int +fbsd_print_auxv (struct gdbarch *gdbarch, struct ui_file *file, CORE_ADDR type, + CORE_ADDR val) +{ + const char *name; + const char *description; + enum auxv_format flavor; + + switch (type) + { +#define _TAGNAME(tag) #tag +#define TAGNAME(tag) _TAGNAME(AT_##tag) +#define TAG(tag, text, kind) \ + case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; flavor = kind; break + TAG (EXECPATH, _("Executable path"), str); + TAG (CANARY, _("Canary for SSP"), hex); + TAG (CANARYLEN, ("Length of the SSP canary"), dec); + TAG (OSRELDATE, _("OSRELDATE"), dec); + TAG (NCPUS, _("Number of CPUs"), dec); + TAG (PAGESIZES, _("Pagesizes"), hex); + TAG (PAGESIZESLEN, _("Number of pagesizes"), dec); + TAG (TIMEKEEP, _("Pointer to timehands"), hex); + TAG (STACKPROT, _("Initial stack protection"), hex); + default: + return (0); + } + + fprint_single_auxv (file, name, description, flavor, type, val); + return (1); +} + /* To be called from GDB_OSABI_FREEBSD_ELF handlers. */ void @@ -291,4 +323,5 @@ fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_core_pid_to_str (gdbarch, fbsd_core_pid_to_str); set_gdbarch_core_thread_name (gdbarch, fbsd_core_thread_name); set_gdbarch_make_corefile_notes (gdbarch, fbsd_make_corefile_notes); + set_gdbarch_print_auxv (gdbarch, fbsd_print_auxv); } -- 2.8.4 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 6/6] Add a gdbarch 'print_auxv' method for FreeBSD ABIs. 2016-06-16 6:02 ` [PATCH 6/6] Add a gdbarch 'print_auxv' method for FreeBSD ABIs John Baldwin @ 2016-06-20 23:43 ` Pedro Alves 0 siblings, 0 replies; 16+ messages in thread From: Pedro Alves @ 2016-06-20 23:43 UTC (permalink / raw) To: John Baldwin, gdb-patches, binutils On 06/16/2016 07:02 AM, John Baldwin wrote: > > +static int > +fbsd_print_auxv (struct gdbarch *gdbarch, struct ui_file *file, CORE_ADDR type, > + CORE_ADDR val) Missing intro comment. > +{ > + const char *name; > + const char *description; > + enum auxv_format flavor; > + > + switch (type) > + { > +#define _TAGNAME(tag) #tag > +#define TAGNAME(tag) _TAGNAME(AT_##tag) > +#define TAG(tag, text, kind) \ > + case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; flavor = kind; break > + TAG (EXECPATH, _("Executable path"), str); > + TAG (CANARY, _("Canary for SSP"), hex); > + TAG (CANARYLEN, ("Length of the SSP canary"), dec); > + TAG (OSRELDATE, _("OSRELDATE"), dec); > + TAG (NCPUS, _("Number of CPUs"), dec); > + TAG (PAGESIZES, _("Pagesizes"), hex); > + TAG (PAGESIZESLEN, _("Number of pagesizes"), dec); > + TAG (TIMEKEEP, _("Pointer to timehands"), hex); > + TAG (STACKPROT, _("Initial stack protection"), hex); > + default: > + return (0); Write: return 0; However, with the suggestion in the previous patch, this would be a direct call to default_print_auxv_entry. > + } > + > + fprint_single_auxv (file, name, description, flavor, type, val); > + return (1); return 1; Thanks, Pedro Alves ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 3/6] Fetch the ELF auxiliary vector from live processes on FreeBSD. 2016-06-16 6:02 [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin 2016-06-16 6:02 ` [PATCH 6/6] Add a gdbarch 'print_auxv' method for FreeBSD ABIs John Baldwin @ 2016-06-16 6:02 ` John Baldwin 2016-06-20 23:01 ` Pedro Alves 2016-06-16 6:02 ` [PATCH 2/6] Add elfcore_grok_freebsd_note to parse FreeBSD ELF core notes John Baldwin ` (4 subsequent siblings) 6 siblings, 1 reply; 16+ messages in thread From: John Baldwin @ 2016-06-16 6:02 UTC (permalink / raw) To: gdb-patches, binutils Use the kern.proc.auxv.<pid> sysctl to fetch the ELF auxiliary vector for a live process. gdb/ChangeLog: * fbsd-nat.c [KERN_PROC_AUXV] New variable super_xfer_partial. (fbsd_xfer_partial): New function. (fbsd_nat_add_target) [KERN_PROC_AUXV] Set "to_xfer_partial" to "fbsd_xfer_partial". --- gdb/ChangeLog | 7 ++++++ gdb/fbsd-nat.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9e57431..b11174c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2016-06-15 John Baldwin <jhb@FreeBSD.org> + + * fbsd-nat.c [KERN_PROC_AUXV] New variable super_xfer_partial. + (fbsd_xfer_partial): New function. + (fbsd_nat_add_target) [KERN_PROC_AUXV] Set "to_xfer_partial" to + "fbsd_xfer_partial". + 2016-06-14 John Baldwin <jhb@FreeBSD.org> * v850-tdep.c (v850_use_struct_convention): Trim type length checks. diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index b582abe..f9cfee6 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -206,6 +206,76 @@ fbsd_find_memory_regions (struct target_ops *self, } #endif +#ifdef KERN_PROC_AUXV +static enum target_xfer_status (*super_xfer_partial) (struct target_ops *ops, + enum target_object object, + const char *annex, + gdb_byte *readbuf, + const gdb_byte *writebuf, + ULONGEST offset, + ULONGEST len, + ULONGEST *xfered_len); + +static enum target_xfer_status +fbsd_xfer_partial (struct target_ops *ops, enum target_object object, + const char *annex, gdb_byte *readbuf, + const gdb_byte *writebuf, + ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) +{ + pid_t pid = ptid_get_pid (inferior_ptid); + + switch (object) + { + case TARGET_OBJECT_AUXV: + { + struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); + unsigned char *buf; + size_t buflen; + int mib[4]; + + if (writebuf) + return TARGET_XFER_E_IO; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_AUXV; + mib[3] = pid; + if (offset == 0) + { + buf = readbuf; + buflen = len; + } + else + { + buflen = offset + len; + buf = XCNEWVEC (unsigned char, buflen); + cleanup = make_cleanup (xfree, buf); + } + if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0) + { + if (offset != 0) + { + if (buflen > offset) + { + buflen -= offset; + memcpy (readbuf, buf + offset, buflen); + } + else + buflen = 0; + } + do_cleanups (cleanup); + *xfered_len = buflen; + return (buflen == 0) ? TARGET_XFER_EOF : TARGET_XFER_OK; + } + do_cleanups (cleanup); + return TARGET_XFER_E_IO; + } + default: + return super_xfer_partial (ops, object, annex, readbuf, writebuf, offset, + len, xfered_len); + } +} +#endif + #ifdef PT_LWPINFO static int debug_fbsd_lwp; @@ -824,6 +894,10 @@ fbsd_nat_add_target (struct target_ops *t) { t->to_pid_to_exec_file = fbsd_pid_to_exec_file; t->to_find_memory_regions = fbsd_find_memory_regions; +#ifdef KERN_PROC_AUXV + super_xfer_partial = t->to_xfer_partial; + t->to_xfer_partial = fbsd_xfer_partial; +#endif #ifdef PT_LWPINFO t->to_thread_alive = fbsd_thread_alive; t->to_pid_to_str = fbsd_pid_to_str; -- 2.8.4 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 3/6] Fetch the ELF auxiliary vector from live processes on FreeBSD. 2016-06-16 6:02 ` [PATCH 3/6] Fetch the ELF auxiliary vector from live processes on FreeBSD John Baldwin @ 2016-06-20 23:01 ` Pedro Alves 0 siblings, 0 replies; 16+ messages in thread From: Pedro Alves @ 2016-06-20 23:01 UTC (permalink / raw) To: John Baldwin, gdb-patches, binutils On 06/16/2016 07:01 AM, John Baldwin wrote: > +static enum target_xfer_status > +fbsd_xfer_partial (struct target_ops *ops, enum target_object object, "Implement foo"-style intro comment missing. > + switch (object) > + { > + case TARGET_OBJECT_AUXV: > + { > + struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); > + unsigned char *buf; > + size_t buflen; > + int mib[4]; > + > + if (writebuf) writebuf != NULL. Otherwise LGTM. Thanks, Pedro Alves ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 2/6] Add elfcore_grok_freebsd_note to parse FreeBSD ELF core notes. 2016-06-16 6:02 [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin 2016-06-16 6:02 ` [PATCH 6/6] Add a gdbarch 'print_auxv' method for FreeBSD ABIs John Baldwin 2016-06-16 6:02 ` [PATCH 3/6] Fetch the ELF auxiliary vector from live processes on FreeBSD John Baldwin @ 2016-06-16 6:02 ` John Baldwin 2016-06-17 8:28 ` Nick Clifton 2016-06-16 6:02 ` [PATCH 1/6] Add constants for FreeBSD-specific auxiliary vector entry types John Baldwin ` (3 subsequent siblings) 6 siblings, 1 reply; 16+ messages in thread From: John Baldwin @ 2016-06-16 6:02 UTC (permalink / raw) To: gdb-patches, binutils Move parsing of FreeBSD-specific ELF core notes out of elfcore_grok_note into a new elfcore_grok_freebsd_note function. Add core note grok routines for FreeBSD's psinfo and prstatus notes while here rather than depending on the native handling in elfcore_grok_note. bfd/ChangeLog: * elf.c (elfcore_grok_note): Remove handling of NT_X86_XSTATE for FreeBSD. Remove case for NT_FREEBSD_THRMISC. (elfcore_grok_freebsd_psinfo): New function. (elfcore_grok_freebsd_prstatus): New function. (elfcore_grok_freebsd_note): New function. (elf_parse_notes): Use "elfcore_grok_freebsd_note" for "FreeBSD" notes. --- bfd/ChangeLog | 10 +++++ bfd/elf.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 139 insertions(+), 9 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 344e08b..881ce6d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,13 @@ +2016-06-15 John Baldwin <jhb@FreeBSD.org> + + * elf.c (elfcore_grok_note): Remove handling of NT_X86_XSTATE for + FreeBSD. Remove case for NT_FREEBSD_THRMISC. + (elfcore_grok_freebsd_psinfo): New function. + (elfcore_grok_freebsd_prstatus): New function. + (elfcore_grok_freebsd_note): New function. + (elf_parse_notes): Use "elfcore_grok_freebsd_note" for "FreeBSD" + notes. + 2016-06-15 H.J. Lu <hongjiu.lu@intel.com> * elf32-i386.c (elf_i386_check_relocs): Check SEC_ALLOC before diff --git a/bfd/elf.c b/bfd/elf.c index aaf2b53..2d8f621 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -9327,9 +9327,6 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) if (note->namesz == 6 && strcmp (note->namedata, "LINUX") == 0) return elfcore_grok_xstatereg (abfd, note); - else if (note->namesz == 8 - && strcmp (note->namedata, "FreeBSD") == 0) - return elfcore_grok_xstatereg (abfd, note); else return TRUE; @@ -9485,12 +9482,6 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) return elfcore_make_note_pseudosection (abfd, ".note.linuxcore.siginfo", note); - case NT_FREEBSD_THRMISC: - if (note->namesz == 8 - && strcmp (note->namedata, "FreeBSD") == 0) - return elfcore_make_note_pseudosection (abfd, ".thrmisc", note); - else - return TRUE; } } @@ -9556,6 +9547,134 @@ elfobj_grok_stapsdt_note (bfd *abfd, Elf_Internal_Note *note) } static bfd_boolean +elfcore_grok_freebsd_psinfo (bfd *abfd, Elf_Internal_Note *note) +{ + size_t offset; + + /* Check for version 1 in pr_version. */ + if (bfd_h_get_32 (abfd, (bfd_byte *) note->descdata) != 1) + return FALSE; + offset = 4; + + /* Skip over pr_psinfosz. */ + switch (abfd->arch_info->bits_per_word) + { + case 32: + offset += 4; + break; + + case 64: + offset += 4; /* Padding before pr_psinfosz. */ + offset += 8; + break; + + default: + return FALSE; + } + + /* pr_fname is PRFNAMESZ (16) + 1 bytes in size. */ + elf_tdata (abfd)->core->program + = _bfd_elfcore_strndup (abfd, note->descdata + offset, 17); + offset += 17; + + /* pr_psargs is PRARGSZ (80) + 1 bytes in size. */ + elf_tdata (abfd)->core->command + = _bfd_elfcore_strndup (abfd, note->descdata + offset, 81); + + return TRUE; +} + +static bfd_boolean +elfcore_grok_freebsd_prstatus (bfd *abfd, Elf_Internal_Note *note) +{ + size_t offset; + size_t size; + + /* Check for version 1 in pr_version. */ + if (bfd_h_get_32 (abfd, (bfd_byte *) note->descdata) != 1) + return FALSE; + offset = 4; + + /* Skip over pr_statussz. */ + switch (abfd->arch_info->bits_per_word) + { + case 32: + offset += 4; + break; + + case 64: + offset += 4; /* Padding before pr_statussz. */ + offset += 8; + break; + + default: + return FALSE; + } + + /* Extract size of pr_reg from pr_gregsetsz. */ + if (abfd->arch_info->bits_per_word == 32) + size = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset); + else + size = bfd_h_get_64 (abfd, (bfd_byte *) note->descdata + offset); + + /* Skip over pr_gregsetsz and pr_fpregsetsz. */ + offset += (abfd->arch_info->bits_per_word / 8) * 2; + + /* Skip over pr_osreldate. */ + offset += 4; + + /* Read signal from pr_cursig. */ + if (elf_tdata (abfd)->core->signal == 0) + elf_tdata (abfd)->core->signal + = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset); + offset += 4; + + /* Read TID from pr_pid. */ + elf_tdata (abfd)->core->lwpid + = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset); + offset += 4; + + /* Padding before pr_reg. */ + if (abfd->arch_info->bits_per_word == 64) + offset += 4; + + /* Make a ".reg/999" section and a ".reg" section. */ + return _bfd_elfcore_make_pseudosection (abfd, ".reg", + size, note->descpos + offset); +} + +static bfd_boolean +elfcore_grok_freebsd_note (bfd *abfd, Elf_Internal_Note *note) +{ + switch (note->type) + { + case NT_PRSTATUS: + return elfcore_grok_freebsd_prstatus (abfd, note); + + case NT_FPREGSET: + return elfcore_grok_prfpreg (abfd, note); + + case NT_PRPSINFO: + return elfcore_grok_freebsd_psinfo (abfd, note); + + case NT_FREEBSD_THRMISC: + if (note->namesz == 8) + return elfcore_make_note_pseudosection (abfd, ".thrmisc", note); + else + return TRUE; + + case NT_X86_XSTATE: + if (note->namesz == 8) + return elfcore_grok_xstatereg (abfd, note); + else + return TRUE; + + default: + return TRUE; + } +} + +static bfd_boolean elfcore_netbsd_get_lwpid (Elf_Internal_Note *note, int *lwpidp) { char *cp; @@ -10467,6 +10586,7 @@ elf_parse_notes (bfd *abfd, char *buf, size_t size, file_ptr offset) grokers[] = { GROKER_ELEMENT ("", elfcore_grok_note), + GROKER_ELEMENT ("FreeBSD", elfcore_grok_freebsd_note), GROKER_ELEMENT ("NetBSD-CORE", elfcore_grok_netbsd_note), GROKER_ELEMENT ( "OpenBSD", elfcore_grok_openbsd_note), GROKER_ELEMENT ("QNX", elfcore_grok_nto_note), -- 2.8.4 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 2/6] Add elfcore_grok_freebsd_note to parse FreeBSD ELF core notes. 2016-06-16 6:02 ` [PATCH 2/6] Add elfcore_grok_freebsd_note to parse FreeBSD ELF core notes John Baldwin @ 2016-06-17 8:28 ` Nick Clifton 0 siblings, 0 replies; 16+ messages in thread From: Nick Clifton @ 2016-06-17 8:28 UTC (permalink / raw) To: John Baldwin, gdb-patches, binutils Hi John, > bfd/ChangeLog: > > * elf.c (elfcore_grok_note): Remove handling of NT_X86_XSTATE for > FreeBSD. Remove case for NT_FREEBSD_THRMISC. > (elfcore_grok_freebsd_psinfo): New function. > (elfcore_grok_freebsd_prstatus): New function. > (elfcore_grok_freebsd_note): New function. > (elf_parse_notes): Use "elfcore_grok_freebsd_note" for "FreeBSD" > notes. Approved - please apply. Cheers Nick ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 1/6] Add constants for FreeBSD-specific auxiliary vector entry types. 2016-06-16 6:02 [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin ` (2 preceding siblings ...) 2016-06-16 6:02 ` [PATCH 2/6] Add elfcore_grok_freebsd_note to parse FreeBSD ELF core notes John Baldwin @ 2016-06-16 6:02 ` John Baldwin 2016-06-17 8:27 ` Nick Clifton 2016-06-16 6:11 ` [PATCH 4/6] Create a psuedo section for the ELF AUXV core dump note on FreeBSD John Baldwin ` (2 subsequent siblings) 6 siblings, 1 reply; 16+ messages in thread From: John Baldwin @ 2016-06-16 6:02 UTC (permalink / raw) To: gdb-patches, binutils include/ChangeLog: * elf/common.h (AT_FREEBSD_EXECPATH, AT_FREEBSD_CANARY) (AT_FREEBSD_CANARYLEN, AT_FREEBSD_OSRELDATE, AT_FREEBSD_NCPUS) (AT_FREEBSD_PAGESIZES, AT_FREEBSD_PAGESIZESLEN) (AT_FREEBSD_TIMEKEEP, AT_FREEBSD_STACKPROT): Define. --- include/ChangeLog | 7 +++++++ include/elf/common.h | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/ChangeLog b/include/ChangeLog index 46a2f3a..248c1a6 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,10 @@ +2016-06-15 John Baldwin <jhb@FreeBSD.org> + + * elf/common.h (AT_FREEBSD_EXECPATH, AT_FREEBSD_CANARY) + (AT_FREEBSD_CANARYLEN, AT_FREEBSD_OSRELDATE, AT_FREEBSD_NCPUS) + (AT_FREEBSD_PAGESIZES, AT_FREEBSD_PAGESIZESLEN) + (AT_FREEBSD_TIMEKEEP, AT_FREEBSD_STACKPROT): Define. + 2016-06-14 John Baldwin <jhb@FreeBSD.org> * opcode/msp430-decode.h (MSP430_Size): Remove. diff --git a/include/elf/common.h b/include/elf/common.h index 087d876..d2da009d 100644 --- a/include/elf/common.h +++ b/include/elf/common.h @@ -1012,6 +1012,16 @@ #define AT_L2_CACHESHAPE 36 #define AT_L3_CACHESHAPE 37 +#define AT_FREEBSD_EXECPATH 15 /* Path to the executable. */ +#define AT_FREEBSD_CANARY 16 /* Canary for SSP. */ +#define AT_FREEBSD_CANARYLEN 17 /* Length of the canary. */ +#define AT_FREEBSD_OSRELDATE 18 /* OSRELDATE. */ +#define AT_FREEBSD_NCPUS 19 /* Number of CPUs. */ +#define AT_FREEBSD_PAGESIZES 20 /* Pagesizes. */ +#define AT_FREEBSD_PAGESIZESLEN 21 /* Number of pagesizes. */ +#define AT_FREEBSD_TIMEKEEP 22 /* Pointer to timehands. */ +#define AT_FREEBSD_STACKPROT 23 /* Initial stack protection. */ + #define AT_SUN_UID 2000 /* Effective user ID. */ #define AT_SUN_RUID 2001 /* Real user ID. */ #define AT_SUN_GID 2002 /* Effective group ID. */ -- 2.8.4 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/6] Add constants for FreeBSD-specific auxiliary vector entry types. 2016-06-16 6:02 ` [PATCH 1/6] Add constants for FreeBSD-specific auxiliary vector entry types John Baldwin @ 2016-06-17 8:27 ` Nick Clifton 0 siblings, 0 replies; 16+ messages in thread From: Nick Clifton @ 2016-06-17 8:27 UTC (permalink / raw) To: John Baldwin, gdb-patches, binutils Hi John, > include/ChangeLog: > > * elf/common.h (AT_FREEBSD_EXECPATH, AT_FREEBSD_CANARY) > (AT_FREEBSD_CANARYLEN, AT_FREEBSD_OSRELDATE, AT_FREEBSD_NCPUS) > (AT_FREEBSD_PAGESIZES, AT_FREEBSD_PAGESIZESLEN) > (AT_FREEBSD_TIMEKEEP, AT_FREEBSD_STACKPROT): Define. Approved - please apply. Cheers Nick ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 4/6] Create a psuedo section for the ELF AUXV core dump note on FreeBSD. 2016-06-16 6:02 [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin ` (3 preceding siblings ...) 2016-06-16 6:02 ` [PATCH 1/6] Add constants for FreeBSD-specific auxiliary vector entry types John Baldwin @ 2016-06-16 6:11 ` John Baldwin 2016-06-17 8:28 ` Nick Clifton 2016-06-20 23:45 ` Pedro Alves 2016-06-16 6:11 ` [PATCH 5/6] Add a new gdbarch method to print a single AUXV entry John Baldwin 2016-06-20 17:10 ` [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin 6 siblings, 2 replies; 16+ messages in thread From: John Baldwin @ 2016-06-16 6:11 UTC (permalink / raw) To: gdb-patches, binutils The procstat AUXV core dump note in FreeBSD consists of 32-bit integer followed by an array of auxiliary vector entries. bfd/ChangeLog: * elf.c (elfcore_grok_freebsd_note): Handle NT_FREEBSD_PROCSTAT_AUXV notes. --- bfd/ChangeLog | 5 +++++ bfd/elf.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 881ce6d..7afc44e 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,10 @@ 2016-06-15 John Baldwin <jhb@FreeBSD.org> + * elf.c (elfcore_grok_freebsd_note): Handle NT_FREEBSD_PROCSTAT_AUXV + notes. + +2016-06-15 John Baldwin <jhb@FreeBSD.org> + * elf.c (elfcore_grok_note): Remove handling of NT_X86_XSTATE for FreeBSD. Remove case for NT_FREEBSD_THRMISC. (elfcore_grok_freebsd_psinfo): New function. diff --git a/bfd/elf.c b/bfd/elf.c index 2d8f621..d947cf3 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -9663,6 +9663,20 @@ elfcore_grok_freebsd_note (bfd *abfd, Elf_Internal_Note *note) else return TRUE; + case NT_FREEBSD_PROCSTAT_AUXV: + { + asection *sect = bfd_make_section_anyway_with_flags (abfd, ".auxv", + SEC_HAS_CONTENTS); + + if (sect == NULL) + return FALSE; + sect->size = note->descsz - 4; + sect->filepos = note->descpos + 4; + sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32; + + return TRUE; + } + case NT_X86_XSTATE: if (note->namesz == 8) return elfcore_grok_xstatereg (abfd, note); -- 2.8.4 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 4/6] Create a psuedo section for the ELF AUXV core dump note on FreeBSD. 2016-06-16 6:11 ` [PATCH 4/6] Create a psuedo section for the ELF AUXV core dump note on FreeBSD John Baldwin @ 2016-06-17 8:28 ` Nick Clifton 2016-06-20 23:45 ` Pedro Alves 1 sibling, 0 replies; 16+ messages in thread From: Nick Clifton @ 2016-06-17 8:28 UTC (permalink / raw) To: John Baldwin, gdb-patches, binutils Hi John, > bfd/ChangeLog: > > * elf.c (elfcore_grok_freebsd_note): Handle NT_FREEBSD_PROCSTAT_AUXV > notes. Approved - please apply. Cheers Nick ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 4/6] Create a psuedo section for the ELF AUXV core dump note on FreeBSD. 2016-06-16 6:11 ` [PATCH 4/6] Create a psuedo section for the ELF AUXV core dump note on FreeBSD John Baldwin 2016-06-17 8:28 ` Nick Clifton @ 2016-06-20 23:45 ` Pedro Alves 1 sibling, 0 replies; 16+ messages in thread From: Pedro Alves @ 2016-06-20 23:45 UTC (permalink / raw) To: John Baldwin, gdb-patches, binutils "pseudo" :-) Thanks, Pedro Alves ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 5/6] Add a new gdbarch method to print a single AUXV entry. 2016-06-16 6:02 [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin ` (4 preceding siblings ...) 2016-06-16 6:11 ` [PATCH 4/6] Create a psuedo section for the ELF AUXV core dump note on FreeBSD John Baldwin @ 2016-06-16 6:11 ` John Baldwin 2016-06-20 23:40 ` Pedro Alves 2016-06-20 17:10 ` [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin 6 siblings, 1 reply; 16+ messages in thread From: John Baldwin @ 2016-06-16 6:11 UTC (permalink / raw) To: gdb-patches, binutils Different platforms have different meanings for auxiliary vector entries. The 'print_auxv' gdbarch method allows an architecture to output a suitable description for platform-specific entries. A fprint_single_auxv function is split out of fprint_target_auxv. This function outputs the description of a single auxiliary vector entry to the specified file using caller-supplied formatting and strings to describe the vector type. The existing switch on auxiliary vector types is moved out of fprint_target_auxv into a new default_print_auxv function. default_print_auxv chooses an appropriate format and description and calls fprint_single_auxv to describe a single vector entry. fprint_target_auxv now invokes the gdbarch 'print_auxv' function on each vector entry. If the function is not present or returns zero, default_printf_auxv is called to output a description for the vector. gdb/ChangeLog: * auxv.c (fprint_single_auxv): New function. (default_print_auxv): New function. (fprint_target_auxv): Use gdbarch_print_auxv and default_print_auxv. * auxv.h (enum auxv_format): New enum. (fprint_single_auxv): Declare. * gdbarch.sh (print_auxv): New. * gdbarch.c, gdbarch.h: Re-generated. --- gdb/ChangeLog | 10 +++ gdb/auxv.c | 191 +++++++++++++++++++++++++++++++-------------------------- gdb/auxv.h | 8 +++ gdb/gdbarch.c | 32 ++++++++++ gdb/gdbarch.h | 11 ++++ gdb/gdbarch.sh | 6 ++ 6 files changed, 172 insertions(+), 86 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b11174c..2426a2f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2016-06-15 John Baldwin <jhb@FreeBSD.org> + * auxv.c (fprint_single_auxv): New function. + (default_print_auxv): New function. + (fprint_target_auxv): Use gdbarch_print_auxv and default_print_auxv. + * auxv.h (enum auxv_format): New enum. + (fprint_single_auxv): Declare. + * gdbarch.sh (print_auxv): New. + * gdbarch.c, gdbarch.h: Re-generated. + +2016-06-15 John Baldwin <jhb@FreeBSD.org> + * fbsd-nat.c [KERN_PROC_AUXV] New variable super_xfer_partial. (fbsd_xfer_partial): New function. (fbsd_nat_add_target) [KERN_PROC_AUXV] Set "to_xfer_partial" to diff --git a/gdb/auxv.c b/gdb/auxv.c index 396862e..275c23e 100644 --- a/gdb/auxv.c +++ b/gdb/auxv.c @@ -407,10 +407,112 @@ target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp) } +/* Print a description of a single AUXV entry on the specified file. */ +void +fprint_single_auxv (struct ui_file *file, const char *name, + const char *description, enum auxv_format flavor, + CORE_ADDR type, CORE_ADDR val) +{ + fprintf_filtered (file, "%-4s %-20s %-30s ", + plongest (type), name, description); + switch (flavor) + { + case dec: + fprintf_filtered (file, "%s\n", plongest (val)); + break; + case hex: + fprintf_filtered (file, "%s\n", paddress (target_gdbarch (), val)); + break; + case str: + { + struct value_print_options opts; + + get_user_print_options (&opts); + if (opts.addressprint) + fprintf_filtered (file, "%s ", paddress (target_gdbarch (), val)); + val_print_string (builtin_type (target_gdbarch ())->builtin_char, + NULL, val, -1, file, &opts); + fprintf_filtered (file, "\n"); + } + break; + } +} + +static void +default_print_auxv (struct ui_file *file, CORE_ADDR type, CORE_ADDR val) +{ + const char *name = "???"; + const char *description = ""; + enum auxv_format flavor = hex; + + switch (type) + { +#define TAG(tag, text, kind) \ + case tag: name = #tag; description = text; flavor = kind; break + TAG (AT_NULL, _("End of vector"), hex); + TAG (AT_IGNORE, _("Entry should be ignored"), hex); + TAG (AT_EXECFD, _("File descriptor of program"), dec); + TAG (AT_PHDR, _("Program headers for program"), hex); + TAG (AT_PHENT, _("Size of program header entry"), dec); + TAG (AT_PHNUM, _("Number of program headers"), dec); + TAG (AT_PAGESZ, _("System page size"), dec); + TAG (AT_BASE, _("Base address of interpreter"), hex); + TAG (AT_FLAGS, _("Flags"), hex); + TAG (AT_ENTRY, _("Entry point of program"), hex); + TAG (AT_NOTELF, _("Program is not ELF"), dec); + TAG (AT_UID, _("Real user ID"), dec); + TAG (AT_EUID, _("Effective user ID"), dec); + TAG (AT_GID, _("Real group ID"), dec); + TAG (AT_EGID, _("Effective group ID"), dec); + TAG (AT_CLKTCK, _("Frequency of times()"), dec); + TAG (AT_PLATFORM, _("String identifying platform"), str); + TAG (AT_HWCAP, _("Machine-dependent CPU capability hints"), hex); + TAG (AT_FPUCW, _("Used FPU control word"), dec); + TAG (AT_DCACHEBSIZE, _("Data cache block size"), dec); + TAG (AT_ICACHEBSIZE, _("Instruction cache block size"), dec); + TAG (AT_UCACHEBSIZE, _("Unified cache block size"), dec); + TAG (AT_IGNOREPPC, _("Entry should be ignored"), dec); + TAG (AT_BASE_PLATFORM, _("String identifying base platform"), str); + TAG (AT_RANDOM, _("Address of 16 random bytes"), hex); + TAG (AT_HWCAP2, _("Extension of AT_HWCAP"), hex); + TAG (AT_EXECFN, _("File name of executable"), str); + TAG (AT_SECURE, _("Boolean, was exec setuid-like?"), dec); + TAG (AT_SYSINFO, _("Special system info/entry points"), hex); + TAG (AT_SYSINFO_EHDR, _("System-supplied DSO's ELF header"), hex); + TAG (AT_L1I_CACHESHAPE, _("L1 Instruction cache information"), hex); + TAG (AT_L1D_CACHESHAPE, _("L1 Data cache information"), hex); + TAG (AT_L2_CACHESHAPE, _("L2 cache information"), hex); + TAG (AT_L3_CACHESHAPE, _("L3 cache information"), hex); + TAG (AT_SUN_UID, _("Effective user ID"), dec); + TAG (AT_SUN_RUID, _("Real user ID"), dec); + TAG (AT_SUN_GID, _("Effective group ID"), dec); + TAG (AT_SUN_RGID, _("Real group ID"), dec); + TAG (AT_SUN_LDELF, _("Dynamic linker's ELF header"), hex); + TAG (AT_SUN_LDSHDR, _("Dynamic linker's section headers"), hex); + TAG (AT_SUN_LDNAME, _("String giving name of dynamic linker"), str); + TAG (AT_SUN_LPAGESZ, _("Large pagesize"), dec); + TAG (AT_SUN_PLATFORM, _("Platform name string"), str); + TAG (AT_SUN_HWCAP, _("Machine-dependent CPU capability hints"), hex); + TAG (AT_SUN_IFLUSH, _("Should flush icache?"), dec); + TAG (AT_SUN_CPU, _("CPU name string"), str); + TAG (AT_SUN_EMUL_ENTRY, _("COFF entry point address"), hex); + TAG (AT_SUN_EMUL_EXECFD, _("COFF executable file descriptor"), dec); + TAG (AT_SUN_EXECNAME, + _("Canonicalized file name given to execve"), str); + TAG (AT_SUN_MMU, _("String for name of MMU module"), str); + TAG (AT_SUN_LDDATA, _("Dynamic linker's data segment address"), hex); + TAG (AT_SUN_AUXFLAGS, + _("AF_SUN_ flags passed from the kernel"), hex); + } + + fprint_single_auxv (file, name, description, flavor, type, val); +} + /* Print the contents of the target's AUXV on the specified file. */ int fprint_target_auxv (struct ui_file *file, struct target_ops *ops) { + struct gdbarch *gdbarch = target_gdbarch(); CORE_ADDR type, val; gdb_byte *data; gdb_byte *ptr; @@ -426,93 +528,10 @@ fprint_target_auxv (struct ui_file *file, struct target_ops *ops) while (target_auxv_parse (ops, &ptr, data + info->length, &type, &val) > 0) { - const char *name = "???"; - const char *description = ""; - enum { dec, hex, str } flavor = hex; - - switch (type) - { -#define TAG(tag, text, kind) \ - case tag: name = #tag; description = text; flavor = kind; break - TAG (AT_NULL, _("End of vector"), hex); - TAG (AT_IGNORE, _("Entry should be ignored"), hex); - TAG (AT_EXECFD, _("File descriptor of program"), dec); - TAG (AT_PHDR, _("Program headers for program"), hex); - TAG (AT_PHENT, _("Size of program header entry"), dec); - TAG (AT_PHNUM, _("Number of program headers"), dec); - TAG (AT_PAGESZ, _("System page size"), dec); - TAG (AT_BASE, _("Base address of interpreter"), hex); - TAG (AT_FLAGS, _("Flags"), hex); - TAG (AT_ENTRY, _("Entry point of program"), hex); - TAG (AT_NOTELF, _("Program is not ELF"), dec); - TAG (AT_UID, _("Real user ID"), dec); - TAG (AT_EUID, _("Effective user ID"), dec); - TAG (AT_GID, _("Real group ID"), dec); - TAG (AT_EGID, _("Effective group ID"), dec); - TAG (AT_CLKTCK, _("Frequency of times()"), dec); - TAG (AT_PLATFORM, _("String identifying platform"), str); - TAG (AT_HWCAP, _("Machine-dependent CPU capability hints"), hex); - TAG (AT_FPUCW, _("Used FPU control word"), dec); - TAG (AT_DCACHEBSIZE, _("Data cache block size"), dec); - TAG (AT_ICACHEBSIZE, _("Instruction cache block size"), dec); - TAG (AT_UCACHEBSIZE, _("Unified cache block size"), dec); - TAG (AT_IGNOREPPC, _("Entry should be ignored"), dec); - TAG (AT_BASE_PLATFORM, _("String identifying base platform"), str); - TAG (AT_RANDOM, _("Address of 16 random bytes"), hex); - TAG (AT_HWCAP2, _("Extension of AT_HWCAP"), hex); - TAG (AT_EXECFN, _("File name of executable"), str); - TAG (AT_SECURE, _("Boolean, was exec setuid-like?"), dec); - TAG (AT_SYSINFO, _("Special system info/entry points"), hex); - TAG (AT_SYSINFO_EHDR, _("System-supplied DSO's ELF header"), hex); - TAG (AT_L1I_CACHESHAPE, _("L1 Instruction cache information"), hex); - TAG (AT_L1D_CACHESHAPE, _("L1 Data cache information"), hex); - TAG (AT_L2_CACHESHAPE, _("L2 cache information"), hex); - TAG (AT_L3_CACHESHAPE, _("L3 cache information"), hex); - TAG (AT_SUN_UID, _("Effective user ID"), dec); - TAG (AT_SUN_RUID, _("Real user ID"), dec); - TAG (AT_SUN_GID, _("Effective group ID"), dec); - TAG (AT_SUN_RGID, _("Real group ID"), dec); - TAG (AT_SUN_LDELF, _("Dynamic linker's ELF header"), hex); - TAG (AT_SUN_LDSHDR, _("Dynamic linker's section headers"), hex); - TAG (AT_SUN_LDNAME, _("String giving name of dynamic linker"), str); - TAG (AT_SUN_LPAGESZ, _("Large pagesize"), dec); - TAG (AT_SUN_PLATFORM, _("Platform name string"), str); - TAG (AT_SUN_HWCAP, _("Machine-dependent CPU capability hints"), hex); - TAG (AT_SUN_IFLUSH, _("Should flush icache?"), dec); - TAG (AT_SUN_CPU, _("CPU name string"), str); - TAG (AT_SUN_EMUL_ENTRY, _("COFF entry point address"), hex); - TAG (AT_SUN_EMUL_EXECFD, _("COFF executable file descriptor"), dec); - TAG (AT_SUN_EXECNAME, - _("Canonicalized file name given to execve"), str); - TAG (AT_SUN_MMU, _("String for name of MMU module"), str); - TAG (AT_SUN_LDDATA, _("Dynamic linker's data segment address"), hex); - TAG (AT_SUN_AUXFLAGS, - _("AF_SUN_ flags passed from the kernel"), hex); - } + if (!gdbarch_print_auxv_p (gdbarch) + || gdbarch_print_auxv (gdbarch, file, type, val) == 0) + default_print_auxv (file, type, val); - fprintf_filtered (file, "%-4s %-20s %-30s ", - plongest (type), name, description); - switch (flavor) - { - case dec: - fprintf_filtered (file, "%s\n", plongest (val)); - break; - case hex: - fprintf_filtered (file, "%s\n", paddress (target_gdbarch (), val)); - break; - case str: - { - struct value_print_options opts; - - get_user_print_options (&opts); - if (opts.addressprint) - fprintf_filtered (file, "%s ", paddress (target_gdbarch (), val)); - val_print_string (builtin_type (target_gdbarch ())->builtin_char, - NULL, val, -1, file, &opts); - fprintf_filtered (file, "\n"); - } - break; - } ++ents; if (type == AT_NULL) break; diff --git a/gdb/auxv.h b/gdb/auxv.h index 9efe604..91d94f9 100644 --- a/gdb/auxv.h +++ b/gdb/auxv.h @@ -46,6 +46,14 @@ extern int target_auxv_parse (struct target_ops *ops, extern int target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp); +/* Print a description of a single AUXV entry on the specified file. */ +enum auxv_format { dec, hex, str }; + +extern void fprint_single_auxv (struct ui_file *file, const char *name, + const char *description, + enum auxv_format flavor, CORE_ADDR type, + CORE_ADDR val); + /* Print the contents of the target's AUXV on the specified file. */ extern int fprint_target_auxv (struct ui_file *file, struct target_ops *ops); diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 313502b..15a4a98 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -328,6 +328,7 @@ struct gdbarch gdbarch_insn_is_ret_ftype *insn_is_ret; gdbarch_insn_is_jump_ftype *insn_is_jump; gdbarch_auxv_parse_ftype *auxv_parse; + gdbarch_print_auxv_ftype *print_auxv; gdbarch_vsyscall_range_ftype *vsyscall_range; gdbarch_infcall_mmap_ftype *infcall_mmap; gdbarch_infcall_munmap_ftype *infcall_munmap; @@ -678,6 +679,7 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of insn_is_ret, invalid_p == 0 */ /* Skip verify of insn_is_jump, invalid_p == 0 */ /* Skip verify of auxv_parse, has predicate. */ + /* Skip verify of print_auxv, has predicate. */ /* Skip verify of vsyscall_range, invalid_p == 0 */ /* Skip verify of infcall_mmap, invalid_p == 0 */ /* Skip verify of infcall_munmap, invalid_p == 0 */ @@ -1167,6 +1169,12 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) "gdbarch_dump: pointer_to_address = <%s>\n", host_address_to_string (gdbarch->pointer_to_address)); fprintf_unfiltered (file, + "gdbarch_dump: gdbarch_print_auxv_p() = %d\n", + gdbarch_print_auxv_p (gdbarch)); + fprintf_unfiltered (file, + "gdbarch_dump: print_auxv = <%s>\n", + host_address_to_string (gdbarch->print_auxv)); + fprintf_unfiltered (file, "gdbarch_dump: print_float_info = <%s>\n", host_address_to_string (gdbarch->print_float_info)); fprintf_unfiltered (file, @@ -4770,6 +4778,30 @@ set_gdbarch_auxv_parse (struct gdbarch *gdbarch, } int +gdbarch_print_auxv_p (struct gdbarch *gdbarch) +{ + gdb_assert (gdbarch != NULL); + return gdbarch->print_auxv != NULL; +} + +int +gdbarch_print_auxv (struct gdbarch *gdbarch, struct ui_file *file, CORE_ADDR type, CORE_ADDR val) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->print_auxv != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_print_auxv called\n"); + return gdbarch->print_auxv (gdbarch, file, type, val); +} + +void +set_gdbarch_print_auxv (struct gdbarch *gdbarch, + gdbarch_print_auxv_ftype print_auxv) +{ + gdbarch->print_auxv = print_auxv; +} + +int gdbarch_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range) { gdb_assert (gdbarch != NULL); diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index a6366fc..9cd1175 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -1464,6 +1464,17 @@ typedef int (gdbarch_auxv_parse_ftype) (struct gdbarch *gdbarch, gdb_byte **read extern int gdbarch_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp); extern void set_gdbarch_auxv_parse (struct gdbarch *gdbarch, gdbarch_auxv_parse_ftype *auxv_parse); +/* Print the description of a single auxv entry described by TYPE and VAL + to FILE. Return 0 and output no description if the TYPE is unknown. + Return 0 if the TYPE of the auxv entry is unknown. + Return 1 if a description was output. */ + +extern int gdbarch_print_auxv_p (struct gdbarch *gdbarch); + +typedef int (gdbarch_print_auxv_ftype) (struct gdbarch *gdbarch, struct ui_file *file, CORE_ADDR type, CORE_ADDR val); +extern int gdbarch_print_auxv (struct gdbarch *gdbarch, struct ui_file *file, CORE_ADDR type, CORE_ADDR val); +extern void set_gdbarch_print_auxv (struct gdbarch *gdbarch, gdbarch_print_auxv_ftype *print_auxv); + /* Find the address range of the current inferior's vsyscall/vDSO, and write it to *RANGE. If the vsyscall's length can't be determined, a range with zero length is returned. Returns true if the vsyscall is diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh index f170c10..1b4342f 100755 --- a/gdb/gdbarch.sh +++ b/gdb/gdbarch.sh @@ -1110,6 +1110,12 @@ m:int:insn_is_jump:CORE_ADDR addr:addr::default_insn_is_jump::0 # Return 1 if an entry was read into *TYPEP and *VALP. M:int:auxv_parse:gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp:readptr, endptr, typep, valp +# Print the description of a single auxv entry described by TYPE and VAL +# to FILE. Return 0 and output no description if the TYPE is unknown. +# Return 0 if the TYPE of the auxv entry is unknown. +# Return 1 if a description was output. +M:int:print_auxv:struct ui_file *file, CORE_ADDR type, CORE_ADDR val:file, type, val + # Find the address range of the current inferior's vsyscall/vDSO, and # write it to *RANGE. If the vsyscall's length can't be determined, a # range with zero length is returned. Returns true if the vsyscall is -- 2.8.4 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 5/6] Add a new gdbarch method to print a single AUXV entry. 2016-06-16 6:11 ` [PATCH 5/6] Add a new gdbarch method to print a single AUXV entry John Baldwin @ 2016-06-20 23:40 ` Pedro Alves 2016-06-23 20:19 ` John Baldwin 0 siblings, 1 reply; 16+ messages in thread From: Pedro Alves @ 2016-06-20 23:40 UTC (permalink / raw) To: John Baldwin, gdb-patches, binutils On 06/16/2016 07:02 AM, John Baldwin wrote: > Different platforms have different meanings for auxiliary vector > entries. The 'print_auxv' gdbarch method allows an architecture > to output a suitable description for platform-specific entries. > > A fprint_single_auxv function is split out of fprint_target_auxv. > This function outputs the description of a single auxiliary vector > entry to the specified file using caller-supplied formatting and > strings to describe the vector type. > > The existing switch on auxiliary vector types is moved out of > fprint_target_auxv into a new default_print_auxv function. > default_print_auxv chooses an appropriate format and description > and calls fprint_single_auxv to describe a single vector entry. > > fprint_target_auxv now invokes the gdbarch 'print_auxv' function > on each vector entry. If the function is not present or returns > zero, default_printf_auxv is called to output a description for > the vector. I like the idea. Though, I think we can simplify this. How about: - make default_print_auxv be the default gdbarch_print_auxv implementation, in gdbarch.sh. - make fprint_target_auxv calls gdbarch_print_auxv unconditionally. - remove the support for gdbarch_print_auxv returning 0. Instead, implementations that want to defer to default_print_auxv simply call it directly. Also, I think it'd be a bit less confusing to rename things like this: gdbarch_print_auxv -> gdbarch_print_auxv_entry default_print_auxv -> default_print_auxv_entry fprint_single_auxv -> fprint_auxv_entry This way methods that print a single entry are consistently named, and not so easily confused with methods that print the whole table, like fprint_target_auxv. > > > +/* Print a description of a single AUXV entry on the specified file. */ > +void Empty line between comment and function. > +fprint_single_auxv (struct ui_file *file, const char *name, > + const char *description, enum auxv_format flavor, > + CORE_ADDR type, CORE_ADDR val) > +{ > + fprintf_filtered (file, "%-4s %-20s %-30s ", > + plongest (type), name, description); If not translatable, wrap string in () [not _()], in order to avoid ARI complaints. > + switch (flavor) > + { > + case dec: > + fprintf_filtered (file, "%s\n", plongest (val)); > + break; > + case hex: > + fprintf_filtered (file, "%s\n", paddress (target_gdbarch (), val)); > + break; > + case str: > + { > + struct value_print_options opts; > + > + get_user_print_options (&opts); > + if (opts.addressprint) > + fprintf_filtered (file, "%s ", paddress (target_gdbarch (), val)); > + val_print_string (builtin_type (target_gdbarch ())->builtin_char, > + NULL, val, -1, file, &opts); > + fprintf_filtered (file, "\n"); > + } Likewise the other format strings. > + > +static void > +default_print_auxv (struct ui_file *file, CORE_ADDR type, CORE_ADDR val) > +{ Intro comment. Something like "default implementation of ...". > + > /* Print the contents of the target's AUXV on the specified file. */ > int > fprint_target_auxv (struct ui_file *file, struct target_ops *ops) > { > + struct gdbarch *gdbarch = target_gdbarch(); Space before open parenthesis. > diff --git a/gdb/auxv.h b/gdb/auxv.h > index 9efe604..91d94f9 100644 > --- a/gdb/auxv.h > +++ b/gdb/auxv.h > @@ -46,6 +46,14 @@ extern int target_auxv_parse (struct target_ops *ops, > extern int target_auxv_search (struct target_ops *ops, > CORE_ADDR match, CORE_ADDR *valp); > > +/* Print a description of a single AUXV entry on the specified file. */ > +enum auxv_format { dec, hex, str }; These very generic names used to be OK, because they were defined inside the function. But now that this is in a header, the potential for conflict is much higher. hex could conflict with std::hex, for instance. Please rename the values to for example: AUXV_FORMAT_DEC / AUXV_FORMAT_HEX / AUXV_FORMAT_STR. We should add a comment for what each value means, too, since we lost the pass of obvious-because-of-locality. > + > +extern void fprint_single_auxv (struct ui_file *file, const char *name, > + const char *description, > + enum auxv_format flavor, CORE_ADDR type, I'd find it more consistent to call parameter "format" instead of "flavor", which then avoids people looking for enum auxv_flavor. > +# Print the description of a single auxv entry described by TYPE and VAL > +# to FILE. Return 0 and output no description if the TYPE is unknown. > +# Return 0 if the TYPE of the auxv entry is unknown. > +# Return 1 if a description was output. > +M:int:print_auxv:struct ui_file *file, CORE_ADDR type, CORE_ADDR val:file, type, val Thanks, Pedro Alves ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 5/6] Add a new gdbarch method to print a single AUXV entry. 2016-06-20 23:40 ` Pedro Alves @ 2016-06-23 20:19 ` John Baldwin 0 siblings, 0 replies; 16+ messages in thread From: John Baldwin @ 2016-06-23 20:19 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches, binutils On Tuesday, June 21, 2016 12:40:16 AM Pedro Alves wrote: > On 06/16/2016 07:02 AM, John Baldwin wrote: > > Different platforms have different meanings for auxiliary vector > > entries. The 'print_auxv' gdbarch method allows an architecture > > to output a suitable description for platform-specific entries. > > > > A fprint_single_auxv function is split out of fprint_target_auxv. > > This function outputs the description of a single auxiliary vector > > entry to the specified file using caller-supplied formatting and > > strings to describe the vector type. > > > > The existing switch on auxiliary vector types is moved out of > > fprint_target_auxv into a new default_print_auxv function. > > default_print_auxv chooses an appropriate format and description > > and calls fprint_single_auxv to describe a single vector entry. > > > > fprint_target_auxv now invokes the gdbarch 'print_auxv' function > > on each vector entry. If the function is not present or returns > > zero, default_printf_auxv is called to output a description for > > the vector. > > I like the idea. Though, I think we can simplify this. How about: > > - make default_print_auxv be the default gdbarch_print_auxv > implementation, in gdbarch.sh. > > - make fprint_target_auxv calls gdbarch_print_auxv unconditionally. > > - remove the support for gdbarch_print_auxv returning 0. Instead, > implementations that want to defer to default_print_auxv simply > call it directly. > > > Also, I think it'd be a bit less confusing to rename things like this: > > gdbarch_print_auxv -> gdbarch_print_auxv_entry > default_print_auxv -> default_print_auxv_entry > fprint_single_auxv -> fprint_auxv_entry > > This way methods that print a single entry are consistently named, > and not so easily confused with methods that print the whole table, > like fprint_target_auxv. Agreed, thanks. I've made these changes along with the auxv_format enum rename and the other issues you've pointed out. Will be posting a v2 series with those fixes in a bit. -- John Baldwin ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD 2016-06-16 6:02 [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin ` (5 preceding siblings ...) 2016-06-16 6:11 ` [PATCH 5/6] Add a new gdbarch method to print a single AUXV entry John Baldwin @ 2016-06-20 17:10 ` John Baldwin 6 siblings, 0 replies; 16+ messages in thread From: John Baldwin @ 2016-06-20 17:10 UTC (permalink / raw) To: gdb-patches On Wednesday, June 15, 2016 11:01:56 PM John Baldwin wrote: > This patch series fixes 'info auxv' to work on live binaries and cores > for FreeBSD. I believe most of these patches are straightforward. > I broke out parsing of FreeBSD-specific ELF core notes to avoid a > collision with duplicate NT_* values (NT_FREEBSD_PROCSTAT_AUXV conflicts > with NT_LWPSTATUS). The biggest change is adding a new gdbarch method > to handle formatting individual auxv vectors. FreeBSD uses AT_* constants > that overlap with existing AT_* constants but with different meanings. > One result of making the interpretation of AT_* constants a gdbarch > method is that 'info auxv' shows the correct output (Linux values) > when gdb inspects a Linux binary executing on FreeBSD via FreeBSD's > Linux ABI support. Ping? The binutils patches have been ok'd, but the gdb patches haven't been reviewed yet. -- John Baldwin ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2016-06-23 20:19 UTC | newest] Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-06-16 6:02 [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin 2016-06-16 6:02 ` [PATCH 6/6] Add a gdbarch 'print_auxv' method for FreeBSD ABIs John Baldwin 2016-06-20 23:43 ` Pedro Alves 2016-06-16 6:02 ` [PATCH 3/6] Fetch the ELF auxiliary vector from live processes on FreeBSD John Baldwin 2016-06-20 23:01 ` Pedro Alves 2016-06-16 6:02 ` [PATCH 2/6] Add elfcore_grok_freebsd_note to parse FreeBSD ELF core notes John Baldwin 2016-06-17 8:28 ` Nick Clifton 2016-06-16 6:02 ` [PATCH 1/6] Add constants for FreeBSD-specific auxiliary vector entry types John Baldwin 2016-06-17 8:27 ` Nick Clifton 2016-06-16 6:11 ` [PATCH 4/6] Create a psuedo section for the ELF AUXV core dump note on FreeBSD John Baldwin 2016-06-17 8:28 ` Nick Clifton 2016-06-20 23:45 ` Pedro Alves 2016-06-16 6:11 ` [PATCH 5/6] Add a new gdbarch method to print a single AUXV entry John Baldwin 2016-06-20 23:40 ` Pedro Alves 2016-06-23 20:19 ` John Baldwin 2016-06-20 17:10 ` [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).