From patchwork Tue Aug 20 17:10:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 96177 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 86679387086D for ; Tue, 20 Aug 2024 17:12:26 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTP id 5E19638432D5 for ; Tue, 20 Aug 2024 17:10:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E19638432D5 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 5E19638432D5 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=1724173862; cv=none; b=fVjOnaGRTb2kSLUAPvMXGK88Z1NRQy711bshdNdydlC/1M/ZJOKNK0elx59mi7CM2JsXoC8WKR47wGulQCM4g/KVtOD3cJX0PRWFZbq61t7nHDUOVoAFhtBiYL+x92VnsB9tkRcqjDq+QEDqGzYtO94E771nbxyPZSfJYR/o+WQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724173862; c=relaxed/simple; bh=RDaAhjypfNdNe8eDSbTI9wXx+XD//HzeUtdkn0NFJMo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=OtDeqc12knppYPuxwkScNh0sUNoOsXxSYGgPsv4dk0pfYJTCwtpdDuknKA+Q0IeYJ6mOt8gHRmq4I/pLAP5LbJ8/Vv5PPZZZNtMhxNTZ7JsoHX0fOKnscR7frdHj6Vixu8kUr9gi3xUzwJhsK7qz3lJlm7WdOQOqOoCdEEtCCaA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724173858; 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=aRGVWa3WS311cVktuJOrBNFMS2SEtPY3tuKIoXpXpOc=; b=f44MC01eL90kL6QWUSOcO+NNvMlzNH7ma2XM9HqE4QP7V9trbyEJVWCsYEXY9RTuOLRqCr SVhM5jgta0uk8lx4aDcNEn+YqwRBHNBpYb3ZzmQj4zdr7IWTEggJqeLFdLWYumN3yYkSeK oTAgt6j1M6HVR9BqAi9Wfwd3etnz/00= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-281-pIwajB_KMYqi5-SZPDTkJQ-1; Tue, 20 Aug 2024 13:10:56 -0400 X-MC-Unique: pIwajB_KMYqi5-SZPDTkJQ-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3718eb22836so3162476f8f.3 for ; Tue, 20 Aug 2024 10:10:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724173853; x=1724778653; 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=aRGVWa3WS311cVktuJOrBNFMS2SEtPY3tuKIoXpXpOc=; b=UVfXRyZXnsAJiYf2CZrFBDuLOlOqQKAPrd2LXbPMLBsyGTAvawWvxwnZJa+iXiszbx U/M5x4laCnoMyZ1suZoLQw42F9E+fX3hhv8sJNpvfXN4pVYp5iJf8Kx6Q0Dyh8eoKSeo Ga3+ljlkTRU5AHjDtebwiJpRHn7KqTce3uMGwsxWz85wHwCXDOYu0bY5JBuc1dHLHIEY z1krUmBSs+To3r/lMxQHasZ10WAd2127QBH/KFGpalDWTJdhaMxoTSK0QCXJ3ct7M9hg iiVMHXz6Oqz7ynbwUc9WGpH8H4ArhnlPbAUMakOzPMCbq3uzQA/RWrw6ZNlrxTfZKByM CcyQ== X-Gm-Message-State: AOJu0YxH0dxK0h8QUYQjAqyeJROOgMwUT+giQMqTNyUNJgvFSM4jq71V 2YrQkEjKKnFnfSsvMhHQ/i8IYgF2ExbIcewxhV4EHE0yMf69lwD99U9epWosxiKQBdWmYEHfnoC l0n5RFcibDdvleieaCiAXmksqVJUcV6Cm3lZG7EQa0EZZEe2hLbHZeFGpFRXO/wGoweNH5oT+bR fzPaFGBcDt3/hPYf0J6Tfycds89jY+0RtxYIz1QSsDlDg= X-Received: by 2002:a5d:452b:0:b0:371:8c06:82ea with SMTP id ffacd0b85a97d-371943150a3mr8706527f8f.1.1724173853500; Tue, 20 Aug 2024 10:10:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAhSzoF+jFNZwtM3D91IHrn1+0u2EvkNhrteRMhOYx7qaBDQUayEnfRDYWamx90p8sGIWnIg== X-Received: by 2002:a5d:452b:0:b0:371:8c06:82ea with SMTP id ffacd0b85a97d-371943150a3mr8706495f8f.1.1724173852699; Tue, 20 Aug 2024 10:10:52 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded1813dsm208695045e9.7.2024.08.20.10.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 10:10:51 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Tom Tromey Subject: [PATCHv5 04/14] gdb: move display of completion results into completion_result class Date: Tue, 20 Aug 2024 18:10:34 +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 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, 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~patchwork=sourceware.org@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 58bb62e89d6..fd8e27735f0 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 ();