Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv2 1/7] gdb: remove skip_quoted and skip_quoted_chars
Date: Wed,  6 Mar 2024 10:23:33 +0000	[thread overview]
Message-ID: <eb65c21093f6bb25665a5f4b7ea2d8351d280235.1709720449.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1709720449.git.aburgess@redhat.com>

The function skip_quoted_chars (completer.c) is only used by
skip_quoted (also completer.c), so could be made static.  The function
skip_quoted just calls directly to skip_quoted_chars but fills in some
default arguments.

The function skip_quoted is only used by the Pascal expression parser,
and is only used in one place.

The skip_quoted_chars function skips a single string; it either looks
for a string between matching quotes, or for a string up to a word
break character.

However, given how the Pascal expression parser calls this function,
we know that the first character will always be a single quote, in
which case skip_quoted_chars will looks for a string between matching
single quotes.

The skip_quoted_chars doesn't do any escaped character handling, it
will just stop at the next single quote character.

In this commit I propose to remove skip_quoted and skip_quoted_chars,
and replace these with a smaller function pascal_skip_string  which
I've placed in p-exp.y.  This new function only skips a string between
matching single quotes, which is exactly the use case that we need.

The benefit of this change is to remove (some) code duplication.  It
feels like skip_quoted is similar in some ways to
extract_string_maybe_quoted, however, there are some differences;
skip_quoted uses the quotes and word break characters from the
completion engine which extract_string_maybe_quoted does not.

However, I'm currently working on improving filename completion, one
part of this is that I'm looking at allowing filenames to be quoted
with single or double quotes, while the default string quoting in
GDB (for expressions) can only use single quotes.  If I do end up
allowing single and double quotes in some cases, but we retain the
single quotes only for expressions then skip_quoted starts to become a
problem, should it accept both quote types, or only one?

But given how skip_quoted is used, I can avoid worrying about this by
simply removing skip_quoted.

The Pascal tests do still pass.  The code that called skip_quoted is
called at least once in the Pascal tests (adding an abort() call
causes gdb.pascal/types.exp to fail), but I doubt the testing is
extensive.  Not sure how widely used GDB for Pascal actually is
though.
---
 gdb/completer.c | 55 -------------------------------------------------
 gdb/completer.h |  5 -----
 gdb/p-exp.y     | 26 ++++++++++++++++++++++-
 3 files changed, 25 insertions(+), 61 deletions(-)

diff --git a/gdb/completer.c b/gdb/completer.c
index 168fab74d14..8168f79de0e 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -2371,61 +2371,6 @@ gdb_rl_attempted_completion_function (const char *text, int start, int end)
   return NULL;
 }
 
-/* Skip over the possibly quoted word STR (as defined by the quote
-   characters QUOTECHARS and the word break characters BREAKCHARS).
-   Returns pointer to the location after the "word".  If either
-   QUOTECHARS or BREAKCHARS is NULL, use the same values used by the
-   completer.  */
-
-const char *
-skip_quoted_chars (const char *str, const char *quotechars,
-		   const char *breakchars)
-{
-  char quote_char = '\0';
-  const char *scan;
-
-  if (quotechars == NULL)
-    quotechars = gdb_completer_quote_characters;
-
-  if (breakchars == NULL)
-    breakchars = current_language->word_break_characters ();
-
-  for (scan = str; *scan != '\0'; scan++)
-    {
-      if (quote_char != '\0')
-	{
-	  /* Ignore everything until the matching close quote char.  */
-	  if (*scan == quote_char)
-	    {
-	      /* Found matching close quote.  */
-	      scan++;
-	      break;
-	    }
-	}
-      else if (strchr (quotechars, *scan))
-	{
-	  /* Found start of a quoted string.  */
-	  quote_char = *scan;
-	}
-      else if (strchr (breakchars, *scan))
-	{
-	  break;
-	}
-    }
-
-  return (scan);
-}
-
-/* Skip over the possibly quoted word STR (as defined by the quote
-   characters and word break characters used by the completer).
-   Returns pointer to the location after the "word".  */
-
-const char *
-skip_quoted (const char *str)
-{
-  return skip_quoted_chars (str, NULL, NULL);
-}
-
 /* Return a message indicating that the maximum number of completions
    has been reached and that there may be more.  */
 
diff --git a/gdb/completer.h b/gdb/completer.h
index f0b9e68e120..f604a95011f 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -662,11 +662,6 @@ extern void complete_expression (completion_tracker &tracker,
 extern void complete_nested_command_line (completion_tracker &tracker,
 					  const char *text);
 
-extern const char *skip_quoted_chars (const char *, const char *,
-				      const char *);
-
-extern const char *skip_quoted (const char *);
-
 /* Called from command completion function to skip over /FMT
    specifications, allowing the rest of the line to be completed.  Returns
    true if the /FMT is at the end of the current line and there is nothing
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index ea7eb8c8d7e..bfb1cad60a7 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -76,6 +76,8 @@ static void yyerror (const char *);
 
 static char *uptok (const char *, int);
 
+static const char *pascal_skip_string (const char *str);
+
 using namespace expr;
 %}
 
@@ -1042,6 +1044,28 @@ uptok (const char *tokstart, int namelen)
   return uptokstart;
 }
 
+/* Skip over a Pascal string.  STR must point to the opening single quote
+   character.  This function returns a pointer to the character after the
+   closing single quote character.
+
+   This function does not support embedded, escaped single quotes, which
+   is done by placing two consecutive single quotes into a string.
+   Support for this would be easy to add, but this function is only used
+   from the Python expression parser, and if we did skip over escaped
+   quotes then the rest of the expression parser wouldn't handle them
+   correctly.  */
+static const char *
+pascal_skip_string (const char *str)
+{
+  gdb_assert (*str == '\'');
+
+  do
+    ++str;
+  while (*str != '\0' && *str != '\'');
+
+  return str;
+}
+
 /* Read one token, getting characters through lexptr.  */
 
 static int
@@ -1120,7 +1144,7 @@ yylex (void)
       c = *pstate->lexptr++;
       if (c != '\'')
 	{
-	  namelen = skip_quoted (tokstart) - tokstart;
+	  namelen = pascal_skip_string (tokstart) - tokstart;
 	  if (namelen > 2)
 	    {
 	      pstate->lexptr = tokstart + namelen;
-- 
2.25.4


  reply	other threads:[~2024-03-06 10:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16 21:23 [PATCH 0/5] Cleanup and changes for file name completion Andrew Burgess
2024-01-16 21:23 ` [PATCH 1/5] gdb: remove skip_quoted and skip_quoted_chars Andrew Burgess
2024-01-16 21:23 ` [PATCH 2/5] gdb: fix bug where quote characters would become nullptr Andrew Burgess
2024-01-16 21:24 ` [PATCH 3/5] gdb: allow double quotes for quoting filenames Andrew Burgess
2024-01-16 21:24 ` [PATCH 4/5] gdb: remove some dead code from completer.c Andrew Burgess
2024-01-16 21:24 ` [PATCH 5/5] gdb: remove special case completion word handling for filenames Andrew Burgess
2024-01-17 12:09   ` Eli Zaretskii
2024-01-17 16:29     ` Hannes Domani
2024-01-17 16:52       ` Eli Zaretskii
2024-01-18  9:33       ` Andrew Burgess
2024-03-06 10:23 ` [PATCHv2 0/7] Cleanup and changes for file name completion Andrew Burgess
2024-03-06 10:23   ` Andrew Burgess [this message]
2024-03-06 10:23   ` [PATCHv2 2/7] gdb: fix bug where quote characters would become nullptr Andrew Burgess
2024-03-06 10:23   ` [PATCHv2 3/7] gdb: allow double quotes for quoting filenames Andrew Burgess
2024-03-06 10:23   ` [PATCHv2 4/7] gdb: remove some dead code from completer.c Andrew Burgess
2024-03-06 10:23   ` [PATCHv2 5/7] gdb: remove special case completion word handling for filenames Andrew Burgess
2024-03-06 10:23   ` [PATCHv2 6/7] gdb/completion: make completion_find_completion_word static Andrew Burgess
2024-03-06 10:23   ` [PATCHv2 7/7] gdb: move more completion setup into completer.c Andrew Burgess
2024-03-25 18:30   ` [PATCHv2 0/7] Cleanup and changes for file name completion Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb65c21093f6bb25665a5f4b7ea2d8351d280235.1709720449.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox