From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YFE5Gt2u0Wb19xkAWB0awg (envelope-from ) for ; Fri, 30 Aug 2024 07:37:01 -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=dHxJpor7; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 64ACC1E0D0; Fri, 30 Aug 2024 07:37:01 -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 480A21E0AC for ; Fri, 30 Aug 2024 07:36:59 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E4A4E3861028 for ; Fri, 30 Aug 2024 11:36:58 +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 ESMTP id 2D95E385B532 for ; Fri, 30 Aug 2024 11:34:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D95E385B532 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 2D95E385B532 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=1725017657; cv=none; b=FVY2KWtp6W3nVL/2YfVEtobbRwWW+V/F/OIDWtXc04YlXnpVg+Eek0fj51bQsiOVtO706DhM6iVRx7hZ3oC7ZYnkWpFRqj4hLA0o4V4qZMDEMUmP20SBhjcmhJ4fAJoEoIrzzbGSBJOBA3s67HxHGJx/8icw+0Q3thylXhPtfzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725017657; c=relaxed/simple; bh=gc7CF8aqrfSljFS3I/XtZE0s2W20VlQKZlJYMgKbG5Y=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=LxtVaoKdVVpO79h2DY4P67RElh5XlMLLgsxf6mpm0MO/WXQferXL1y2gFdYplIzkYAJOZINGaKdrL1TRtZwycfkuWT2KTnXgVSkJNWwu44sdgMXaCbJeG6rmBFCIxMw/nR+VyxRMDkvu6AgHgqgjOc/hMLHXnVViM3KBQgJUqqg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725017654; 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=JpLNou6SmIjyle0dz59EJyqS67m0b9Zt4XKhKWbuNYI=; b=dHxJpor7nI0iBwn3NatiY4v/AQ/WnUUg6fHg7c2HzbBcQhS1StaYevyz6ebG61WPal6aym ujVb4aGPsmr2eyieFd9RDd37HxaJjqsja69+GNFvnnIMh/ZkIy8JhSrxw5FrktQDjdbhDT go4DIUrIF4Fv3c+2X5q1Mvg124U3+EU= 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-7WNI_hDhMWSCUJX94aDk1g-1; Fri, 30 Aug 2024 07:34:13 -0400 X-MC-Unique: 7WNI_hDhMWSCUJX94aDk1g-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2f3e7cbbceaso15465781fa.1 for ; Fri, 30 Aug 2024 04:34:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725017651; x=1725622451; 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=JpLNou6SmIjyle0dz59EJyqS67m0b9Zt4XKhKWbuNYI=; b=AdDBBF7zychA7M0z/oPil1YTtCefmN0UIsil3xoQ2Khw1b0TQfsfS99bFKUoFkTimE vFTsVMqk2O5TDD7/7OYYPZTJkzIEQKqjDAkC7d+FHw/0C0sdP2zo1BxPTo3iLPLz+hrs QdX2JSnyjaNHR+18PLmGgNOO1CHcGIM3ddsEn5qnywRpkLwGCnoJho/29EO2rGzwuHA3 4ERDJRyvVbNOMMOTqL33LJlHlegA+KrJ5xI6GsoF3Rdj3hJ8tt4SHnG/0DgUWnqDRoJT Nb+ti0tNZsFdbhC42IbaBz1cpfr/6CHMLkXcdoxAwdIpPZa5W7Dnu5Tx8QQ8PPaznkW5 RgWQ== X-Gm-Message-State: AOJu0YwrMxlGKWwioDsqWhKt9cOOLBitoPWEdJTPHLYPrzJ9cUMmgIRw /tX5b/TKA7CP5DlKVerFzTycyzPNfnE9wMRtaiGAGd1FLF10UWXim1Kh5yNUMyn8FQ+ZWYMo3BU kSWFHFj5HFoSC3cezGdaJk1J31JcIHNOgLLbt+oftTUTadF5OLiT72PM/TGG1aZ6UoplYI1U5wl d7GVctI5ej245frhBRT9o48dpdLSJ45enup04SF/GTWOc= X-Received: by 2002:a05:651c:b27:b0:2f3:eeab:7f17 with SMTP id 38308e7fff4ca-2f61054a141mr44549391fa.41.1725017651520; Fri, 30 Aug 2024 04:34:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1X8FjCum5BY+FEXev1O67W82OcXjX7YTqbF3pTSjanAiOglSemD3oFnPl7H1IzA59X4xLMw== X-Received: by 2002:a05:651c:b27:b0:2f3:eeab:7f17 with SMTP id 38308e7fff4ca-2f61054a141mr44549071fa.41.1725017650627; Fri, 30 Aug 2024 04:34:10 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c226c72d35sm1910236a12.21.2024.08.30.04.34.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 04:34:10 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv6 09/14] gdb: implement readline rl_directory_rewrite_hook callback Date: Fri, 30 Aug 2024 12:33:49 +0100 Message-Id: <57af3bf38f0b7fb55d2e68f0adf1aa43e5d78322.1725017349.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=-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~public-inbox=simark.ca@sourceware.org Implement the readline rl_directory_rewrite_hook callback function, this is used when readline needs to offer completions from within a directory. The important thing is that this function should remove any escaping, this allows GDB to correctly offer completions in situations like this: (gdb) file /tmp/directory\ with\ spaces/ Note the escaping in 'directory\ with\ spaces'. Without the rl_directory_rewrite_hook callback readline will try to open a directory literally called '/tmp/directory\ with\ spaces' which obviously doesn't exist. There are tests added to cover this new functionality. --- gdb/completer.c | 21 +++++++++++++++++++ .../gdb.base/filename-completion.exp | 12 +++++++++++ 2 files changed, 33 insertions(+) diff --git a/gdb/completer.c b/gdb/completer.c index b0e999ef514..b80649c5260 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -321,6 +321,26 @@ gdb_completer_file_name_dequote (char *filename, int quote_char) return strdup (tmp.c_str ()); } +/* Implement readline's rl_directory_rewrite_hook. Remove any quoting from + the string *DIRNAME,update *DIRNAME, and return non-zero. If *DIRNAME + doesn't need updating then return zero. See readline docs for more + information. */ + +static int +gdb_completer_directory_rewrite (char **dirname) +{ + if (!rl_completion_found_quote) + return 0; + + int quote_char = rl_completion_quote_character; + char *new_dirname + = gdb_completer_file_name_dequote (*dirname, quote_char); + free (*dirname); + *dirname = new_dirname; + + return 1; +} + /* Apply character escaping to the filename in TEXT and return a newly allocated buffer containing the possibly updated filename. @@ -3416,6 +3436,7 @@ _initialize_completer () rl_filename_quote_characters = " \t\n\\\"'"; rl_filename_dequoting_function = gdb_completer_file_name_dequote; rl_filename_quoting_function = gdb_completer_file_name_quote; + rl_directory_rewrite_hook = gdb_completer_directory_rewrite; add_setshow_zuinteger_unlimited_cmd ("max-completions", no_class, &max_completions, _("\ diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp index a4b411c1c67..cf00d007ca7 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -170,6 +170,11 @@ proc run_quoting_and_escaping_tests { root } { set dq "\\\"" } + test_gdb_complete_unique "${cmd} ${qc}${root}/bb2/dir${sp}1/" \ + "${cmd} ${qc}${root}/bb2/dir${sp}1/unique${sp}file${qc}" " " \ + false \ + "expand a unique file name in a directory containing a space" + test_gdb_complete_filename_multiple "$cmd ${qc}${root}/bb2/" \ "d" "ir${sp}" { "dir 1/" @@ -177,6 +182,13 @@ proc run_quoting_and_escaping_tests { root } { } "" "${qc}" false \ "expand multiple directory names containing spaces" + test_gdb_complete_filename_multiple "${cmd} ${qc}${root}/bb2/dir${sp}2/" \ + "f" "ile${sp}" { + "file 1" + "file 2" + } "" "${qc}" false \ + "expand contents of a directory containing a space" + test_gdb_complete_filename_multiple "$cmd ${qc}${root}/aaa/" \ "a" "a${sp}" { "aa bb" -- 2.25.4