Ejemplo n.º 1
0
static gdb::byte_vector
rs6000_ptrace_ldinfo (ptid_t ptid)
{
  const int pid = ptid.pid ();
  gdb::byte_vector ldi (1024);
  int rc = -1;

  while (1)
    {
      if (ARCH64 ())
	rc = rs6000_ptrace64 (PT_LDINFO, pid, (unsigned long) ldi.data (),
			      ldi.size (), NULL);
      else
	rc = rs6000_ptrace32 (PT_LDINFO, pid, (int *) ldi.data (),
			      ldi.size (), NULL);

      if (rc != -1)
	break; /* Success, we got the entire ld_info data.  */

      if (errno != ENOMEM)
	perror_with_name (_("ptrace ldinfo"));

      /* ldi is not big enough.  Double it and try again.  */
      ldi.resize (ldi.size () * 2);
    }

  return ldi;
}
Ejemplo n.º 2
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
    {
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
void
inf_ptrace_target::post_startup_inferior (ptid_t pid)
{
  ptrace_event_t pe;

  /* Set the initial event mask.  */
  memset (&pe, 0, sizeof pe);
  pe.pe_set_event |= PTRACE_FORK;
  if (ptrace (PT_SET_EVENT_MASK, pid.pid (),
	      (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
    perror_with_name (("ptrace"));
}
Ejemplo n.º 6
0
ptid_t
rs6000_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
			 int options)
{
  pid_t pid;
  int status, save_errno;

  do
    {
      set_sigint_trap ();

      do
	{
	  pid = waitpid (ptid.pid (), &status, 0);
	  save_errno = errno;
	}
      while (pid == -1 && errno == EINTR);

      clear_sigint_trap ();

      if (pid == -1)
	{
	  fprintf_unfiltered (gdb_stderr,
			      _("Child process unexpectedly missing: %s.\n"),
			      safe_strerror (save_errno));

	  /* Claim it exited with unknown signal.  */
	  ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
	  ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
	  return inferior_ptid;
	}

      /* Ignore terminated detached child processes.  */
      if (!WIFSTOPPED (status) && pid != inferior_ptid.pid ())
	pid = -1;
    }
  while (pid == -1);

  /* AIX has a couple of strange returns from wait().  */

  /* stop after load" status.  */
  if (status == 0x57c)
    ourstatus->kind = TARGET_WAITKIND_LOADED;
  /* signal 0.  I have no idea why wait(2) returns with this status word.  */
  else if (status == 0x7f)
    ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
  /* A normal waitstatus.  Let the usual macros deal with it.  */
  else
    store_waitstatus (ourstatus, status);

  return ptid_t (pid);
}
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;
}
Ejemplo n.º 8
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 */
Ejemplo n.º 9
0
int
ptid_get_pid (const ptid_t &ptid)
{
  return ptid.pid ();
}
Ejemplo n.º 10
0
bool
inf_ptrace_target::thread_alive (ptid_t ptid)
{
  /* ??? Is kill the right way to do this?  */
  return (::kill (ptid.pid (), 0) != -1);
}
Ejemplo n.º 11
0
ptid_t
inf_ptrace_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
			 int options)
{
  pid_t pid;
  int status, save_errno;

  do
    {
      set_sigint_trap ();

      do
	{
	  pid = waitpid (ptid.pid (), &status, 0);
	  save_errno = errno;
	}
      while (pid == -1 && errno == EINTR);

      clear_sigint_trap ();

      if (pid == -1)
	{
	  fprintf_unfiltered (gdb_stderr,
			      _("Child process unexpectedly missing: %s.\n"),
			      safe_strerror (save_errno));

	  /* Claim it exited with unknown signal.  */
	  ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
	  ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
	  return inferior_ptid;
	}

      /* Ignore terminated detached child processes.  */
      if (!WIFSTOPPED (status) && pid != inferior_ptid.pid ())
	pid = -1;
    }
  while (pid == -1);

#ifdef PT_GET_PROCESS_STATE
  if (WIFSTOPPED (status))
    {
      ptrace_state_t pe;
      pid_t fpid;

      if (ptrace (PT_GET_PROCESS_STATE, pid,
		  (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
	perror_with_name (("ptrace"));

      switch (pe.pe_report_event)
	{
	case PTRACE_FORK:
	  ourstatus->kind = TARGET_WAITKIND_FORKED;
	  ourstatus->value.related_pid = ptid_t (pe.pe_other_pid);

	  /* Make sure the other end of the fork is stopped too.  */
	  fpid = waitpid (pe.pe_other_pid, &status, 0);
	  if (fpid == -1)
	    perror_with_name (("waitpid"));

	  if (ptrace (PT_GET_PROCESS_STATE, fpid,
		      (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
	    perror_with_name (("ptrace"));

	  gdb_assert (pe.pe_report_event == PTRACE_FORK);
	  gdb_assert (pe.pe_other_pid == pid);
	  if (fpid == inferior_ptid.pid ())
	    {
	      ourstatus->value.related_pid = ptid_t (pe.pe_other_pid);
	      return ptid_t (fpid);
	    }

	  return ptid_t (pid);
	}
    }
#endif

  store_waitstatus (ourstatus, status);
  return ptid_t (pid);
}