11 February 2012

GDB 7.4 with TUI win32

GDB UI for windows is rare indeed, I've looking at Insight but the latest version only support GDB 6.8 and apparently gdbtk also withdrawn from GDB source code tarball. Thats only leave TUI, fortunately it's not that complicated to enable it. We need latest ncurses (5.9) to make it happen, but since GDB has its own termcap implementation for windows this will conflicting ncurses' (see patch below). However when using gdb.exe (instead of gdbtui.exe) it will crash immediately once we type as this mode expect for GDB's own termcap that being disabled earlier. Thus only gdbtui.exe usable, to build normal gdb.exe we will need to rebuild with --disable-tui.

And there is more catch about gdbtui, if it was run under MSYS (TERM=cygwin) gdb will print ugly UI. We need to unset TERM before execute gdbtui and only plain Windows console that works (console2, rxvt or mintty won't). Here is a screenie under CMD window:


Patch to enable TUI (need ncurses 5.9):

--- gdb/configure Tue Dec 13 20:08:05 2011
+++ gdb/configure Sat Feb 11 18:06:04 2012
@@ -9799,9 +9799,10 @@
     ac_cv_search_tgetent="none required"
     ;;
   *mingw32*)
-    ac_cv_search_tgetent="none required"
-    CONFIG_OBS="$CONFIG_OBS windows-termcap.o"
-    ;;
+    if test x"$enable_tui" = xno; then
+      ac_cv_search_tgetent="none required"
+      CONFIG_OBS="$CONFIG_OBS windows-termcap.o"
+    fi ;;
 esac

 # These are the libraries checked by Readline.


Patch to make portable python integration:

--- gdb/python/python.c Sun Jan 15 01:04:05 2012
+++ gdb/python/python.c Sat Feb 11 19:21:56 2012
@@ -1429,6 +1429,12 @@
   # interpreter to find them.\n\
   if old_dir in sys.path:\n\
    sys.path.remove (old_dir)\n\
+  if (os.getenv ('PYTHONHOME')):\n\
+    if os.path.isdir (os.getenv ('PYTHONHOME'), 'Lib', 'site-packages')):\n\
+      gdb.PYTHONDIR = os.getenv ('PYTHONHOME'), 'Lib', 'site-packages')\n\
+  else:\n\
+    gdb.PYTHONDIR = os.path.join (os.path.split (sys.executable)[0], 'gdb', 'python')\n\
+\n\
   sys.path.insert (0, gdb.PYTHONDIR)\n\
 \n\
  # Tell python where to find submodules of gdb.\n\


Downloads:
gdbtui74.7z 2.59MB with python 2.6

update:
7.4.1 with python 2.6 against pdcurses + the old insight 6.8-1a, gdb linked to msvcr90.dll
gdbtui.7z
7.5.1 with keybinding patch (see comment)
gdb-7.5.1.7z

10 comments:

  1. Free Pascal has GDB integrated in their textmode IDE.

    ReplyDelete
  2. Can not display command typed before when using UP and DOWN arrow, and I have set focus to CMD window, please fix this issue.

    ReplyDelete
    Replies
    1. Yeah I'm aware of that issue, curses sometime has wrong keybinding. Readline is supposed to use gdb's windows-termcap.c not curses. All arrows not work anyway

      Dunno if this help but try Ctrl-p, works for me, yeah weird

      Delete
  3. I was today able to build a gdb with TUI support, and still use it without -tui. Maybe you want to try it out as well:

    --- gdb/main.c 2012-08-29 21:27:58 +0200
    +++ gdb/main.c 2013-04-18 19:24:08 +0200
    @@ -43,6 +43,10 @@
    #include "objfiles.h"
    #include "auto-load.h"

    +#if defined(__MINGW32__) && defined(TUI)
    +#include
    +#endif
    +
    /* The selected interpreter. This will be used as a set command
    variable, so it should always be malloc'ed - since
    do_setshow_command will free it. */
    @@ -792,6 +796,26 @@
    operations. */
    }

    +#if defined(__MINGW32__) && defined(TUI)
    + {
    + /* workaround for mingw with TUI:
    + * getch() needs (all?) this initialization */
    + WINDOW *w = initscr ();
    + cbreak ();
    + noecho ();
    + nodelay (w, FALSE);
    + nl ();
    + keypad (w, TRUE);
    + def_prog_mode ();
    + wrefresh (w);
    +
    + def_shell_mode ();
    + clearok (stdscr, TRUE);
    +
    + endwin ();
    + }
    +#endif
    +
    /* Install the default UI. All the interpreters should have had a
    look at things by now. Initialize the default interpreter. */

    ReplyDelete
    Replies
    1. Thanks ssbssa, which GDB version this intended to? I've heard GDB 7.5 drop the separate mode.

      Does it fix keybinding issue?

      Delete
    2. It's for 7.5.1.

      I didn't even notice that there was a keybinding issue as I always use ctrl-p/n.
      I tried it out, sadly it doesn't fix it.

      Delete
  4. keybinding issue: ncurses (for windows) doesn't return any special keys when the "keypad" is deactivated.
    My workaround was to always keep it enabled and let readline convert them to the expected key-sequences:

    --- readline/readline.c 2011-05-12 01:38:39 +0200
    +++ readline/readline.c 2013-04-21 16:04:24 +0200
    @@ -548,6 +548,50 @@
    #endif
    }

    +#ifdef __MINGW32__
    + if (c>=256)
    + {
    + int stuffed = 1;
    + switch (c)
    + {
    + case 0403: // KEY_UP
    + _rl_unget_char ('A');
    + break;
    +
    + case 0402: // KEY_DOWN
    + _rl_unget_char ('B');
    + break;
    +
    + case 0405: // KEY_RIGHT
    + _rl_unget_char ('C');
    + break;
    +
    + case 0404: // KEY_LEFT
    + _rl_unget_char ('D');
    + break;
    +
    + case 0406: // KEY_HOME
    + _rl_unget_char ('H');
    + break;
    +
    + case 0550: // KEY_END
    + _rl_unget_char ('F');
    + break;
    +
    + default:
    + c = 256;
    + stuffed = 0;
    + break;
    + }
    +
    + if (stuffed)
    + {
    + c = 033;
    + _rl_unget_char ('[');
    + }
    + }
    +#endif
    +
    lastc = c;
    _rl_dispatch ((unsigned char)c, _rl_keymap);
    RL_CHECK_SIGNALS ();
    --- gdb/tui/tui.c 2012-01-04 09:27:59 +0100
    +++ gdb/tui/tui.c 2013-04-21 15:40:42 +0200
    @@ -223,7 +223,9 @@
    tui_set_win_focus_to (win_info);
    if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible)
    tui_refresh_data_win ();
    +#ifndef __MINGW32__
    keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
    +#endif
    }
    return 0;
    }
    --- gdb/tui/tui-win.c 2012-03-16 19:22:24 +0100
    +++ gdb/tui/tui-win.c 2013-04-21 15:42:14 +0200
    @@ -674,7 +674,9 @@
    resize_term (screenheight, screenwidth);
    #endif
    /* Turn keypad off while we resize. */
    +#ifndef __MINGW32__
    if (win_with_focus != TUI_CMD_WIN)
    +#endif
    keypad (TUI_CMD_WIN->generic.handle, FALSE);
    tui_update_gdb_sizes ();
    tui_set_term_height_to (screenheight);
    @@ -808,7 +810,9 @@
    }
    /* Turn keypad back on, unless focus is in the command
    window. */
    +#ifndef __MINGW32__
    if (win_with_focus != TUI_CMD_WIN)
    +#endif
    keypad (TUI_CMD_WIN->generic.handle, TRUE);
    }
    }
    @@ -934,7 +938,9 @@
    else
    {
    tui_set_win_focus_to (win_info);
    +#ifndef __MINGW32__
    keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
    +#endif
    }

    if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible)

    ReplyDelete
    Replies
    1. wow that's fast man!
      definitely will try your patches one day, thanks a lot!

      Delete
  5. Hmmm something strange with 7.5 I can't get cross debugger to work: 64bit app with 32bit cross-gdb on 64bit windows. I can do this with previous 7.4 though. BTW your patches works fine. Thanks

    ReplyDelete