aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorPatrick Palka <patrick@parcs.ath.cx>2015-06-21 22:54:10 -0400
committerPatrick Palka <patrick@parcs.ath.cx>2015-06-26 10:11:28 -0400
commit2e52ae68e7cedc3a1f9908c98ee60a8602705835 (patch)
treea5cf504057eace75c9b3eea3adaa7ab0a8f6e41b /gdb/tui
parent6e22494e5076e4d3c0b2c2785883162f83db499e (diff)
downloadgdb-2e52ae68e7cedc3a1f9908c98ee60a8602705835.zip
gdb-2e52ae68e7cedc3a1f9908c98ee60a8602705835.tar.gz
gdb-2e52ae68e7cedc3a1f9908c98ee60a8602705835.tar.bz2
Add tab completion for TUI's "focus" command
The implementation is pretty straightforward, with the only caveat being that the "src", "cmd", "next" and "prev" entries get delibrately added to the completion list even when the TUI has not yet been initialized (i.e. has never been enabled during the session), since invoking the "focus" command with these arguments already works when the TUI has not yet been initialized. gdb/ChangeLog: * tui/tui-win.c (focus_completer): New static function. (_initialize_tui_win): Set the completion function of the "focus" command to focus_completer. gdb/testsuite/ChangeLog: * gdb.base/completion.exp: Test the completion of the "focus" command.
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-win.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 8c0685b..feb360b 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -354,6 +354,71 @@ tui_set_var_cmd (char *null_args, int from_tty, struct cmd_list_element *c)
tui_rehighlight_all ();
}
+/* Complete possible window names to focus on. TEXT is the complete text
+ entered so far, WORD is the word currently being completed. */
+
+static VEC (char_ptr) *
+focus_completer (struct cmd_list_element *ignore,
+ const char *text, const char *word)
+{
+ VEC (const_char_ptr) *completion_name_vec = NULL;
+ VEC (char_ptr) *matches_vec;
+ int win_type;
+
+ for (win_type = SRC_WIN; win_type < MAX_MAJOR_WINDOWS; win_type++)
+ {
+ const char *completion_name = NULL;
+
+ /* We can't focus on an invisible window. */
+ if (tui_win_list[win_type] == NULL
+ || !tui_win_list[win_type]->generic.is_visible)
+ continue;
+
+ switch (win_type)
+ {
+ case SRC_WIN:
+ completion_name = "src";
+ break;
+ case DISASSEM_WIN:
+ completion_name = "asm";
+ break;
+ case DATA_WIN:
+ completion_name = "regs";
+ break;
+ case CMD_WIN:
+ completion_name = "cmd";
+ break;
+ default:
+ break;
+ }
+
+ if (completion_name != NULL)
+ VEC_safe_push (const_char_ptr, completion_name_vec, completion_name);
+ }
+
+ /* If no windows are considered visible then the TUI has not yet been
+ initialized. But still "focus src" and "focus cmd" will work because
+ invoking the focus command will entail initializing the TUI which sets the
+ default layout to SRC_COMMAND. */
+ if (VEC_length (const_char_ptr, completion_name_vec) == 0)
+ {
+ VEC_safe_push (const_char_ptr, completion_name_vec, "src");
+ VEC_safe_push (const_char_ptr, completion_name_vec, "cmd");
+ }
+
+ VEC_safe_push (const_char_ptr, completion_name_vec, "next");
+ VEC_safe_push (const_char_ptr, completion_name_vec, "prev");
+ VEC_safe_push (const_char_ptr, completion_name_vec, NULL);
+
+ matches_vec
+ = complete_on_enum (VEC_address (const_char_ptr, completion_name_vec),
+ text, word);
+
+ VEC_free (const_char_ptr, completion_name_vec);
+
+ return matches_vec;
+}
+
/* Function to initialize gdb commands, for tui window
manipulation. */
@@ -365,6 +430,7 @@ _initialize_tui_win (void)
{
static struct cmd_list_element *tui_setlist;
static struct cmd_list_element *tui_showlist;
+ struct cmd_list_element *focus_cmd;
/* Define the classes of commands.
They will appear in the help list in the reverse of this order. */
@@ -393,7 +459,7 @@ regs : the register display\n"));
add_com_alias ("wh", "winheight", class_tui, 0);
add_info ("win", tui_all_windows_info,
_("List of all displayed windows.\n"));
- add_com ("focus", class_tui, tui_set_focus_command, _("\
+ focus_cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\
Set focus to named window or next/prev window.\n\
Usage: focus {<win> | next | prev}\n\
Valid Window names are:\n\
@@ -402,6 +468,7 @@ asm : the disassembly window\n\
regs : the register display\n\
cmd : the command window\n"));
add_com_alias ("fs", "focus", class_tui, 0);
+ set_cmd_completer (focus_cmd, focus_completer);
add_com ("+", class_tui, tui_scroll_forward_command, _("\
Scroll window forward.\n\
Usage: + [win] [n]\n"));