21#include "gdbsupport/block-signals.h"
22#include "gdbsupport/byte-vector.h"
23#include "gdbsupport/event-loop.h"
31#include "gdbsupport/buildargv.h"
32#include "gdbsupport/gdb_wait.h"
36#ifdef HAVE_SYS_PROCCTL_H
37#include <sys/procctl.h>
39#include <sys/procfs.h>
40#include <sys/ptrace.h>
41#include <sys/signal.h>
42#include <sys/sysctl.h>
51#define PT_GETREGSET 42
52#define PT_SETREGSET 43
76 return gdb::checked_static_cast<fbsd_inferior *> (
inf->priv.get ());
95 if (event.ptid.matches (filter))
102gdb::optional<fbsd_nat_target::pending_event>
106 if (it->ptid.matches (filter))
126 static char buf[PATH_MAX];
132 mib[2] = KERN_PROC_PATHNAME;
135 if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0)
139 return buflen == 0 ? NULL : buf;
153 struct kinfo_vmentry *kve;
157 gdb::unique_xmalloc_ptr<struct kinfo_vmentry>
158 vmentl (kinfo_getvmmap (
pid, &nitems));
160 perror_with_name (_(
"Couldn't fetch VM map entries"));
162 for (i = 0, kve = vmentl.get (); i < nitems; i++, kve++)
165 if (!(kve->kve_protection & KVME_PROT_READ)
166 || kve->kve_flags & KVME_FLAG_NOCOREDUMP)
170 if (kve->kve_type != KVME_TYPE_DEFAULT
171 && kve->kve_type != KVME_TYPE_VNODE
172 && kve->kve_type != KVME_TYPE_SWAP
173 && kve->kve_type != KVME_TYPE_PHYS)
176 size = kve->kve_end - kve->kve_start;
179 gdb_printf (
"Save segment, %ld bytes at %s (%c%c%c)\n",
182 kve->kve_protection & KVME_PROT_READ ?
'r' :
'-',
183 kve->kve_protection & KVME_PROT_WRITE ?
'w' :
'-',
184 kve->kve_protection & KVME_PROT_EXEC ?
'x' :
'-');
189 func (kve->kve_start,
size, kve->kve_protection & KVME_PROT_READ,
190 kve->kve_protection & KVME_PROT_WRITE,
191 kve->kve_protection & KVME_PROT_EXEC, 1,
false, data);
198static gdb::unique_xmalloc_ptr<char>
207 mib[2] = KERN_PROC_ARGS;
209 if (sysctl (mib, 4, NULL, &len, NULL, 0) == -1)
215 gdb::unique_xmalloc_ptr<char> cmdline ((
char *)
xmalloc (len));
216 if (sysctl (mib, 4, cmdline.get (), &len, NULL, 0) == -1)
220 char *cp = cmdline.get ();
221 for (
size_t i = 0; i < len - 1; i++)
241 mib[2] = KERN_PROC_PID;
243 return (sysctl (mib, 4, kp, &len, NULL, 0) == 0);
251 gdb::unique_xmalloc_ptr<struct kinfo_file> fdtbl;
253 struct kinfo_proc kp;
255 bool do_cmdline =
false;
258 bool do_files =
false;
259 bool do_mappings =
false;
260 bool do_status =
false;
297 error (_(
"Not supported on this target."));
300 gdb_argv built_argv (args);
301 if (built_argv.count () == 0)
305 error (_(
"No current process: you must name one."));
307 else if (built_argv.count () == 1 && isdigit (built_argv[0][0]))
308 pid = strtol (built_argv[0], NULL, 10);
310 error (_(
"Invalid arguments."));
313 if (do_cwd || do_exe || do_files)
314 fdtbl.reset (kinfo_getfile (
pid, &nfd));
319 if (cmdline !=
nullptr)
320 gdb_printf (
"cmdline = '%s'\n", cmdline.get ());
322 warning (_(
"unable to fetch command line"));
326 const char *cwd = NULL;
327 struct kinfo_file *kf = fdtbl.get ();
328 for (
int i = 0; i < nfd; i++, kf++)
330 if (kf->kf_type == KF_TYPE_VNODE && kf->kf_fd == KF_FD_TYPE_CWD)
339 warning (_(
"unable to fetch current working directory"));
343 const char *exe = NULL;
344 struct kinfo_file *kf = fdtbl.get ();
345 for (
int i = 0; i < nfd; i++, kf++)
347 if (kf->kf_type == KF_TYPE_VNODE && kf->kf_fd == KF_FD_TYPE_TEXT)
358 warning (_(
"unable to fetch executable path name"));
362 struct kinfo_file *kf = fdtbl.get ();
367 for (
int i = 0; i < nfd; i++, kf++)
369 kf->kf_offset, kf->kf_vnode_type,
370 kf->kf_sock_domain, kf->kf_sock_type,
371 kf->kf_sock_protocol, &kf->kf_sa_local,
372 &kf->kf_sa_peer, kf->kf_path);
375 warning (_(
"unable to fetch list of open files"));
380 gdb::unique_xmalloc_ptr<struct kinfo_vmentry>
381 vmentl (kinfo_getvmmap (
pid, &nvment));
383 if (vmentl !=
nullptr)
385 int addr_bit = TARGET_CHAR_BIT *
sizeof (
void *);
388 struct kinfo_vmentry *kve = vmentl.get ();
389 for (
int i = 0; i < nvment; i++, kve++)
391 kve->kve_end, kve->kve_offset,
392 kve->kve_flags, kve->kve_protection,
396 warning (_(
"unable to fetch virtual memory map"));
401 warning (_(
"Failed to fetch process information"));
414 state =
"R (running)";
417 state =
"T (stopped)";
420 state =
"Z (zombie)";
423 state =
"S (sleeping)";
426 state =
"W (interrupt wait)";
429 state =
"L (blocked on lock)";
432 state =
"? (unknown)";
436 gdb_printf (
"Parent process: %d\n", kp.ki_ppid);
437 gdb_printf (
"Process group: %d\n", kp.ki_pgid);
439 gdb_printf (
"TTY: %s\n", pulongest (kp.ki_tdev));
440 gdb_printf (
"TTY owner process group: %d\n", kp.ki_tpgid);
441 gdb_printf (
"User IDs (real, effective, saved): %d %d %d\n",
442 kp.ki_ruid, kp.ki_uid, kp.ki_svuid);
443 gdb_printf (
"Group IDs (real, effective, saved): %d %d %d\n",
444 kp.ki_rgid, kp.ki_groups[0], kp.ki_svgid);
446 for (
int i = 0; i < kp.ki_ngroups; i++)
449 gdb_printf (
"Minor faults (no memory page): %ld\n",
450 kp.ki_rusage.ru_minflt);
452 kp.ki_rusage_ch.ru_minflt);
453 gdb_printf (
"Major faults (memory page faults): %ld\n",
454 kp.ki_rusage.ru_majflt);
456 kp.ki_rusage_ch.ru_majflt);
458 plongest (kp.ki_rusage.ru_utime.tv_sec),
459 kp.ki_rusage.ru_utime.tv_usec);
461 plongest (kp.ki_rusage.ru_stime.tv_sec),
462 kp.ki_rusage.ru_stime.tv_usec);
464 plongest (kp.ki_rusage_ch.ru_utime.tv_sec),
465 kp.ki_rusage_ch.ru_utime.tv_usec);
467 plongest (kp.ki_rusage_ch.ru_stime.tv_sec),
468 kp.ki_rusage_ch.ru_stime.tv_usec);
469 gdb_printf (
"'nice' value: %d\n", kp.ki_nice);
471 plongest (kp.ki_start.tv_sec),
472 kp.ki_start.tv_usec);
473 pgtok = getpagesize () / 1024;
475 pulongest (kp.ki_size / 1024));
477 pulongest (kp.ki_dsize * pgtok));
479 pulongest (kp.ki_ssize * pgtok));
481 pulongest (kp.ki_tsize * pgtok));
483 pulongest (kp.ki_rssize * pgtok));
485 pulongest (kp.ki_rusage.ru_maxrss));
487 for (
int i = 0; i < _SIG_WORDS; i++)
488 gdb_printf (
"%08x ", kp.ki_siglist.__bits[i]);
491 for (
int i = 0; i < _SIG_WORDS; i++)
492 gdb_printf (
"%08x ", kp.ki_sigignore.__bits[i]);
495 for (
int i = 0; i < _SIG_WORDS; i++)
496 gdb_printf (
"%08x ", kp.ki_sigcatch.__bits[i]);
526 union sigval32 si_value;
563 return sizeof (
struct siginfo32);
565 return sizeof (siginfo_t);
582 struct siginfo32 si32;
584 si32.si_signo = si->si_signo;
585 si32.si_errno = si->si_errno;
586 si32.si_code = si->si_code;
587 si32.si_pid = si->si_pid;
588 si32.si_uid = si->si_uid;
589 si32.si_status = si->si_status;
590 si32.si_addr = (uintptr_t) si->si_addr;
595#if _BYTE_ORDER == _BIG_ENDIAN
596 if (si->si_value.sival_int == 0)
597 si32.si_value.sival_ptr = (uintptr_t) si->si_value.sival_ptr;
599 si32.si_value.sival_int = si->si_value.sival_int;
601 si32.si_value.sival_int = si->si_value.sival_int;
606 si32._reason.__spare__.__spare1__ = si->_reason.__spare__.__spare1__;
607 for (
int i = 0; i < 7; i++)
608 si32._reason.__spare__.__spare2__[i] = si->_reason.__spare__.__spare2__[i];
609 switch (si->si_signo) {
614 si32.si_trapno = si->si_trapno;
617 switch (si->si_code) {
619 si32.si_timerid = si->si_timerid;
620 si32.si_overrun = si->si_overrun;
623 si32.si_mqd = si->si_mqd;
627 memcpy(si, &si32,
sizeof (si32));
635 const char *annex, gdb_byte *readbuf,
636 const gdb_byte *writebuf,
637 ULONGEST offset, ULONGEST len,
638 ULONGEST *xfered_len)
646 struct ptrace_lwpinfo pl;
650 if (writebuf != NULL)
657 if (offset > siginfo_size)
667 if (offset + len > siginfo_size)
668 len = siginfo_size - offset;
670 memcpy (readbuf, ((gdb_byte *) &pl.pl_siginfo) + offset, len);
677 gdb::byte_vector buf_storage;
682 if (writebuf != NULL)
686 mib[2] = KERN_PROC_AUXV;
695 buflen = offset + len;
696 buf_storage.resize (buflen);
697 buf = buf_storage.data ();
699 if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0)
706 memcpy (readbuf, buf + offset, buflen);
711 *xfered_len = buflen;
717#if defined(KERN_PROC_VMMAP) && defined(KERN_PROC_PS_STRINGS)
721 gdb::byte_vector buf_storage;
727 uint32_t struct_size;
731 proc_target = KERN_PROC_VMMAP;
732 struct_size =
sizeof (
struct kinfo_vmentry);
735 proc_target = KERN_PROC_PS_STRINGS;
736 struct_size =
sizeof (
void *);
740 if (writebuf != NULL)
745 mib[2] = proc_target;
748 if (sysctl (mib, 4, NULL, &buflen, NULL, 0) != 0)
750 buflen +=
sizeof (struct_size);
752 if (offset >= buflen)
758 buf_storage.resize (buflen);
759 buf = buf_storage.data ();
761 memcpy (buf, &struct_size,
sizeof (struct_size));
762 buflen -=
sizeof (struct_size);
763 if (sysctl (mib, 4, buf +
sizeof (struct_size), &buflen, NULL, 0) != 0)
765 buflen +=
sizeof (struct_size);
767 if (buflen - offset < len)
768 len = buflen - offset;
769 memcpy (readbuf, buf + offset, len);
776 readbuf, writebuf, offset,
788 gdb_printf (file, _(
"Debugging of FreeBSD lwp module is %s.\n"),
value);
795 gdb_printf (file, _(
"Debugging of FreeBSD native target is %s.\n"),
799#define fbsd_lwp_debug_printf(fmt, ...) \
800 debug_prefixed_printf_cond (debug_fbsd_lwp, "fbsd-lwp", fmt, ##__VA_ARGS__)
802#define fbsd_nat_debug_printf(fmt, ...) \
803 debug_prefixed_printf_cond (debug_fbsd_nat, "fbsd-nat", fmt, ##__VA_ARGS__)
805#define fbsd_nat_debug_start_end(fmt, ...) \
806 scoped_debug_start_end (debug_fbsd_nat, "fbsd-nat", fmt, ##__VA_ARGS__)
842 struct ptrace_lwpinfo pl;
844 if (
ptrace (PT_LWPINFO, ptid.lwp (), (caddr_t) &pl,
sizeof pl)
854 if (pl.pl_flags & PL_FLAG_EXITED)
872 int pid = ptid.pid ();
874 return string_printf (
"LWP %d of process %d", lwp,
pid);
880#ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME
887 struct ptrace_lwpinfo pl;
888 struct kinfo_proc kp;
890 long lwp = thr->
ptid.lwp ();
891 static char buf[
sizeof pl.pl_tdname + 1];
898 if (
ptrace (PT_LWPINFO, lwp, (caddr_t) &pl,
sizeof pl) == -1)
900 if (strcmp (kp.ki_comm, pl.pl_tdname) == 0)
902 xsnprintf (buf,
sizeof buf,
"%s", pl.pl_tdname);
923#ifdef PT_GET_EVENT_MASK
927 sizeof (events)) == -1)
928 perror_with_name ((
"ptrace (PT_GET_EVENT_MASK)"));
929 events |= PTRACE_FORK | PTRACE_LWP;
931 events |= PTRACE_VFORK;
934 sizeof (events)) == -1)
935 perror_with_name ((
"ptrace (PT_SET_EVENT_MASK)"));
939 perror_with_name ((
"ptrace (PT_FOLLOW_FORK)"));
943 perror_with_name ((
"ptrace (PT_LWP_EVENTS)"));
960 nlwps =
ptrace (PT_GETNUMLWPS,
pid, NULL, 0);
962 perror_with_name ((
"ptrace (PT_GETNUMLWPS)"));
964 gdb::unique_xmalloc_ptr<lwpid_t[]> lwps (XCNEWVEC (lwpid_t, nlwps));
966 nlwps =
ptrace (PT_GETLWPLIST,
pid, (caddr_t) lwps.get (), nlwps);
968 perror_with_name ((
"ptrace (PT_GETLWPLIST)"));
972 gdb_assert (fbsd_inf !=
nullptr);
973 for (i = 0; i < nlwps; i++)
975 ptid_t ptid = ptid_t (
pid, lwps[i]);
980 struct ptrace_lwpinfo pl;
984 if (
ptrace (PT_LWPINFO, lwps[i], (caddr_t) &pl,
sizeof pl) == -1)
985 perror_with_name ((
"ptrace (PT_LWPINFO)"));
986 if (pl.pl_flags & PL_FLAG_EXITED)
1036 int old_errno = errno;
1061 gdb::block_signals blocker;
1066 internal_error (
"failed to create event pipe.");
1115static std::list<ptid_t> fbsd_pending_children;
1121fbsd_remember_child (ptid_t
pid)
1123 fbsd_pending_children.push_front (
pid);
1130fbsd_is_child_pending (pid_t
pid)
1132 for (
auto it = fbsd_pending_children.begin ();
1133 it != fbsd_pending_children.end (); it++)
1134 if (it->pid () ==
pid)
1137 fbsd_pending_children.erase (it);
1147fbsd_wait_for_fork_child (pid_t
pid)
1149 ptid_t ptid = fbsd_is_child_pending (
pid);
1150 if (ptid != null_ptid)
1156 perror_with_name ((
"waitpid"));
1158 gdb_assert (wpid ==
pid);
1160 struct ptrace_lwpinfo pl;
1161 if (
ptrace (PT_LWPINFO, wpid, (caddr_t) &pl,
sizeof pl) == -1)
1162 perror_with_name ((
"ptrace (PT_LWPINFO)"));
1164 gdb_assert (pl.pl_flags & PL_FLAG_CHILD);
1165 return ptid_t (wpid, pl.pl_lwpid);
1172fbsd_add_vfork_done (ptid_t
pid)
1188 enum gdb_signal signo)
1192 gdb_signal_to_name (signo));
1210 if (!ptid.lwp_p() || tp->ptid.lwp () == ptid.lwp ())
1212 if (
ptrace (PT_RESUME, tp->ptid.lwp (), NULL, 0) == -1)
1213 perror_with_name ((
"ptrace (PT_RESUME)"));
1219 if (
ptrace (PT_SUSPEND, tp->ptid.lwp (), NULL, 0) == -1)
1220 perror_with_name ((
"ptrace (PT_SUSPEND)"));
1227 signo = GDB_SIGNAL_0;
1228 gdb_assert (!ptid.lwp_p ());
1233#if __FreeBSD_version < 1200052
1260 perror_with_name ((
"ptrace (PT_SETSTEP)"));
1263 ptid = ptid_t (ptid.pid ());
1277 gdb_signal_to_name (signo));
1280 gdb_assert (!scope_ptid.tid_p ());
1282 if (scope_ptid == minus_one_ptid)
1293#ifdef USE_SIGTRAP_SIGINFO
1300 const struct ptrace_lwpinfo &pl)
1311 if (pl.pl_flags !=
PL_FLAG_SI || pl.pl_siginfo.si_signo != SIGTRAP)
1316 if (pl.pl_siginfo.si_code == TRAP_TRACE)
1322 if (pl.pl_siginfo.si_code == TRAP_BRKPT)
1350 target_wait_flags target_options)
1359 struct ptrace_lwpinfo pl;
1360 pid_t
pid = wptid.pid ();
1361 if (
ptrace (PT_LWPINFO,
pid, (caddr_t) &pl,
sizeof pl) == -1)
1362 perror_with_name ((
"ptrace (PT_LWPINFO)"));
1364 wptid = ptid_t (
pid, pl.pl_lwpid);
1369 pl.pl_lwpid, pl.pl_event, pl.pl_flags);
1372 pl.pl_siginfo.si_signo,
1373 pl.pl_siginfo.si_code);
1381 gdb_assert (fbsd_inf !=
nullptr || pl.pl_flags & PL_FLAG_CHILD);
1384 if (pl.pl_flags & PL_FLAG_EXITED)
1413 perror_with_name ((
"ptrace (PT_CONTINUE)"));
1432 if (pl.pl_flags & PL_FLAG_BORN)
1454 if (pl.pl_flags & PL_FLAG_FORKED)
1457 struct kinfo_proc kp;
1459 bool is_vfork =
false;
1463 child = pl.pl_child_pid;
1465 if (pl.pl_flags & PL_FLAG_VFORKED)
1470 child_ptid = fbsd_wait_for_fork_child (child);
1480 if (kp.ki_flag & P_PPWAIT)
1484 warning (_(
"Failed to fetch process information"));
1497 if (pl.pl_flags & PL_FLAG_CHILD)
1502 fbsd_remember_child (wptid);
1507 if (pl.pl_flags & PL_FLAG_VFORK_DONE)
1515 if (pl.pl_flags & PL_FLAG_EXEC)
1522#ifdef USE_SIGTRAP_SIGINFO
1523 if (fbsd_handle_debug_trap (
this, wptid, pl))
1534 if (pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX)
1535 && ourstatus->
sig () == GDB_SIGNAL_TRAP)
1537#ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_SYSCALL_CODE
1542 if (pl.pl_flags & PL_FLAG_SCE)
1557 perror_with_name ((
"ptrace (PT_CONTINUE)"));
1569 perror_with_name ((
"ptrace (PT_CONTINUE)"));
1588 gdb_assert (fbsd_inf !=
nullptr);
1598 if (wptid != minus_one_ptid)
1641 if (
status.sig () == GDB_SIGNAL_STOP)
1660 target_wait_flags target_options)
1667 if (event.has_value ())
1675 event->status.to_string ().c_str ());
1676 gdb_assert (event->ptid.matches (ptid));
1677 *ourstatus =
event->status;
1688 wptid =
wait_1 (ptid, ourstatus, target_options);
1696 gdb_assert (winf !=
nullptr);
1698 gdb_assert (fbsd_inf !=
nullptr);
1712 if (
ptrace (PT_SUSPEND, wptid.lwp (), NULL, 0) == -1)
1713 perror_with_name ((
"ptrace (PT_SUSPEND)"));
1715 perror_with_name ((
"ptrace (PT_CONTINUE)"));
1736 || ptid != minus_one_ptid))
1745#ifdef USE_SIGTRAP_SIGINFO
1751 struct ptrace_lwpinfo pl;
1758 && pl.pl_siginfo.si_signo == SIGTRAP
1759 && pl.pl_siginfo.si_code == TRAP_BRKPT);
1780 if (procctl (P_PID, getpid (), PROC_ASLR_STATUS, &m_aslr_ctl) == -1)
1782 warning (_(
"Failed to fetch current address space randomization "
1783 "status: %s"), safe_strerror (errno));
1787 m_aslr_ctl &= ~PROC_ASLR_ACTIVE;
1788 if (m_aslr_ctl == PROC_ASLR_FORCE_DISABLE)
1791 int ctl = PROC_ASLR_FORCE_DISABLE;
1792 if (procctl (P_PID, getpid (), PROC_ASLR_CTL, &ctl) == -1)
1794 warning (_(
"Error disabling address space randomization: %s"),
1795 safe_strerror (errno));
1799 m_aslr_ctl_set =
true;
1807 if (procctl (P_PID, getpid (), PROC_ASLR_CTL, &m_aslr_ctl) == -1)
1808 warning (_(
"Error restoring address space randomization: %s"),
1809 safe_strerror (errno));
1816 bool m_aslr_ctl_set =
false;
1823 const std::string &allargs,
1824 char **env,
int from_tty)
1867 (void)
ptrace (PT_DETACH,
pid, (caddr_t) 1, 0);
1877 (void)
ptrace (PT_DETACH,
pid, (caddr_t) 1, 0);
1897 ptid_t ptid = ptid_t (
inf->
pid);
1903 if (!event.has_value ())
1906 switch (event->status.kind ())
1914 pid_t
pid =
event->status.child_ptid ().pid ();
1916 (void)
ptrace (PT_DETACH,
pid, (caddr_t) 1, 0);
1934 gdb::function_view<ptrace_event_ftype> callback)
1939 if (
ptrace (PT_LWPINFO,
pid, (caddr_t) &pl,
sizeof (pl)) != 0)
1940 perror_with_name ((
"ptrace (PT_LWPINFO)"));
1941 lwpid_t lwpid = pl.pl_lwpid;
1943 int nlwps =
ptrace (PT_GETNUMLWPS,
pid, NULL, 0);
1945 perror_with_name ((
"ptrace (PT_GETLWPLIST)"));
1949 gdb::unique_xmalloc_ptr<lwpid_t[]> lwps (XCNEWVEC (lwpid_t, nlwps));
1951 nlwps =
ptrace (PT_GETLWPLIST,
pid, (caddr_t) lwps.get (), nlwps);
1953 perror_with_name ((
"ptrace (PT_GETLWPLIST)"));
1955 for (
int i = 0; i < nlwps; i++)
1957 if (lwps[i] == lwpid)
1960 if (
ptrace (PT_LWPINFO, lwps[i], (caddr_t) &pl,
sizeof (pl)) != 0)
1961 perror_with_name ((
"ptrace (PT_LWPINFO)"));
1974 auto lambda = [] (
const struct ptrace_lwpinfo &pl)
1976#if defined(PT_LWP_EVENTS) && __FreeBSD_kernel_version < 1400090
1977 if (pl.pl_flags == PL_FLAG_BORN)
1981 if (pl.pl_flags & PL_FLAG_FORKED)
1984 if (pl.pl_event == PL_EVENT_SIGNAL)
1991 if (pl.pl_siginfo.si_signo == SIGTRAP)
1997 gdb::make_function_view (lambda));
2021 ptid_t ptid = ptid_t (
inf->
pid);
2027 if (pending_sigstop)
2039 perror_with_name ((
"ptrace(PT_CONTINUE)"));
2042 ptid_t wptid =
wait_1 (ptid, &ws, 0);
2058 (void)
ptrace (PT_DETACH,
pid, (caddr_t) 1, 0);
2063 sig = gdb_signal_to_host (ws.
sig ());
2067 if (pending_sigstop)
2070 pending_sigstop =
false;
2074#ifndef USE_SIGTRAP_SIGINFO
2109 if (
ptrace (PT_DETACH,
inf->
pid, (caddr_t) 1, 0) == -1)
2110 perror_with_name ((
"ptrace (PT_DETACH)"));
2138 auto lambda = [] (
const struct ptrace_lwpinfo &pl)
2140 if (pl.pl_flags & PL_FLAG_FORKED)
2142 pid_t child = pl.pl_child_pid;
2146 fbsd_wait_for_fork_child (child);
2149 (void)
ptrace (PT_DETACH, child, (caddr_t) 1, 0);
2157 perror_with_name ((
"ptrace (PT_KILL)"));
2174 const char *execd_pathname)
2180 if (orig_inf != follow_inf)
2183 follow_inf->
priv.reset (orig_inf->
priv.release ());
2199 if (child_inf !=
nullptr)
2202 child_inf->
priv.reset (fbsd_inf);
2208 pid_t child_pid = child_ptid.pid ();
2214 perror_with_name ((
"ptrace (PT_DETACH)"));
2303#ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_SYSCALL_CODE
2307 gdb::array_view<const int> syscall_counts)
2338 int regbase,
void *regs,
size_t size)
2349 perror_with_name (_(
"Couldn't get registers"));
2361 int fetch_op,
int store_op,
2363 void *regs,
size_t size)
2374 perror_with_name (_(
"Couldn't get registers"));
2379 perror_with_name (_(
"Couldn't write registers"));
2393 iov.iov_base =
nullptr;
2405 void *regs,
size_t size)
2417 iov.iov_base = regs;
2420 perror_with_name (_(
"Couldn't get registers"));
2431 void *regs,
size_t size)
2443 iov.iov_base = regs;
2446 perror_with_name (_(
"Couldn't get registers"));
2451 perror_with_name (_(
"Couldn't write registers"));
2462 struct ptrace_lwpinfo pl;
2465 if (
ptrace (PT_LWPINFO,
pid, (caddr_t) &pl,
sizeof pl) == -1)
2469 *siginfo = pl.pl_siginfo;
2479Set debugging of FreeBSD lwp module."), _(
"\
2480Show debugging of FreeBSD lwp module."), _(
"\
2481Enables printf debugging output."),
2487Set debugging of FreeBSD native target."), _(
"\
2488Show debugging of FreeBSD native target."), _(
"\
2489Enables printf debugging output."),
static void handle_target_event(gdb_client_data client_data)
struct gdbarch * target_gdbarch(void)
int catch_syscall_enabled(void)
bool catching_syscall_number(int syscall_number)
void remove_breakpoints_inf(inferior *inf)
int breakpoint_inserted_here_p(const address_space *aspace, CORE_ADDR pc)
bool can_async_p() override
gdb::optional< pending_event > take_pending_event(ptid_t filter)
size_t have_regset(ptid_t ptid, int note)
std::list< pending_event > m_pending_events
void mourn_inferior() override
int find_memory_regions(find_memory_region_ftype func, void *data) override
bool store_regset(struct regcache *regcache, int regnum, int note, const struct regset *regset, int regbase, void *regs, size_t size)
bool fetch_register_set(struct regcache *regcache, int regnum, int fetch_op, const struct regset *regset, int regbase, void *regs, size_t size)
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
int remove_exec_catchpoint(int) override
bool store_register_set(struct regcache *regcache, int regnum, int fetch_op, int store_op, const struct regset *regset, int regbase, void *regs, size_t size)
int insert_exec_catchpoint(int) override
void detach_fork_children(thread_info *tp)
void add_pending_event(const ptid_t &ptid, const target_waitstatus &status)
std::string pid_to_str(ptid_t) override
bool supports_multi_process() override
void stop_process(inferior *)
void create_inferior(const char *, const std::string &, char **, int) override
void async(bool) override
bool supports_disable_randomization() override
virtual void low_new_fork(ptid_t parent, pid_t child)
void update_thread_list() override
void follow_exec(inferior *, ptid_t, const char *) override
void post_startup_inferior(ptid_t) override
bool info_proc(const char *, enum info_proc_what) override
void attach(const char *, int) override
bool thread_alive(ptid_t ptid) override
const char * pid_to_exec_file(int pid) override
virtual void low_delete_thread(thread_info *)
bool fetch_regset(struct regcache *regcache, int regnum, int note, const struct regset *regset, int regbase, void *regs, size_t size)
virtual void low_prepare_to_resume(thread_info *)
void detach(inferior *, int) override
ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags) override
bool have_pending_event(ptid_t filter)
void resume_one_process(ptid_t, int, enum gdb_signal)
ptid_t wait_1(ptid_t, struct target_waitstatus *, target_wait_flags)
void resume(ptid_t, int, enum gdb_signal) override
void post_attach(int) override
void follow_exec(inferior *follow_inf, ptid_t ptid, const char *execd_pathname) override
std::unique_ptr< private_inferior > priv
DISABLE_COPY_AND_ASSIGN(maybe_disable_address_space_randomization)
maybe_disable_address_space_randomization(int disable_randomization)
~maybe_disable_address_space_randomization()
void follow_fork(inferior *child_inf, ptid_t child_ptid, target_waitkind fork_kind, bool follow_child, bool detach_on_fork) override
thread_info * find_thread(ptid_t ptid)
const address_space * aspace() const
bool has_pending_waitstatus() const
struct target_waitstatus pending_follow
const target_waitstatus & pending_waitstatus() const
struct cmd_list_element * showdebuglist
struct cmd_list_element * setdebuglist
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int(* find_memory_region_ftype)(CORE_ADDR addr, unsigned long size, int read, int write, int exec, int modified, bool memory_tagged, void *data)
static fbsd_inferior * get_fbsd_inferior(inferior *inf)
#define fbsd_lwp_debug_printf(fmt,...)
#define fbsd_nat_debug_start_end(fmt,...)
static gdb::unique_xmalloc_ptr< char > fbsd_fetch_cmdline(pid_t pid)
static void show_fbsd_nat_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static void sigchld_handler(int signo)
#define fbsd_nat_debug_printf(fmt,...)
void _initialize_fbsd_nat()
static bool fbsd_fetch_kinfo_proc(pid_t pid, struct kinfo_proc *kp)
static void fbsd_add_threads(fbsd_nat_target *target, pid_t pid)
static bool iterate_other_ptrace_events(pid_t pid, gdb::function_view< ptrace_event_ftype > callback)
static bool pending_ptrace_events(inferior *inf)
static size_t fbsd_siginfo_size()
static bool debug_fbsd_nat
static void handle_target_event(int error, gdb_client_data client_data)
static void fbsd_enable_proc_events(pid_t pid)
static void show_fbsd_lwp_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
bool ptrace_event_ftype(const struct ptrace_lwpinfo &pl)
bool fbsd_nat_get_siginfo(ptid_t ptid, siginfo_t *siginfo)
static void fbsd_convert_siginfo(siginfo_t *si)
static bool debug_fbsd_lwp
void fbsd_info_proc_files_entry(int kf_type, int kf_fd, int kf_flags, LONGEST kf_offset, int kf_vnode_type, int kf_sock_domain, int kf_sock_type, int kf_sock_protocol, const void *kf_sa_local, const void *kf_sa_peer, const void *kf_path)
void fbsd_info_proc_mappings_entry(int addr_bit, ULONGEST kve_start, ULONGEST kve_end, ULONGEST kve_offset, int kve_flags, int kve_protection, const void *kve_path)
void fbsd_info_proc_mappings_header(int addr_bit)
void fbsd_info_proc_files_header()
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
frame_info_ptr get_current_frame(void)
#define ptrace(request, pid, addr, data)
CORE_ADDR gdbarch_decr_pc_after_break(struct gdbarch *gdbarch)
int gdbarch_long_bit(struct gdbarch *gdbarch)
struct thread_info * add_thread(process_stratum_target *targ, ptid_t ptid)
void delete_thread(thread_info *thread)
void thread_change_ptid(process_stratum_target *targ, ptid_t old_ptid, ptid_t new_ptid)
bool in_thread_list(process_stratum_target *targ, ptid_t ptid)
void delete_exited_threads(void)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
void inferior_event_handler(enum inferior_event_type event_type)
pid_t get_ptrace_pid(ptid_t ptid)
struct inferior * find_inferior_ptid(process_stratum_target *targ, ptid_t ptid)
struct inferior * current_inferior(void)
all_non_exited_inferiors_range all_non_exited_inferiors(process_stratum_target *proc_target=nullptr)
bool disable_randomization
CORE_ADDR regcache_read_pc(struct regcache *regcache)
bool regcache_map_supplies(const struct regcache_map_entry *map, int regnum, struct gdbarch *gdbarch, size_t size)
void regcache_write_pc(struct regcache *regcache, CORE_ADDR pc)
struct regcache * get_thread_regcache(process_stratum_target *target, ptid_t ptid)
void(* func)(remote_target *remote, char *)
unsigned int running_lwps
void create_inferior(const char *, const std::string &, char **, int) override
void detach_success(inferior *inf)
int async_wait_fd() override
bool is_async_p() override
void resume(ptid_t, int, enum gdb_signal) override
void mourn_inferior() override
void attach(const char *, int) override
static void async_file_mark_if_open()
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags) override
collect_regset_ftype * collect_regset
supply_regset_ftype * supply_regset
virtual bool stopped_by_sw_breakpoint() TARGET_DEFAULT_RETURN(false)
virtual int insert_fork_catchpoint(int) TARGET_DEFAULT_RETURN(1)
virtual bool supports_stopped_by_sw_breakpoint() TARGET_DEFAULT_RETURN(false)
virtual const char * thread_name(thread_info *) TARGET_DEFAULT_RETURN(NULL)
virtual int insert_vfork_catchpoint(int) TARGET_DEFAULT_RETURN(1)
virtual int remove_fork_catchpoint(int) TARGET_DEFAULT_RETURN(1)
virtual int remove_vfork_catchpoint(int) TARGET_DEFAULT_RETURN(1)
virtual int set_syscall_catchpoint(int, bool, int, gdb::array_view< const int >) TARGET_DEFAULT_RETURN(1)
target_waitstatus & set_spurious()
target_waitstatus & set_syscall_return(int syscall_number)
target_waitstatus & set_vfork_done()
target_waitstatus & set_forked(ptid_t child_ptid)
target_waitstatus & set_execd(gdb::unique_xmalloc_ptr< char > execd_pathname)
target_waitstatus & set_vforked(ptid_t child_ptid)
target_waitstatus & set_syscall_entry(int syscall_number)
target_waitkind kind() const
std::string to_string() const
void target_announce_detach(int from_tty)
bool target_async_permitted
std::string target_options_to_string(target_wait_flags target_options)
std::string target_pid_to_str(ptid_t ptid)
std::string normal_pid_to_str(ptid_t ptid)
void target_mourn_inferior(ptid_t ptid)
@ TARGET_OBJECT_FREEBSD_PS_STRINGS
@ TARGET_OBJECT_SIGNAL_INFO
@ TARGET_OBJECT_FREEBSD_VMMAP
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
void gdb_printf(struct ui_file *stream, const char *format,...)
@ TARGET_WAITKIND_NO_RESUMED
@ TARGET_WAITKIND_SIGNALLED
@ TARGET_WAITKIND_STOPPED
@ TARGET_WAITKIND_VFORKED