summaryrefslogtreecommitdiff
path: root/gdb/mi/mi-main.c
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-03-02 11:11:47 +0000
committerAndrew Burgess <aburgess@redhat.com>2022-03-07 19:39:04 +0000
commit6fd90137e776c1a29f75651af8e7a129337254c7 (patch)
treecb2fa47236787daaef73d74ce4073399aace6e69 /gdb/mi/mi-main.c
parentd43bd54d543742c76fb20a0fe379817ccca4e5f2 (diff)
downloadbinutils-gdb-6fd90137e776c1a29f75651af8e7a129337254c7.tar.gz
gdb/mi: add --no-connection to MI -add-inferior command
Following on from the previous commit, where the -add-inferior command now uses the same connection as the current inferior, this commit adds a --no-connection option to -add-inferior. This new option matches the existing option of the same name for the CLI version of add-inferior; the new inferior is created with no connection. I've added a new 'connection' field to the MI output of -add-inferior, which includes the connection number and short name. I haven't included the longer description field, this is the MI after all. My expectation would be that if the frontend wanted to display all the connection details then this would be looked up from 'info connection' (or the MI equivalent if/when such a command is added). The existing -add-inferior tests are updated, as are the docs.
Diffstat (limited to 'gdb/mi/mi-main.c')
-rw-r--r--gdb/mi/mi-main.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 2fab592d6fb..b3592964e3d 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1703,18 +1703,53 @@ mi_cmd_list_target_features (const char *command, char **argv, int argc)
void
mi_cmd_add_inferior (const char *command, char **argv, int argc)
{
- struct inferior *inf;
+ bool no_connection = false;
- if (argc != 0)
- error (_("-add-inferior should be passed no arguments"));
+ /* Parse the command options. */
+ enum opt
+ {
+ NO_CONNECTION_OPT,
+ };
+ static const struct mi_opt opts[] =
+ {
+ {"-no-connection", NO_CONNECTION_OPT, 0},
+ {NULL, 0, 0},
+ };
+
+ int oind = 0;
+ char *oarg;
+
+ while (1)
+ {
+ int opt = mi_getopt ("-add-inferior", argc, argv, opts, &oind, &oarg);
+
+ if (opt < 0)
+ break;
+ switch ((enum opt) opt)
+ {
+ case NO_CONNECTION_OPT:
+ no_connection = true;
+ break;
+ }
+ }
scoped_restore_current_pspace_and_thread restore_pspace_thread;
- inf = add_inferior_with_spaces ();
+ inferior *inf = add_inferior_with_spaces ();
- switch_to_inferior_and_push_target (inf, false, current_inferior ());
+ switch_to_inferior_and_push_target (inf, no_connection,
+ current_inferior ());
current_uiout->field_fmt ("inferior", "i%d", inf->num);
+
+ process_stratum_target *proc_target = inf->process_target ();
+
+ if (proc_target != nullptr)
+ {
+ ui_out_emit_tuple tuple_emitter (current_uiout, "connection");
+ current_uiout->field_unsigned ("number", proc_target->connection_number);
+ current_uiout->field_string ("name", proc_target->shortname ());
+ }
}
void