public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] "backtrace full/no-filters/hide" completer
@ 2019-06-12 23:29 Pedro Alves
  0 siblings, 0 replies; only message in thread
From: Pedro Alves @ 2019-06-12 23:29 UTC (permalink / raw)
  To: gdb-cvs

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

commit 90a1ef8762a57f3f57007db2186099c026152034
Author: Pedro Alves <palves@redhat.com>
Date:   Thu Jun 13 00:06:53 2019 +0100

    "backtrace full/no-filters/hide" completer
    
    "backtrace"'s completer now completes on command options:
    
     (gdb) bt -[TAB]
     -entry-values         -full                 -no-filters           -past-main
     -frame-arguments      -hide                 -past-entry           -raw-frame-arguments
    
    But it doesn't know how to complete on qualifiers:
    
     (gdb) bt fu[TAB]
     funlockfile       futimens          futimes.c
     funlockfile.c     futimens.c        futimesat
     futex-internal.h  futimes           futimesat.c
    
    This commit fixes that:
    
     (gdb) bt fu[TAB]ll
     (gdb) bt n[TAB]o-filters
     (gdb) bt h[TAB]ide
    
    I considered teaching the gdb::option framework to handle non-'-'
    options, but decided it wasn't worth it for this special case, and I'd
    rather not make it easy to add new qualifier-like options.
    
    gdb/ChangeLog:
    2019-06-13  Pedro Alves  <palves@redhat.com>
    
    	* stack.c (parse_backtrace_qualifiers): New.
    	(backtrace_command): Use it.
    	(backtrace_command_completer): Complete on qualifiers.
    
    gdb/testsuite/ChangeLog:
    2019-06-13  Pedro Alves  <palves@redhat.com>
    
    	* gdb.base/options.exp (test-backtrace): Test completing qualifiers.

Diff:
---
 gdb/ChangeLog                      |  6 +++
 gdb/stack.c                        | 84 ++++++++++++++++++++++++++++----------
 gdb/testsuite/ChangeLog            |  4 ++
 gdb/testsuite/gdb.base/options.exp | 11 +++++
 4 files changed, 83 insertions(+), 22 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 08621ca..c21a5eb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2019-06-13  Pedro Alves  <palves@redhat.com>
 
+	* stack.c (parse_backtrace_qualifiers): New.
+	(backtrace_command): Use it.
+	(backtrace_command_completer): Complete on qualifiers.
+
+2019-06-13  Pedro Alves  <palves@redhat.com>
+
 	* frame.c: Include "cli/cli-option.h.
 	(user_set_backtrace_options): New.
 	(backtrace_past_main, backtrace_past_entry, backtrace_limit):
diff --git a/gdb/stack.c b/gdb/stack.c
index 5e878d3..1cb1fc9 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -2027,6 +2027,45 @@ make_backtrace_options_def_group (frame_print_options *fp_opts,
   }};
 }
 
+/* Parse the backtrace command's qualifiers.  Returns ARG advanced
+   past the qualifiers, if any.  BT_CMD_OPTS, if not null, is used to
+   store the parsed qualifiers.  */
+
+static const char *
+parse_backtrace_qualifiers (const char *arg,
+			    backtrace_cmd_options *bt_cmd_opts = nullptr)
+{
+  while (true)
+    {
+      const char *save_arg = arg;
+      std::string this_arg = extract_arg (&arg);
+
+      if (this_arg.empty ())
+	return arg;
+
+      if (subset_compare (this_arg.c_str (), "no-filters"))
+	{
+	  if (bt_cmd_opts != nullptr)
+	    bt_cmd_opts->no_filters = true;
+	}
+      else if (subset_compare (this_arg.c_str (), "full"))
+	{
+	  if (bt_cmd_opts != nullptr)
+	    bt_cmd_opts->full = true;
+	}
+      else if (subset_compare (this_arg.c_str (), "hide"))
+	{
+	  if (bt_cmd_opts != nullptr)
+	    bt_cmd_opts->hide = true;
+	}
+      else
+	{
+	  /* Not a recognized qualifier, so stop.  */
+	  return save_arg;
+	}
+    }
+}
+
 static void
 backtrace_command (const char *arg, int from_tty)
 {
@@ -2043,28 +2082,7 @@ backtrace_command (const char *arg, int from_tty)
      compatibility.  */
   if (arg != NULL)
     {
-      while (true)
-	{
-	  const char *save_arg = arg;
-	  std::string this_arg = extract_arg (&arg);
-
-	  if (this_arg.empty ())
-	    break;
-
-	  if (subset_compare (this_arg.c_str (), "no-filters"))
-	    bt_cmd_opts.no_filters = true;
-	  else if (subset_compare (this_arg.c_str (), "full"))
-	    bt_cmd_opts.full = true;
-	  else if (subset_compare (this_arg.c_str (), "hide"))
-	    bt_cmd_opts.hide = true;
-	  else
-	    {
-	      /* Not a recognized argument, so stop.  */
-	      arg = save_arg;
-	      break;
-	    }
-	}
-
+      arg = parse_backtrace_qualifiers (arg, &bt_cmd_opts);
       if (*arg == '\0')
 	arg = NULL;
     }
@@ -2090,6 +2108,28 @@ backtrace_command_completer (struct cmd_list_element *ignore,
       (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group))
     return;
 
+  if (*text != '\0')
+    {
+      const char *p = skip_to_space (text);
+      if (*p == '\0')
+	{
+	  static const char *const backtrace_cmd_qualifier_choices[] = {
+	    "full", "no-filters", "hide", nullptr,
+	  };
+	  complete_on_enum (tracker, backtrace_cmd_qualifier_choices,
+			    text, text);
+
+	  if (tracker.have_completions ())
+	    return;
+	}
+      else
+	{
+	  const char *cmd = parse_backtrace_qualifiers (text);
+	  tracker.advance_custom_word_point_by (cmd - text);
+	  text = cmd;
+	}
+    }
+
   const char *word = advance_to_expression_complete_word_point (tracker, text);
   expression_completer (ignore, tracker, text, word);
 }
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 4485f29..d2063f2 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,9 @@
 2019-06-13  Pedro Alves  <palves@redhat.com>
 
+	* gdb.base/options.exp (test-backtrace): Test completing qualifiers.
+
+2019-06-13  Pedro Alves  <palves@redhat.com>
+
 	* gdb.base/options.exp (test-backtrace): New.
 	(top level): Call it.
 
diff --git a/gdb/testsuite/gdb.base/options.exp b/gdb/testsuite/gdb.base/options.exp
index 1757346..5a35074 100644
--- a/gdb/testsuite/gdb.base/options.exp
+++ b/gdb/testsuite/gdb.base/options.exp
@@ -256,6 +256,17 @@ proc_with_prefix test-backtrace {} {
 	"-raw-frame-arguments"
     }
 
+    # Test that we complete the qualifiers, if there's any.
+    test_gdb_complete_unique \
+	"backtrace ful" \
+	"backtrace full"
+    test_gdb_complete_unique \
+	"backtrace hid" \
+	"backtrace hide"
+    test_gdb_complete_unique \
+	"backtrace no-fil" \
+	"backtrace no-filters"
+
     global binfile
     clean_restart $binfile


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

only message in thread, other threads:[~2019-06-12 23:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-12 23:29 [binutils-gdb] "backtrace full/no-filters/hide" completer Pedro Alves

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).