From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +PCXC3WwhmY/PxsAWB0awg (envelope-from ) for ; Thu, 04 Jul 2024 10:23:49 -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=Oq4YM5Kw; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 299A21E0C3; Thu, 4 Jul 2024 10:23:49 -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 059731E030 for ; Thu, 4 Jul 2024 10:23:47 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5BACE384A44A for ; Thu, 4 Jul 2024 14:23:46 +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 7F958384A45A for ; Thu, 4 Jul 2024 14:21:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F958384A45A 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 7F958384A45A 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=1720102896; cv=none; b=B7mt0s2CnEHn0wb1XP0lCbAmz6hVW+tB2qddlqoMKhNJePoitkngKpdhnuhJ30r5ckalUZoytVLxW9IBJs8KWH07dgZM0wGb0vaC+V9mUSpzkzNyyISq+8ZSfxXmgP7wD1uO++J5xqnit1iAxJlD3YvfbH51mGZ/zeTknC3Br7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720102896; c=relaxed/simple; bh=gc7CF8aqrfSljFS3I/XtZE0s2W20VlQKZlJYMgKbG5Y=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=pEhsADlK4BH+0IA867W+kxJxrvOkJ0Gvky4yRucT5TUmQlvT4g3afh2wWyWlFExl+mMssbJlfJTPb0rOpfJFS64dJ9teTfCLcq62TkeXGdTHfanSRkremdmdl3JTOyMH7yY/JU2257A4oiWz0kEcKOfLtMo14PR1ymnTJi6/ZUc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720102894; 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=Oq4YM5KwiY3cs136PJtgiGS7SfAX1V+srmmu0RGKogZBFRBk5CGpL47wSyqWeOIyUYLjJ1 t5j4piuM3sh8E+MTuHTtEQfYtlCK9ihJ64CMi/V/sKhoDZeXnak4Se6UsE3sisFgORu+1d dQtkjfSuwpA7Q8vlTOH6BNhbWxmQd+0= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-148-zSRnO1tqOT-GPfq3fVKbvg-1; Thu, 04 Jul 2024 10:21:32 -0400 X-MC-Unique: zSRnO1tqOT-GPfq3fVKbvg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4257f95fe85so5141585e9.1 for ; Thu, 04 Jul 2024 07:21:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720102891; x=1720707691; 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=Fewv7w9Cz48hnQXsKWstsYGG/b1xR3B98xcWdJ4tFg1VKHiHC8hoR8YuPcoUIZWy4r L9j7dfUrkBNiPiV2+9ZJcLCrhN21mN9p+37TC7Tioy/r9A4myjVv2EFVVRMWJYZyaDIz LLLNaK/IAw4xPLsZxgQ017NKkbsEESBoLWNVsXTMD4jhEEF9LQEOiDKIfz6mHV2H0GU6 8QRTnoNAJjWz6M2qsd7a2WZHbTJnzSZH181I4gKLwQZlBOKENaeK24u52AVu50EjAKmf y2NMQewU55XTpwmNzPxyvMRoWH4s6DoEPQRa/RMDcu/1c+5aX3/fN60/rGeOoRu+J0wX JCsg== X-Gm-Message-State: AOJu0Yxi9V14oOCVW1zq45zApgySI1EWO55kevd7Qt0xekmHkRu193zA M2ZejYOzs+mJ1ay5Apxi7WrFWMKI5QKpBByNF0CbmWC0r6yR3ucDnIDiUdD0wh5lQKrBxGOhHp+ UvZmP9uD9MKsDje2QI4d09QvpdUDZ1NN1/mWv6fM19X2tGGg8OIUZTAzjXApSbahlfT1n7lro9a KM9X8/MGvWgN06+pYhbsj+Dtq1GVBZ4NhvuiH0m3qyK00= X-Received: by 2002:a05:600c:21c8:b0:425:5a26:a12c with SMTP id 5b1f17b1804b1-4264a3e1cb5mr12758095e9.13.1720102890846; Thu, 04 Jul 2024 07:21:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHY3m0XK+NEUsGVVYkVID0Q2RDQPxv58cFyQOQZ1RfE2IpvSrQ/4/qkWQolSw6AeWYtUUnvAg== X-Received: by 2002:a05:600c:21c8:b0:425:5a26:a12c with SMTP id 5b1f17b1804b1-4264a3e1cb5mr12757925e9.13.1720102890515; Thu, 04 Jul 2024 07:21:30 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4264a1d1650sm27160705e9.2.2024.07.04.07.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 07:21:28 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv4 09/14] gdb: implement readline rl_directory_rewrite_hook callback Date: Thu, 4 Jul 2024 15:21:04 +0100 Message-Id: <4fa1ad1a88e5e025e710745eb5ae456b8f0ae884.1720101827.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.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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~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