From patchwork Tue Apr 4 12:45:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 67259 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 70B9A385B522 for ; Tue, 4 Apr 2023 12:46:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70B9A385B522 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680612368; bh=nB5GjBDzEDnSb4ToPyRHLwAwhDK0Iaw3ToH0W+MsyLs=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=YI7vtseTQkuqhQbQGniOFPrwT01ebjN34FgZp99iTh3VZQSVxO3dXBlNJrnbBpVuv YNiTam3SO45+CsOiMOz23ZSEu46+X2XZA2fTmnlwp+CKvOMiPfaCF5MxrvRJ+K3PTi RKWqz//fw0/qPzmauJwoBcVlKW6emHcH9/OVVvXQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 3B8B43858C54 for ; Tue, 4 Apr 2023 12:45:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B8B43858C54 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-220-szKbsAdmMGm-cpdDE3kTEg-1; Tue, 04 Apr 2023 08:45:40 -0400 X-MC-Unique: szKbsAdmMGm-cpdDE3kTEg-1 Received: by mail-qt1-f199.google.com with SMTP id t15-20020a05622a180f00b003e37dd114e3so21991602qtc.10 for ; Tue, 04 Apr 2023 05:45:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680612340; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nB5GjBDzEDnSb4ToPyRHLwAwhDK0Iaw3ToH0W+MsyLs=; b=G2VFsSAsH15Yi3dfJSsVd/tAajkiEPFJ8Bm4VN5q1BG0wj1NJRqciUVY7k4fdpziHi glubtI/jet/4Jfn1WGWpbcLbU2/iUfpB2fCO2DmRnTrKJjjPzXVlAIA3NLBAOhjUhdVz DisxHdm3JmaSz6FZ3SJrCQJTwW0vmaOhh9qz/lFTEufZi5BnZ9qh3E0jI4Gyy0NcKObA 2kJoOcGdT0GhUkOwh6cZahnnB3CFCaynBmEEiNPbm1ZoZvRH4YfXLAr28sSPokBgAOSf ZCiZG8sqw7u9stuSJWOssNlNIdOEXiQF2pTV8XZazzy5/DEm9U/OxAEdn8y2S3NBSxgZ dxtg== X-Gm-Message-State: AAQBX9cTw7svvOJoWqxWlBWC8dj2sIp0SdlQWhnhQlDYpeYhg1fNArAr 2gBsKb4tFnhmgDD51FCAG8t/eEYpL0cXbkod/afo2DJkCJhtyfmiRl55IfY4wHdq2NajlRFbaAy wlumlgt01E+q1JpIL0mGXKfFuqmBXAK2Cgbyuslv37ldj77KMNJhd9Cb4Q1BGD7xSU9RoFtpAea /NQEmUQA== X-Received: by 2002:a05:6214:5099:b0:5c3:f621:59c8 with SMTP id kk25-20020a056214509900b005c3f62159c8mr2819410qvb.1.1680612340060; Tue, 04 Apr 2023 05:45:40 -0700 (PDT) X-Google-Smtp-Source: AKy350aExPEKEjaBuSGgzI9hvgM8Wd7yhHd74kzK94Gpzr3fiC9pJU0oy+bwnA+AGUn2XqqeeFNVEg== X-Received: by 2002:a05:6214:5099:b0:5c3:f621:59c8 with SMTP id kk25-20020a056214509900b005c3f62159c8mr2819369qvb.1.1680612339658; Tue, 04 Apr 2023 05:45:39 -0700 (PDT) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id bz16-20020ad44c10000000b005dd8b9345c0sm1951550qvb.88.2023.04.04.05.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 05:45:39 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/5] gdb: cleanup command creation in infcmd.c Date: Tue, 4 Apr 2023 13:45:27 +0100 Message-Id: <92f0e49903b9824179feb87b0060ab4a1b4beb96.1680608960.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 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_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" In infcmd.c, in order to add command completion to some of the 'set' commands, we are currently creating the command, then looking up the command by calling lookup_cmd. This is no longer necessary, we already return the relevant cmd_list_element object when the set/show command is created, and we can use that to set the command completion callback. I don't know if there's actually any tests for completion of these commands, but I manually checked, and each command still appears to offer the expected filename completion. There should be no user visible changes after this commit. --- gdb/infcmd.c | 59 +++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index a68611538f2..dd5808b17e7 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -3138,55 +3138,48 @@ _initialize_infcmd () { static struct cmd_list_element *info_proc_cmdlist; struct cmd_list_element *c = nullptr; - const char *cmd_name; /* Add the filename of the terminal connected to inferior I/O. */ - add_setshow_optional_filename_cmd ("inferior-tty", class_run, - &inferior_io_terminal_scratch, _("\ -Set terminal for future runs of program being debugged."), _("\ + auto tty_set_show = + add_setshow_optional_filename_cmd ("inferior-tty", class_run, + &inferior_io_terminal_scratch, _("\ +Set terminal for future runs of program being debugged."), _(" \ Show terminal for future runs of program being debugged."), _("\ Usage: set inferior-tty [TTY]\n\n\ If TTY is omitted, the default behavior of using the same terminal as GDB\n\ is restored."), - set_inferior_tty_command, - show_inferior_tty_command, - &setlist, &showlist); - cmd_name = "inferior-tty"; - c = lookup_cmd (&cmd_name, setlist, "", nullptr, -1, 1); - gdb_assert (c != nullptr); - add_alias_cmd ("tty", c, class_run, 0, &cmdlist); - - cmd_name = "args"; - add_setshow_string_noescape_cmd (cmd_name, class_run, - &inferior_args_scratch, _("\ + set_inferior_tty_command, + show_inferior_tty_command, + &setlist, &showlist); + add_alias_cmd ("tty", tty_set_show.set, class_run, 0, &cmdlist); + + auto args_set_show + = add_setshow_string_noescape_cmd ("args", class_run, + &inferior_args_scratch, _("\ Set argument list to give program being debugged when it is started."), _("\ Show argument list to give program being debugged when it is started."), _("\ Follow this command with any number of args, to be passed to the program."), - set_args_command, - show_args_command, - &setlist, &showlist); - c = lookup_cmd (&cmd_name, setlist, "", nullptr, -1, 1); - gdb_assert (c != nullptr); - set_cmd_completer (c, filename_completer); - - cmd_name = "cwd"; - add_setshow_string_noescape_cmd (cmd_name, class_run, - &inferior_cwd_scratch, _("\ + set_args_command, + show_args_command, + &setlist, &showlist); + set_cmd_completer (args_set_show.set, filename_completer); + + auto cwd_set_show = + add_setshow_string_noescape_cmd ("cwd", class_run, + &inferior_cwd_scratch, _("\ Set the current working directory to be used when the inferior is started.\n\ Changing this setting does not have any effect on inferiors that are\n\ already running."), - _("\ + _("\ Show the current working directory that is used when the inferior is started."), - _("\ + _("\ Use this command to change the current working directory that will be used\n\ when the inferior is started. This setting does not affect GDB's current\n\ working directory."), - set_cwd_command, - show_cwd_command, - &setlist, &showlist); - c = lookup_cmd (&cmd_name, setlist, "", nullptr, -1, 1); - gdb_assert (c != nullptr); - set_cmd_completer (c, filename_completer); + set_cwd_command, + show_cwd_command, + &setlist, &showlist); + set_cmd_completer (cwd_set_show.set, filename_completer); c = add_cmd ("environment", no_class, environment_info, _("\ The environment to give the program, or one variable's value.\n\