diff options
author | Jan Vrany <jan.vrany@fit.cvut.cz> | 2019-05-17 10:58:23 +0100 |
---|---|---|
committer | Jan Vrany <jan.vrany@fit.cvut.cz> | 2019-05-17 10:58:23 +0100 |
commit | 26648588294d039fcf1efbf512d785753cb6286d (patch) | |
tree | 3a2635afa20d8e731d56ad29feb8f23100e0feda /gdb/mi/mi-main.c | |
parent | 6e035501e15e72398fcd9db88c97dd30e585a9ae (diff) | |
download | binutils-26648588294d039fcf1efbf512d785753cb6286d.zip binutils-26648588294d039fcf1efbf512d785753cb6286d.tar.gz binutils-26648588294d039fcf1efbf512d785753cb6286d.tar.bz2 |
MI: Add new command -complete
There is a CLI command 'complete' intended to use with emacs. Such a command
would also be useful for MI frontends, when separate CLI and MI channels cannot
be used. For example, on Windows (because of lack of PTYs) or when GDB is used
through SSH session.
This commit adds a new '-complete' MI command.
gdb/Changelog:
2019-01-28 Jan Vrany <jan.vrany@fit.cvut.cz>
* mi/mi-cmds.h (mi_cmd_complete): New function.
* mi/mi-main.c (mi_cmd_complete): Likewise.
* mi/mi-cmds.c: Define new MI command -complete.
* NEWS: Mention new -complete command.
gdb/doc/ChangeLog:
2019-01-28 Jan Vrany <jan.vrany@fit.cvut.cz>
* gdb.texinfo (Miscellaneous GDB/MI Commands): Document new
MI command -complete.
gdb/testsuite/ChangeLog:
2019-01-28 Jan Vrany <jan.vrany@fit.cvut.cz>
* gdb.mi/mi-complete.exp: New file.
* gdb.mi/mi-complete.cc: Likewise.
Diffstat (limited to 'gdb/mi/mi-main.c')
-rw-r--r-- | gdb/mi/mi-main.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 01786c3..4921c13 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -2708,6 +2708,51 @@ mi_cmd_fix_multi_location_breakpoint_output (const char *command, char **argv, fix_multi_location_breakpoint_output_globally = true; } +/* Implement the "-complete" command. */ + +void +mi_cmd_complete (const char *command, char **argv, int argc) +{ + if (argc != 1) + error (_("Usage: -complete COMMAND")); + + if (max_completions == 0) + error (_("max-completions is zero, completion is disabled.")); + + int quote_char = '\0'; + const char *word; + + completion_result result = complete (argv[0], &word, "e_char); + + std::string arg_prefix (argv[0], word - argv[0]); + + struct ui_out *uiout = current_uiout; + + if (result.number_matches > 0) + uiout->field_fmt ("completion", "%s%s", + arg_prefix.c_str (),result.match_list[0]); + + { + ui_out_emit_list completions_emitter (uiout, "matches"); + + if (result.number_matches == 1) + uiout->field_fmt (NULL, "%s%s", + arg_prefix.c_str (), result.match_list[0]); + else + { + result.sort_match_list (); + for (size_t i = 0; i < result.number_matches; i++) + { + uiout->field_fmt (NULL, "%s%s", + arg_prefix.c_str (), result.match_list[i + 1]); + } + } + } + uiout->field_string ("max_completions_reached", + result.number_matches == max_completions ? "1" : "0"); +} + + void _initialize_mi_main (void) { |