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: [PATCH 2/3] gdb: make skip_over_slash_fmt available outside printcmd.c
Date: Fri, 20 Oct 2023 22:33:10 +0100	[thread overview]
Message-ID: <c5d514a0f42422bed013915a0543247fcc7bd8a8.1697837539.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1697837538.git.aburgess@redhat.com>

Move the function skip_over_slash_fmt into completer.c, and make it
extern, with a declaration in completer.h.

This is a refactor in order to support the next commit.  I've not
changed any of the code in skip_over_slash_fmt.

There should be no user visible changes after this commit.
---
 gdb/completer.c | 53 ++++++++++++++++++++++++++++++++++++++++
 gdb/completer.h | 17 +++++++++++++
 gdb/printcmd.c  | 65 -------------------------------------------------
 3 files changed, 70 insertions(+), 65 deletions(-)

diff --git a/gdb/completer.c b/gdb/completer.c
index 2abf3998345..42ac7be297a 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -2991,6 +2991,59 @@ gdb_display_match_list (char **matches, int len, int max,
     }
 }
 
+/* See completer.h.  */
+
+bool
+skip_over_slash_fmt (completion_tracker &tracker, const char **args)
+{
+  const char *text = *args;
+
+  if (text[0] == '/')
+    {
+      bool in_fmt;
+      tracker.set_use_custom_word_point (true);
+
+      if (text[1] == '\0')
+	{
+	  /* The user tried to complete after typing just the '/' character
+	     of the /FMT string.  Step the completer past the '/', but we
+	     don't offer any completions.  */
+	  in_fmt = true;
+	  ++text;
+	}
+      else
+	{
+	  /* The user has typed some characters after the '/', we assume
+	     this is a complete /FMT string, first skip over it.  */
+	  text = skip_to_space (text);
+
+	  if (*text == '\0')
+	    {
+	      /* We're at the end of the input string.  The user has typed
+		 '/FMT' and asked for a completion.  Push an empty
+		 completion string, this will cause readline to insert a
+		 space so the user now has '/FMT '.  */
+	      in_fmt = true;
+	      tracker.add_completion (make_unique_xstrdup (text));
+	    }
+	  else
+	    {
+	      /* The user has already typed things after the /FMT, skip the
+		 whitespace and return false.  Whoever called this function
+		 should then try to complete what comes next.  */
+	      in_fmt = false;
+	      text = skip_spaces (text);
+	    }
+	}
+
+      tracker.advance_custom_word_point_by (text - *args);
+      *args = text;
+      return in_fmt;
+    }
+
+  return false;
+}
+
 void _initialize_completer ();
 void
 _initialize_completer ()
diff --git a/gdb/completer.h b/gdb/completer.h
index 67d2fbf9d38..d96c4b515d3 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -657,6 +657,23 @@ extern const char *skip_quoted_chars (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
+   left to complete, otherwise false is returned.
+
+   In either case *ARGS can be updated to point after any part of /FMT that
+   is present.
+
+   This function is designed so that trying to complete '/' will offer no
+   completions, the user needs to insert the format specification
+   themselves.  Trying to complete '/FMT' (where FMT is any non-empty set
+   of alpha-numeric characters) will cause readline to insert a single
+   space, setting the user up to enter the expression.  */
+
+extern bool skip_over_slash_fmt (completion_tracker &tracker,
+				 const char **args);
+
 /* Maximum number of candidates to consider before the completer
    bails by throwing MAX_COMPLETIONS_REACHED_ERROR.  Negative values
    disable limiting.  */
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 5e9c8a5b222..fd6e74ec61c 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1378,71 +1378,6 @@ print_command_1 (const char *args, int voidprint)
     }
 }
 
-/* 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
-   left to complete, otherwise false is returned.
-
-   In either case *ARGS can be updated to point after any part of /FMT that
-   is present.
-
-   This function is designed so that trying to complete '/' will offer no
-   completions, the user needs to insert the format specification
-   themselves.  Trying to complete '/FMT' (where FMT is any non-empty set
-   of alpha-numeric characters) will cause readline to insert a single
-   space, setting the user up to enter the expression.  */
-
-static bool
-skip_over_slash_fmt (completion_tracker &tracker, const char **args)
-{
-  const char *text = *args;
-
-  if (text[0] == '/')
-    {
-      bool in_fmt;
-      tracker.set_use_custom_word_point (true);
-
-      if (text[1] == '\0')
-	{
-	  /* The user tried to complete after typing just the '/' character
-	     of the /FMT string.  Step the completer past the '/', but we
-	     don't offer any completions.  */
-	  in_fmt = true;
-	  ++text;
-	}
-      else
-	{
-	  /* The user has typed some characters after the '/', we assume
-	     this is a complete /FMT string, first skip over it.  */
-	  text = skip_to_space (text);
-
-	  if (*text == '\0')
-	    {
-	      /* We're at the end of the input string.  The user has typed
-		 '/FMT' and asked for a completion.  Push an empty
-		 completion string, this will cause readline to insert a
-		 space so the user now has '/FMT '.  */
-	      in_fmt = true;
-	      tracker.add_completion (make_unique_xstrdup (text));
-	    }
-	  else
-	    {
-	      /* The user has already typed things after the /FMT, skip the
-		 whitespace and return false.  Whoever called this function
-		 should then try to complete what comes next.  */
-	      in_fmt = false;
-	      text = skip_spaces (text);
-	    }
-	}
-
-      tracker.advance_custom_word_point_by (text - *args);
-      *args = text;
-      return in_fmt;
-    }
-
-  return false;
-}
-
 /* See valprint.h.  */
 
 void
-- 
2.25.4


  parent reply	other threads:[~2023-10-20 21:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-20 21:33 [PATCH 0/3] Improve disassemble command completion Andrew Burgess
2023-10-20 21:33 ` [PATCH 1/3] gdb: error if /r and /b are used with disassemble command Andrew Burgess
2023-10-21  7:22   ` Eli Zaretskii
2023-10-20 21:33 ` Andrew Burgess [this message]
2023-10-20 21:33 ` [PATCH 3/3] gdb: add a custom command completer for " Andrew Burgess
2023-11-08 11:21 ` [PATCH 0/3] Improve disassemble command 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=c5d514a0f42422bed013915a0543247fcc7bd8a8.1697837539.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