From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sMUkODawhmZUPhsAWB0awg (envelope-from ) for ; Thu, 04 Jul 2024 10:22:46 -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=OqfPlNg/; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E268B1E0C3; Thu, 4 Jul 2024 10:22:46 -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 CF5F31E030 for ; Thu, 4 Jul 2024 10:22:44 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89E43384A450 for ; Thu, 4 Jul 2024 14:22:44 +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 CBCC4384A441 for ; Thu, 4 Jul 2024 14:21:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBCC4384A441 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 CBCC4384A441 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=1720102886; cv=none; b=bMAnMmz8SOr6OhXYUr9VInLninDQ2pnIZxNwQv9oTVkSovBGh3j7ct3arqgCYwwFVDQVeOIC70AoVZdB4mAN+aDsOzKwlhiuvWCaVi/srpwUC4RoEyNiu/0Cfb4RxSdEemto49/Y9HQrysUQo4MHAMAb8DPgjDZh/o2FUVgkFsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720102886; c=relaxed/simple; bh=+1QQb81QyGAzdyC2XiYu6J/pfci1/AY++nrNP3BT4R0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=OPGCzxZGXbwUDM6FbaaC57nYpTOW3pgDHUza/9iSbGMwGHZws5zhAP61dAYe2Gu0jZyJ1pL36k+J10g9SgIJhCN5EyxT57O5HW3UfM1sqcQ1GJpxvUPSSKyQ7IRu85q+GnnpErS2dOLYM/umtWgO49GR/FBil5AVanalk28E444= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720102883; 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=p91xA7KC5mpRV1abmLsYc5iNhv7nL++hEhtJfCusNwk=; b=OqfPlNg/ZaZULI1VtU+vl4hvz7F27J8kgW89JUKHmP/aLeJnwplzrtSfytdzO46Ylyzjum XvNSScWSH0G/5vKY46r/DYgVBbjcsyKt7+Va89A3G1YsjMhiCpQ1Ajga1a3b9U4fVYLMDD M/L7J7CpEEMwPmOMmSPsjrY22U7HBc8= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-xTyXZO8yOumXZoDCFJ76MA-1; Thu, 04 Jul 2024 10:21:22 -0400 X-MC-Unique: xTyXZO8yOumXZoDCFJ76MA-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2ee4a63e95cso8490561fa.1 for ; Thu, 04 Jul 2024 07:21:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720102880; x=1720707680; 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=p91xA7KC5mpRV1abmLsYc5iNhv7nL++hEhtJfCusNwk=; b=AUxYutoKt/1yllNiCyrKK+xnobVveBFiN2MR48WmmsGTalP+WU1Rsweq2Mdil0ZmSh 9lzYqr9b2tZIF5E4t58mFYXhsTGQ/PuokW3Jw56SumAE8nBxpCX07Zx9CDDqAMmCTw+d eVUN+cQ4HdTyExqSS4p4Yhordp3Ey9fZ8QEGX+RkiEcGaKdJzBQlcPqzhT5ylzDcV/N5 jzikqUfVSDx1OuesdeEx9ttRlnqnYjSL8DLkYsfhlBc3aZqNzs4LcnTINZyBQV5GHMy2 hjSugncL2vfCFQT17lD33Wsnm5gmAOkPD6W+tj1gXep4KeNOAY/yrUKqlToL4VvTSmo2 nYpw== X-Gm-Message-State: AOJu0YxAotQXhbraFtgSSs8FLXqfI29DGanpPv/MxURsvOkj7Nut8kJ/ AYrAUp5BPcgcd483fAzhYebqs8MudFd7FvGBfuwyaZi+VI4JjGmcusP+tq2be/5ANM7VW/nRzSK C2Xiw7WKG++ZcCjkpVuR9KSoH+8KCZR2rNPJzanjh9Rk5cp1q58OMxnfBLDq7hj6zkGcObGL+VG 7Slk+ArDMVEkNaxiJcBsgcKRSbVj6fYuXjV2eVGgUNxg0= X-Received: by 2002:a2e:818d:0:b0:2ee:8777:f86b with SMTP id 38308e7fff4ca-2ee8edd3edbmr12069861fa.35.1720102880206; Thu, 04 Jul 2024 07:21:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUp9zwq3wEohCyGY7JIZWynuQIu9fWYaWrCI+pKdt5M9TJUE61rIherJCk5l7zeK0uraVfBQ== X-Received: by 2002:a2e:818d:0:b0:2ee:8777:f86b with SMTP id 38308e7fff4ca-2ee8edd3edbmr12069661fa.35.1720102879787; Thu, 04 Jul 2024 07:21:19 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4264a21cc59sm26331825e9.25.2024.07.04.07.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 07:21:18 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Tom Tromey Subject: [PATCHv4 04/14] gdb: move display of completion results into completion_result class Date: Thu, 4 Jul 2024 15:20:59 +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.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_H4, RCVD_IN_MSPIKE_WL, 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.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. Approved-By: Tom Tromey --- 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 c69eddc3412..73a650a3e62 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 3ab342dab4f..370a57e6d7f 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -2504,6 +2504,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 70f123ec32f..e6dc9417932 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