From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 31CBB3858D33; Mon, 25 Mar 2024 18:29:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31CBB3858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1711391389; bh=3MtjLqrAd7znQsKNjWk5xxbU/P+IF2QchH6MVIyjxNY=; h=From:To:Subject:Date:From; b=AnkwQWJfBPTpVdn20hwzPGp+/nDFbOTdpHE64RDlK0EgkGI7N/l/m4snaRo9RRErd BZ2ICbvC/f6a/Utpq6biktInBl2pO++Goz0sZ9gVDZADftQKhTYeuIbgz/Vt7VFQ7f rj+wgyc0XGdKylRrV8fKg8D8E64R7J7qckS7sWzo= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: allow double quotes for quoting filenames X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 5792be924413fcd2195242d87252857b888086dd X-Git-Newrev: 4f440ff33d1cf8812d4f652f6fddbfa3d117268e Message-Id: <20240325182949.31CBB3858D33@sourceware.org> Date: Mon, 25 Mar 2024 18:29:47 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D4f440ff33d1c= f8812d4f652f6fddbfa3d117268e commit 4f440ff33d1cf8812d4f652f6fddbfa3d117268e Author: Andrew Burgess Date: Tue Jan 16 12:21:52 2024 +0000 gdb: allow double quotes for quoting filenames =20 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. =20 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. =20 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. =20 The testing has been extended to cover double quotes in addition to the existing single quote testing. =20 This change does a number of things: =20 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, =20 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, =20 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_chara= cters[] =3D " \t\n*|\"';:?><"; #endif =20 -/* 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[] =3D "'"; +static const char gdb_completer_expression_quote_characters[] =3D "'"; + +/* 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[] =3D "'\""; =0C =20 /* 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 =3D gdb_completer_file_name_quote_characte= rs; =20 - subsequent_name =3D 0; + int subsequent_name =3D 0; while (1) { gdb::unique_xmalloc_ptr p_rl @@ -256,6 +261,8 @@ filename_completer_handle_brkchars (struct cmd_list_ele= ment *ignore, { set_rl_completer_word_break_characters (gdb_completer_file_name_break_characters); + + rl_completer_quote_characters =3D gdb_completer_file_name_quote_characte= rs; } =20 /* 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; =20 info.word_break_characters =3D word_break_characters; - info.quote_characters =3D gdb_completer_quote_characters; + info.quote_characters =3D quote_characters; info.basic_quote_characters =3D rl_basic_quote_characters; =20 int delimiter; @@ -431,7 +439,8 @@ advance_to_expression_complete_word_point (completion_t= racker &tracker, const char *text) { const char *brk_chars =3D current_language->word_break_characters (); - return advance_to_completion_word (tracker, brk_chars, text); + const char *quote_chars =3D gdb_completer_expression_quote_characters; + return advance_to_completion_word (tracker, brk_chars, quote_chars, text= ); } =20 /* See completer.h. */ @@ -441,7 +450,8 @@ advance_to_filename_complete_word_point (completion_tra= cker &tracker, const char *text) { const char *brk_chars =3D gdb_completer_file_name_break_characters; - return advance_to_completion_word (tracker, brk_chars, text); + const char *quote_chars =3D gdb_completer_file_name_quote_characters; + return advance_to_completion_word (tracker, brk_chars, quote_chars, text= ); } =20 /* See completer.h. */ @@ -1262,8 +1272,10 @@ complete_line_internal_1 (completion_tracker &tracke= r, set_rl_completer_word_break_characters (current_language->word_break_characters ()); =20 - /* Likewise for the quote characters. */ - rl_completer_quote_characters =3D 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 =3D gdb_completer_expression_quote_charact= ers; =20 /* 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; =20 info.word_break_characters =3D rl_completer_word_break_characters; - info.quote_characters =3D gdb_completer_quote_characters; + info.quote_characters =3D rl_completer_quote_characters; info.basic_quote_characters =3D rl_basic_quote_characters; =20 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" =20 - foreach_with_prefix qc [list "" "'"] { + foreach_with_prefix qc [list "" "'" "\""] { test_gdb_complete_none "file ${qc}${root}/xx" \ "expand a non-existent filename"