From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qALzKkT0pmXn/j0AWB0awg (envelope-from ) for ; Tue, 16 Jan 2024 16:25:24 -0500 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Gj7PUU5m; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id AAF0B1E0C3; Tue, 16 Jan 2024 16:25:24 -0500 (EST) 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 99ED91E098 for ; Tue, 16 Jan 2024 16:25:22 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 275403858436 for ; Tue, 16 Jan 2024 21:25:22 +0000 (GMT) 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 94C0A3858C60 for ; Tue, 16 Jan 2024 21:24:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94C0A3858C60 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 94C0A3858C60 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=1705440256; cv=none; b=oeSVS0xfKx1efLNfaAlETQypNppm7F1Z/dgc/m7Dck7uktnA6aETyO5MiSCuwiCfAWUVXgeuetPHIyGRDHoUPMaHp1jMl9nVz5SIZOzm2ZAgT1KN1SRiS3V7C5vyjvDlQIA3i38RJ4TCor5TXBheGfLVtCP0gSfJVYpf2CmP9Yo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705440256; c=relaxed/simple; bh=tFqYMzaJ9hgBScjhX5SPqACHsXEnztoXEJTbV69RGco=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Mc71fCQdErfmZOx2LkTdShcHty9L3GMddmHXZoqPPDY4Ij+B/QWbRBioIW/5NyFIWAmgfHqK0GeTOuCKPbUmI2CA1KsHRl0i0Vs3x0B1GtJDTkS8LsyRcopHuR/YAZ0yL0l3a1oRQpzebD31xugrIy0dSsbXOMrhucvhjk0EE7k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705440253; 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=509Ee8CAQ3pCvrdRnXWDcUsmRB+LfmIRSvQjlLIWrq8=; b=Gj7PUU5mZ5EoSyPQqFgxOUEKenLoQoqNY+CSiXYm1A4gsr4zDzUuMs8R1UlsSIcIEfyBRF Q3IWOAl5GcRvuSFd+R2DrSt8KCiishSrhxapuVObQlP5H8BtEOX4ZaRg50/1XivWKj+DGG 7hhkTjXT0eoxXUmN5CasdTcGfJ0jwQs= 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-632-H7hZshl4PSu815F4zNh79A-1; Tue, 16 Jan 2024 16:24:12 -0500 X-MC-Unique: H7hZshl4PSu815F4zNh79A-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-40e4c1dd8a3so65978165e9.0 for ; Tue, 16 Jan 2024 13:24:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705440250; x=1706045050; 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=SvwFlrUgD8V2FriR4YcmNsG7sI3RPA6zu7iB5swoOyU=; b=T3CZub55fxMfSLXsIWUu6BOdIO8XYZuusVZLK3KHt8uZBoQFQ1+osZGQSsGd+SOoRn 8ryQNebU5ifcdt+hBgaJuXU/A9x3iJUQObcC8uuyY15C+sT9NQm6RXiGdn+trjm7h9EP LcYs1qhh2itx8Wz4EkkSo4dqRM031Rv/JrDvPOjZL1++8Won8KE2iaSxRw68UbuygFaX uiNZHFI0Dv8V+9e7/5RWqzjeJRZw5xzsegGDCL+TAO6bTiYTMl4MCEtpVFX8yS1mO7tt nN/U4sGHWRwsJCCODphx5HYGfynUB83+GB4I1iNa9fpKUog1B+BynZWXQJyCxCrwu5qG 4lWQ== X-Gm-Message-State: AOJu0YxMhTOZEa4DCzmqEErmbn9KzAVLhUse7B1wSnSlsMMU7yRjeppz NU93pFFVr881k1bK2S+iiK7SCp7zu45azXL3QgPvl2K4/80ajTg9OGdckWN/0Ov8nop+Pflwb6H /PsbDvd6Hs7qI/zBkDuKpBEfY1QMNsOJoR0G/LZfzRLRD8GPM2eiO8hSeqPRMZvsDc0eVzJn+Xm 2Rjeid7/cyH1EgEw== X-Received: by 2002:a05:600c:524c:b0:40d:7f19:40b1 with SMTP id fc12-20020a05600c524c00b0040d7f1940b1mr3973837wmb.169.1705440249767; Tue, 16 Jan 2024 13:24:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEovI+MUXnShv1ENwn++0jAywOr2T0uMP6WJAeLA9BljO7DQirU9oYpE4oTAU6XIUO1tnlaCg== X-Received: by 2002:a05:600c:524c:b0:40d:7f19:40b1 with SMTP id fc12-20020a05600c524c00b0040d7f1940b1mr3973833wmb.169.1705440249458; Tue, 16 Jan 2024 13:24:09 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id q20-20020a05600c46d400b0040e395cd20bsm24254254wmo.7.2024.01.16.13.24.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 13:24:08 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/5] gdb: allow double quotes for quoting filenames Date: Tue, 16 Jan 2024 21:24:00 +0000 Message-Id: <75584e37d6f4422e80945577884df464b0b34da4.1705439706.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 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, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, 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+public-inbox=simark.ca@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 | 30 +++++++++++++------ .../gdb.base/filename-completion.exp | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 44da6548eb4..198d7893a6f 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -179,7 +179,12 @@ static const char gdb_completer_file_name_break_characters[] = /* Characters that can be used to quote completion strings. Note that we can't include '"' 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 now 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" -- 2.25.4