public inbox for gdb-cvs@sourceware.org help / color / mirror / Atom feed
From: John Baldwin <jhb@sourceware.org> To: gdb-cvs@sourceware.org Subject: [binutils-gdb] fbsd-tdep: Implement the vsyscall_range gdbarch hook. Date: Wed, 2 Mar 2022 22:03:39 +0000 (GMT) [thread overview] Message-ID: <20220302220339.B40EC3858D39@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c1dae0a6a0ab03a778221a0f88048395d1d0796c commit c1dae0a6a0ab03a778221a0f88048395d1d0796c Author: John Baldwin <jhb@FreeBSD.org> Date: Wed Mar 2 14:00:36 2022 -0800 fbsd-tdep: Implement the vsyscall_range gdbarch hook. FreeBSD recently added a real vDSO in its shared page for the amd64 architecture. The vDSO is mapped at the address given by the AT_KPRELOAD ELF auxiliary vector entry. To find the end of the mapping range, parse the list of virtual map entries used by 'info proc mappings' either from the NT_PROCSTAT_VMMAP core dump note, or via the kinfo_getvmmap function for native targets (fetched from the native target as the TARGET_OBJECT_FREEBSD_VMMAP object). This silences warnings on recent FreeBSD/amd64 kernels due to not finding symbols for the vdso: warning: Could not load shared library symbols for [vdso]. Do you need "set solib-search-path" or "set sysroot"? Diff: --- gdb/fbsd-tdep.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index 47c98ab9793..744fa6dad72 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -510,6 +510,13 @@ struct fbsd_pspace_data LONGEST off_linkmap = 0; LONGEST off_tlsindex = 0; bool rtld_offsets_valid = false; + + /* vDSO mapping range. */ + struct mem_range vdso_range {}; + + /* Zero if the range hasn't been searched for, > 0 if a range was + found, or < 0 if a range was not found. */ + int vdso_range_p = 0; }; /* Per-program-space data for FreeBSD architectures. */ @@ -2261,6 +2268,108 @@ fbsd_report_signal_info (struct gdbarch *gdbarch, struct ui_out *uiout, } } +/* Search a list of struct kinfo_vmmap entries in the ENTRIES buffer + of LEN bytes to find the length of the entry starting at ADDR. + Returns the length of the entry or zero if no entry was found. */ + +static ULONGEST +fbsd_vmmap_length (struct gdbarch *gdbarch, unsigned char *entries, size_t len, + CORE_ADDR addr) +{ + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + unsigned char *descdata = entries; + unsigned char *descend = descdata + len; + + /* Skip over the structure size. */ + descdata += 4; + + while (descdata + KVE_PATH < descend) + { + ULONGEST structsize = extract_unsigned_integer (descdata + + KVE_STRUCTSIZE, 4, + byte_order); + if (structsize < KVE_PATH) + return false; + + ULONGEST start = extract_unsigned_integer (descdata + KVE_START, 8, + byte_order); + ULONGEST end = extract_unsigned_integer (descdata + KVE_END, 8, + byte_order); + if (start == addr) + return end - start; + + descdata += structsize; + } + return 0; +} + +/* Helper for fbsd_vsyscall_range that does the real work of finding + the vDSO's address range. */ + +static bool +fbsd_vdso_range (struct gdbarch *gdbarch, struct mem_range *range) +{ + struct target_ops *ops = current_inferior ()->top_target (); + + if (target_auxv_search (ops, AT_FREEBSD_KPRELOAD, &range->start) <= 0) + return false; + + if (!target_has_execution ()) + { + /* Search for the ending address in the NT_PROCSTAT_VMMAP note. */ + asection *section = bfd_get_section_by_name (core_bfd, + ".note.freebsdcore.vmmap"); + if (section == nullptr) + return false; + + size_t note_size = bfd_section_size (section); + if (note_size < 4) + return false; + + gdb::def_vector<unsigned char> contents (note_size); + if (!bfd_get_section_contents (core_bfd, section, contents.data (), + 0, note_size)) + return false; + + range->length = fbsd_vmmap_length (gdbarch, contents.data (), note_size, + range->start); + } + else + { + /* Fetch the list of address space entries from the running target. */ + gdb::optional<gdb::byte_vector> buf = + target_read_alloc (ops, TARGET_OBJECT_FREEBSD_VMMAP, nullptr); + if (!buf || buf->empty ()) + return false; + + range->length = fbsd_vmmap_length (gdbarch, buf->data (), buf->size (), + range->start); + } + return range->length != 0; +} + +/* Return the address range of the vDSO for the current inferior. */ + +static int +fbsd_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range) +{ + struct fbsd_pspace_data *data = get_fbsd_pspace_data (current_program_space); + + if (data->vdso_range_p == 0) + { + if (fbsd_vdso_range (gdbarch, &data->vdso_range)) + data->vdso_range_p = 1; + else + data->vdso_range_p = -1; + } + + if (data->vdso_range_p < 0) + return 0; + + *range = data->vdso_range; + return 1; +} + /* To be called from GDB_OSABI_FREEBSD handlers. */ void @@ -2277,6 +2386,7 @@ fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_gdb_signal_to_target (gdbarch, fbsd_gdb_signal_to_target); set_gdbarch_report_signal_info (gdbarch, fbsd_report_signal_info); set_gdbarch_skip_solib_resolver (gdbarch, fbsd_skip_solib_resolver); + set_gdbarch_vsyscall_range (gdbarch, fbsd_vsyscall_range); /* `catch syscall' */ set_xml_syscall_file_name (gdbarch, "syscalls/freebsd.xml");
reply other threads:[~2022-03-02 22:03 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220302220339.B40EC3858D39@sourceware.org \ --to=jhb@sourceware.org \ --cc=gdb-cvs@sourceware.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: linkBe 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; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).