aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-cmds.c54
-rw-r--r--gdb/cli/cli-decode.c35
2 files changed, 47 insertions, 42 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 0930342..fa5dd4c 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -238,6 +238,7 @@ help_command (char *command, int from_tty)
help_cmd (command, gdb_stdout);
}
+
/* Note: The "complete" command is used by Emacs to implement completion.
[Is that why this function writes output with *_unfiltered?] */
@@ -246,8 +247,6 @@ complete_command (char *arg_entry, int from_tty)
{
const char *arg = arg_entry;
int argpoint;
- char *arg_prefix;
- VEC (char_ptr) *completions;
dont_repeat ();
@@ -279,43 +278,46 @@ complete_command (char *arg_entry, int from_tty)
point--;
}
- arg_prefix = (char *) alloca (point - arg + 1);
- memcpy (arg_prefix, arg, point - arg);
- arg_prefix[point - arg] = 0;
-
- completions = complete_line (point, arg, argpoint);
+ completion_tracker tracker_handle_completions;
- if (completions)
+ TRY
+ {
+ complete_line (tracker_handle_completions, point, arg, strlen (arg));
+ }
+ CATCH (ex, RETURN_MASK_ALL)
{
- int ix, size = VEC_length (char_ptr, completions);
- char *item, *prev = NULL;
+ return;
+ }
- qsort (VEC_address (char_ptr, completions), size,
- sizeof (char *), compare_strings);
+ std::string arg_prefix (arg, point - arg);
- /* We do extra processing here since we only want to print each
- unique item once. */
- for (ix = 0; VEC_iterate (char_ptr, completions, ix, item); ++ix)
+ completion_result result
+ = (tracker_handle_completions.build_completion_result
+ (point, point - arg, strlen (arg)));
+
+ if (result.number_matches != 0)
+ {
+ if (result.number_matches == 1)
+ printf_unfiltered ("%s%s\n", arg_prefix.c_str (), result.match_list[0]);
+ else
{
- if (prev == NULL || strcmp (item, prev) != 0)
+ result.sort_match_list ();
+
+ for (size_t i = 0; i < result.number_matches; i++)
{
- printf_unfiltered ("%s%s\n", arg_prefix, item);
- xfree (prev);
- prev = item;
+ printf_unfiltered ("%s%s",
+ arg_prefix.c_str (),
+ result.match_list[i + 1]);
+ printf_unfiltered ("\n");
}
- else
- xfree (item);
}
- xfree (prev);
- VEC_free (char_ptr, completions);
-
- if (size == max_completions)
+ if (result.number_matches == max_completions)
{
/* ARG_PREFIX and POINT are included in the output so that emacs
will include the message in the output. */
printf_unfiltered (_("%s%s %s\n"),
- arg_prefix, point,
+ arg_prefix.c_str (), point,
get_max_completions_reached_message ());
}
}
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 064b481..1bbbe46 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -657,8 +657,9 @@ add_setshow_optional_filename_cmd (const char *name, enum command_class theclass
/* Completes on literal "unlimited". Used by integer commands that
support a special "unlimited" value. */
-static VEC (char_ptr) *
+static void
integer_unlimited_completer (struct cmd_list_element *ignore,
+ completion_tracker &tracker,
const char *text, const char *word)
{
static const char * const keywords[] =
@@ -667,7 +668,7 @@ integer_unlimited_completer (struct cmd_list_element *ignore,
NULL,
};
- return complete_on_enum (keywords, text, word);
+ complete_on_enum (tracker, keywords, text, word);
}
/* Add element named NAME to both the set and show command LISTs (the
@@ -1771,13 +1772,13 @@ lookup_cmd_composition (const char *text,
"foo" and we want to complete to "foobar". If WORD is "oo", return
"oobar"; if WORD is "baz/foo", return "baz/foobar". */
-VEC (char_ptr) *
+void
complete_on_cmdlist (struct cmd_list_element *list,
+ completion_tracker &tracker,
const char *text, const char *word,
int ignore_help_classes)
{
struct cmd_list_element *ptr;
- VEC (char_ptr) *matchlist = NULL;
int textlen = strlen (text);
int pass;
int saw_deprecated_match = 0;
@@ -1786,8 +1787,10 @@ complete_on_cmdlist (struct cmd_list_element *list,
commands. If we see no matching commands in the first pass, and
if we did happen to see a matching deprecated command, we do
another loop to collect those. */
- for (pass = 0; matchlist == 0 && pass < 2; ++pass)
+ for (pass = 0; pass < 2; ++pass)
{
+ bool got_matches = false;
+
for (ptr = list; ptr; ptr = ptr->next)
if (!strncmp (ptr->name, text, textlen)
&& !ptr->abbrev_flag
@@ -1820,32 +1823,34 @@ complete_on_cmdlist (struct cmd_list_element *list,
match[text - word] = '\0';
strcat (match, ptr->name);
}
- VEC_safe_push (char_ptr, matchlist, match);
+ tracker.add_completion (gdb::unique_xmalloc_ptr<char> (match));
+ got_matches = true;
}
+
+ if (got_matches)
+ break;
+
/* If we saw no matching deprecated commands in the first pass,
just bail out. */
if (!saw_deprecated_match)
break;
}
-
- return matchlist;
}
/* Helper function for SYMBOL_COMPLETION_FUNCTION. */
-/* Return a vector of char pointers which point to the different
- possible completions in CMD of TEXT.
+/* Add the different possible completions in ENUMLIST of TEXT.
WORD points in the same buffer as TEXT, and completions should be
returned relative to this position. For example, suppose TEXT is "foo"
and we want to complete to "foobar". If WORD is "oo", return
"oobar"; if WORD is "baz/foo", return "baz/foobar". */
-VEC (char_ptr) *
-complete_on_enum (const char *const *enumlist,
+void
+complete_on_enum (completion_tracker &tracker,
+ const char *const *enumlist,
const char *text, const char *word)
{
- VEC (char_ptr) *matchlist = NULL;
int textlen = strlen (text);
int i;
const char *name;
@@ -1870,10 +1875,8 @@ complete_on_enum (const char *const *enumlist,
match[text - word] = '\0';
strcat (match, name);
}
- VEC_safe_push (char_ptr, matchlist, match);
+ tracker.add_completion (gdb::unique_xmalloc_ptr<char> (match));
}
-
- return matchlist;
}