From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id MCsTAjz7K2B3UAAAWB0awg (envelope-from ) for ; Tue, 16 Feb 2021 12:05:00 -0500 Received: by simark.ca (Postfix, from userid 112) id EB2951EF78; Tue, 16 Feb 2021 12:04:59 -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 C074B1E54D for ; Tue, 16 Feb 2021 12:04:58 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 40279383F843; Tue, 16 Feb 2021 17:04:58 +0000 (GMT) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 2C2F5383F843 for ; Tue, 16 Feb 2021 17:04:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2C2F5383F843 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x42d.google.com with SMTP id t15so13955372wrx.13 for ; Tue, 16 Feb 2021 09:04:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=mGUfR1wWP2psltcnRRzbqeO7P3QW+n36tLFp/yqn+d4=; b=ITSP/996y5YcjaAUc0B2/58fvT8L3e7q7QS5xqDGRwd/dBmSui4FR9o7ffWFrIX6is VOCcJpRpWKvWDkMEgj+lHBiQ2Avq0zcx0WXWcT7Oisy1PKyW/58BD8yN+I+isdfqZ54B WSX08Muxs/BAcJbdKSYTuboMwgOkZIiGseLGGpRS0cpecL5joZvmjTTWj1C2pEZeoyw4 Aej49IAEWV4spZ3HHn/9/hlUUMXhRdQz6ylTIGwwJXwAFGUUJ4pnz/NE2wn0GsaZHw9K 1g08stVFcTNreotMN8k906gyHJ+mjnzphV80tOQun+Dz5o+9QDMiG3XepNsrku8hbReS AF0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=mGUfR1wWP2psltcnRRzbqeO7P3QW+n36tLFp/yqn+d4=; b=dt7FS7vkZ7IrXUfjRdCK2mB5EBxX6fmdYWRVnqkAIhDR7OfzbarKcbSCbfXEcKYSf5 c3Wevvmo+kM6X84HvTS2WRq3h8CbsYI6i7aMCRXk/9+OheqXV0xI6/Wgd7enhb4YRQgU CfnwX8BeC+tykDrKGNgtISm8i4gGM+ZPXs3Hca7YU6bmBRm66N63aA2/RpmiZUVLPobe RXRBodMlGY8Q7TNBsUFrk63N4TxG2MoelxWBnD0V9vkprLj5fci6Wgke/++mVu4Mw53n WvbX2Kpd2hOvXBkR55OyLxe9VpQo4AGR9pxnEgH1YlHwNB/VwWJGqnnBGp81/TOPk0T9 2q+w== X-Gm-Message-State: AOAM5309dohzbX8nTA4eA8pz2tPCoFo6BXat/1PvfHkyKuYfMy74m8bP ZSljQiVdNahb0M2awgn74u7ZZ0sEKpPYgw== X-Google-Smtp-Source: ABdhPJwyQ1FGWTn3NGuWXiGoFxMw1bfCICRgBD+BiDQyTfcOfo5g8SoH3SG2sVMFi4dwZgPgmb9Yfg== X-Received: by 2002:adf:b60e:: with SMTP id f14mr24826290wre.99.1613495094181; Tue, 16 Feb 2021 09:04:54 -0800 (PST) Received: from localhost (host86-186-80-154.range86-186.btcentralplus.com. [86.186.80.154]) by smtp.gmail.com with ESMTPSA id o13sm15267897wro.15.2021.02.16.09.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 09:04:53 -0800 (PST) Date: Tue, 16 Feb 2021 17:04:52 +0000 From: Andrew Burgess To: Lancelot SIX Subject: Re: [PATCH 3/3] Add completer to the add-inferior command Message-ID: <20210216170452.GR265215@embecosm.com> References: <20210213220752.32581-1-lsix@lancelotsix.com> <20210213220752.32581-4-lsix@lancelotsix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210213220752.32581-4-lsix@lancelotsix.com> X-Operating-System: Linux/5.8.13-100.fc31.x86_64 (x86_64) X-Uptime: 17:04:17 up 69 days, 21:48, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] 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: , Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" * Lancelot SIX via Gdb-patches [2021-02-13 22:07:52 +0000]: > This commit adds a completer to the add-inferior command. Argument > parsing is also updated to benefit from what is offered by the > gdb::option framework. > > gdb/Changelog: > > * inferior.c (struct add_inferior_options): Add struct. > (add_inferior_options_defs): Create. > (make_add_inferior_options_def_group): Create. > (add_inferior_completer): Create. > (add_inferior_command): Use gdb::option parsing for arguments. > (initialize_inferiors): Use new completer for add-inferior > command. > > gdb/testsuite/ChangeLog: > > * gdb.base/completion.exp: Test add-completion completion. > --- > gdb/inferior.c | 123 ++++++++++++++++++-------- > gdb/testsuite/gdb.base/completion.exp | 11 +++ > 2 files changed, 96 insertions(+), 38 deletions(-) > > diff --git a/gdb/inferior.c b/gdb/inferior.c > index 49f869a4c78..6993d043a57 100644 > --- a/gdb/inferior.c > +++ b/gdb/inferior.c > @@ -788,63 +788,110 @@ switch_to_inferior_and_push_target (inferior *new_inf, > printf_filtered (_("Added inferior %d\n"), new_inf->num); > } > > +/* Describes the options for the add-inferior command. */ > + > +struct add_inferior_options > +{ > + /* Number new inferiors to create. */ > + unsigned int copies = 1; > + > + /* Instructs to start the inferior with no target connected. */ > + bool no_connection = false; > + > + /* Path to the file name of the executable to use as main program. */ > + char *exec = nullptr; > + > + ~add_inferior_options () > + { > + if (exec != nullptr) > + { > + xfree (exec); > + exec = nullptr; > + } > + } > +}; > + > +/* Definition of options for the 'add-inferior' command. */ > + > +static const gdb::option::option_def add_inferior_options_defs[] = { > + gdb::option::zuinteger_option_def { > + "copies", > + [] (add_inferior_options *opt) { return &opt->copies; }, > + nullptr, /* show_cmd_cb */ > + nullptr, /* set_doc */ > + nullptr, /* show_doc */ > + nullptr, /* help_doc */ > + }, > + > + gdb::option::flag_option_def { > + "no-connection", > + [] (add_inferior_options *opt) { return &opt->no_connection; }, > + nullptr, /* set_doc */ > + nullptr, /* help_doc */ > + }, > + > + gdb::option::filename_option_def { > + "exec", > + [] (add_inferior_options *opt) { return &opt->exec; }, > + nullptr, /* show_cmd_cb */ > + nullptr, /* set_doc */ > + nullptr, /* show_doc */ > + nullptr, /* help_doc */ > + }, > + > +}; > + > +static gdb::option::option_def_group > +make_add_inferior_options_def_group (struct add_inferior_options *opts) > +{ > + return {{add_inferior_options_defs}, opts}; > +} > + > +/* 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*/) > +{ > + const auto group = make_add_inferior_options_def_group (nullptr); > + if (gdb::option::complete_options > + (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group)) > + return; > +} > + > /* add-inferior [-copies N] [-exec FILENAME] [-no-connection] */ > > static void > add_inferior_command (const char *args, int from_tty) > { > - int i, copies = 1; > + int i; > gdb::unique_xmalloc_ptr exec; > symfile_add_flags add_flags = 0; > - bool no_connection = false; > + > + add_inferior_options opts; > + const gdb::option::option_def_group group > + = make_add_inferior_options_def_group (&opts); > + gdb::option::process_options > + (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group); > > if (from_tty) > add_flags |= SYMFILE_VERBOSE; > > - if (args) > - { > - gdb_argv built_argv (args); > - > - for (char **argv = built_argv.get (); *argv != NULL; argv++) > - { > - if (**argv == '-') > - { > - if (strcmp (*argv, "-copies") == 0) > - { > - ++argv; > - if (!*argv) > - error (_("No argument to -copies")); > - copies = parse_and_eval_long (*argv); > - } > - else if (strcmp (*argv, "-no-connection") == 0) > - no_connection = true; > - else if (strcmp (*argv, "-exec") == 0) > - { > - ++argv; > - if (!*argv) > - error (_("No argument to -exec")); > - exec.reset (tilde_expand (*argv)); > - } > - } > - else > - error (_("Invalid argument")); > - } > - } > - > inferior *orginf = current_inferior (); > > scoped_restore_current_pspace_and_thread restore_pspace_thread; > > - for (i = 0; i < copies; ++i) > + for (i = 0; i < opts.copies; ++i) > { > inferior *inf = add_inferior_with_spaces (); > > - switch_to_inferior_and_push_target (inf, no_connection, orginf); > + switch_to_inferior_and_push_target (inf, opts.no_connection, orginf); > > - if (exec != NULL) > + if (opts.filename != nullptr) > { > - exec_file_attach (exec.get (), from_tty); > - symbol_file_add_main (exec.get (), add_flags); > + exec_file_attach (opts.filename, from_tty); > + symbol_file_add_main (opts.filename, add_flags); This patch doesn't build for me as opts.filename is unknown. Did you mean opts.exec maybe? Thanks, Andrew > } > } > } > @@ -997,7 +1044,7 @@ 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_handle_brkchars (c, add_inferior_completer); > > add_com ("remove-inferiors", no_class, remove_inferior_command, _("\ > Remove inferior ID (or list of IDs).\n\ > diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp > index 076134cdc33..c83aa8994e2 100644 > --- a/gdb/testsuite/gdb.base/completion.exp > +++ b/gdb/testsuite/gdb.base/completion.exp > @@ -980,3 +980,14 @@ 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 the completer of the add-inferior command. > +gdb_test_no_output "set max-completions unlimited" > +test_gdb_complete_multiple "add-inferior " "-" "" { > + "-copies" > + "-exec" > + "-no-connection" > +} > +test_gdb_complete_unique \ > + "add-inferior -copies 2 -exec some\\ file -n" \ > + "add-inferior -copies 2 -exec some\\ file -no-connection" > -- > 2.29.2 >