From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WPkPKz1r4l8oAgAAWB0awg (envelope-from ) for ; Tue, 22 Dec 2020 16:55:09 -0500 Received: by simark.ca (Postfix, from userid 112) id A11C21F0AA; Tue, 22 Dec 2020 16:55:09 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [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 EA17E1E552 for ; Tue, 22 Dec 2020 16:55:07 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18091387086B; Tue, 22 Dec 2020 21:55:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18091387086B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608674107; bh=0onzZ7eUSaNQ0g3vYHIS01PvLhvktBN6Zrxf8KTu5QI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=aMup5thBcZP+I73Zn/RkQT2IM7hFRbdCViPBMRF9OR754Ut9ZEXzxJk5db6rLY8dq 7xFNJZZz6FFb1j62CISwixFNp8safdjanlA/gHMGgxeikAVNEHxMB2pwfDnxJ4lJlH wV66Msay1IX807YBWMBHVizyEHzj3nYLYtP/nyoA= Received: from beryx.lancelotsix.com (beryx.lancelotsix.com [164.132.98.193]) by sourceware.org (Postfix) with ESMTPS id 9B508387084D for ; Tue, 22 Dec 2020 21:55:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9B508387084D Received: from gwenhwyvar.int.quiet-oceans.com (unknown [IPv6:2a02:390:8443:0:a8a3:fed1:3a2c:a232]) by beryx.lancelotsix.com (Postfix) with ESMTPSA id 06BD62E070; Tue, 22 Dec 2020 22:55:01 +0100 (CET) To: gdb-patches@sourceware.org Subject: [PATCH] [PR cli/16269] Add completer for the inferior commands Date: Tue, 22 Dec 2020 21:54:39 +0000 Message-Id: <20201222215439.4563-1-lsix@lancelotsix.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (beryx.lancelotsix.com [0.0.0.0]); Tue, 22 Dec 2020 22:55:02 +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 Cc: Lancelot SIX Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This patch adds or improves completers for the following commands: * inferior * add-inferior * clone-inferior * remove-inferiors * kill inferiors * detach inferiors 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. Tested with 'make check TESTS="gdb.base/completion.exp"' My copyright assignment is still pending. gdb/ChangeLog: 2020-12-22 Lancelot SIX 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 gdb/testsuite/ChangeLog: 2020-12-22 Lancelot SIX 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(-) 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 *requested_inferiors) } } +/* 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 = std::to_string (inf->num); + if (st.rfind(text, 0) == 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) } } +/* 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[] = { + "-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] */ static void @@ -919,6 +949,20 @@ clone_inferior_command (const char *args, int from_tty) } } +/* 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[] = { + "-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); - add_com ("remove-inferiors", no_class, remove_inferior_command, _("\ + c = 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); - add_com ("clone-inferior", no_class, clone_inferior_command, _("\ + c = 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); - add_cmd ("inferiors", class_run, detach_inferior_command, _("\ + c = 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); - add_cmd ("inferiors", class_run, kill_inferior_command, _("\ + c = 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); - add_cmd ("inferior", class_run, inferior_command, _("\ + c = 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); add_setshow_boolean_cmd ("inferior-events", no_class, &print_inferior_events, _("\ diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/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=set 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" -- 2.29.2