aboutsummaryrefslogtreecommitdiff
path: root/gdb/completer.c
diff options
context:
space:
mode:
authorJan Vrany <jan.vrany@fit.cvut.cz>2019-05-17 10:58:23 +0100
committerJan Vrany <jan.vrany@fit.cvut.cz>2019-05-17 10:58:23 +0100
commit6e035501e15e72398fcd9db88c97dd30e585a9ae (patch)
tree6613a2f7386b73461c6887ae1b9dd28b57229a6d /gdb/completer.c
parent7d0e2ecedef69de0a242ac49a475f6a3968d4476 (diff)
downloadgdb-6e035501e15e72398fcd9db88c97dd30e585a9ae.zip
gdb-6e035501e15e72398fcd9db88c97dd30e585a9ae.tar.gz
gdb-6e035501e15e72398fcd9db88c97dd30e585a9ae.tar.bz2
MI: extract command completion logic from complete_command()
Extract completion logic from CLI complete_command() into a new helper function complete(). gdb/Changelog: * completer.h (complete): New function. * completer.c (complete): Likewise. * cli/cli-cmds.c: (complete_command): Update to use new complete() function defined in completer.h.
Diffstat (limited to 'gdb/completer.c')
-rw-r--r--gdb/completer.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/gdb/completer.c b/gdb/completer.c
index 5d1decc..cc2f80b 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1613,6 +1613,41 @@ make_completion_match_str (gdb::unique_xmalloc_ptr<char> &&match_name,
return gdb::unique_xmalloc_ptr<char> (newobj);
}
+/* See complete.h. */
+
+completion_result
+complete (const char *line, char const **word, int *quote_char)
+{
+ completion_tracker tracker_handle_brkchars;
+ completion_tracker tracker_handle_completions;
+ completion_tracker *tracker;
+
+ try
+ {
+ *word = completion_find_completion_word (tracker_handle_brkchars,
+ line, quote_char);
+
+ /* Completers that provide a custom word point in the
+ handle_brkchars phase also compute their completions then.
+ Completers that leave the completion word handling to readline
+ must be called twice. */
+ if (tracker_handle_brkchars.use_custom_word_point ())
+ tracker = &tracker_handle_brkchars;
+ else
+ {
+ complete_line (tracker_handle_completions, *word, line, strlen (line));
+ tracker = &tracker_handle_completions;
+ }
+ }
+ catch (const gdb_exception &ex)
+ {
+ return {};
+ }
+
+ return tracker->build_completion_result (*word, *word - line, strlen (line));
+}
+
+
/* Generate completions all at once. Does nothing if max_completions
is 0. If max_completions is non-negative, this will collect at
most max_completions strings.