public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb: allow double quotes for quoting filenames
@ 2024-03-25 18:29 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2024-03-25 18:29 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4f440ff33d1cf8812d4f652f6fddbfa3d117268e

commit 4f440ff33d1cf8812d4f652f6fddbfa3d117268e
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Tue Jan 16 12:21:52 2024 +0000

    gdb: allow double quotes for quoting filenames
    
    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.

Diff:
---
 gdb/completer.c                                | 34 +++++++++++++++++---------
 gdb/testsuite/gdb.base/filename-completion.exp |  2 +-
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/gdb/completer.c b/gdb/completer.c
index 44da6548eb4..cefac605a33 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -176,10 +176,15 @@ static const char gdb_completer_file_name_break_characters[] =
   " \t\n*|\"';:?><";
 #endif
 
-/* Characters that can be used to quote completion strings.  Note that
-   we can't include '"' because the gdb C parser treats such quoted
+/* 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.  */
-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 not passed through the C
+   expression parser.  */
+static const char gdb_completer_file_name_quote_characters[] = "'\"";
 \f
 
 /* 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<char> 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"

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-25 18:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-25 18:29 [binutils-gdb] gdb: allow double quotes for quoting filenames Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).