From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iAm6BGf0pmXu/j0AWB0awg (envelope-from ) for ; Tue, 16 Jan 2024 16:25:59 -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=VmUdUUzU; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 0E71A1E0C3; Tue, 16 Jan 2024 16:25:59 -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 EE31E1E098 for ; Tue, 16 Jan 2024 16:25:56 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E5DE385841F for ; Tue, 16 Jan 2024 21:25:56 +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 40F953858403 for ; Tue, 16 Jan 2024 21:25:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 40F953858403 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 40F953858403 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=1705440306; cv=none; b=uCoBJHh1giuo6K685eAgflt93y4RoTm1+k2l76VoIaGgUzLw/Nb5WlXcwXY/mFJxK7s5rSZ1/+MpK/z/vMvdE1HlUj8W5TBnh8E8I4jgV35y6vM00LeImyf0vk8/4lGCjFY6z3bwOsh5JkbDYxIpJzusaIivOlpmuU36bdbhlk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705440306; c=relaxed/simple; bh=JVbNlPBio32aEthIcS2hs+QqcznABMkth2XHgpUb4J8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=bA+uQWsDlkGCceEs1bCGGmgdvxFgbc1Y9Gcd91ik4oNTno8fhPNfIgOT3NdLNSbSIq5OmKPyDNoEqwIyAn6LIiyBLqwNL3JtduNRvupXoATXSVnyfNvAsuEhlZCnSSfkd3uIGmsJuvx8RaSZApqvah0gp/bEkcNHYRfJ6eNPprM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705440303; 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=KlU54hTmXmjDLnwG+m5bfWsU9zvUmZ6/kdBSf0NYO5w=; b=VmUdUUzUQetCzpK/ib0HXsuDrNcQp0g+fpdQBEDtoP91dEBJIGuvZvPSEvP1ASttzB52gi SoEpkPxtVbAw1ECCPir5I4p/evmYx/ohblYqMtpkpDY9CFolJ2FvN3kq4hwYqh+IoBuB+w RjsiHnstSnrMnmZALAouLkRvuKrC0dU= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-fTWwdmXePsGAkPHOxbBXNA-1; Tue, 16 Jan 2024 16:24:54 -0500 X-MC-Unique: fTWwdmXePsGAkPHOxbBXNA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-40e46bceed8so72665465e9.0 for ; Tue, 16 Jan 2024 13:24:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705440248; x=1706045048; 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=PnZREqSDuZh4CU8XUPYnCJ0vBIpZv1bx36qnjW/497k=; b=Rw0WxUtObcu4nAP2Sp9Dot0SJUE22sQX2alEV/ufrBuogVhdY0KeInPLf9KIMH9Nez bDFjXh1UEk8OVHNeF3eD8Q5fJz+X2v04IdwPhrMlkGa85GZDvHNd9FjsEjsaBN2iV8vQ Uv/DnZCWErbScFssWi1E5kyZi9K2zAgg8QysQqXIBMx2PD65lJFKyOoPM+wlDBd00zws X1tN9FkWSif+m1V/iaPIHIGz4zzci6X2spa4R2rx9MOZaAPZ9/LTpir7jXSMasCU9E7o joYnnmSP3NLS0Q78mCXJHe/KJTnv2fT/s02eKG838Dwt6yesTf//Eu2s3pEU/3kKURyx G1lA== X-Gm-Message-State: AOJu0YyPWOG8jEnw81SxdM7dz+fp/EtSu9woOnQ4MMZ7T8F55plrEFQf 9/SONvVCsKgTTdKLpIwHWMxIuRFG1lAcWdCTDq9/Ksg5u49gIbOcw/rVE6+r8WKl0ohFyTSBo2Y l78+tZGSiIRy/XWsECrpkDrAeM1gXcsqjE2KLZamfUZQh+ckAz21lRyOFxRqDxA4wLf+Nll1Qzr HXgOeBEcHJgK7H0Q== X-Received: by 2002:a05:600c:17d3:b0:40d:5c7e:6f69 with SMTP id y19-20020a05600c17d300b0040d5c7e6f69mr4319658wmo.147.1705440248110; Tue, 16 Jan 2024 13:24:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpJ/lhMoL9XIoy8heghLoh7bhz1wPq5aHydm8qTi9IalPqwMqmsReIV2hf3LY6D9B/tlx2aw== X-Received: by 2002:a05:600c:17d3:b0:40d:5c7e:6f69 with SMTP id y19-20020a05600c17d300b0040d5c7e6f69mr4319648wmo.147.1705440247525; Tue, 16 Jan 2024 13:24:07 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id z10-20020a05600c0a0a00b0040e486bc0dfsm24634800wmp.27.2024.01.16.13.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 13:24:06 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/5] gdb: fix bug where quote characters would become nullptr Date: Tue, 16 Jan 2024 21:23:59 +0000 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 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 In gdb_completion_word_break_characters_throw, after calling complete_line_internal, if the completion function chose to use a custom word point then we set rl_completer_quote_characters to NULL. However, nowhere do we set rl_completer_quote_characters back to its default value, which is setup in init_main (top.c). An example of something that uses a custom word point for its completion is 'thread apply all ...'. An example of something that relies on rl_completer_quote_characters would be completion of a quoted filename that contains white space. Consider this shell and GDB session. The markers indicate where I've used tab to trigger completion: $ mkdir /tmp/aaa\ bbb $ touch /tmp/aaa\ bbb/xx\ 11 $ touch /tmp/aaa\ bbb/xx\ 22 $ gdb -q (gdb) file '/tmp/aaa bbb/xx xx 11 xx 22 (gdb) thread apply all hel (gdb) thread apply all help (gdb) file '/tmp/aaa bbb/xx First I create a directory structure which uses white space within file and directory names. Then within GDB I use the 'file' command and use a single quote to quote the filename. When I tab complete GDB correctly offers the two files within the directory '/tmp/aaa bbb/'. This works because rl_completer_quote_characters contains the single quote, and so readline knows that it is trying to complete the string that starts after the single quote: /tmp/aaa bbb/xx Next I invoke the completer for the 'thread apply all' command, to do this I type 'thread apply all hel' and hit tab, this expands to the one completion 'thread apply all help'. We can run this command or not, it doesn't matter (there are no threads, so we'll get no output). Now I repeat the original 'file' completion. This time though I don't get offered any completions. The reason is that the 'thread apply all' completer set rl_completer_quote_characters to nullptr. Now, when readline tries to figure out the word to complete it doesn't see the single quote as the start of a quoted word, so instead readline falls back to the word break characters, and in this case spots the white space. As a result readline tries to complete the string 'bbb/xx' which obviously doesn't have any completions. By setting rl_completer_quote_characters each time completion is invoked this problem is resolved and the second 'file' command completes as expected. I've extended gdb.base/filename-completion.exp to also test with quoted filenames, and added a 'thread apply all' completion at the start to expose this bug. As setting of rl_completer_quote_characters is now all done in the completer.c file the function get_gdb_completer_quote_characters() could be made static. However, as this function is only used one time to initialise rl_completer_quote_characters, I've instead just deleted get_gdb_completer_quote_characters() and used gdb_completer_quote_characters directly. --- gdb/completer.c | 10 +-- gdb/completer.h | 2 - .../gdb.base/filename-completion.exp | 66 +++++++++++++------ gdb/top.c | 1 - 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 8168f79de0e..44da6548eb4 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -181,13 +181,6 @@ static const char gdb_completer_file_name_break_characters[] = sequences as strings. */ static const char gdb_completer_quote_characters[] = "'"; -/* Accessor for some completer data that may interest other files. */ - -const char * -get_gdb_completer_quote_characters (void) -{ - return gdb_completer_quote_characters; -} /* This can be used for functions which don't want to complete on symbols but don't want to complete on anything else either. */ @@ -1269,6 +1262,9 @@ 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; + /* Decide whether to complete on a list of gdb commands or on symbols. */ tmp_command = (char *) alloca (point + 1); diff --git a/gdb/completer.h b/gdb/completer.h index f604a95011f..0a95ced8a80 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -619,8 +619,6 @@ extern void reggroup_completer (struct cmd_list_element *, completion_tracker &tracker, const char *, const char *); -extern const char *get_gdb_completer_quote_characters (void); - extern char *gdb_completion_word_break_characters (void); /* Set the word break characters array to BREAK_CHARS. This function diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp index 20ca227f96d..7d8ab1a3350 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -37,6 +37,9 @@ proc setup_directory_tree {} { remote_exec host "mkdir -p ${root}/cc1" remote_exec host "touch ${root}/cc2" + remote_exec host "touch \"${root}/aaa/aa bb\"" + remote_exec host "touch \"${root}/aaa/aa cc\"" + return $root } @@ -45,26 +48,49 @@ proc setup_directory_tree {} { # sub-directory of the user's home directory ROOT might have been # modified to replace the $HOME prefix with a single "~" character. proc run_tests { root } { - test_gdb_complete_none "file ${root}/xx" \ - "expand a non-existent filename" - - test_gdb_complete_unique "file ${root}/a" \ - "file ${root}/aaa/" "" false \ - "expand a unique filename" - - test_gdb_complete_multiple "file ${root}/" \ - "b" "b" { - "bb1/" - "bb2/" - } "" "" false \ - "expand multiple directory names" - - test_gdb_complete_multiple "file ${root}/" \ - "c" "c" { - "cc1/" - "cc2" - } "" "" false \ - "expand mixed directory and file names" + + # Completing 'thread apply all ...' commands uses a custom word + # point. At one point we had a bug where doing this would break + # completion of quoted filenames that contained white space. + test_gdb_complete_unique "thread apply all hel" \ + "thread apply all help" " " false \ + "complete a 'thread apply all' command" + + foreach_with_prefix qc [list "" "'"] { + test_gdb_complete_none "file ${qc}${root}/xx" \ + "expand a non-existent filename" + + test_gdb_complete_unique "file ${qc}${root}/a" \ + "file ${qc}${root}/aaa/" "" false \ + "expand a unique filename" + + test_gdb_complete_multiple "file ${qc}${root}/" \ + "b" "b" { + "bb1/" + "bb2/" + } "" "${qc}" false \ + "expand multiple directory names" + + test_gdb_complete_multiple "file ${qc}${root}/" \ + "c" "c" { + "cc1/" + "cc2" + } "" "${qc}" false \ + "expand mixed directory and file names" + + # GDB does not currently escape word break characters + # (e.g. white space) correctly in unquoted filenames. + if { $qc ne "" } { + set sp " " + + test_gdb_complete_multiple "file ${qc}${root}/aaa/" \ + "a" "a${sp}" { + "aa bb" + "aa cc" + } "" "${qc}" false \ + "expand filenames containing spaces" + } + } } gdb_start diff --git a/gdb/top.c b/gdb/top.c index fb15c719564..543d6cdfbc0 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -2150,7 +2150,6 @@ init_main (void) rl_completion_word_break_hook = gdb_completion_word_break_characters; rl_attempted_completion_function = gdb_rl_attempted_completion_function; set_rl_completer_word_break_characters (default_word_break_characters ()); - rl_completer_quote_characters = get_gdb_completer_quote_characters (); rl_completion_display_matches_hook = cli_display_match_list; rl_readline_name = "gdb"; rl_terminal_name = getenv ("TERM"); -- 2.25.4