28#include "gdbsupport/buildargv.h"
31#include <sys/ptrace.h>
32#include <sys/sysctl.h>
51 int mib[4] = {CTL_KERN, KERN_PROC_ARGS,
pid, KERN_PROC_CWD};
52 buflen =
sizeof (buf);
53 if (sysctl (mib, ARRAY_SIZE (mib), buf, &buflen, NULL, 0))
63 gdb_assert (kp !=
nullptr);
65 size_t size =
sizeof (*kp);
66 int mib[6] = {CTL_KERN, KERN_PROC2, KERN_PROC_PID,
pid,
67 static_cast<int> (
size), 1};
68 return !sysctl (mib, ARRAY_SIZE (mib), kp, &
size, NULL, 0);
73static gdb::unique_xmalloc_ptr<char[]>
76 int mib[4] = {CTL_KERN, KERN_PROC_ARGS,
pid, KERN_PROC_ARGV};
79 if (::sysctl (mib, ARRAY_SIZE (mib), NULL, &
size, NULL, 0) == -1 ||
size == 0)
82 gdb::unique_xmalloc_ptr<char[]> args (XNEWVAR (
char,
size));
84 if (::sysctl (mib, ARRAY_SIZE (mib), args.get (), &
size, NULL, 0) == -1
90 for (
size_t i = 0; i <
size - 1; i++)
93 args[
size - 1] =
'\0';
112 ptid_t ptid = thr->
ptid;
122 = [&target] (ptid_t ptid)
166 int lwp = ptid.lwp ();
170 pid_t
pid = ptid.pid ();
172 return string_printf (
"LWP %d of process %d", lwp,
pid);
180static gdb::unique_xmalloc_ptr<struct kinfo_vmentry[]>
183 int mib[5] = {CTL_VM, VM_PROC, VM_PROC_MAP,
pid,
184 sizeof (
struct kinfo_vmentry)};
187 if (sysctl (mib, ARRAY_SIZE (mib), NULL, &length, NULL, 0))
196 length = length * 5 / 3;
198 gdb::unique_xmalloc_ptr<struct kinfo_vmentry[]> kiv
199 (XNEWVAR (kinfo_vmentry, length));
201 if (sysctl (mib, ARRAY_SIZE (mib), kiv.get (), &length, NULL, 0))
207 *
size = length /
sizeof (
struct kinfo_vmentry);
222 gdb::unique_xmalloc_ptr<struct kinfo_vmentry[]> vmentl
225 perror_with_name (_(
"Couldn't fetch VM map entries"));
227 for (
size_t i = 0; i < nitems; i++)
229 struct kinfo_vmentry *kve = &vmentl[i];
232 if (!(kve->kve_protection & KVME_PROT_READ)
233 || kve->kve_flags & KVME_FLAG_NOCOREDUMP)
237 switch (kve->kve_type)
239 case KVME_TYPE_VNODE:
241 case KVME_TYPE_SUBMAP:
242 case KVME_TYPE_OBJECT:
248 size_t size = kve->kve_end - kve->kve_start;
251 gdb_printf (
"Save segment, %ld bytes at %s (%c%c%c)\n",
254 kve->kve_protection & KVME_PROT_READ ?
'r' :
'-',
255 kve->kve_protection & KVME_PROT_WRITE ?
'w' :
'-',
256 kve->kve_protection & KVME_PROT_EXEC ?
'x' :
'-');
261 func (kve->kve_start,
size, kve->kve_protection & KVME_PROT_READ,
262 kve->kve_protection & KVME_PROT_WRITE,
263 kve->kve_protection & KVME_PROT_EXEC, 1,
false, data);
274 bool do_cmdline =
false;
277 bool do_mappings =
false;
278 bool do_status =
false;
311 error (_(
"Not supported on this target."));
314 gdb_argv built_argv (args);
315 if (built_argv.count () == 0)
319 error (_(
"No current process: you must name one."));
321 else if (built_argv.count () == 1 && isdigit (built_argv[0][0]))
322 pid = strtol (built_argv[0], NULL, 10);
324 error (_(
"Invalid arguments."));
331 if (cmdline !=
nullptr)
332 gdb_printf (
"cmdline = '%s'\n", cmdline.get ());
334 warning (_(
"unable to fetch command line"));
342 warning (_(
"unable to fetch current working directory"));
350 warning (_(
"unable to fetch executable path name"));
355 gdb::unique_xmalloc_ptr<struct kinfo_vmentry[]> vmentl
358 if (vmentl !=
nullptr)
360 int addr_bit = TARGET_CHAR_BIT *
sizeof (
void *);
363 struct kinfo_vmentry *kve = vmentl.get ();
364 for (
int i = 0; i < nvment; i++, kve++)
366 kve->kve_end, kve->kve_offset,
367 kve->kve_flags, kve->kve_protection,
371 warning (_(
"unable to fetch virtual memory map"));
375 struct kinfo_proc2 kp;
377 warning (_(
"Failed to fetch process information"));
398 return "? (unknown)";
403 gdb_printf (
"State: %s\n", process_status(kp.p_realstat));
404 gdb_printf (
"Parent process: %" PRId32
"\n", kp.p_ppid);
405 gdb_printf (
"Process group: %" PRId32
"\n", kp.p__pgid);
406 gdb_printf (
"Session id: %" PRId32
"\n", kp.p_sid);
408 gdb_printf (
"TTY owner process group: %" PRId32
"\n", kp.p_tpgid);
409 gdb_printf (
"User IDs (real, effective, saved): "
410 "%" PRIu32
" %" PRIu32
" %" PRIu32
"\n",
411 kp.p_ruid, kp.p_uid, kp.p_svuid);
412 gdb_printf (
"Group IDs (real, effective, saved): "
413 "%" PRIu32
" %" PRIu32
" %" PRIu32
"\n",
414 kp.p_rgid, kp.p_gid, kp.p_svgid);
417 for (
int i = 0; i < kp.p_ngroups; i++)
420 gdb_printf (
"Minor faults (no memory page): %" PRIu64
"\n",
422 gdb_printf (
"Major faults (memory page faults): %" PRIu64
"\n",
424 gdb_printf (
"utime: %" PRIu32
".%06" PRIu32
"\n",
425 kp.p_uutime_sec, kp.p_uutime_usec);
426 gdb_printf (
"stime: %" PRIu32
".%06" PRIu32
"\n",
427 kp.p_ustime_sec, kp.p_ustime_usec);
428 gdb_printf (
"utime+stime, children: %" PRIu32
".%06" PRIu32
"\n",
429 kp.p_uctime_sec, kp.p_uctime_usec);
430 gdb_printf (
"'nice' value: %" PRIu8
"\n", kp.p_nice);
431 gdb_printf (
"Start time: %" PRIu32
".%06" PRIu32
"\n",
432 kp.p_ustart_sec, kp.p_ustart_usec);
433 int pgtok = getpagesize () / 1024;
435 (uintmax_t) kp.p_vm_dsize * pgtok);
437 (uintmax_t) kp.p_vm_ssize * pgtok);
439 (uintmax_t) kp.p_vm_tsize * pgtok);
440 gdb_printf (
"Resident set size: %" PRIuMAX
" kB\n",
441 (uintmax_t) kp.p_vm_rssize * pgtok);
442 gdb_printf (
"Maximum RSS: %" PRIu64
" kB\n", kp.p_uru_maxrss);
444 for (
size_t i = 0; i < ARRAY_SIZE (kp.p_siglist.__bits); i++)
445 gdb_printf (
" %08" PRIx32, kp.p_siglist.__bits[i]);
448 for (
size_t i = 0; i < ARRAY_SIZE (kp.p_sigignore.__bits); i++)
449 gdb_printf (
" %08" PRIx32, kp.p_sigignore.__bits[i]);
452 for (
size_t i = 0; i < ARRAY_SIZE (kp.p_sigcatch.__bits); i++)
453 gdb_printf (
" %08" PRIx32, kp.p_sigcatch.__bits[i]);
468 enum gdb_signal signal)
472 gdb_assert (minus_one_ptid != ptid);
481 if (tp->ptid.lwp () == ptid.lwp ())
484 request = PT_SUSPEND;
486 if (
ptrace (request, tp->ptid.pid (), NULL, tp->ptid.lwp ()) == -1)
487 perror_with_name ((
"ptrace"));
495 if (
ptrace (PT_RESUME, tp->ptid.pid (), NULL, tp->ptid.lwp ()) == -1)
496 perror_with_name ((
"ptrace"));
502 if (
ptrace (PT_SETSTEP, tp->ptid.pid (), NULL, tp->ptid.lwp ()) == -1)
503 perror_with_name ((
"ptrace"));
508 if (
ptrace (PT_CLEARSTEP, tp->ptid.pid (), NULL, tp->ptid.lwp ()) == -1)
509 perror_with_name ((
"ptrace"));
520 if (
ptrace (request, ptid.pid (), (
void *)1, gdb_signal_to_host (signal)) == -1)
521 perror_with_name ((
"ptrace"));
531 if (minus_one_ptid != ptid)
544 target_wait_flags options)
556 while (
pid == -1 && errno == EINTR);
561 perror_with_name (_(
"Child process unexpectedly missing"));
573 target_wait_flags target_options)
575 pid_t
pid =
nbsd_wait (ptid, ourstatus, target_options);
576 ptid_t wptid = ptid_t (
pid);
584 if (
ptrace (PT_GET_SIGINFO,
pid, &psi,
sizeof (psi)) == -1)
585 perror_with_name ((
"ptrace"));
588 siginfo_t *si = &psi.psi_siginfo;
590 int lwp = psi.psi_lwpid;
593 const int code = si->si_code;
597 wptid = ptid_t (
pid, lwp, 0);
600 if (signo != SIGTRAP)
604 if (
code <= SI_USER ||
code == SI_NOINFO)
608 ptrace_state_t pst = {};
609 if (
code == TRAP_LWP)
611 if (
ptrace (PT_GET_PROCESS_STATE,
pid, &pst,
sizeof (pst)) == -1)
612 perror_with_name ((
"ptrace"));
615 if (
code == TRAP_LWP && pst.pe_report_event == PTRACE_LWP_EXIT)
634 perror_with_name ((
"ptrace"));
642 if (
code == TRAP_LWP && pst.pe_report_event == PTRACE_LWP_CREATE)
658 if (
code == TRAP_EXEC)
664 if (
code == TRAP_TRACE)
670 if (
code == TRAP_SCE ||
code == TRAP_SCX)
672 int sysnum = si->si_sysnum;
681 if (
code == TRAP_SCE)
688 if (
code == TRAP_BRKPT)
722 gdb::array_view<const int> syscall_counts)
742 const char *annex, gdb_byte *readbuf,
743 const gdb_byte *writebuf,
744 ULONGEST offset, ULONGEST len,
745 ULONGEST *xfered_len)
766 if (writebuf !=
nullptr)
774 "Is PaX MPROTECT active? See security(7), "
775 "sysctl(7), paxctl(8)\n",
776 (writebuf ?
"write to" :
"read from"),
777 pulongest (offset), safe_strerror (errno));
782 *xfered_len = (ULONGEST) xfered;
787 readbuf, writebuf, offset,
807 if (
ptrace (PT_DUMPCORE,
pid,
const_cast<char *
>(filename),
808 strlen (filename)) == -1)
809 perror_with_name ((
"ptrace"));
struct gdbarch * target_gdbarch(void)
int catch_syscall_enabled(void)
bool catching_syscall_number(int syscall_number)
thread_info * find_thread(ptid_t ptid)
int(* find_memory_region_ftype)(CORE_ADDR addr, unsigned long size, int read, int write, int exec, int modified, bool memory_tagged, void *data)
#define ptrace(request, pid, addr, data)
struct thread_info * add_thread(process_stratum_target *targ, ptid_t ptid)
void delete_thread(thread_info *thread)
all_non_exited_threads_range all_non_exited_threads(process_stratum_target *proc_target=nullptr, ptid_t filter_ptid=minus_one_ptid)
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
target_waitstatus host_status_to_waitstatus(int hoststatus)
struct inferior * find_inferior_ptid(process_stratum_target *targ, ptid_t ptid)
void set_sigint_trap(void)
void clear_sigint_trap(void)
all_non_exited_inferiors_range all_non_exited_inferiors(process_stratum_target *proc_target=nullptr)
int write_memory(pid_t pid, unsigned const char *writebuf, CORE_ADDR offset, size_t len, size_t *xfered_len)
void enable_proc_events(pid_t pid)
void for_each_thread(pid_t pid, gdb::function_view< void(ptid_t)> callback)
const char * pid_to_exec_file(pid_t pid)
const char * thread_name(ptid_t ptid)
int qxfer_siginfo(pid_t pid, const char *annex, unsigned char *readbuf, unsigned const char *writebuf, CORE_ADDR offset, int len)
bool thread_alive(ptid_t ptid)
int read_memory(pid_t pid, unsigned char *readbuf, CORE_ADDR offset, size_t len, size_t *xfered_len)
static gdb::unique_xmalloc_ptr< struct kinfo_vmentry[]> nbsd_kinfo_get_vmmap(pid_t pid, size_t *size)
static void nbsd_add_threads(nbsd_nat_target *target, pid_t pid)
static std::string nbsd_pid_to_cwd(int pid)
static pid_t nbsd_wait(ptid_t ptid, struct target_waitstatus *ourstatus, target_wait_flags options)
static void nbsd_resume(nbsd_nat_target *target, ptid_t ptid, int step, enum gdb_signal signal)
static gdb::unique_xmalloc_ptr< char[]> nbsd_pid_to_cmdline(int pid)
static bool nbsd_pid_to_kinfo_proc2(pid_t pid, struct kinfo_proc2 *kp)
void nbsd_info_proc_mappings_entry(int addr_bit, ULONGEST kve_start, ULONGEST kve_end, ULONGEST kve_offset, int kve_flags, int kve_protection, const char *kve_path)
void nbsd_info_proc_mappings_header(int addr_bit)
void(* func)(remote_target *remote, char *)
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
void dumpcore(const char *filename) override
void resume(ptid_t, int, enum gdb_signal) override
const char * pid_to_exec_file(int pid) override
void post_attach(int pid) override
void post_startup_inferior(ptid_t ptid) override
bool thread_alive(ptid_t ptid) override
int insert_exec_catchpoint(int pid) override
bool supports_multi_process() override
int remove_exec_catchpoint(int pid) override
const char * thread_name(struct thread_info *thr) override
bool supports_dumpcore() override
int find_memory_regions(find_memory_region_ftype func, void *data) override
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 set_syscall_catchpoint(int pid, bool needed, int any_count, gdb::array_view< const int > syscall_counts) override
void update_thread_list() override
std::string pid_to_str(ptid_t ptid) override
bool info_proc(const char *, enum info_proc_what) override
ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags) override
target_waitstatus & set_spurious()
target_waitstatus & set_syscall_return(int syscall_number)
target_waitstatus & set_execd(gdb::unique_xmalloc_ptr< char > execd_pathname)
target_waitstatus & set_thread_exited(int exit_status)
target_waitstatus & set_syscall_entry(int syscall_number)
target_waitkind kind() const
target_waitstatus & set_thread_created()
std::string normal_pid_to_str(ptid_t ptid)
@ TARGET_OBJECT_SIGNAL_INFO
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
void gdb_printf(struct ui_file *stream, const char *format,...)
@ TARGET_WAITKIND_STOPPED