From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 9A09E38449C8 for ; Tue, 20 Aug 2024 17:10:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A09E38449C8 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 9A09E38449C8 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=1724173854; cv=none; b=LPQm26893o5Babz5b3vEbCxlz/OoH0a9q6VN6UVSA3HmNv4wM8wLf/ZYSrz6px7Xuwfe+No1hZ8dHkO69nPfX6TV8UkcIsCiQ1b8nfLmcjNN2wPJtwK+HTvwCweWy+aYJgVPuwOmmYvcqiCzsZMezL3yMipqmus74L2K5yLAM74= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724173854; c=relaxed/simple; bh=WsIcto8Pw324T4As0v9L7iEr2pbRU2xvMhfslkuosM0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=DurHRH+ULwsm12waheYjgG0IPhmKtbBjMgdjeHqwcVBk7dvRNnY0jGNGztqFuS6NFgg4s5t96qA0bRkUuW9K4k8DnF2sbz5NiUkykKQWswtOHt+vHfWb5r9u4REyMgWXfHju0QcR6gDNUyJ+MBuJ7CaZQ8nlL4wq11yOZpiaIng= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724173851; 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=lq4kkaOolZR8dybAnTrQRt4t1JTHKg2/oMlyN1e0HuE=; b=Vs5Rpo6scJBpDxUG5RTLDNbH1FhbYrD1wWcvKfQaZyI+cTUb9K9jn7QY8Pmko185WL9VMC lmrHtbbPObmPJemxezUoE3mSOgauJggfq0/0UfPAsnS8DAb1n2Iw9fySEUa/+bgCvD5Yf5 +iapKFN5eFlB/yT80sP8wh0qyoBSdMA= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-CpCccBQJPyeMJAWZLg_DQg-1; Tue, 20 Aug 2024 13:10:50 -0400 X-MC-Unique: CpCccBQJPyeMJAWZLg_DQg-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3717cc80ce1so3550819f8f.0 for ; Tue, 20 Aug 2024 10:10:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724173848; x=1724778648; 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=lq4kkaOolZR8dybAnTrQRt4t1JTHKg2/oMlyN1e0HuE=; b=lC6VULubZVDPcwEswFy1bSXhE+dNsn9OBY5kl9NerEwopkWqtJjSDVUELPgXHKUh4e x83og419PmfDCZkrW9EsqdUu3CyuAyf0BXGpfHDDXZfvVWQaLkdc5MSz/P5ocUJPdtZj PJZY/Rlnxh5KQcF0332anPqQy+wNKcCMVsHrFvCU5ZUXunQ4YfCGzn/0nCkCjF6VKf0D PNqUe6iJU+kwlVxpG4LTJgFSk9bTXtTamu2Oe3HD/FsLhLltzIjmi7r0k6I8Sea/FX6u HApzUQoGgULgbCeU+8ctNJZc550v0+Yo9Id2YCVXdX9yyPO8gmLnVHBLVRmQ6HdaRq3z u73A== X-Gm-Message-State: AOJu0Yxu1U9yVqna96RlAazbwr8msASRic3rtphIIlfu/Ejl5IEEJ9D3 dCa+IFMEiU1n70iXK5bhTLQiC95fxx3e+fWGCzOEZ2FxrBcgRWsWshpZTTpqUYyR9FST6aALC/A LtmIJ3Zbl0RECSGTcfLmNVg4isZ8QIiIQvLEqiQr/pkjMZ8LA94vrMfarBOpMtPW1kiHptkYQp+ Mg3mz28GuQdGxL05pFfqLtpjwZigRudevXN4y7oxoXraw= X-Received: by 2002:a5d:404c:0:b0:371:8341:d589 with SMTP id ffacd0b85a97d-37194316ac0mr12984959f8f.12.1724173848033; Tue, 20 Aug 2024 10:10:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHi3Mtvb6lZyIeipSb2F2i12W/fE19fp/D4AULcEqc/py1UYt8MlEiva9YDIXIv5U2vfki+gw== X-Received: by 2002:a5d:404c:0:b0:371:8341:d589 with SMTP id ffacd0b85a97d-37194316ac0mr12984910f8f.12.1724173846742; Tue, 20 Aug 2024 10:10:46 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-371898ac074sm13529575f8f.106.2024.08.20.10.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 10:10:46 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv5 01/14] gdb: split apart two different types of filename completion Date: Tue, 20 Aug 2024 18:10:31 +0100 Message-Id: <952b55483af16f9633d78b30626469ef0a1a2030.1724173728.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_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 List-Id: Unfortunately we have two different types of filename completion in GDB. The majority of commands have what I call unquoted filename completion, this is for commands like 'set logging file ...', 'target core ...', and 'add-auto-load-safe-path ...'. For these commands everything after the command name (that is not a command option) is treated as a single filename. If the filename contains white space then this does not need to be escaped, nor does the filename need to be quoted. In fact, the filename argument is not de-quoted, and does not have any escaping removed, so if a user does try to add such things, they will be treated as part of the filename. As an example: (gdb) target core "/path/that contains/some white space" Will look for a directory calls '"' (double quotes) in the local directory. A small number of commands do de-quote and remove escapes from filename arguments. These command accept what I call quoted and escaped filenames. Right now these are the commands that specify the file for GDB to debug, so: file exec-file symbol-file add-symbol-file remove-symbol-file As an example of this in action: (gdb) file "/path/that contains/some white space" In this case GDB would load the file: /path/that contains/some white space Current filename completion always assumes that filenames can be quoted, though escaping doesn't work in completion right now. But the assumption that quoting is allowed is clearly wrong. This commit splits filename completion into two. The existing filename_completer is retained, and is used for unquoted filenames. A second filename_maybe_quoted_completer is added which can be used for completing quoted filenames. The filename completion test has been extended to cover more cases. As part of the extended testing I need to know the character that should be used to separate filenames within a path. For this TCL 8.6+ has $::tcl_platform(pathSeparator). To support older versions of TCL I've added some code to testsuite/lib/gdb.exp. You might notice that after this commit the completion for unquoted files is all done in the brkchars phase, that is the function filename_completer_handle_brkchars calculates the completions and marks the completion_tracker as using a custom word point. The reason for this is that we don't want to break on white space for this completion, but if we rely on readline to find the completion word, readline will consider the entire command line, and with no white space in the word break character set, readline will end up using the entire command line as the word to complete. For now at least, the completer for quoted filenames does generate its completions during the completion phase, though this is going to change in a later commit. --- gdb/completer.c | 86 +++++-- gdb/completer.h | 24 +- gdb/exec.c | 4 +- gdb/guile/scm-cmd.c | 2 +- gdb/python/py-cmd.c | 2 +- gdb/symfile.c | 4 +- .../gdb.base/filename-completion.exp | 209 ++++++++++++++---- gdb/testsuite/lib/gdb.exp | 10 + 8 files changed, 269 insertions(+), 72 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 1008ec23ba5..93eb8db6db0 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -182,6 +182,17 @@ static const char gdb_completer_file_name_break_characters[] = " \t\n*|\"';:?><"; #endif +/* When completing on file names, for commands that don't accept quoted + file names, the only character that can be used as a word separator is + the path separator. Every other character is treated as a literal + character within the filename. */ +static const char gdb_completer_path_break_characters[] = +#ifdef HAVE_DOS_BASED_FILE_SYSTEM + ";"; +#else + ":"; +#endif + /* 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. */ @@ -203,15 +214,15 @@ noop_completer (struct cmd_list_element *ignore, { } -/* Complete on filenames. */ +/* Generate filename completions of WORD, storing the completions into + TRACKER. This is used for generating completions for commands that + only accept unquoted filenames as well as for commands that accept + quoted and escaped filenames. */ -void -filename_completer (struct cmd_list_element *ignore, - completion_tracker &tracker, - const char *text, const char *word) +static void +filename_completer_generate_completions (completion_tracker &tracker, + const char *word) { - rl_completer_quote_characters = gdb_completer_file_name_quote_characters; - int subsequent_name = 0; while (1) { @@ -249,13 +260,13 @@ filename_completer (struct cmd_list_element *ignore, } } -/* The corresponding completer_handle_brkchars - implementation. */ +/* The brkchars callback used when completing filenames that can be + quoted. */ static void -filename_completer_handle_brkchars (struct cmd_list_element *ignore, - completion_tracker &tracker, - const char *text, const char *word) +filename_maybe_quoted_completer_handle_brkchars + (struct cmd_list_element *ignore, completion_tracker &tracker, + const char *text, const char *word) { set_rl_completer_word_break_characters (gdb_completer_file_name_break_characters); @@ -263,6 +274,50 @@ filename_completer_handle_brkchars (struct cmd_list_element *ignore, rl_completer_quote_characters = gdb_completer_file_name_quote_characters; } +/* Complete on filenames. This is for commands that accepts possibly + quoted filenames. */ + +void +filename_maybe_quoted_completer (struct cmd_list_element *ignore, + completion_tracker &tracker, + const char *text, const char *word) +{ + filename_maybe_quoted_completer_handle_brkchars (ignore, tracker, + text, word); + filename_completer_generate_completions (tracker, word); +} + +/* The brkchars callback used by commands that don't accept quoted + filenames. */ + +static void +filename_completer_handle_brkchars + (struct cmd_list_element *ignore, completion_tracker &tracker, + const char *text, const char *word) +{ + gdb_assert (word == nullptr); + + set_rl_completer_word_break_characters (gdb_completer_path_break_characters); + rl_completer_quote_characters = nullptr; + rl_filename_quoting_desired = 0; + + tracker.set_use_custom_word_point (true); + word = advance_to_filename_complete_word_point (tracker, text); + filename_completer (ignore, tracker, text, word); +} + +/* See completer.h. */ + +void +filename_completer + (struct cmd_list_element *ignore, completion_tracker &tracker, + const char *text, const char *word) +{ + gdb_assert (tracker.use_custom_word_point ()); + gdb_assert (word != nullptr); + filename_completer_generate_completions (tracker, word); +} + /* Find the bounds of the current word for completion purposes, and return a pointer to the end of the word. This mimics (and is a modified version of) readline's _rl_find_completion_word internal @@ -447,8 +502,8 @@ const char * advance_to_filename_complete_word_point (completion_tracker &tracker, const char *text) { - const char *brk_chars = gdb_completer_file_name_break_characters; - const char *quote_chars = gdb_completer_file_name_quote_characters; + const char *brk_chars = gdb_completer_path_break_characters; + const char *quote_chars = nullptr; return advance_to_completion_word (tracker, brk_chars, quote_chars, text); } @@ -1880,6 +1935,9 @@ completer_handle_brkchars_func_for_completer (completer_ftype *fn) if (fn == filename_completer) return filename_completer_handle_brkchars; + if (fn == filename_maybe_quoted_completer) + return filename_maybe_quoted_completer_handle_brkchars; + if (fn == location_completer) return location_completer_handle_brkchars; diff --git a/gdb/completer.h b/gdb/completer.h index 98a12f3907c..c6d064ec9d6 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -563,9 +563,10 @@ extern completion_result const char *advance_to_expression_complete_word_point (completion_tracker &tracker, const char *text); -/* Assuming TEXT is an filename, find the completion word point for - TEXT, emulating the algorithm readline uses to find the word - point. */ +/* Assuming TEXT is a filename, find the completion word point for TEXT, + emulating the algorithm readline uses to find the word point. The + filenames that are located by this function assume no filename + quoting, this function should be paired with filename_completer. */ extern const char *advance_to_filename_complete_word_point (completion_tracker &tracker, const char *text); @@ -573,10 +574,27 @@ extern void noop_completer (struct cmd_list_element *, completion_tracker &tracker, const char *, const char *); +/* Filename completer for commands that don't accept quoted filenames. + This completer does support completing a list of filenames that are + separated with the path separator (':' for UNIX and ';' for MS-DOS). + + When adding a new command it is better to write the command so it + accepts quoted filenames and use filename_maybe_quoted_completer, for + examples see the 'exec' and 'exec-file' commands. */ + extern void filename_completer (struct cmd_list_element *, completion_tracker &tracker, const char *, const char *); +/* Filename completer for commands where the filename argument can be + quoted. This completer also supports completing a list of filenames + that are separated with the path separator (':' for UNIX and ';' for + MS-DOS). */ + +extern void filename_maybe_quoted_completer (struct cmd_list_element *, + completion_tracker &tracker, + const char *, const char *); + extern void expression_completer (struct cmd_list_element *, completion_tracker &tracker, const char *, const char *); diff --git a/gdb/exec.c b/gdb/exec.c index 63eee4297bc..f30ed62e4b3 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -1074,14 +1074,14 @@ and it is the program executed when you use the `run' command.\n\ If FILE cannot be found as specified, your execution directory path\n\ ($PATH) is searched for a command of that name.\n\ No arg means to have no executable file and no symbols."), &cmdlist); - set_cmd_completer (c, filename_completer); + set_cmd_completer (c, filename_maybe_quoted_completer); c = add_cmd ("exec-file", class_files, exec_file_command, _("\ Use FILE as program for getting contents of pure memory.\n\ If FILE cannot be found as specified, your execution directory path\n\ is searched for a command of that name.\n\ No arg means have no executable file."), &cmdlist); - set_cmd_completer (c, filename_completer); + set_cmd_completer (c, filename_maybe_quoted_completer); add_com ("section", class_files, set_section_command, _("\ Change the base address of section SECTION of the exec file to ADDR.\n\ diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c index 2a5507686b0..8255529a2fe 100644 --- a/gdb/guile/scm-cmd.c +++ b/gdb/guile/scm-cmd.c @@ -110,7 +110,7 @@ struct cmdscm_completer static const struct cmdscm_completer cmdscm_completers[] = { { "COMPLETE_NONE", noop_completer }, - { "COMPLETE_FILENAME", filename_completer }, + { "COMPLETE_FILENAME", filename_maybe_quoted_completer }, { "COMPLETE_LOCATION", location_completer }, { "COMPLETE_COMMAND", command_completer }, { "COMPLETE_SYMBOL", symbol_completer }, diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c index f83b45dd210..4deeb35eba0 100644 --- a/gdb/python/py-cmd.c +++ b/gdb/python/py-cmd.c @@ -39,7 +39,7 @@ struct cmdpy_completer static const struct cmdpy_completer completers[] = { { "COMPLETE_NONE", noop_completer }, - { "COMPLETE_FILENAME", filename_completer }, + { "COMPLETE_FILENAME", filename_maybe_quoted_completer }, { "COMPLETE_LOCATION", location_completer }, { "COMPLETE_COMMAND", command_completer }, { "COMPLETE_SYMBOL", symbol_completer }, diff --git a/gdb/symfile.c b/gdb/symfile.c index cf7ab0b94e6..c3cd961c0b9 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3814,7 +3814,7 @@ Usage: symbol-file [-readnow | -readnever] [-o OFF] FILE\n\ OFF is an optional offset which is added to each section address.\n\ The `file' command can also load symbol tables, as well as setting the file\n\ to execute.\n" READNOW_READNEVER_HELP), &cmdlist); - set_cmd_completer (c, filename_completer); + set_cmd_completer (c, filename_maybe_quoted_completer); c = add_cmd ("add-symbol-file", class_files, add_symbol_file_command, _("\ Load symbols from FILE, assuming FILE has been dynamically loaded.\n\ @@ -3828,7 +3828,7 @@ OFF is an optional offset which is added to the default load addresses\n\ of all sections for which no other address was specified.\n" READNOW_READNEVER_HELP), &cmdlist); - set_cmd_completer (c, filename_completer); + set_cmd_completer (c, filename_maybe_quoted_completer); c = add_cmd ("remove-symbol-file", class_files, remove_symbol_file_command, _("\ diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp index b700977cec5..37629bfbf77 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -23,8 +23,16 @@ load_lib completion-support.exp # # root/ [ DIRECTORY ] # aaa/ [ DIRECTORY ] +# aa bb [ FILE ] +# aa cc [ FILE ] +# aaa/ [ DIRECTORY ] # bb1/ [ DIRECTORY ] # bb2/ [ DIRECTORY ] +# dir 1/ [ DIRECTORY ] +# unique file [ FILE ] +# dir 2/ [ DIRECTORY ] +# file 1 [ FILE ] +# file 2 [ FILE ] # cc1/ [ DIRECTORY ] # cc2 [ FILE ] proc setup_directory_tree {} { @@ -36,68 +44,170 @@ proc setup_directory_tree {} { remote_exec host "mkdir -p ${root}/bb2" 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\"" + remote_exec host "mkdir -p \"${root}/bb2/dir 1\"" + remote_exec host "mkdir -p \"${root}/bb2/dir 2\"" + remote_exec host "touch \"${root}/bb2/dir 1/unique file\"" + remote_exec host "touch \"${root}/bb2/dir 2/file 1\"" + remote_exec host "touch \"${root}/bb2/dir 2/file 2\"" return $root } -# Run filename completetion tests. ROOT is the base directory as -# returned from setup_directory_tree, though, if ROOT is a -# 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 } { - - # 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" +# Run filename completetion tests for those command that accept quoting and +# escaping of the filename argument. +# +# ROOT is the base directory as returned from setup_directory_tree, though, +# if ROOT is a sub-directory of the user's home directory ROOT might have +# been modified to replace the $HOME prefix with a single "~" character. +proc run_quoting_and_escaping_tests { root } { + # Test all the commands which allow quoting of filenames, and + # which require whitespace to be escaped in unquoted filenames. + foreach_with_prefix cmd { file exec-file symbol-file add-symbol-file } { + gdb_start + + # 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 "$cmd ${qc}${root}/xx" \ + "expand a non-existent filename" + + test_gdb_complete_unique "$cmd ${qc}${root}/a" \ + "$cmd ${qc}${root}/aaa/" "" false \ + "expand a unique filename" + + test_gdb_complete_multiple "$cmd ${qc}${root}/" \ + "b" "b" { + "bb1/" + "bb2/" + } "" "${qc}" false \ + "expand multiple directory names" + + test_gdb_complete_multiple "$cmd ${qc}${root}/" \ + "c" "c" { + "cc1/" + "cc2" } "" "${qc}" false \ - "expand filenames containing spaces" + "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 "$cmd ${qc}${root}/aaa/" \ + "a" "a${sp}" { + "aa bb" + "aa cc" + } "" "${qc}" false \ + "expand filenames containing spaces" + } } + + gdb_exit } } -gdb_start +# Helper for run_unquoted_tests. ROOT is the root directory as setup +# by setup_directory_tree. CMD is the GDB command to test. PREFIX is +# a possible prefix filename to prepend to the filename being +# completed. +proc run_unquoted_tests_core { root cmd { prefix "" } } { + gdb_start + + if { $prefix != "" } { + # Platform specific path separator (':' on UNIX, ';' on MS-DOS). + set pathsep $::tcl_platform(pathSeparator) + + set prefix ${prefix}${pathsep} + } + + test_gdb_complete_none "$cmd ${prefix}${root}${root}/xx" \ + "expand a non-existent filename" + + test_gdb_complete_unique "$cmd ${prefix}${root}/a" \ + "$cmd ${prefix}${root}/aaa/" "" false \ + "expand a unique filename" + + test_gdb_complete_unique "$cmd ${prefix}${root}/bb2/dir 1/uni" \ + "$cmd ${prefix}${root}/bb2/dir 1/unique file" " " false \ + "expand a unique filename containing whitespace" + + test_gdb_complete_multiple "$cmd ${prefix}${root}/" \ + "b" "b" { + "bb1/" + "bb2/" + } "" "" false \ + "expand multiple directory names" + + test_gdb_complete_multiple "$cmd ${prefix}${root}/" \ + "c" "c" { + "cc1/" + "cc2" + } "" "" false \ + "expand mixed directory and file names" + + test_gdb_complete_multiple "$cmd ${prefix}${root}/aaa/" \ + "a" "a " { + "aa bb" + "aa cc" + } "" "" false \ + "expand filenames containing spaces" + + test_gdb_complete_multiple "$cmd ${prefix}${root}/bb2/dir 2/" \ + "fi" "le " { + "file 1" + "file 2" + } "" "" false \ + "expand filenames containing spaces in path" + + gdb_exit +} + + +# Run filename completetion tests for a sample of commands that take an +# unquoted, unescaped filename as an argument. Only a sample of commands +# are (currently) tested as there's a lot of commands that accept this style +# of filename argument. +# +# ROOT is the base directory as returned from setup_directory_tree, though, +# if ROOT is a sub-directory of the user's home directory ROOT might have +# been modified to replace the $HOME prefix with a single "~" character. +proc run_unquoted_tests { root } { + # Test all the commands which allow quoting of filenames, and + # which require whitespace to be escaped in unquoted filenames. + foreach_with_prefix cmd { "maint print c-tdesc" "set logging file" \ + "target core" "add-auto-load-safe-path" } { + run_unquoted_tests_core $root $cmd + } + + foreach prefix [list \ + "${root}/bb2/dir 1" \ + "${root}/bb2/dir 1/unique file" \ + "${root}/cc1" \ + "${root}/cc2"] { + + # Don't use the full path in the test name, just use the + # part after the ROOT directory. + set id [string range $prefix [string length ${root}] end] + with_test_prefix "prefix=$id" { + foreach_with_prefix cmd { "add-auto-load-safe-path" "path" } { + run_unquoted_tests_core $root $cmd $prefix + } + } + } +} set root [setup_directory_tree] -run_tests $root +run_quoting_and_escaping_tests $root +run_unquoted_tests $root # This test relies on using the $HOME directory. We could make this # work for remote hosts, but right now, this isn't supported. @@ -114,7 +224,8 @@ if {![is_remote host]} { with_test_prefix "with tilde" { # And rerun the tests. - run_tests $tilde_root + run_quoting_and_escaping_tests $tilde_root + run_unquoted_tests $tilde_root } } } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 1c49b6a36d7..c0b91c2e850 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -1697,6 +1697,16 @@ if { [tcl_version_at_least 8 6] == 0 } { return $res } + + # ::tcl_platform(pathSeparator) was added in 8.6. + switch $::tcl_platform(platform) { + windows { + set ::tcl_platform(pathSeparator) ; + } + default { + set ::tcl_platform(pathSeparator) : + } + } } if { [tcl_version_at_least 8 6 2] == 0 } { -- 2.25.4