connection of the current inferior, this restores the behaviour of
GDB as it was prior to GDB 10.
+ ** The '-add-inferior' command now accepts a '--no-connection'
+ option, which causes the new inferior to start without a
+ connection.
+
* New targets
GNU/Linux/LoongArch loongarch*-*-linux*
@w{@code{remove-inferiors}} command.
@table @code
+@anchor{add_inferior_cli}
@kindex add-inferior
@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
Adds @var{n} inferiors to be run using @var{executable} as the
@subheading Synopsis
@smallexample
--add-inferior
+-add-inferior [ --no-connection ]
@end smallexample
Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
inferior is not associated with any executable. Such association may
be established with the @samp{-file-exec-and-symbols} command
-(@pxref{GDB/MI File Commands}). The command response has a single
-field, @samp{inferior}, whose value is the identifier of the
-thread group corresponding to the new inferior.
+(@pxref{GDB/MI File Commands}).
+
+By default, the new inferior begins connected to the same target
+connection as the current inferior. For example, if the current
+inferior was connected to @code{gdbserver} with @code{target remote},
+then the new inferior will be connected to the same @code{gdbserver}
+instance. The @samp{--no-connection} option starts the new inferior
+with no connection yet. You can then for example use the
+@code{-target-select remote} command to connect to some other
+@code{gdbserver} instance, use @code{-exec-run} to spawn a local
+program, etc.
+
+The command response always has a field, @var{inferior}, whose value
+is the identifier of the thread group corresponding to the new
+inferior.
+
+An additional section field, @var{connection}, is optional. This
+field will only exist if the new inferior has a target connection. If
+this field exists, then its value will be a tuple containing the
+following fields:
+
+@table @samp
+@item number
+The number of the connection used for the new inferior.
+
+@item name
+The name of the connection type used for the new inferior.
+@end table
+
+@subheading @value{GDBN} Command
+
+The corresponding @value{GDBN} command is @samp{add-inferior}
+(@pxref{add_inferior_cli,,@samp{add-inferior}}).
@subheading Example
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
set use_second_inferior [expr {![use_gdb_stub]}]
if { $use_second_inferior } {
- # The inferior created by the -add-inferior MI command does not inherit the
- # target connection of the first inferior. If debugging through an
- # extended-remote connection, that means we can't run that second inferior
- # on the remote connection. Use the add-inferior CLI command as a stop-gap.
- if { [mi_is_target_remote] } {
- mi_gdb_test "add-inferior" \
- "\\^done" \
- "add inferior 2"
- } else {
- mi_gdb_test "-add-inferior" \
- "\\^done,inferior=\"i2\"" \
- "add inferior 2"
- }
+ mi_gdb_test "-add-inferior" \
+ "\\^done,inferior=\"i2\",connection=\\{\[^\}\]+\\}" \
+ "add inferior 2"
mi_gdb_test "-file-exec-and-symbols --thread-group i2 $::binfile" \
"\\^done" \
"set executable of inferior 2"
[multi_line "=thread-group-added,id=\"\[^\"\]+\"" \
"~\"\\\[New inferior 2\\\]\\\\n\"" \
"\~\"Added inferior 2 on connection ${conn_pattern}\\\\n\"" \
- "\\^done,inferior=\"\[^\"\]+\"" ] \
+ "\\^done,inferior=\"\[^\"\]+\",connection=\{number=\"$decimal\",name=\"\[^\"\]+\"\}" ] \
"mi add inferior"
# Now run 'info inferiors' again to check that the currently selected
pass $gdb_test_name
}
}
+
+# Add a third inferior, but this time, use --no-connection.
+mi_gdb_test "-add-inferior --no-connection" \
+ [multi_line "=thread-group-added,id=\"\[^\"\]+\"" \
+ "~\"\\\[New inferior 3\\\]\\\\n\"" \
+ "\~\"Added inferior 3\\\\n\"" \
+ "\\^done,inferior=\"\[^\"\]+\"" ] \
+ "mi add inferior with no connection"