]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/remote.c
Remove pid_to_ptid
[thirdparty/binutils-gdb.git] / gdb / remote.c
index 7cef0cf19fba79eda73ac330656089bcb1a1bb5a..40080b54eeace483ce8e1fbced654eb9417e0e41 100644 (file)
@@ -737,7 +737,7 @@ public: /* Remote specific methods.  */
                                           ptid_t ptid);
   static void open_1 (const char *name, int from_tty, int extended_p);
   void start_remote (int from_tty, int extended_p);
-  void remote_detach_1 (int from_tty, struct inferior *inf);
+  void remote_detach_1 (struct inferior *inf, int from_tty);
 
   char *append_resumption (char *p, char *endp,
                           ptid_t ptid, int step, gdb_signal siggnal);
@@ -758,7 +758,7 @@ public: /* Remote specific methods.  */
 
   void process_initial_stop_replies (int from_tty);
 
-  void remote_add_thread (ptid_t ptid, bool running, bool executing);
+  thread_info *remote_add_thread (ptid_t ptid, bool running, bool executing);
 
   void btrace_sync_conf (const btrace_config *conf);
 
@@ -2374,11 +2374,12 @@ remote_target::remote_add_inferior (int fake_pid_p, int pid, int attached,
 }
 
 static remote_thread_info *get_remote_thread_info (thread_info *thread);
+static remote_thread_info *get_remote_thread_info (ptid_t ptid);
 
 /* Add thread PTID to GDB's thread list.  Tag it as executing/running
    according to RUNNING.  */
 
-void
+thread_info *
 remote_target::remote_add_thread (ptid_t ptid, bool running, bool executing)
 {
   struct remote_state *rs = get_remote_state ();
@@ -2398,6 +2399,8 @@ remote_target::remote_add_thread (ptid_t ptid, bool running, bool executing)
   get_remote_thread_info (thread)->vcont_resumed = executing;
   set_executing (ptid, executing);
   set_running (ptid, running);
+
+  return thread;
 }
 
 /* Come here when we learn about a thread id from the remote target.
@@ -2418,7 +2421,8 @@ remote_target::remote_notice_new_inferior (ptid_t currthread, int executing)
   /* If this is a new thread, add it to GDB's thread list.
      If we leave it up to WFI to do this, bad things will happen.  */
 
-  if (in_thread_list (currthread) && is_exited (currthread))
+  thread_info *tp = find_thread_ptid (currthread);
+  if (tp != NULL && tp->state == THREAD_EXITED)
     {
       /* We're seeing an event on a thread id we knew had exited.
         This has to be a new thread reusing the old id.  Add it.  */
@@ -2439,7 +2443,7 @@ remote_target::remote_notice_new_inferior (ptid_t currthread, int executing)
             stub doesn't support qC.  This is the first stop reported
             after an attach, so this is the main thread.  Update the
             ptid in the thread list.  */
-         if (in_thread_list (pid_to_ptid (pid)))
+         if (in_thread_list (ptid_t (pid)))
            thread_change_ptid (inferior_ptid, currthread);
          else
            {
@@ -2464,7 +2468,7 @@ remote_target::remote_notice_new_inferior (ptid_t currthread, int executing)
         extended-remote which already was debugging an inferior, we
         may not know about it yet.  Add it before adding its child
         thread, so notifications are emitted in a sensible order.  */
-      if (!in_inferior_list (ptid_get_pid (currthread)))
+      if (find_inferior_pid (ptid_get_pid (currthread)) == NULL)
        {
          struct remote_state *rs = get_remote_state ();
          int fake_pid_p = !remote_multi_process_p (rs);
@@ -2474,7 +2478,8 @@ remote_target::remote_notice_new_inferior (ptid_t currthread, int executing)
        }
 
       /* This is really a new thread.  Add it.  */
-      remote_add_thread (currthread, running, executing);
+      thread_info *new_thr
+       = remote_add_thread (currthread, running, executing);
 
       /* If we found a new inferior, let the common code do whatever
         it needs to with it (e.g., read shared libraries, insert
@@ -2485,7 +2490,7 @@ remote_target::remote_notice_new_inferior (ptid_t currthread, int executing)
          struct remote_state *rs = get_remote_state ();
 
          if (!rs->starting_up)
-           notice_new_inferior (currthread, executing, 0);
+           notice_new_inferior (new_thr, executing, 0);
        }
     }
 }
@@ -2503,14 +2508,11 @@ get_remote_thread_info (thread_info *thread)
   return static_cast<remote_thread_info *> (thread->priv.get ());
 }
 
-/* Return PTID's private thread data, creating it if necessary.  */
-
 static remote_thread_info *
 get_remote_thread_info (ptid_t ptid)
 {
-  struct thread_info *info = find_thread_ptid (ptid);
-
-  return get_remote_thread_info (info);
+  thread_info *thr = find_thread_ptid (ptid);
+  return get_remote_thread_info (thr);
 }
 
 /* Call this function as a result of
@@ -2953,7 +2955,7 @@ read_ptid (const char *buf, const char **obuf)
       pp = unpack_varlen_hex (p + 1, &tid);
       if (obuf)
        *obuf = pp;
-      return ptid_build (pid, tid, 0);
+      return ptid_t (pid, tid, 0);
     }
 
   /* No multi-process.  Just a tid.  */
@@ -2978,7 +2980,7 @@ read_ptid (const char *buf, const char **obuf)
 
   if (obuf)
     *obuf = pp;
-  return ptid_build (pid, tid, 0);
+  return ptid_t (pid, tid, 0);
 }
 
 static int
@@ -3773,7 +3775,7 @@ remote_target::update_thread_list ()
          if (!context.contains_thread (tp->ptid))
            {
              /* Not found.  */
-             delete_thread (tp->ptid);
+             delete_thread (tp);
            }
        }
 
@@ -3795,7 +3797,8 @@ remote_target::update_thread_list ()
 
              remote_notice_new_inferior (item.ptid, executing);
 
-             remote_thread_info *info = get_remote_thread_info (item.ptid);
+             thread_info *tp = find_thread_ptid (item.ptid);
+             remote_thread_info *info = get_remote_thread_info (tp);
              info->core = item.core;
              info->extra = std::move (item.extra);
              info->name = std::move (item.name);
@@ -3827,12 +3830,9 @@ const char *
 remote_target::extra_thread_info (thread_info *tp)
 {
   struct remote_state *rs = get_remote_state ();
-  int result;
   int set;
   threadref id;
   struct gdb_ext_thread_info threadinfo;
-  static char display_buf[100];        /* arbitrary...  */
-  int n = 0;                    /* position in display_buf */
 
   if (rs->remote_desc == 0)            /* paranoia */
     internal_error (__FILE__, __LINE__,
@@ -3844,17 +3844,18 @@ remote_target::extra_thread_info (thread_info *tp)
        server doesn't know about it.  */
     return NULL;
 
+  std::string &extra = get_remote_thread_info (tp)->extra;
+
+  /* If already have cached info, use it.  */
+  if (!extra.empty ())
+    return extra.c_str ();
+
   if (packet_support (PACKET_qXfer_threads) == PACKET_ENABLE)
     {
-      struct thread_info *info = find_thread_ptid (tp->ptid);
-
-      if (info != NULL && info->priv != NULL)
-       {
-         const std::string &extra = get_remote_thread_info (info)->extra;
-         return !extra.empty () ? extra.c_str () : NULL;
-       }
-      else
-       return NULL;
+      /* If we're using qXfer:threads:read, then the extra info is
+        included in the XML.  So if we didn't have anything cached,
+        it's because there's really no extra info.  */
+      return NULL;
     }
 
   if (rs->use_threadextra_query)
@@ -3870,10 +3871,9 @@ remote_target::extra_thread_info (thread_info *tp)
       getpkt (&rs->buf, &rs->buf_size, 0);
       if (rs->buf[0] != 0)
        {
-         n = std::min (strlen (rs->buf) / 2, sizeof (display_buf));
-         result = hex2bin (rs->buf, (gdb_byte *) display_buf, n);
-         display_buf [result] = '\0';
-         return display_buf;
+         extra.resize (strlen (rs->buf) / 2);
+         hex2bin (rs->buf, (gdb_byte *) &extra[0], extra.size ());
+         return extra.c_str ();
        }
     }
 
@@ -3886,22 +3886,20 @@ remote_target::extra_thread_info (thread_info *tp)
     if (threadinfo.active)
       {
        if (*threadinfo.shortname)
-         n += xsnprintf (&display_buf[0], sizeof (display_buf) - n,
-                         " Name: %s,", threadinfo.shortname);
+         string_appendf (extra, " Name: %s", threadinfo.shortname);
        if (*threadinfo.display)
-         n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
-                         " State: %s,", threadinfo.display);
+         {
+           if (!extra.empty ())
+             extra += ',';
+           string_appendf (extra, " State: %s", threadinfo.display);
+         }
        if (*threadinfo.more_display)
-         n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
-                         " Priority: %s", threadinfo.more_display);
-
-       if (n > 0)
          {
-           /* For purely cosmetic reasons, clear up trailing commas.  */
-           if (',' == display_buf[n-1])
-             display_buf[n-1] = ' ';
-           return display_buf;
+           if (!extra.empty ())
+             extra += ',';
+           string_appendf (extra, " Priority: %s", threadinfo.more_display);
          }
+       return extra.c_str ();
       }
   return NULL;
 }
@@ -3974,7 +3972,7 @@ remote_target::static_tracepoint_markers_by_strid (const char *strid)
 ptid_t
 remote_target::get_ada_task_ptid (long lwp, long thread)
 {
-  return ptid_build (ptid_get_pid (inferior_ptid), lwp, 0);
+  return ptid_t (ptid_get_pid (inferior_ptid), lwp, 0);
 }
 \f
 
@@ -4329,8 +4327,8 @@ print_one_stopped_thread (struct thread_info *thread)
 {
   struct target_waitstatus *ws = &thread->suspend.waitstatus;
 
-  switch_to_thread (thread->ptid);
-  stop_pc = get_frame_pc (get_current_frame ());
+  switch_to_thread (thread);
+  thread->suspend.stop_pc = get_frame_pc (get_current_frame ());
   set_current_sal_from_frame (get_current_frame ());
 
   thread->suspend.waitstatus_pending_p = 0;
@@ -4432,9 +4430,8 @@ remote_target::process_initial_stop_replies (int from_tty)
 
       if (non_stop)
        {
-         thread = any_live_thread_of_process (inf->pid);
-         notice_new_inferior (thread->ptid,
-                              thread->state == THREAD_RUNNING,
+         thread = any_live_thread_of_inferior (inf);
+         notice_new_inferior (thread, thread->state == THREAD_RUNNING,
                               from_tty);
        }
     }
@@ -4455,7 +4452,7 @@ remote_target::process_initial_stop_replies (int from_tty)
 
          if (inf->needs_setup)
            {
-             thread = any_live_thread_of_process (inf->pid);
+             thread = any_live_thread_of_inferior (inf);
              switch_to_thread_no_regs (thread);
              setup_inferior (0);
            }
@@ -4471,7 +4468,7 @@ remote_target::process_initial_stop_replies (int from_tty)
        first = thread;
 
       if (!non_stop)
-       set_running (thread->ptid, 0);
+       thread->set_running (false);
       else if (thread->state != THREAD_STOPPED)
        continue;
 
@@ -5654,11 +5651,10 @@ remote_target::remote_detach_pid (int pid)
    one.  */
 
 void
-remote_target::remote_detach_1 (int from_tty, inferior *inf)
+remote_target::remote_detach_1 (inferior *inf, int from_tty)
 {
   int pid = ptid_get_pid (inferior_ptid);
   struct remote_state *rs = get_remote_state ();
-  struct thread_info *tp = find_thread_ptid (inferior_ptid);
   int is_fork_parent;
 
   if (!target_has_execution)
@@ -5673,6 +5669,8 @@ remote_target::remote_detach_1 (int from_tty, inferior *inf)
   if (from_tty && !rs->extended && number_of_live_inferiors () == 1)
     puts_filtered (_("Ending remote debugging.\n"));
 
+  struct thread_info *tp = find_thread_ptid (inferior_ptid);
+
   /* Check to see if we are detaching a fork parent.  Note that if we
      are detaching a fork child, tp == NULL.  */
   is_fork_parent = (tp != NULL
@@ -5684,7 +5682,7 @@ remote_target::remote_detach_1 (int from_tty, inferior *inf)
     {
       /* Save the pid as a string before mourning, since that will
         unpush the remote target, and we need the string after.  */
-      std::string infpid = target_pid_to_str (pid_to_ptid (pid));
+      std::string infpid = target_pid_to_str (ptid_t (pid));
 
       target_mourn_inferior (inferior_ptid);
       if (print_inferior_events)
@@ -5694,20 +5692,20 @@ remote_target::remote_detach_1 (int from_tty, inferior *inf)
   else
     {
       inferior_ptid = null_ptid;
-      detach_inferior (pid);
+      detach_inferior (current_inferior ());
     }
 }
 
 void
 remote_target::detach (inferior *inf, int from_tty)
 {
-  remote_detach_1 (from_tty, inf);
+  remote_detach_1 (inf, from_tty);
 }
 
 void
 extended_remote_target::detach (inferior *inf, int from_tty)
 {
-  remote_detach_1 (from_tty, inf);
+  remote_detach_1 (inf, from_tty);
 }
 
 /* Target follow-fork function for remote targets.  On entry, and
@@ -5806,10 +5804,10 @@ extended_remote_target::attach (const char *args, int from_tty)
 
       if (exec_file)
        printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
-                          target_pid_to_str (pid_to_ptid (pid)));
+                          target_pid_to_str (ptid_t (pid)));
       else
        printf_unfiltered (_("Attaching to %s\n"),
-                          target_pid_to_str (pid_to_ptid (pid)));
+                          target_pid_to_str (ptid_t (pid)));
 
       gdb_flush (gdb_stdout);
     }
@@ -5830,19 +5828,19 @@ extended_remote_target::attach (const char *args, int from_tty)
        }
       else if (strcmp (rs->buf, "OK") != 0)
        error (_("Attaching to %s failed with: %s"),
-              target_pid_to_str (pid_to_ptid (pid)),
+              target_pid_to_str (ptid_t (pid)),
               rs->buf);
       break;
     case PACKET_UNKNOWN:
       error (_("This target does not support attaching to a process"));
     default:
       error (_("Attaching to %s failed"),
-            target_pid_to_str (pid_to_ptid (pid)));
+            target_pid_to_str (ptid_t (pid)));
     }
 
   set_current_inferior (remote_add_inferior (0, pid, 1, 0));
 
-  inferior_ptid = pid_to_ptid (pid);
+  inferior_ptid = ptid_t (pid);
 
   if (target_is_non_stop_p ())
     {
@@ -5851,11 +5849,11 @@ extended_remote_target::attach (const char *args, int from_tty)
       /* Get list of threads.  */
       update_thread_list ();
 
-      thread = first_thread_of_process (pid);
+      thread = first_thread_of_inferior (current_inferior ());
       if (thread)
        inferior_ptid = thread->ptid;
       else
-       inferior_ptid = pid_to_ptid (pid);
+       inferior_ptid = ptid_t (pid);
 
       /* Invalidate our notion of the remote current thread.  */
       record_currthread (rs, minus_one_ptid);
@@ -6039,7 +6037,7 @@ remote_target::append_resumption (char *p, char *endp,
       ptid_t nptid;
 
       /* All (-1) threads of process.  */
-      nptid = ptid_build (ptid_get_pid (ptid), -1, 0);
+      nptid = ptid_t (ptid_get_pid (ptid), -1, 0);
 
       p += xsnprintf (p, endp - p, ":");
       p = write_ptid (p, endp, nptid);
@@ -6577,7 +6575,7 @@ remote_target::commit_resume ()
            {
              if (get_remote_inferior (inf)->may_wildcard_vcont)
                {
-                 vcont_builder.push_action (pid_to_ptid (inf->pid),
+                 vcont_builder.push_action (ptid_t (inf->pid),
                                             false, GDB_SIGNAL_0);
                }
            }
@@ -6617,7 +6615,7 @@ remote_target::remote_stop_ns (ptid_t ptid)
 
       if (ptid_is_pid (ptid))
          /* All (-1) threads of process.  */
-       nptid = ptid_build (ptid_get_pid (ptid), -1, 0);
+       nptid = ptid_t (ptid_get_pid (ptid), -1, 0);
       else
        {
          /* Small optimization: if we already have a stop reply for
@@ -7532,7 +7530,7 @@ Packet: '%s'\n"),
          }
        else
          error (_("unknown stop reply packet: %s"), buf);
-       event->ptid = pid_to_ptid (pid);
+       event->ptid = ptid_t (pid);
       }
       break;
     case 'N':
@@ -11323,7 +11321,7 @@ threadalive_test (const char *cmd, int tty)
 {
   int sample_thread = SAMPLE_THREAD;
   int pid = ptid_get_pid (inferior_ptid);
-  ptid_t ptid = ptid_build (pid, sample_thread, 0);
+  ptid_t ptid = ptid_t (pid, sample_thread, 0);
 
   if (remote_thread_alive (ptid))
     printf_filtered ("PASS: Thread alive test\n");
@@ -14739,7 +14737,7 @@ stepping is supported by the target.  The default is on."),
 
   /* Take advantage of the fact that the TID field is not used, to tag
      special ptids with it set to != 0.  */
-  magic_null_ptid = ptid_build (42000, -1, 1);
-  not_sent_ptid = ptid_build (42000, -2, 1);
-  any_thread_ptid = ptid_build (42000, 0, 1);
+  magic_null_ptid = ptid_t (42000, -1, 1);
+  not_sent_ptid = ptid_t (42000, -2, 1);
+  any_thread_ptid = ptid_t (42000, 0, 1);
 }