From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qHhPJfeGBGCDBgAAWB0awg (envelope-from ) for ; Sun, 17 Jan 2021 13:50:31 -0500 Received: by simark.ca (Postfix, from userid 112) id 89B6E1EF80; Sun, 17 Jan 2021 13:50:31 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5A6411E590 for ; Sun, 17 Jan 2021 13:50:30 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 737FF3894C28; Sun, 17 Jan 2021 18:50:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 737FF3894C28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1610909429; bh=XSyqRPlA/oNSJGaHpjVxd+8LqZWbagd56FEi+IuQlZw=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Q8kDI3DmsJEiDmJZZTrrshFN7aKuLQwD921dQBE5uGSmmIP3QuBBuJsaGBYJKobxh Jjij7YtuGyneXwB3hopBsr3bREH0UAZAfgF5UTKjNTIEJoTNbKhu0dJkKnlB3dbdmZ 1mr2ERhEUxeT39GhXGpm3RLgFSoDQy58wxkSJWqg= Received: from beryx.lancelotsix.com (beryx.lancelotsix.com [164.132.98.193]) by sourceware.org (Postfix) with ESMTPS id 55C1B386F036 for ; Sun, 17 Jan 2021 18:50:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 55C1B386F036 Received: from Plymouth (unknown [IPv6:2a02:390:8443:0:6847:5282:9a8b:b8b7]) by beryx.lancelotsix.com (Postfix) with ESMTPSA id 9FF352E071 for ; Sun, 17 Jan 2021 19:50:23 +0100 (CET) Date: Sun, 17 Jan 2021 18:50:21 +0000 To: gdb-patches@sourceware.org Subject: Re: [PATCH] [PR cli/16269] Add completer for the inferior commands Message-ID: References: <20201222215439.4563-1-lsix@lancelotsix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20201222215439.4563-1-lsix@lancelotsix.com> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (beryx.lancelotsix.com [0.0.0.0]); Sun, 17 Jan 2021 19:50:23 +0100 (CET) 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: , From: Lancelot SIX via Gdb-patches Reply-To: Lancelot SIX Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Hi, Even if those completers are an improvement to the actual state of things, I realise they still have limitations. I=E2=80=99ll work on a new version of this patch, and will probably migrate= the inferior related commands to gdb::option style. This patch can be ignored as it is. Lancelot. Le Tue, Dec 22, 2020 at 09:54:39PM +0000, Lancelot SIX a =C3=A9crit : > This patch adds or improves completers for the following commands: >=20 > * inferior > * add-inferior > * clone-inferior > * remove-inferiors > * kill inferiors > * detach inferiors >=20 > Before the patch, the 'inferior', 'clone-inferior', 'remove-inferiors', > 'kill inferiors' and 'detach inferiors' commands complete on symbols > which is unexpected. The 'add-inferior' only completes on filename and > fails to complete on option flags. >=20 > Tested with 'make check TESTS=3D"gdb.base/completion.exp"' >=20 > My copyright assignment is still pending. >=20 > gdb/ChangeLog: >=20 > 2020-12-22 Lancelot SIX >=20 > PR cli/16269 > * inferior.c (inferior_id_completer): add completer > (add_inferior_completer): add completer > (clone_inferior_completer): add completer > (initialize_inferiors): declare use of completers >=20 > gdb/testsuite/ChangeLog: >=20 > 2020-12-22 Lancelot SIX >=20 > PR cli/16269 > * gdb.base/completion.exp: test completion of inferior related > commands > --- > gdb/inferior.c | 61 ++++++++++++++++++++++++--- > gdb/testsuite/gdb.base/completion.exp | 18 ++++++++ > 2 files changed, 73 insertions(+), 6 deletions(-) >=20 > diff --git a/gdb/inferior.c b/gdb/inferior.c > index a6652b6920..406e5030d7 100644 > --- a/gdb/inferior.c > +++ b/gdb/inferior.c > @@ -539,6 +539,22 @@ print_inferior (struct ui_out *uiout, const char *re= quested_inferiors) > } > } > =20 > +/* Complete available inferior IDs */ > + > +static void > +inferior_id_completer (struct cmd_list_element *ignore, > + completion_tracker &tracker, > + const char *text, const char *word) > +{ > + for (inferior *inf : all_inferiors ()) > + { > + std::string const st =3D std::to_string (inf->num); > + if (st.rfind(text, 0) =3D=3D 0) > + tracker.add_completion > + (make_completion_match_str (st.c_str (), text, word)); > + } > +} > + > static void > detach_inferior_command (const char *args, int from_tty) > { > @@ -833,6 +849,20 @@ add_inferior_command (const char *args, int from_tty) > } > } > =20 > +/* Completer for the add-inferior command */ > + > +static void > +add_inferior_completer (struct cmd_list_element *cmd, > + completion_tracker &tracker, > + const char *text, const char *word) > +{ > + static const char * const options[] =3D { > + "-copies", "-exec", "-no-connection", nullptr > + }; > + complete_on_enum (tracker, options, text, word); > + filename_completer (cmd, tracker, text, word); > +} > + > /* clone-inferior [-copies N] [ID] [-no-connection] */ > =20 > static void > @@ -919,6 +949,20 @@ clone_inferior_command (const char *args, int from_t= ty) > } > } > =20 > +/* Completer for the clone-inferior command */ > + > +static void > +clone_inferior_completer (struct cmd_list_element *cmd, > + completion_tracker &tracker, > + const char *text, const char *word) > +{ > + static const char * const options[] =3D { > + "-copies", "-no-connection", nullptr > + }; > + complete_on_enum (tracker, options, text, word); > + inferior_id_completer (cmd, tracker, text, word); > +} > + > /* Print notices when new inferiors are created and die. */ > static void > show_print_inferior_events (struct ui_file *file, int from_tty, > @@ -981,13 +1025,14 @@ as main program.\n\ > By default, the new inferior inherits the current inferior's connection.= \n\ > If -no-connection is specified, the new inferior begins with\n\ > no target connection yet.")); > - set_cmd_completer (c, filename_completer); > + set_cmd_completer (c, add_inferior_completer); > =20 > - add_com ("remove-inferiors", no_class, remove_inferior_command, _("\ > + c =3D add_com ("remove-inferiors", no_class, remove_inferior_command, = _("\ > Remove inferior ID (or list of IDs).\n\ > Usage: remove-inferiors ID...")); > + set_cmd_completer(c, inferior_id_completer); > =20 > - add_com ("clone-inferior", no_class, clone_inferior_command, _("\ > + c =3D add_com ("clone-inferior", no_class, clone_inferior_command, _("\ > Clone inferior ID.\n\ > Usage: clone-inferior [-copies N] [-no-connection] [ID]\n\ > Add N copies of inferior ID. The new inferiors have the same\n\ > @@ -997,22 +1042,26 @@ that is cloned.\n\ > By default, the new inferiors inherit the copied inferior's connection.\= n\ > If -no-connection is specified, the new inferiors begin with\n\ > no target connection yet.")); > + set_cmd_completer (c, clone_inferior_completer); > =20 > - add_cmd ("inferiors", class_run, detach_inferior_command, _("\ > + c =3D add_cmd ("inferiors", class_run, detach_inferior_command, _("\ > Detach from inferior ID (or list of IDS).\n\ > Usage; detach inferiors ID..."), > &detachlist); > + set_cmd_completer(c, inferior_id_completer); > =20 > - add_cmd ("inferiors", class_run, kill_inferior_command, _("\ > + c =3D add_cmd ("inferiors", class_run, kill_inferior_command, _("\ > Kill inferior ID (or list of IDs).\n\ > Usage: kill inferiors ID..."), > &killlist); > + set_cmd_completer(c, inferior_id_completer); > =20 > - add_cmd ("inferior", class_run, inferior_command, _("\ > + c =3D add_cmd ("inferior", class_run, inferior_command, _("\ > Use this command to switch between inferiors.\n\ > Usage: inferior ID\n\ > The new inferior ID must be currently known."), > &cmdlist); > + set_cmd_completer(c, inferior_id_completer); > =20 > add_setshow_boolean_cmd ("inferior-events", no_class, > &print_inferior_events, _("\ > diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.ba= se/completion.exp > index 8000d52049..cc3b7b7182 100644 > --- a/gdb/testsuite/gdb.base/completion.exp > +++ b/gdb/testsuite/gdb.base/completion.exp > @@ -975,3 +975,21 @@ test_gdb_complete_unique "xxx_yyy_" "xxx_yyy_zzz" > gdb_test_no_output "alias set aaa_bbb_ccc=3Dset debug" > gdb_test_no_output "maint deprecate set aaa_bbb_ccc" > test_gdb_complete_unique "set aaa_bbb_" "set aaa_bbb_ccc" > + > +# Test completion of inferior related commands > + > +gdb_test "complete add-inferior -cop" "-copies" > +gdb_test "complete add-inferior -no-con" "-no-connection" > +gdb_test "complete add-inferior -e" "-exec" > + > +gdb_test "complete clone-inferior -c" "-copies" > +gdb_test "complete clone-inferior -n" "-no-connection" > + > +# The following test will ensure that the completer yields the list of > +# available inferiors. We expect to only have 1 present, with ID '1' > +gdb_test "complete clone-inferior " ".*clone-inferior 1.*" > + > +gdb_test "complete remove-inferiors " "remove-inferiors 1" > +gdb_test "complete kill inferiors " "kill inferiors 1" > +gdb_test "complete detach inferiors " "detach inferiors 1" > +gdb_test "complete inferior " "inferior 1" > --=20 > 2.29.2 >=20