Пример #1
0
static std::string
i386_windows_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
{
  if (ptid.lwp () != 0)
    return string_printf ("Thread 0x%lx", ptid.lwp ());

  return normal_pid_to_str (ptid);
}
Пример #2
0
std::string
core_target::pid_to_str (ptid_t ptid)
{
  struct inferior *inf;
  int pid;

  /* The preferred way is to have a gdbarch/OS specific
     implementation.  */
  if (m_core_gdbarch != nullptr
      && gdbarch_core_pid_to_str_p (m_core_gdbarch))
    return gdbarch_core_pid_to_str (m_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.lwp ();
  if (pid != 0)
    return normal_pid_to_str (ptid_t (pid));

  /* Otherwise, this isn't a "threaded" core -- use the PID field, but
     only if it isn't a fake PID.  */
  inf = find_inferior_ptid (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.  */
  return "<main task>";
}
Пример #3
0
void
fbsd_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
{
#if defined(TDP_RFPPWAIT) && !defined(PTRACE_VFORK)
  pid_t pid;

  /* Don't PT_CONTINUE a process which has a pending vfork done event.  */
  if (minus_one_ptid == ptid)
    pid = inferior_ptid.pid ();
  else
    pid = ptid.pid ();
  if (fbsd_is_vfork_done_pending (pid))
    return;
#endif

  if (debug_fbsd_lwp)
    fprintf_unfiltered (gdb_stdlog,
			"FLWP: fbsd_resume for ptid (%d, %ld, %ld)\n",
			ptid.pid (), ptid.lwp (),
			ptid.tid ());
  if (ptid.lwp_p ())
    {
      /* If ptid is a specific LWP, suspend all other LWPs in the process.  */
      struct thread_info *tp;
      int request;

      ALL_NON_EXITED_THREADS (tp)
        {
	  if (tp->ptid.pid () != ptid.pid ())
	    continue;

	  if (tp->ptid.lwp () == ptid.lwp ())
	    request = PT_RESUME;
	  else
	    request = PT_SUSPEND;

	  if (ptrace (request, tp->ptid.lwp (), NULL, 0) == -1)
	    perror_with_name (("ptrace"));
	}
    }
  else
    {
Пример #4
0
static void
store_debug_register (ptid_t ptid, int idx, long val)
{
  int tid;

  tid = ptid.lwp ();
  if (tid == 0)
    tid = ptid.pid ();

  (void) ptrace (PT_WRITE_U, tid, (PTRACE_TYPE_ARG3) (PT_DBR + 8 * idx), val);
}
Пример #5
0
pid_t
get_ptrace_pid (ptid_t ptid)
{
  pid_t pid;

  /* If we have an LWPID to work with, use it.  Otherwise, we're
     dealing with a non-threaded program/target.  */
  pid = ptid.lwp ();
  if (pid == 0)
    pid = ptid.pid ();
  return pid;
}
Пример #6
0
static unsigned long
i386_gnu_dr_get_reg (ptid_t ptid, int regnum)
{
  struct i386_debug_state regs;
  struct proc *thread;

  /* Make sure we know about new threads.  */
  inf_update_procs (gnu_current_inf);

  thread = inf_tid_to_thread (gnu_current_inf, ptid.lwp ());
  i386_gnu_dr_get (&regs, thread);

  return regs.dr[regnum];
}
int
linux_common_core_of_thread (ptid_t ptid)
{
  char filename[sizeof ("/proc//task//stat") + 2 * MAX_PID_T_STRLEN];
  char *content = NULL;
  char *p;
  char *ts = 0;
  int content_read = 0;
  int i;
  int core;

  sprintf (filename, "/proc/%lld/task/%lld/stat",
	   (PID_T) ptid.pid (), (PID_T) ptid.lwp ());
  gdb_file_up f = gdb_fopen_cloexec (filename, "r");
  if (!f)
    return -1;

  for (;;)
    {
      int n;
      content = (char *) xrealloc (content, content_read + 1024);
      n = fread (content + content_read, 1, 1024, f.get ());
      content_read += n;
      if (n < 1024)
	{
	  content[content_read] = '\0';
	  break;
	}
    }

  /* ps command also relies on no trailing fields ever contain ')'.  */
  p = strrchr (content, ')');
  if (p != NULL)
    p++;

  /* If the first field after program name has index 0, then core number is
     the field with index 36.  There's no constant for that anywhere.  */
  if (p != NULL)
    p = strtok_r (p, " ", &ts);
  for (i = 0; p != NULL && i != 36; ++i)
    p = strtok_r (NULL, " ", &ts);

  if (p == NULL || sscanf (p, "%d", &core) == 0)
    core = -1;

  xfree (content);

  return core;
}
Пример #8
0
static int
find_one_thread (ptid_t ptid)
{
  td_thrhandle_t th;
  td_thrinfo_t ti;
  td_err_e err;
  struct lwp_info *lwp;
  struct thread_db *thread_db = current_process ()->priv->thread_db;
  int lwpid = ptid.lwp ();

  thread_info *thread = find_thread_ptid (ptid);
  lwp = get_thread_lwp (thread);
  if (lwp->thread_known)
    return 1;

  /* Get information about this thread.  */
  err = thread_db->td_ta_map_lwp2thr_p (thread_db->thread_agent, lwpid, &th);
  if (err != TD_OK)
    error ("Cannot get thread handle for LWP %d: %s",
	   lwpid, thread_db_err_str (err));

  err = thread_db->td_thr_get_info_p (&th, &ti);
  if (err != TD_OK)
    error ("Cannot get thread info for LWP %d: %s",
	   lwpid, thread_db_err_str (err));

  if (debug_threads)
    debug_printf ("Found thread %ld (LWP %d)\n",
		  (unsigned long) ti.ti_tid, ti.ti_lid);

  if (lwpid != ti.ti_lid)
    {
      warning ("PID mismatch!  Expected %ld, got %ld",
	       (long) lwpid, (long) ti.ti_lid);
      return 0;
    }

  /* If the new thread ID is zero, a final thread ID will be available
     later.  Do not enable thread debugging yet.  */
  if (ti.ti_tid == 0)
    return 0;

  lwp->thread_known = 1;
  lwp->th = th;
  lwp->thread_handle = ti.ti_tid;

  return 1;
}
Пример #9
0
bool
fbsd_nat_target::thread_alive (ptid_t ptid)
{
  if (ptid.lwp_p ())
    {
      struct ptrace_lwpinfo pl;

      if (ptrace (PT_LWPINFO, ptid.lwp (), (caddr_t) &pl, sizeof pl)
	  == -1)
	return false;
#ifdef PL_FLAG_EXITED
      if (pl.pl_flags & PL_FLAG_EXITED)
	return false;
#endif
    }

  return true;
}
Пример #10
0
namespace ptid {

/* Check that the ptid_t class is POD.

   This is a requirement for as long as we have ptids embedded in
   structures allocated with malloc. */

static_assert (std::is_pod<ptid_t>::value, "ptid_t is POD");

/* We want to avoid implicit conversion from int to ptid_t.  */

static_assert (!std::is_convertible<int, ptid_t>::value,
	       "constructor is explicit");

/* Build some useful ptids.  */

static constexpr ptid_t pid = ptid_t (1);
static constexpr ptid_t lwp = ptid_t (1, 2, 0);
static constexpr ptid_t tid = ptid_t (1, 0, 2);
static constexpr ptid_t both = ptid_t (1, 2, 2);

/* Build some constexpr version of null_ptid and minus_one_ptid to use in
   static_assert.  Once the real ones are made constexpr, we can get rid of
   these.  */

static constexpr ptid_t null = ptid_t::make_null ();
static constexpr ptid_t minus_one = ptid_t::make_minus_one ();

/* Verify pid.  */

static_assert (pid.pid () == 1, "pid's pid is right");
static_assert (lwp.pid () == 1, "lwp's pid is right");
static_assert (tid.pid () == 1, "tid's pid is right");
static_assert (both.pid () == 1, "both's pid is right");

/* Verify lwp_p.  */

static_assert (!pid.lwp_p (), "pid's lwp_p is right");
static_assert (lwp.lwp_p (), "lwp's lwp_p is right");
static_assert (!tid.lwp_p (), "tid's lwp_p is right");
static_assert (both.lwp_p (), "both's lwp_p is right");

/* Verify lwp.  */

static_assert (pid.lwp () == 0, "pid's lwp is right");
static_assert (lwp.lwp () == 2, "lwp's lwp is right");
static_assert (tid.lwp () == 0, "tid's lwp is right");
static_assert (both.lwp () == 2, "both's lwp is right");

/* Verify tid_p.  */

static_assert (!pid.tid_p (), "pid's tid_p is right");
static_assert (!lwp.tid_p (), "lwp's tid_p is right");
static_assert (tid.tid_p (), "tid's tid_p is right");
static_assert (both.tid_p (), "both's tid_p is right");

/* Verify tid.  */

static_assert (pid.tid () == 0, "pid's tid is right");
static_assert (lwp.tid () == 0, "lwp's tid is right");
static_assert (tid.tid () == 2, "tid's tid is right");
static_assert (both.tid () == 2, "both's tid is right");

/* Verify is_pid.  */

static_assert (pid.is_pid (), "pid is a pid");
static_assert (!lwp.is_pid (), "lwp isn't a pid");
static_assert (!tid.is_pid (), "tid isn't a pid");
static_assert (!both.is_pid (), "both isn't a pid");
static_assert (!null.is_pid (), "null ptid isn't a pid");
static_assert (!minus_one.is_pid (), "minus one ptid isn't a pid");

/* Verify operator ==.  */

static_assert (pid == ptid_t (1, 0, 0), "pid operator== is right");
static_assert (lwp == ptid_t (1, 2, 0), "lwp operator== is right");
static_assert (tid == ptid_t (1, 0, 2), "tid operator== is right");
static_assert (both == ptid_t (1, 2, 2), "both operator== is right");

/* Verify operator !=.  */

static_assert (pid != ptid_t (2, 0, 0), "pid isn't equal to a different pid");
static_assert (pid != lwp, "pid isn't equal to one of its thread");
static_assert (lwp != tid, "lwp isn't equal to tid");
static_assert (both != lwp, "both isn't equal to lwp");
static_assert (both != tid, "both isn't equal to tid");

/* Verify matches against minus_one.  */

static_assert (pid.matches (minus_one), "pid matches minus one");
static_assert (lwp.matches (minus_one), "lwp matches minus one");
static_assert (tid.matches (minus_one), "tid matches minus one");
static_assert (both.matches (minus_one), "both matches minus one");

/* Verify matches against pid.  */

static_assert (pid.matches (pid), "pid matches pid");
static_assert (lwp.matches (pid), "lwp matches pid");
static_assert (tid.matches (pid), "tid matches pid");
static_assert (both.matches (pid), "both matches pid");
static_assert (!ptid_t (2, 0, 0).matches (pid), "other pid doesn't match pid");
static_assert (!ptid_t (2, 2, 0).matches (pid), "other lwp doesn't match pid");
static_assert (!ptid_t (2, 0, 2).matches (pid), "other tid doesn't match pid");
static_assert (!ptid_t (2, 2, 2).matches (pid), "other both doesn't match pid");

/* Verify matches against exact matches.  */

static_assert (!pid.matches (lwp), "pid doesn't match lwp");
static_assert (lwp.matches (lwp), "lwp matches lwp");
static_assert (!tid.matches (lwp), "tid doesn't match lwp");
static_assert (!both.matches (lwp), "both doesn't match lwp");
static_assert (!ptid_t (2, 2, 0).matches (lwp), "other lwp doesn't match lwp");

static_assert (!pid.matches (tid), "pid doesn't match tid");
static_assert (!lwp.matches (tid), "lwp doesn't match tid");
static_assert (tid.matches (tid), "tid matches tid");
static_assert (!both.matches (tid), "both doesn't match tid");
static_assert (!ptid_t (2, 0, 2).matches (tid), "other tid doesn't match tid");

static_assert (!pid.matches (both), "pid doesn't match both");
static_assert (!lwp.matches (both), "lwp doesn't match both");
static_assert (!tid.matches (both), "tid doesn't match both");
static_assert (both.matches (both), "both matches both");
static_assert (!ptid_t (2, 2, 2).matches (both),
	       "other both doesn't match both");


} /* namespace ptid */
Пример #11
0
long
ptid_get_lwp (const ptid_t &ptid)
{
  return ptid.lwp ();
}