+/* See fbsd-tdep.h. */
+
+CORE_ADDR
+fbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
+{
+ struct bound_minimal_symbol msym = lookup_bound_minimal_symbol ("_rtld_bind");
+ if (msym.minsym != nullptr && msym.value_address () == pc)
+ return frame_unwind_caller_pc (get_current_frame ());
+
+ return 0;
+}
+
+/* Return description of signal code or nullptr. */
+
+static const char *
+fbsd_signal_cause (enum gdb_signal siggnal, int code)
+{
+ /* Signal-independent causes. */
+ switch (code)
+ {
+ case FBSD_SI_USER:
+ return _("Sent by kill()");
+ case FBSD_SI_QUEUE:
+ return _("Sent by sigqueue()");
+ case FBSD_SI_TIMER:
+ return _("Timer expired");
+ case FBSD_SI_ASYNCIO:
+ return _("Asynchronous I/O request completed");
+ case FBSD_SI_MESGQ:
+ return _("Message arrived on empty message queue");
+ case FBSD_SI_KERNEL:
+ return _("Sent by kernel");
+ case FBSD_SI_LWP:
+ return _("Sent by thr_kill()");
+ }
+
+ switch (siggnal)
+ {
+ case GDB_SIGNAL_ILL:
+ switch (code)
+ {
+ case FBSD_ILL_ILLOPC:
+ return _("Illegal opcode");
+ case FBSD_ILL_ILLOPN:
+ return _("Illegal operand");
+ case FBSD_ILL_ILLADR:
+ return _("Illegal addressing mode");
+ case FBSD_ILL_ILLTRP:
+ return _("Illegal trap");
+ case FBSD_ILL_PRVOPC:
+ return _("Privileged opcode");
+ case FBSD_ILL_PRVREG:
+ return _("Privileged register");
+ case FBSD_ILL_COPROC:
+ return _("Coprocessor error");
+ case FBSD_ILL_BADSTK:
+ return _("Internal stack error");
+ }
+ break;
+ case GDB_SIGNAL_BUS:
+ switch (code)
+ {
+ case FBSD_BUS_ADRALN:
+ return _("Invalid address alignment");
+ case FBSD_BUS_ADRERR:
+ return _("Address not present");
+ case FBSD_BUS_OBJERR:
+ return _("Object-specific hardware error");
+ case FBSD_BUS_OOMERR:
+ return _("Out of memory");
+ }
+ break;
+ case GDB_SIGNAL_SEGV:
+ switch (code)
+ {
+ case FBSD_SEGV_MAPERR:
+ return _("Address not mapped to object");
+ case FBSD_SEGV_ACCERR:
+ return _("Invalid permissions for mapped object");
+ case FBSD_SEGV_PKUERR:
+ return _("PKU violation");
+ }
+ break;
+ case GDB_SIGNAL_FPE:
+ switch (code)
+ {
+ case FBSD_FPE_INTOVF:
+ return _("Integer overflow");
+ case FBSD_FPE_INTDIV:
+ return _("Integer divide by zero");
+ case FBSD_FPE_FLTDIV:
+ return _("Floating point divide by zero");
+ case FBSD_FPE_FLTOVF:
+ return _("Floating point overflow");
+ case FBSD_FPE_FLTUND:
+ return _("Floating point underflow");
+ case FBSD_FPE_FLTRES:
+ return _("Floating point inexact result");
+ case FBSD_FPE_FLTINV:
+ return _("Invalid floating point operation");
+ case FBSD_FPE_FLTSUB:
+ return _("Subscript out of range");
+ }
+ break;
+ case GDB_SIGNAL_TRAP:
+ switch (code)
+ {
+ case FBSD_TRAP_BRKPT:
+ return _("Breakpoint");
+ case FBSD_TRAP_TRACE:
+ return _("Trace trap");
+ case FBSD_TRAP_DTRACE:
+ return _("DTrace-induced trap");
+ case FBSD_TRAP_CAP:
+ return _("Capability violation");
+ }
+ break;
+ case GDB_SIGNAL_CHLD:
+ switch (code)
+ {
+ case FBSD_CLD_EXITED:
+ return _("Child has exited");
+ case FBSD_CLD_KILLED:
+ return _("Child has terminated abnormally");
+ case FBSD_CLD_DUMPED:
+ return _("Child has dumped core");
+ case FBSD_CLD_TRAPPED:
+ return _("Traced child has trapped");
+ case FBSD_CLD_STOPPED:
+ return _("Child has stopped");
+ case FBSD_CLD_CONTINUED:
+ return _("Stopped child has continued");
+ }
+ break;
+ case GDB_SIGNAL_POLL:
+ switch (code)
+ {
+ case FBSD_POLL_IN:
+ return _("Data input available");
+ case FBSD_POLL_OUT:
+ return _("Output buffers available");
+ case FBSD_POLL_MSG:
+ return _("Input message available");
+ case FBSD_POLL_ERR:
+ return _("I/O error");
+ case FBSD_POLL_PRI:
+ return _("High priority input available");
+ case FBSD_POLL_HUP:
+ return _("Device disconnected");
+ }
+ break;
+ }
+
+ return nullptr;
+}
+
+/* Report additional details for a signal stop. */
+
+static void
+fbsd_report_signal_info (struct gdbarch *gdbarch, struct ui_out *uiout,
+ enum gdb_signal siggnal)
+{
+ LONGEST code, mqd, pid, status, timerid, uid;
+
+ try
+ {
+ code = parse_and_eval_long ("$_siginfo.si_code");
+ pid = parse_and_eval_long ("$_siginfo.si_pid");
+ uid = parse_and_eval_long ("$_siginfo.si_uid");
+ status = parse_and_eval_long ("$_siginfo.si_status");
+ timerid = parse_and_eval_long ("$_siginfo._reason._timer.si_timerid");
+ mqd = parse_and_eval_long ("$_siginfo._reason._mesgq.si_mqd");
+ }
+ catch (const gdb_exception_error &e)
+ {
+ return;
+ }
+
+ const char *meaning = fbsd_signal_cause (siggnal, code);
+ if (meaning == nullptr)
+ return;
+
+ uiout->text (".\n");
+ uiout->field_string ("sigcode-meaning", meaning);
+
+ switch (code)
+ {
+ case FBSD_SI_USER:
+ case FBSD_SI_QUEUE:
+ case FBSD_SI_LWP:
+ uiout->text (" from pid ");
+ uiout->field_string ("sending-pid", plongest (pid));
+ uiout->text (" and user ");
+ uiout->field_string ("sending-uid", plongest (uid));
+ return;
+ case FBSD_SI_TIMER:
+ uiout->text (": timerid ");
+ uiout->field_string ("timerid", plongest (timerid));
+ return;
+ case FBSD_SI_MESGQ:
+ uiout->text (": message queue ");
+ uiout->field_string ("message-queue", plongest (mqd));
+ return;
+ case FBSD_SI_ASYNCIO:
+ return;
+ }
+
+ if (siggnal == GDB_SIGNAL_CHLD)
+ {
+ uiout->text (": pid ");
+ uiout->field_string ("child-pid", plongest (pid));
+ uiout->text (", uid ");
+ uiout->field_string ("child-uid", plongest (uid));
+ if (code == FBSD_CLD_EXITED)
+ {
+ uiout->text (", exit status ");
+ uiout->field_string ("exit-status", plongest (status));
+ }
+ else
+ {
+ uiout->text (", signal ");
+ uiout->field_string ("signal", plongest (status));
+ }
+ }
+}
+
+/* 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)
+{
+ if (target_auxv_search (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 (current_inferior ()->top_target (),
+ 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;
+}
+