char * sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) { static char buf[80]; struct inferior *inf; int pid; /* Check whether we're printing an LWP (gdb thread) or a process. */ pid = ptid_get_lwp (ptid); if (pid != 0) { /* A thread. */ xsnprintf (buf, sizeof buf, "LWP %ld", ptid_get_lwp (ptid)); return buf; } /* GDB didn't use to put a NT_PSTATUS note in Solaris cores. If that's missing, then we're dealing with a fake PID corelow.c made up. */ inf = find_inferior_pid (ptid_get_pid (ptid)); if (inf == NULL || inf->fake_pid_p) { xsnprintf (buf, sizeof buf, "<core>"); return buf; } /* Not fake; print as usual. */ return normal_pid_to_str (ptid); }
static char * core_pid_to_str (struct target_ops *ops, ptid_t ptid) { static char buf[64]; struct inferior *inf; int pid; /* The preferred way is to have a gdbarch/OS specific implementation. */ if (core_gdbarch && gdbarch_core_pid_to_str_p (core_gdbarch)) return gdbarch_core_pid_to_str (core_gdbarch, ptid); /* Otherwise, if we don't have one, we'll just fallback to "process", with normal_pid_to_str. */ /* Try the LWPID field first. */ pid = ptid_get_lwp (ptid); if (pid != 0) return normal_pid_to_str (pid_to_ptid (pid)); /* Otherwise, this isn't a "threaded" core -- use the PID field, but only if it isn't a fake PID. */ inf = find_inferior_pid (ptid_get_pid (ptid)); if (inf != NULL && !inf->fake_pid_p) return normal_pid_to_str (ptid); /* No luck. We simply don't have a valid PID to print. */ xsnprintf (buf, sizeof buf, "<main task>"); return buf; }
static int inf_ptrace_follow_fork (struct target_ops *ops, int follow_child, int detach_fork) { pid_t pid, fpid; ptrace_state_t pe; pid = ptid_get_pid (inferior_ptid); if (ptrace (PT_GET_PROCESS_STATE, pid, (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1) perror_with_name (("ptrace")); gdb_assert (pe.pe_report_event == PTRACE_FORK); fpid = pe.pe_other_pid; if (follow_child) { struct inferior *parent_inf, *child_inf; struct thread_info *tp; parent_inf = find_inferior_pid (pid); /* Add the child. */ child_inf = add_inferior (fpid); child_inf->attach_flag = parent_inf->attach_flag; copy_terminal_info (child_inf, parent_inf); child_inf->pspace = parent_inf->pspace; child_inf->aspace = parent_inf->aspace; /* Before detaching from the parent, remove all breakpoints from it. */ remove_breakpoints (); if (ptrace (PT_DETACH, pid, (PTRACE_TYPE_ARG3)1, 0) == -1) perror_with_name (("ptrace")); /* Switch inferior_ptid out of the parent's way. */ inferior_ptid = pid_to_ptid (fpid); /* Delete the parent. */ detach_inferior (pid); add_thread_silent (inferior_ptid); } else { /* Breakpoints have already been detached from the child by infrun.c. */ if (ptrace (PT_DETACH, fpid, (PTRACE_TYPE_ARG3)1, 0) == -1) perror_with_name (("ptrace")); } return 0; }
PyObject * find_inferior_object (int pid) { struct inferior *inf = find_inferior_pid (pid); if (inf) return inferior_to_inferior_object (inf); return NULL; }
static void mi_new_thread (struct thread_info *t) { struct mi_interp *mi = top_level_interpreter_data (); struct inferior *inf = find_inferior_pid (ptid_get_pid (t->ptid)); gdb_assert (inf); fprintf_unfiltered (mi->event_channel, "thread-created,id=\"%d\",group-id=\"i%d\"", t->num, inf->num); gdb_flush (mi->event_channel); }
static void mi_thread_exit (struct thread_info *t, int silent) { struct mi_interp *mi; struct inferior *inf; if (silent) return; inf = find_inferior_pid (ptid_get_pid (t->ptid)); mi = top_level_interpreter_data (); target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "thread-exited,id=\"%d\",group-id=\"i%d\"", t->num, inf->num); gdb_flush (mi->event_channel); }
static struct target_waitstatus record_btrace_step_thread (struct thread_info *tp) { struct btrace_insn_iterator *replay, end; struct btrace_thread_info *btinfo; struct address_space *aspace; struct inferior *inf; enum btrace_thread_flag flags; unsigned int steps; btinfo = &tp->btrace; replay = btinfo->replay; flags = btinfo->flags & BTHR_MOVE; btinfo->flags &= ~BTHR_MOVE; DEBUG ("stepping %d (%s): %u", tp->num, target_pid_to_str (tp->ptid), flags); switch (flags) { default: internal_error (__FILE__, __LINE__, _("invalid stepping type.")); case BTHR_STEP: /* We're done if we're not replaying. */ if (replay == NULL) return btrace_step_no_history (); /* We are always able to step at least once. */ steps = btrace_insn_next (replay, 1); gdb_assert (steps == 1); /* Determine the end of the instruction trace. */ btrace_insn_end (&end, btinfo); /* We stop replaying if we reached the end of the trace. */ if (btrace_insn_cmp (replay, &end) == 0) record_btrace_stop_replaying (tp); return btrace_step_stopped (); case BTHR_RSTEP: /* Start replaying if we're not already doing so. */ if (replay == NULL) replay = record_btrace_start_replaying (tp); /* If we can't step any further, we reached the end of the history. */ steps = btrace_insn_prev (replay, 1); if (steps == 0) return btrace_step_no_history (); return btrace_step_stopped (); case BTHR_CONT: /* We're done if we're not replaying. */ if (replay == NULL) return btrace_step_no_history (); inf = find_inferior_pid (ptid_get_pid (tp->ptid)); aspace = inf->aspace; /* Determine the end of the instruction trace. */ btrace_insn_end (&end, btinfo); for (;;) { const struct btrace_insn *insn; /* We are always able to step at least once. */ steps = btrace_insn_next (replay, 1); gdb_assert (steps == 1); /* We stop replaying if we reached the end of the trace. */ if (btrace_insn_cmp (replay, &end) == 0) { record_btrace_stop_replaying (tp); return btrace_step_no_history (); } insn = btrace_insn_get (replay); gdb_assert (insn); DEBUG ("stepping %d (%s) ... %s", tp->num, target_pid_to_str (tp->ptid), core_addr_to_string_nz (insn->pc)); if (breakpoint_here_p (aspace, insn->pc)) return btrace_step_stopped (); } case BTHR_RCONT: /* Start replaying if we're not already doing so. */ if (replay == NULL) replay = record_btrace_start_replaying (tp); inf = find_inferior_pid (ptid_get_pid (tp->ptid)); aspace = inf->aspace; for (;;) { const struct btrace_insn *insn; /* If we can't step any further, we're done. */ steps = btrace_insn_prev (replay, 1); if (steps == 0) return btrace_step_no_history (); insn = btrace_insn_get (replay); gdb_assert (insn); DEBUG ("reverse-stepping %d (%s) ... %s", tp->num, target_pid_to_str (tp->ptid), core_addr_to_string_nz (insn->pc)); if (breakpoint_here_p (aspace, insn->pc)) return btrace_step_stopped (); } } }