From patchwork Wed Mar 6 10:23:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 86860 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 BDFC03858037 for ; Wed, 6 Mar 2024 10:24:28 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id D21BF385802B for ; Wed, 6 Mar 2024 10:23:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D21BF385802B 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 D21BF385802B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709720640; cv=none; b=UcZ8D/KnEG8PPubUvFm5VLfHd3Jkz7kSq6iyu18FvZy3Q5a42bkLqtkkE/MNJnkX2CILqZxIM6B3R6MBynirpw9UTtS+ErzY23Q4Yu19TLG8k9Mz9ZNfD5Qlhn+52+o7FDR0Q2aIpQygYWj9t8g1aYYDVD5WhocUWPC7byuqD/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709720640; c=relaxed/simple; bh=iWSM2djF3lM9sPrwJfvv+ab6CE/zbPNSl3q5hOIlUu8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=CVXnPdpuHCP/6Kur3KQzhqHntdae9Ybr3R+xoXDymUQMXEb9Blu4KFfG8dWcFvgTTebMD3bh5Hve2ioq89xkTgfvN8w0xrldLOVH2+6rdI9eDx81g1rUyhdTxrwqOsOhtG0RArgMSGPSxrxbd57z5wQmrlHNzcimDf9rtFiKAHU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709720638; 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=IVpWDpQxj625l80jIlw6UrI1AoGZRtdaseDX5nde0do=; b=Oe91D4Eqfy+ybCtCesHEyo5JOHvwWkKSMV68NpNyDfU75VCiQG/i1ifvLWkLabAMvyNGiR hHE7V3fO6iz334K0j1/52P5sLmPtzrKc+SNgIjMDBW4EKNBw+0qWlnktpbYHQc1LduJBjL GaKIbanj4MXGsmaRBwm0ze7UPh7wR88= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-ZsTPiJPKOSakzw1DLq2B2Q-1; Wed, 06 Mar 2024 05:23:57 -0500 X-MC-Unique: ZsTPiJPKOSakzw1DLq2B2Q-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a44143c8908so68801566b.1 for ; Wed, 06 Mar 2024 02:23:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709720635; x=1710325435; 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=aagEVFf3icx7lUBXSZDTptpPVI+PM9gyCJtR1nuRkvQ=; b=fwKsSJ+r2cVXWU3bdRY8MXM6nY5xXAWwj4DzbGJ+RKlN9iiC4gdLmDbWT8Jhc7JluJ tu93sdhsfiBZuncKlcBzpyOnh9pd77pzQZ1SBasu2WMCS6vbYbdddaKQE1eVT2Rl6J5v lDDAy3O5IZR7Giu5cBP2SX4dLf1HfrSTHt5utUsITY1N/nRPq+aXtV33TV9HRIosIKuj d/eoFYOrB3qEYwvWCgHZ8r4Mpmtl5LQu4Sj3K0adDa5iQwPEcsr4TOsndgKI5n2jxwUs l22sNd7UJC0Hoqgyer+IPjSaavAfz3CYGM/7Zy0MtUNtkBwc+SkVEVNNowXEIyhky0IT HYxQ== X-Gm-Message-State: AOJu0YwYpoIg4YlwxnUzJZz06pTmNIA9o0GBmbOU86ea+r3MvDbgwOlP 0+Oo+cIRjKHwMUZBLQX7/DsOYty+BgoW4rim2IoPah3oyissQc+gxJOTp3KrVsKJaJNAywoRj9Z 04rELOJOi8Bc4Gy2oCxaD2Ts2SGUjm1tsdcneuKMVtKqMF6Qe+INpIMm0KRQ80VD1TdYdW0qBtw 51wDrsmlw56hKdgmn16l4LmZdV7jTifhFFXXSDIi+gC8Q= X-Received: by 2002:a17:906:684d:b0:a45:bde1:a334 with SMTP id a13-20020a170906684d00b00a45bde1a334mr983841ejs.27.1709720634875; Wed, 06 Mar 2024 02:23:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAExBDypaiGXeM7R6oPqvn9nSDqoRPDFqxb8u+3Elz3J7lCpXx6vrqV4J3LWVllwwD0ZJi+A== X-Received: by 2002:a17:906:684d:b0:a45:bde1:a334 with SMTP id a13-20020a170906684d00b00a45bde1a334mr983814ejs.27.1709720634175; Wed, 06 Mar 2024 02:23:54 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id cu5-20020a170906ba8500b00a440ec600e3sm6949519ejd.121.2024.03.06.02.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 02:23:53 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 3/7] gdb: allow double quotes for quoting filenames Date: Wed, 6 Mar 2024 10:23:35 +0000 Message-Id: <3fd42ec03923acbf824f5f5318291aa7c92bb751.1709720449.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, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, 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+patchwork=sourceware.org@sourceware.org Currently GDB only supports using single quotes for quoting things, the reason for this, as explained in completer.c (next to the variable gdb_completer_expression_quote_characters) is that double quoted strings need to be treated differently by the C expression parser. But for filenames I don't believe this restriction holds. The file names as passed to things like the 'file' command are not passing through the C expression parser, so it seems like we should be fine to allow double quotes for quoting in this case. And so, this commit extends GDB to allow double quotes for quoting filenames. Maybe in future we might be able to allow double quote quoting in additional places, but this seems enough for now. The testing has been extended to cover double quotes in addition to the existing single quote testing. This change does a number of things: 1. Set rl_completer_quote_characters in filename_completer and filename_completer_handle_brkchars, this overrides the default which is set in complete_line_internal_1, 2. In advance_to_completion_word we now take a set of quote characters as a parameter, the two callers advance_to_expression_complete_word_point and advance_to_filename_complete_word_point now pass in the required set of quote characters, 3. In completion_find_completion_word we now use the currently active set of quote characters, this means we'll use gdb_completer_expression_quote_characters or gdb_completer_file_name_quote_characters depending on what type of things we are completing. --- gdb/completer.c | 34 +++++++++++++------ .../gdb.base/filename-completion.exp | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 44da6548eb4..cefac605a33 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -176,10 +176,15 @@ static const char gdb_completer_file_name_break_characters[] = " \t\n*|\"';:?><"; #endif -/* Characters that can be used to quote completion strings. Note that - we can't include '"' because the gdb C parser treats such quoted +/* Characters that can be used to quote expressions. Note that we can't + include '"' (double quote) because the gdb C parser treats such quoted sequences as strings. */ -static const char gdb_completer_quote_characters[] = "'"; +static const char gdb_completer_expression_quote_characters[] = "'"; + +/* Characters that can be used to quote file names. We do allow '"' + (double quotes) in this set as file names are not passed through the C + expression parser. */ +static const char gdb_completer_file_name_quote_characters[] = "'\""; /* This can be used for functions which don't want to complete on @@ -199,9 +204,9 @@ filename_completer (struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word) { - int subsequent_name; + rl_completer_quote_characters = gdb_completer_file_name_quote_characters; - subsequent_name = 0; + int subsequent_name = 0; while (1) { gdb::unique_xmalloc_ptr p_rl @@ -256,6 +261,8 @@ filename_completer_handle_brkchars (struct cmd_list_element *ignore, { set_rl_completer_word_break_characters (gdb_completer_file_name_break_characters); + + rl_completer_quote_characters = gdb_completer_file_name_quote_characters; } /* Find the bounds of the current word for completion purposes, and @@ -401,12 +408,13 @@ gdb_rl_find_completion_word (struct gdb_rl_completion_word_info *info, static const char * advance_to_completion_word (completion_tracker &tracker, const char *word_break_characters, + const char *quote_characters, const char *text) { gdb_rl_completion_word_info info; info.word_break_characters = word_break_characters; - info.quote_characters = gdb_completer_quote_characters; + info.quote_characters = quote_characters; info.basic_quote_characters = rl_basic_quote_characters; int delimiter; @@ -431,7 +439,8 @@ advance_to_expression_complete_word_point (completion_tracker &tracker, const char *text) { const char *brk_chars = current_language->word_break_characters (); - return advance_to_completion_word (tracker, brk_chars, text); + const char *quote_chars = gdb_completer_expression_quote_characters; + return advance_to_completion_word (tracker, brk_chars, quote_chars, text); } /* See completer.h. */ @@ -441,7 +450,8 @@ advance_to_filename_complete_word_point (completion_tracker &tracker, const char *text) { const char *brk_chars = gdb_completer_file_name_break_characters; - return advance_to_completion_word (tracker, brk_chars, text); + const char *quote_chars = gdb_completer_file_name_quote_characters; + return advance_to_completion_word (tracker, brk_chars, quote_chars, text); } /* See completer.h. */ @@ -1262,8 +1272,10 @@ complete_line_internal_1 (completion_tracker &tracker, set_rl_completer_word_break_characters (current_language->word_break_characters ()); - /* Likewise for the quote characters. */ - rl_completer_quote_characters = gdb_completer_quote_characters; + /* Likewise for the quote characters. If we later find out that we are + completing file names then we can switch to the file name quote + character set (i.e., both single- and double-quotes). */ + rl_completer_quote_characters = gdb_completer_expression_quote_characters; /* Decide whether to complete on a list of gdb commands or on symbols. */ @@ -1988,7 +2000,7 @@ completion_find_completion_word (completion_tracker &tracker, const char *text, gdb_rl_completion_word_info info; info.word_break_characters = rl_completer_word_break_characters; - info.quote_characters = gdb_completer_quote_characters; + info.quote_characters = rl_completer_quote_characters; info.basic_quote_characters = rl_basic_quote_characters; return gdb_rl_find_completion_word (&info, quote_char, NULL, text); diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp index 7d8ab1a3350..b700977cec5 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -56,7 +56,7 @@ proc run_tests { root } { "thread apply all help" " " false \ "complete a 'thread apply all' command" - foreach_with_prefix qc [list "" "'"] { + foreach_with_prefix qc [list "" "'" "\""] { test_gdb_complete_none "file ${qc}${root}/xx" \ "expand a non-existent filename"