From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 1EFC53858D39 for ; Thu, 3 Mar 2022 12:44:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1EFC53858D39 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-572-LBYmrFIxMwa3-uPAhdRP8Q-1; Thu, 03 Mar 2022 07:44:42 -0500 X-MC-Unique: LBYmrFIxMwa3-uPAhdRP8Q-1 Received: by mail-wm1-f70.google.com with SMTP id f24-20020a1c6a18000000b00388874b17a8so286569wmc.3 for ; Thu, 03 Mar 2022 04:44:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=c6Hu2gUrX4oibAdvfADwBvtoaejPT86KcNZCy5Sfipg=; b=P1wSTjt91S7K771OJ8oxqlnsDG/OMnlZwkVTBiDyTgKRPvSq9tNuexs102iPglKxq/ 78EzJgL/lfjkpp9Y85sc6CjapJ33Wi8yYqY7XN3VnRnoQtKaWiFRkhPwqopwJ6+lwoeq IP1bM+ITDWCTtad9l5vEI95EXWSEAEQ82pkhj/4zfn2CQlEcASpi489Mey7Y0eqmbJvX +GjC8K+Q8LuXqWkBVfr6kzxRDDjz2zet3YdaGQPmk8JXxLkvWb1hS6klGAJGuAXZwYIb lttNtsHqz6rz0xCwV/zWioovcBxfgLNAOTuz3T9TxL6TBPG9aJDS5zVbjpJYolviEofZ XUQQ== X-Gm-Message-State: AOAM530FzjGjZ7ZsioymuIujN8IMV50ta7wEt6cKy3Y+UVVDXypGIWVP 8R8alqT1sSkDlgplOdfV+vDpvxt0muu4X57YdVwa/u3OawZxPS68Ktly2mZwyHG0RkVA96NWlf4 BEiXPBBYJFMIv3ac1R/m/Rw== X-Received: by 2002:adf:dccb:0:b0:1ed:c1dc:537c with SMTP id x11-20020adfdccb000000b001edc1dc537cmr27103989wrm.406.1646311481443; Thu, 03 Mar 2022 04:44:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyx+QrFq2FeXXcehhzL1j6wWuud/pHsiuLfb/7TKpys6+VctQ5lX4IcKl4sVUz4GG4flcx89A== X-Received: by 2002:adf:dccb:0:b0:1ed:c1dc:537c with SMTP id x11-20020adfdccb000000b001edc1dc537cmr27103981wrm.406.1646311481254; Thu, 03 Mar 2022 04:44:41 -0800 (PST) Received: from localhost (host86-169-131-29.range86-169.btcentralplus.com. [86.169.131.29]) by smtp.gmail.com with ESMTPSA id m26-20020a05600c3b1a00b003817ab146e9sm11934884wms.44.2022.03.03.04.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 04:44:40 -0800 (PST) Date: Thu, 3 Mar 2022 12:44:39 +0000 From: Andrew Burgess To: Eli Zaretskii Cc: gdb-patches@sourceware.org Subject: Re: [PATCHv2 2/2] gdb/mi: add --no-connection to MI -add-inferior command Message-ID: <20220303124439.GF1212730@redhat.com> References: <2d926ccc029733a21d4b1483f89b87739e570b29.1646221667.git.aburgess@redhat.com> <83pmn4jf8w.fsf@gnu.org> MIME-Version: 1.0 In-Reply-To: <83pmn4jf8w.fsf@gnu.org> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 12:43:45 up 4 days, 2:21, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Mar 2022 12:44:46 -0000 * Eli Zaretskii via Gdb-patches [2022-03-02 22:01:19 +0200]: > > Date: Wed, 2 Mar 2022 11:57:36 +0000 > > From: Andrew Burgess via Gdb-patches > > Cc: Andrew Burgess > > > > +The command response always has a field, @samp{inferior}, whose value > > +is the identifier of the thread group corresponding to the new > > +inferior. > > + > > +An additional section field, @samp{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: > > The above two @samp should be @var, since they aren't literal symbols. > > OK with that fixed, thanks. > > Shouldn't this have a NEWS entry? Good point. The patch below has the @samp -> @var change, plus a NEWS entry. Thanks, Andrew --- commit 3480e32d5fc5dd306447feb3d3dead70801f9a10 Author: Andrew Burgess Date: Wed Mar 2 11:11:47 2022 +0000 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. diff --git a/gdb/NEWS b/gdb/NEWS index 41ea84e6063..1e53a55c259 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -136,6 +136,12 @@ info win This command now includes information about the width of the tui windows in its output. +* MI changes + + ** 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* diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 504eb663c14..2222e91b573 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -3310,6 +3310,7 @@ @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 @@ -37101,15 +37102,45 @@ @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 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 diff --git a/gdb/testsuite/gdb.mi/mi-add-inferior.exp b/gdb/testsuite/gdb.mi/mi-add-inferior.exp index 3f0cd7cc06c..85cd6a5271d 100644 --- a/gdb/testsuite/gdb.mi/mi-add-inferior.exp +++ b/gdb/testsuite/gdb.mi/mi-add-inferior.exp @@ -79,7 +79,7 @@ mi_gdb_test "-add-inferior" \ [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 @@ -120,3 +120,11 @@ gdb_test_multiple "info inferiors" \ 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"