From patchwork Sat Apr 20 09:10:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 88795 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 EF6E93858C78 for ; Sat, 20 Apr 2024 09:11:57 +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 ESMTPS id 5BDB0386101D for ; Sat, 20 Apr 2024 09:10:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BDB0386101D 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 5BDB0386101D 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=1713604231; cv=none; b=BQjXarHJsjS4xEm3hKXgMFGpJpMTessyycvVSMOBwrqQWHZZVcUlJzAuougXAR+PSmSxmMdCwM1UblNxTcNGtfRlCD2dJ0zK7qO/9tjY1Lkp7cV+PhUgGLlsducatSjQoaJtNKCaJuY/+UtuzsPAlF+0qIq/VVxFDaDTi07Pcbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713604231; c=relaxed/simple; bh=cxQ1zz1hot54u7iGPNM6RYnpz7jbQX2s9yF1SBA6xPY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=oHWQOmeHFwI8Crl3ExT2eOWkOtQfeyCUYABwnUBeyHzTIehRX8Bjon/vQmKPCvyM9YeJSAhcWfdBbgedbcMEsdl+NDs7j5XjQQcwNO9EtcjkwIxuScy5vN3nWB7qemcb0HAXHnsv+YTlx0xRySumlL7VjoG6LOovk8vwRxXpgvw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713604229; 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=DOQt3CNHAXDXKqYLEeyn2uTW6jrtWN46kzIGkMfFutU=; b=BtIzWz5zslZpwisswk2Huz2PD/C8ZB45tjGgZsbrwuzuNvhHUhV2MIfnkRHaNHc5cIxm64 tY+VhiKmlIAINkfNhdMSq7CyYYkdT07JO6nc/jh4BxFjYEomDVtPsHWWS81iSo1qQ7ntxd Z9CoILlTc4c40o/ZNs7GQs8Wx+VvOFs= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-495-PLfoaM3BPqO8YBMJFWdwYg-1; Sat, 20 Apr 2024 05:10:27 -0400 X-MC-Unique: PLfoaM3BPqO8YBMJFWdwYg-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2d87ba1f5e0so27249501fa.2 for ; Sat, 20 Apr 2024 02:10:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713604225; x=1714209025; 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=DOQt3CNHAXDXKqYLEeyn2uTW6jrtWN46kzIGkMfFutU=; b=rFVMIVToy07ReqsHQHhPa9TpRARgbBzqucWknmGeZbcBLdJSXyCXoVZs+fjO9Rz/7T BljZlHpxFCyuoJWsp9L1/mj2NP14kiNWBYPTaDL3p/fhTk47EK5NInUfAE2QIgQZZdxj MxaYKFE1qppo3FbrvMp9nh5+8WKSpbmHtWsJhAjXQtwX1l6TNQ//0q7vU6KNllbb1KTd feYWwJX+ES9ApMKvmR1O8E9yd8zXEuSHeK/VtobHMM2f4FZ4j87H3fK6TkevYLVvqHD7 f2xNZCVKyiJ3lEn3kf/YjLC1LwnWVvO5K3zb23u2FF9H6pDlF92CmcEBLyMTAEYfhVWk NHmA== X-Gm-Message-State: AOJu0YxjeDaoJrHr+bKuU6vem9Anfy8bCBoJn+tj1CVskF2/l5tzplx9 XhnAbqYNUv2DWsOqi13tq1xwy9QszvqykComLKd4u0Qs2ioNBAFOFmPGD8SrOXLNzoENxpJWNZX btPD03OOCWRxRpQj8GyyqgXDBCNOEpt0km9pMo6BBzLUZWmUdcaBdEJiWfduFriFuEyVX7xEkMn uSebFRsngpn3bvu/OBwecvOXvn/TsnmUYoa5mnyDrvCQg= X-Received: by 2002:a2e:8602:0:b0:2db:a393:27c9 with SMTP id a2-20020a2e8602000000b002dba39327c9mr2578014lji.5.1713604225501; Sat, 20 Apr 2024 02:10:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgRoxQqBP8B52wdSqLnnhIQRdeICfU2yH5kjHJ3h1mksNydMLfB7yLoYdoEPCKiadnpXxc6w== X-Received: by 2002:a2e:8602:0:b0:2db:a393:27c9 with SMTP id a2-20020a2e8602000000b002dba39327c9mr2577998lji.5.1713604224809; Sat, 20 Apr 2024 02:10:24 -0700 (PDT) Received: from localhost (92.40.185.25.threembb.co.uk. [92.40.185.25]) by smtp.gmail.com with ESMTPSA id m16-20020a05600c3b1000b0041496734318sm13314491wms.24.2024.04.20.02.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Apr 2024 02:10:24 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Lancelot SIX , Eli Zaretskii Subject: [PATCHv2 4/8] gdb: move display of completion results into completion_result class Date: Sat, 20 Apr 2024 10:10:04 +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=-9.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, 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+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. --- 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 0a537ca9661..efde7e18f44 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 396b1e0136b..af1c09b45b1 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 ();