Re: building gdb with TUI support on Windows

Hannes Domani
2014-12-30T19:15:54Z

Ofir Cohen <ofircohenn@gmail.com> schrieb am 16:28 Montag, 29.Dezember 2014:
> Hi Hannes,
> Thanks again for the reply =].
>
> > You are aware that with the arrow keys in TUI mode you move in the source
> window, and not in the history?
>
> Yes, ofc, I'm therefore moving the window focus from source to the
> interpreter's CLI window (Ctrl+x, o),
> and only then issue the arrow up/down/left/right commands.
> Unfortunately, it doesn't work, I have to get out of TUI mode (Ctrl+x,
> a), to make the arrow keys respond.
>
> On Linux, when you do the above mentioned steps, it works flawlessly.
>
> A shallow investigation, debugging of gdb with gdb, showed that
> wgetch() function (deep in the call-stack, invoked indirectly by
> stdin_event_handler), is blocking and doesn't return when the
> arrow-keys are issued.
>
> When gdb is not in TUI mode, however, getch() is called instead,
> returns promptly and issues
> the associated dispatch handler.

I figured out the problem here.
When the CLI get the focus, the keypad is disabled. This means wgetch()
should return special keys as escape sequences (like getch() does), and not
as a single value (e.g. KEY_LEFT).
pdcurses instead ignores special keys completely if keypad is disabled.

I've made the following changes to recreate this behavior for some keys:

--- a/pdcurses/getch.c 2008-07-13 18:08:18.000000000 +0200
+++ b/pdcurses/getch.c 2014-12-30 16:46:45.604498500 +0100
@@ -2,6 +2,11 @@

#include <curspriv.h>

+#ifdef _WIN32
+#include <windows.h>
+extern HANDLE pdc_con_in;
+#endif
+
RCSID("$Id: getch.c,v 1.72 2008/07/13 16:08:18 wmcbrine Exp $")

/*man-start**************************************************************
@@ -238,7 +243,55 @@
/* filter special keys if not in keypad mode */

if (!win->_use_keypad)
+ {
+#ifdef _WIN32
+ char backhalf = 0;
+ switch (key)
+ {
+ case KEY_UP:
+ backhalf = 'H';
+ break;
+ case KEY_DOWN:
+ backhalf = 'P';
+ break;
+ case KEY_LEFT:
+ backhalf = 'K';
+ break;
+ case KEY_RIGHT:
+ backhalf = 'M';
+ break;
+ case KEY_HOME:
+ backhalf = 'G';
+ break;
+ case KEY_END:
+ backhalf = 'O';
+ break;
+ case KEY_DC:
+ backhalf = 'S';
+ break;
+ case KEY_IC:
+ backhalf = 'R';
+ break;
+ }
+ if (backhalf)
+ {
+ INPUT_RECORD ir;
+ ir.EventType = KEY_EVENT;
+ ir.Event.KeyEvent.bKeyDown = TRUE;
+ ir.Event.KeyEvent.dwControlKeyState = 0;
+ ir.Event.KeyEvent.uChar.UnicodeChar = backhalf;
+ ir.Event.KeyEvent.wRepeatCount = 1;
+ ir.Event.KeyEvent.wVirtualKeyCode = backhalf;
+ ir.Event.KeyEvent.wVirtualScanCode =
+ MapVirtualKey(backhalf, MAPVK_VK_TO_VSC);
+ DWORD written;
+ WriteConsoleInput(pdc_con_in, &ir, 1, &written);
+ return 0xe0;
+ }
+#endif
+
key = -1;
+ }

/* filter mouse events; translate mouse clicks in the slk
area to function keys */