diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 9d07ac0d97..c3e094a115 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1119,6 +1119,7 @@ COMMON_SFILES = \
symmisc.c \
symtab.c \
target.c \
+ target-connection.c \
target-dcache.c \
target-descriptions.c \
target-memory.c \
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 577d2e194a..061cf5cebb 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -430,6 +430,31 @@ print_selected_inferior (struct ui_out *uiout)
inf->num, inferior_pid_to_str (inf->pid).c_str (), filename);
}
+/* Helper for print_inferior. Returns the 'connection-id' string for
+ PROC_TARGET. */
+
+static std::string
+uiout_field_connection (process_stratum_target *proc_target)
+{
+ if (proc_target == NULL)
+ {
+ return {};
+ }
+ else if (proc_target->connection_string () != NULL)
+ {
+ return string_printf ("%d (%s %s)",
+ proc_target->connection_number,
+ proc_target->shortname (),
+ proc_target->connection_string ());
+ }
+ else
+ {
+ return string_printf ("%d (%s)",
+ proc_target->connection_number,
+ proc_target->shortname ());
+ }
+}
+
/* Prints the list of inferiors and their details on UIOUT. This is a
version of 'info_inferior_command' suitable for use from MI.
@@ -441,6 +466,7 @@ static void
print_inferior (struct ui_out *uiout, const char *requested_inferiors)
{
int inf_count = 0;
+ size_t connection_id_len = 20;
/* Compute number of inferiors we will print. */
for (inferior *inf : all_inferiors ())
@@ -448,6 +474,10 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
if (!number_is_in_list (requested_inferiors, inf->num))
continue;
+ std::string conn = uiout_field_connection (inf->process_target ());
+ if (connection_id_len < conn.size ())
+ connection_id_len = conn.size ();
+
++inf_count;
}
@@ -457,10 +487,12 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
return;
}
- ui_out_emit_table table_emitter (uiout, 4, inf_count, "inferiors");
+ ui_out_emit_table table_emitter (uiout, 5, inf_count, "inferiors");
uiout->table_header (1, ui_left, "current", "");
uiout->table_header (4, ui_left, "number", "Num");
uiout->table_header (17, ui_left, "target-id", "Description");
+ uiout->table_header (connection_id_len, ui_left,
+ "connection-id", "Connection");
uiout->table_header (17, ui_left, "exec", "Executable");
uiout->table_body ();
@@ -480,6 +512,9 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
uiout->field_string ("target-id", inferior_pid_to_str (inf->pid));
+ std::string conn = uiout_field_connection (inf->process_target ());
+ uiout->field_string ("connection-id", conn.c_str ());
+
if (inf->pspace->pspace_exec_filename != NULL)
uiout->field_string ("exec", inf->pspace->pspace_exec_filename);
else
@@ -714,9 +749,22 @@ switch_to_inferior_and_push_target (inferior *new_inf,
/* Reuse the target for new inferior. */
if (!no_connection && proc_target != NULL)
- push_target (proc_target);
-
- printf_filtered (_("Added inferior %d\n"), new_inf->num);
+ {
+ push_target (proc_target);
+ if (proc_target->connection_string () != NULL)
+ printf_filtered (_("Added inferior %d on connection %d (%s %s)\n"),
+ new_inf->num,
+ proc_target->connection_number,
+ proc_target->shortname (),
+ proc_target->connection_string ());
+ else
+ printf_filtered (_("Added inferior %d on connection %d (%s)\n"),
+ new_inf->num,
+ proc_target->connection_number,
+ proc_target->shortname ());
+ }
+ else
+ printf_filtered (_("Added inferior %d\n"), new_inf->num);
}
/* add-inferior [-copies N] [-exec FILENAME] [-no-connection] */
diff --git a/gdb/process-stratum-target.h b/gdb/process-stratum-target.h
index 6081c0a927..53e1c6a618 100644
--- a/gdb/process-stratum-target.h
+++ b/gdb/process-stratum-target.h
@@ -31,6 +31,16 @@ public:
strata stratum () const final override { return process_stratum; }
+ /* Return a string representation of this target's open connection.
+ This string is used to distinguish different instances of a given
+ target type. For example, when remote debugging, the target is
+ called "remote", but since we may have more than one remote
+ target open, connection_string() returns the connection serial
+ connection name, e.g., "localhost:10001", "192.168.0.1:20000",
+ etc. This string is shown in several places, e.g., in "info
+ connections" and "info inferiors". */
+ virtual const char *connection_string () { return nullptr; }
+
/* We must default these because they must be implemented by any
target that can run. */
bool can_async_p () override { return false; }
@@ -58,6 +68,9 @@ public:
stop events for all known threads, because any of those threads
may have spawned new threads we haven't heard of yet. */
bool threads_executing = false;
+
+ /* The connection number. Visible in "info connections". */
+ int connection_number = 0;
};
/* Downcast TARGET to process_stratum_target. */
diff --git a/gdb/remote.c b/gdb/remote.c
index 773c027bf0..28cf56fbad 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -405,6 +405,8 @@ public:
const target_info &info () const override
{ return remote_target_info; }
+ const char *connection_string () override;
+
thread_control_capabilities get_thread_control_capabilities () override
{ return tc_schedlock; }
@@ -4859,6 +4861,17 @@ remote_target::start_remote (int from_tty, int extended_p)
insert_breakpoints ();
}
+const char *
+remote_target::connection_string ()
+{
+ remote_state *rs = get_remote_state ();
+
+ if (rs->remote_desc->name != NULL)
+ return rs->remote_desc->name;
+ else
+ return NULL;
+}
+
/* Open a connection to a remote debugger.
NAME is the filename used for communication. */
diff --git a/gdb/target-connection.c b/gdb/target-connection.c
new file mode 100644
index 0000000000..a079f218bd
--- /dev/null
+++ b/gdb/target-connection.c
@@ -0,0 +1,162 @@
+/* List of target connections for GDB.
+
+ Copyright (C) 2017-2019 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+#include "defs.h"
+#include "target-connection.h"
+
+#include