aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui/tui-win.c
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-12-22 16:26:37 +0000
committerAndrew Burgess <aburgess@redhat.com>2023-01-27 16:20:10 +0000
commit58c6d2ac109965f8e38908146448073ab1152e81 (patch)
treee44d8db7943145c103ea22e96f2418d41dab4163 /gdb/tui/tui-win.c
parentefe1b6507b7e6ae5ee45af5b1568b910a3170750 (diff)
downloadfsf-binutils-gdb-58c6d2ac109965f8e38908146448073ab1152e81.zip
fsf-binutils-gdb-58c6d2ac109965f8e38908146448073ab1152e81.tar.gz
fsf-binutils-gdb-58c6d2ac109965f8e38908146448073ab1152e81.tar.bz2
gdb/tui: improve errors from tui focus command
This commit improves (I think) the errors from the tui focus command. There are a number of errors that can be triggered by the focus command, they include: (1) Window name "NAME" is ambiguous (2) Unrecognized window name "NAME" (3) Window "NAME" cannot be focused Error (1) is triggered when the user gives a partial window name, and the name matches multiple windows in the current layout. It is worth noting that the ambiguity must be within the current layout; if the partial name matches one window in the current layout, and one or more windows not in the current layout, then this is not ambiguous, and focus will shift to the matching window in the current layout. This error was not previous being tested, but in this commit I make use of the Python API to trigger and test this error. Error (3) is simple enough, and was already being tested. This is triggered by something like 'focus status'. The named window needs to be present in the current layout, and non-focusable in order to trigger the error. Error (2) is what I'd like to improve in this commit. This error triggers if the name the user gives doesn't match any window in the current layout. Even if GDB does know about the window, but the window isn't in the current layout, then GDB will say it doesn't recognize the window name. In this commit I propose to to split this error into three different errors. These will be: (a) Unrecognized window name "NAME" (b) No windows matching "NAME" in the current layout (c) Window "NAME" is not in the current layout Error (a) is the same as before, but will now only trigger if GDB doesn't know about window NAME at all. If the window is known, but not in the current layout then one of the other errors will trigger. Error (b) will trigger if NAME is ambiguous for multiple windows that are not in the current layout. If NAME identifies a single window in the current layout then that window will continue to be selected, just as it currently is. Only in the case where NAME doesn't identify a window in the current layout do we then check all the other known windows, if NAME matches multiple of these, then (b) is triggered. Finally, error (c) is used when NAME uniquely identifies a single window that is not in the current layout. The hope with these new errors is that the user will have a better understanding of what went wrong. Instead of GDB claiming to not know about a window, the mention of the current layout will hint to the user that they should first switch layouts. There are tests included for all the new errors.
Diffstat (limited to 'gdb/tui/tui-win.c')
-rw-r--r--gdb/tui/tui-win.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 492a519..008189e 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -728,8 +728,44 @@ tui_set_focus_command (const char *arg, int from_tty)
else
win_info = tui_partial_win_by_name (arg);
- if (win_info == NULL)
- error (_("Unrecognized window name \"%s\""), arg);
+ if (win_info == nullptr)
+ {
+ /* When WIN_INFO is nullptr this can either mean that the window name
+ is unknown to GDB, or that the window is not in the current
+ layout. To try and help the user, give a different error
+ depending on which of these is the case. */
+ std::string matching_window_name;
+ bool is_ambiguous = false;
+
+ for (const std::string &name : all_known_window_names ())
+ {
+ /* Look through all windows in the current layout, if the window
+ is in the current layout then we're not interested is it. */
+ for (tui_win_info *item : all_tui_windows ())
+ if (item->name () == name)
+ continue;
+
+ if (startswith (name, arg))
+ {
+ if (matching_window_name.empty ())
+ matching_window_name = name;
+ else
+ is_ambiguous = true;
+ }
+ };
+
+ if (!matching_window_name.empty ())
+ {
+ if (is_ambiguous)
+ error (_("No windows matching \"%s\" in the current layout"),
+ arg);
+ else
+ error (_("Window \"%s\" is not in the current layout"),
+ matching_window_name.c_str ());
+ }
+ else
+ error (_("Unrecognized window name \"%s\""), arg);
+ }
/* If a window is part of the current layout then it will have a
tui_win_info associated with it and be visible, otherwise, there will