Bug 15163 - Vi settings within ~/.inputrc prevent entering/exiting TUI via C-x a
Summary: Vi settings within ~/.inputrc prevent entering/exiting TUI via C-x a
Status: WAITING
Alias: None
Product: gdb
Classification: Unclassified
Component: tui (show other bugs)
Version: 7.5
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-20 16:51 UTC by Rhys Ulerich
Modified: 2016-09-09 00:29 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rhys Ulerich 2013-02-20 16:51:44 UTC
Having vi-like settings in ~/.inputrc
breaks entering/exiting TUI mode using C-x a or any other key combination documented at http://sourceware.org/gdb/download/onlinedocs/gdb/TUI-Keys.html.

To reproduce:

1. Remove any ~/.inputrc file.
2. Run 'gdb'
3. Hit C-x a and observe TUI mode starting.
4. Quit gdb
5. Create a ~/.inputrc file containing two lines:
   > set editing-mode vi
   > set keymap vi
6. Run 'gdb'
7. Hit C-x a and observe ^X^A being echoed to the screen but TUI mode not starting.

I am unaware of any gdb command that will enter/exit TUI mode independently of the key combination.  Is there one?

Observed generally throughout 7.x and reproduced just now on 7.5.1.

- Rhys
Comment 1 Pedro Alves 2013-02-25 13:02:25 UTC
> I am unaware of any gdb command that will enter/exit TUI mode independently of
the key combination.  Is there one?

Commands like "tui foo", and "layout next" enter the TUI.

I'm not aware of any GDB command to exit the TUI, and looking at the code, I can't find any that would do it as side effect.

However, TUI enter/exit is bound to the readline "tui-switch-mode" command/function:

>  rl_add_defun ("tui-switch-mode", tui_rl_switch_mode, -1);

One should be able to use that to bind any key combo to TUI enter/exit in the inputrc file, per the "Key Bindings" node in the readline manual.  However, I'm not familiar readline's vi mode (emacs user here), and whether key bindings apply in that mode.

Let me know if that helps.
Comment 2 Rhys Ulerich 2013-02-25 16:18:54 UTC
> However, TUI enter/exit is bound to the readline "tui-switch-mode"
> command/function...
> One should be able to use that to bind any key combo to TUI enter/exit in the
> inputrc file, per the "Key Bindings" node in the readline manual.  However, I'm
> not familiar readline's vi mode (emacs user here), and whether key bindings
> apply in that mode.

I'm not familiar either.  Thanks for the suggestion.  I've tried
adding a few things like

Control-x: tui-switch-mode

to my ~/.inputrc without any luck.  However, it seems that

1. Run 'gdb'
2. Hit Escape to enter vi command mode
3. Hit Control-E to enter Emacs mode ('emacs-editing-mode')
4. Hit Control-x a to enter the TUI

works.  Though now I'm in Emacs mode and hitting Control-x a again
does not exit the TUI.  And I can't seem to get  "M-C-J" to trigger
vi-editing-mode again (though this is likely me being an idiot).

- Rhys
Comment 3 Pedro Alves 2013-02-25 18:56:00 UTC
I'm afraid at this point I don't really know if there's a bug, or if there is, if it is GDB specific.  As mentioned, I'm blissfully ignorant on vi things.
However, I'd think that if bash can handle the same style of key bindings in vi mode, then gdb should too.  What does bash do?

> (though this is likely me being an idiot).

:-)  Most probably not.

A gdb command to toggle the TUI off seems like something nice to have, as escape hatch out of broken-beyond-repair terminal settings though.
Comment 4 Memo Salas 2015-06-05 02:11:23 UTC
This is the workaround I found:

in my ~/.inputrc , I added a line that looks like this:
C-P: tui-switch-mode

i.e. ctrl-p will do the switch.

Then, in gdb's source, in the file gdb/tui/tui.c , I found the call that normally looks like this:

rl_add_defun ("tui-switch-mode", tui_rl_switch_mode, -1);

and changed the 3rd parameter (i.e. the key) to be a 16. Why 16? it's what the macro CTRL(X) will do for the letter I want to assign (i.e. ctrl-p in my case).

After that, I can exit in vi-keys out of tui mode by pressing ctrl-p.


So what is the real fix?
It seems to me that a solution will have to do with changing the function "tui_initialize_readline", which is the one that is being called at startup in a way that it hardcodes a key of with value -1 to the "tui-switch-mode", so that the user can provide their own key for it. My question is why is there a -1 being assigned to that function right now in the first place. Does anybody know ?
Comment 5 Memo Salas 2015-06-08 06:53:43 UTC
I changed my workaround by to not hard-code a key combination for exiting the tui mode, and instead pick up a key combination from the ~/.inputrc file, , by modifying the function tui_initialize_readline to call rl_re_read_init_file (in readline/bind.c) before returning.

My ~/.inputrc now has a keyboard mapping to associate to "tui-switch-mode". Regardless, for a better out-of-the-box experience perhaps a better default for vi key bindings is needed, at least for "tui-switch-mode", then things would work without requiring users to modify ~/.inputrc or similar.
Comment 6 Vadim Zeitlin 2015-07-26 21:45:41 UTC
Notice that even when using `gdb -tui` to start gdb in TUI mode, it's impossible to switch to the single key mode as `^X,s` doesn't work with vi bindings neither. Using `<Esc>,^E` does help but as the bindings reset to vi mode when you exit the single key mode, you need to redo it every time which makes the single key mode just not worth it -- even having a command like "tui single-key" would be faster than doing this, but unfortunately gdb doesn't seem to provide anything like this.

Is there any workaround that would allow to use keys starting with `^X` in vi mode?
Comment 7 Oliver Kiddle 2016-09-09 00:29:48 UTC
Not being able to bind ^X,s in vi-mode is perhaps related to ^X alone being bound to self-insert. In any case, I think you're asking the wrong question. Key sequences starting with Ctrl-X is really an emacs thing. What you should be asking is what a natural key combination in vi-mode would be.

I would instead suggest binding a sequence starting with a backslash in vi command mode. This is perhaps more of a vim convention. If you want to look at the vim documentation, see :help leader. <Leader> is a special token in vim key bindings and is a common prefix for keys used by plugins and user configuration. Some people redefine leader to, e.g. comma but comma does have a use even in original vi.