From da204a21787ebc06c23137646b19fa3836927a59 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 17 Jul 2023 22:52:58 +0100 Subject: [PATCH] remote target pid_to_string for gdb.server/ext-attach.exp (incomplete) Change-Id: I7c3e70dbb78ed0e112fff15356ba824199fa95d3 --- gdb/remote.c | 26 +++++++++++++++++--------- gdb/target.c | 4 ++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 413425ab8e7..23b18eadb47 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -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 { diff --git a/gdb/target.c b/gdb/target.c index c55c0878c6b..4fd1aae2fbf 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -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! */ -- 2.47.2