From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sFPSMwhqYGb7RScAWB0awg (envelope-from ) for ; Wed, 05 Jun 2024 09:37:12 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=U3zAWoxr; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CEE8A1E0C0; Wed, 5 Jun 2024 09:37:12 -0400 (EDT) Received: from server2.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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id B90C11E092 for ; Wed, 5 Jun 2024 09:37:10 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5575E3A48A19 for ; Wed, 5 Jun 2024 13:37:10 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 5D2A7398CC2A for ; Wed, 5 Jun 2024 13:36:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D2A7398CC2A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5D2A7398CC2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717594586; cv=none; b=IMhmWabaL+AJFOh+I7sD/Ebc0Bx1cqqybHD9hia1oI6/IWK85EBUxOJwM4of/Z3EuecGhdHqBV7f6uMroEFIk0MwBFkusjrp3dAaKoyioPjJRIAiSuChB7+/eGihEBD0oeTDnwTcPoPO7Rho5wFEOj0CcGPWGLpJ3edLvWNmi/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717594586; c=relaxed/simple; bh=QtoOVoA/H7jc6PrTNBlWhv9P6wuW1OsmA8k6CGLZI0E=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=V72GxdTD8AFSGkZgyLgX0NFMB7pA5Jkzyi50wVWLFekuaDnDQAaTFRCOMrEer/dgF/NZ6zarJwVGJfwn2/7NfmAOwI1qfco+/tM3uNFrTCsB0EhoqDVPh8ITv5mTwu8pu38vSmbaECDM4oP7mPmiwGojtxg3sfFd2CDw4XVcFWM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kGXSHOTA5pQ7WuL7+GSABLBnfVA4fNnM639mvRWgCfk=; b=U3zAWoxrZigDZploJJXPxKn+uq9XDPdPuQhRVz2jWP7qY8H+1AIJpThGmMD0253R0HuF85 OrKMbv2YTnPIxc2vi+L+s8AZDoxzAZ1jF0M+E524RF8W2rNjfXu7rol486FHv+ywVgKUsV c8n/kMfDYr1BfYMxN7cN2H5DNswf6ho= 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.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-351-b2srxdg7NpyZyHdjq3Gfew-1; Wed, 05 Jun 2024 09:36:20 -0400 X-MC-Unique: b2srxdg7NpyZyHdjq3Gfew-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4210d151c5bso51625435e9.3 for ; Wed, 05 Jun 2024 06:36:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717594575; x=1718199375; 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=kGXSHOTA5pQ7WuL7+GSABLBnfVA4fNnM639mvRWgCfk=; b=t1hMRURk56+lcdNuclgWjNOEeHCAqlK1XxdzVX2mOIMnXE5yE+/VT6BcU1FCTFBFPp qO6ZMo3WmsaIWFJNmbVqL+HV7jiCzFkcU2NuzbEFjP4XZ4/8Y9BYlHKj7hLTx22gP8Q+ u3fFXvloiXca1fE81+DA8zmto9THH9I94TJW0GdkAa6kGDAOIzxcxvQ+A11MxSiiepRx nSYVUtJqcgO/ZBHOO1pWv26phsUvRojy8RZYnbo1KoDJzfKK+dafY5DQA1JacicRaSAd owDOr0BUN6beZ2UtAfn/ePlKu4CkNddi0RrDqcTtkEw0APgW49PDahOivxnfIjfxIOAk 3qOA== X-Gm-Message-State: AOJu0YwXrjCtylJ35e8ksfjS14DBiulTfv6B+DY6I4k4Yy8Cz4zNLXCy uNWBgfF4gQfT89VRbKk8ZHEAMFVT9bERkKMX4/rB4u0YI9Feot5iYgwL5QgcTaLsoJi4G/8rsos a/Y4Md8zS8YnHxyM5NQ93xYN5jKwI4JN6S6KGTTDcW/O/ySqtk8xQ52f3ySPBoPCixtwuPLkDM4 ogvScb6elZN7MuB72GSzlLfR/TBusCwPyFdMVR0xny5hc= X-Received: by 2002:a05:600c:2211:b0:421:15f:186a with SMTP id 5b1f17b1804b1-4215636043dmr19302675e9.39.1717594574953; Wed, 05 Jun 2024 06:36:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEg4zr58VYFdtuWk3H8+pFMXMO7uDO+2657bg2AXusOY9w0ouPUT1DLnBx2AdOMifvLPifLhQ== X-Received: by 2002:a05:600c:2211:b0:421:15f:186a with SMTP id 5b1f17b1804b1-4215636043dmr19302415e9.39.1717594574320; Wed, 05 Jun 2024 06:36:14 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-421581020d2sm22339255e9.11.2024.06.05.06.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 06:36:13 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 3/7] gdb: move display of completion results into completion_result class Date: Wed, 5 Jun 2024 14:36:03 +0100 Message-Id: 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.8 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org This commit moves the printing of the 'complete' command results out of the 'complete_command' function. The printing is now done in a new member function 'completion_result::print_matches'. At this point, this is entirely a refactor. The motivation for this refactor is how 'complete' should print the completion of filename arguments. In some cases the filename results need to have escaping added to the output. This escaping needs to be done immediately prior to printing the result as adding too early will result in multiple 'complete' results potentially being sorted incorrectly. See the subsequent commits for more details. There should be no user visible changes after this commit. --- gdb/cli/cli-cmds.c | 26 +------------------------- gdb/completer.c | 33 +++++++++++++++++++++++++++++++++ gdb/completer.h | 13 +++++++++++++ 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 4c2a443246d..1a35a6df484 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -423,31 +423,7 @@ complete_command (const char *arg, int from_tty) { std::string arg_prefix (arg, word - arg); - if (result.number_matches == 1) - printf_unfiltered ("%s%s\n", arg_prefix.c_str (), result.match_list[0]); - else - { - result.sort_match_list (); - - for (size_t i = 0; i < result.number_matches; i++) - { - printf_unfiltered ("%s%s", - arg_prefix.c_str (), - result.match_list[i + 1]); - if (quote_char) - printf_unfiltered ("%c", quote_char); - printf_unfiltered ("\n"); - } - } - - if (result.number_matches == max_completions) - { - /* ARG_PREFIX and WORD are included in the output so that emacs - will include the message in the output. */ - printf_unfiltered (_("%s%s %s\n"), - arg_prefix.c_str (), word, - get_max_completions_reached_message ()); - } + result.print_matches (arg_prefix, word, quote_char); } } diff --git a/gdb/completer.c b/gdb/completer.c index 74b3ec6ca14..dcff9edbea0 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -2459,6 +2459,39 @@ completion_result::reset_match_list () } } +/* See completer.h */ + +void +completion_result::print_matches (const std::string &prefix, + const char *word, int quote_char) +{ + if (this->number_matches == 1) + printf_unfiltered ("%s%s\n", prefix.c_str (), this->match_list[0]); + else + { + this->sort_match_list (); + + for (size_t i = 0; i < this->number_matches; i++) + { + printf_unfiltered ("%s%s", prefix.c_str (), + this->match_list[i + 1]); + if (quote_char) + printf_unfiltered ("%c", quote_char); + printf_unfiltered ("\n"); + } + } + + if (this->number_matches == max_completions) + { + /* PREFIX and WORD are included in the output so that emacs will + include the message in the output. */ + printf_unfiltered (_("%s%s %s\n"), + prefix.c_str (), word, + get_max_completions_reached_message ()); + } + +} + /* Helper for gdb_rl_attempted_completion_function, which does most of the work. This is called by readline to build the match list array and to determine the lowest common denominator. The real matches diff --git a/gdb/completer.h b/gdb/completer.h index fa21156bd1f..200d8a9b3af 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -268,6 +268,19 @@ struct completion_result /* Sort the match list. */ void sort_match_list (); + /* Called to display all matches (used by the 'complete' command). + PREFIX is everything before the completion word. WORD is the word + being completed, this is only used if we reach the maximum number of + completions, otherwise, each line of output consists of PREFIX + followed by one of the possible completion words. + + The QUOTE_CHAR is appended after each possible completion word and + should be the quote character that appears before the completion word, + or the null-character if there is no quote before the completion + word. */ + void print_matches (const std::string &prefix, const char *word, + int quote_char); + private: /* Destroy the match list array and its contents. */ void reset_match_list (); -- 2.25.4