]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
remote target pid_to_string for gdb.server/ext-attach.exp (incomplete)
authorPedro Alves <pedro@palves.net>
Mon, 17 Jul 2023 21:52:58 +0000 (22:52 +0100)
committerPedro Alves <pedro@palves.net>
Mon, 9 Jun 2025 17:49:19 +0000 (18:49 +0100)
Change-Id: I7c3e70dbb78ed0e112fff15356ba824199fa95d3

gdb/remote.c
gdb/target.c

index 413425ab8e75869a13c946133414708ec79464dc..23b18eadb47927c945c5db7621fd0709f18d55c3 100644 (file)
@@ -12403,19 +12403,27 @@ remote_target::pid_to_str (ptid_t ptid)
     {
       /* Printing an inferior target id.  */
 
+      /* When multi-process extensions are on, we have a real PID
+        recorded in the PTID.  */
+      if (m_features.remote_multi_process_p ())
+       return normal_pid_to_str (ptid);
+
       /* When multi-process extensions are off, there's no way in the
         remote protocol to know the remote process id, if there's any
         at all.  There's one exception --- when we're connected with
         target extended-remote, and we manually attached to a process
-        with "attach PID".  We don't record anywhere a flag that
-        allows us to distinguish that case from the case of
-        connecting with extended-remote and the stub already being
-        attached to a process, and reporting yes to qAttached, hence
-        no smart special casing here.  */
-      if (!m_features.remote_multi_process_p ())
-       return "Remote target";
-
-      return normal_pid_to_str (ptid);
+        with "attach PID".  Note we need to be careful to distinguish
+        that case from the case of connecting with extended-remote
+        and the stub already being attached to a process, and
+        reporting yes to qAttached.  We can look at fake_pid_p to
+        tell which case we're handling.  */
+      inferior *inf = find_inferior_ptid (this, ptid);
+      if (inf != nullptr && inf->attach_flag && !inf->fake_pid_p)
+       return normal_pid_to_str (ptid);
+
+      /* No way to figure out a PID.  Return a string that doesn't
+        leak out an internal fake PID to the user.  */
+      return "Remote target";
     }
   else
     {
index c55c0878c6bd4db60ec5caea7741fec3bc953b30..4fd1aae2fbf359acdb24e48b70bec25782adf72d 100644 (file)
@@ -3633,10 +3633,10 @@ target_announce_attach (int from_tty, int pid)
   if (exec_file != nullptr)
     gdb_printf ("Attaching to program: %ps, %s\n",
                styled_string (file_name_style.style (), exec_file),
-               target_pid_to_str (ptid_t (pid)).c_str ());
+               normal_pid_to_str (ptid_t (pid)).c_str ());
   else
     gdb_printf ("Attaching to %s\n",
-               target_pid_to_str (ptid_t (pid)).c_str ());
+               normal_pid_to_str (ptid_t (pid)).c_str ());
 }
 
 /* The inferior process has died.  Long live the inferior!  */