This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] [PR gdb/16762 gdb/15958] Fixes for properly resizing TUI


This patch is to fix Bug 16762 - GDB doesn't update display size when host
terminal resize, and it inadvertently fixes Bug 15958 - readline modifies
env (LINES+COLUMNS) as well.

Before it was getting it's size data from curses, but curses is not
available to the readline based interface, so things would get out of sync.
The readline based interface had no way at all to know if there had been
any changes to the size of the window. 

I have changed it so that both the sides use the same callback function. The
event handler has been changed to call some clean up operations that
readlines needs and then puts in a request to call the resize function in 
the main event loop on the next pass. It does change a couple new parameters
that readline 6.3 introduces, rl_change_environment and rl_prefer_env_winsize
They make it so readline does not set ROWS or COLUMNS in the environment,
and seems to be suggested by the ncurses FAQ [1]. The previous method
that handedled resizing after getting input from curses, along with some
support code, has been removed.

The only problem I am aware of with this patch is that until the first
character is typed after resizing in curses mode, you do not see
the contents of the command window. This seems to have no impact on any
other function. Resizing with, without, or any number of switches in
between curses and readline modes were unable to produce a out of sync
size report for me. Without the patch, any resize operation shrinks the
size of the command portion of the window to 3 lines, which is retained
as the full height of the screen in readline mode until you exit the 
session.

I see no regressions in the test suite, even though this isn't the
sort of issue that automated testing is very good at.

CustaiCo

[1] http://invisible-island.net/ncurses/ncurses.faq.html#handle_resize

                === gdb Summary ===

# of expected passes            28624
# of unexpected failures        98
# of unexpected successes       1
# of expected failures          58
# of known failures             55
# of unresolved testcases       12
# of untested testcases         46
# of unsupported tests          184

---
 gdb/ChangeLog      | 14 ++++++++++++++
 gdb/tui/tui-data.c | 16 ----------------
 gdb/tui/tui-io.c   | 21 ---------------------
 gdb/tui/tui-win.c  | 40 +++++++++++++++++++++++++++++++++++-----
 gdb/utils.c        |  7 +++++--
 5 files changed, 54 insertions(+), 44 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ee82f1f..73be21b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,17 @@
+2014-10-09  CustaiCo  <custaico@openmailbox.org>
+
+	PR gdb/16762
+	PR gdb/15958
+	* tui/tui-win.c: Changed the signal handling code to use the main
+	event loop.
+	* tui/tui-io.c: tui_handle_resize_during_io is not needed. The main
+	event loop handles the call back to resized the windows.
+	* tui/tui-data.c: Support methods for tui_handle_resize_during_io
+	removed.
+	* utils.c: Set new option in latest readline to prevent
+	environment from being changed. Also changed to not incorrectly resize
+	window when tui running.
+
 2014-10-09  Yao Qi  <yao@codesourcery.com>
 
 	* infrun.c (handle_signal_stop): Remove local variable
diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index 7e51b3e..06ea29b 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -98,22 +98,6 @@ tui_set_win_highlight (struct tui_win_info *win_info,
 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
 ******************************************/
 
-/* Answer a whether the terminal window has been resized or not.  */
-int
-tui_win_resized (void)
-{
-  return win_resized;
-}
-
-
-/* Set a whether the terminal window has been resized or not.  */
-void
-tui_set_win_resized_to (int resized)
-{
-  win_resized = resized;
-}
-
-
 /* Answer a pointer to the current layout definition.  */
 struct tui_layout_def *
 tui_layout_def (void)
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 601d278..4c7fca8 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -146,8 +146,6 @@ static int tui_readline_pipe[2];
    This may be the main gdb prompt or a secondary prompt.  */
 static char *tui_rl_saved_prompt;
 
-static unsigned int tui_handle_resize_during_io (unsigned int);
-
 static void
 tui_putc (char c)
 {
@@ -653,7 +651,6 @@ tui_getc (FILE *fp)
 #endif
 
   ch = wgetch (w);
-  ch = tui_handle_resize_during_io (ch);
 
   /* The \n must be echoed because it will not be printed by
      readline.  */
@@ -694,21 +691,3 @@ tui_getc (FILE *fp)
   
   return ch;
 }
-
-
-/* Cleanup when a resize has occured.
-   Returns the character that must be processed.  */
-static unsigned int
-tui_handle_resize_during_io (unsigned int original_ch)
-{
-  if (tui_win_resized ())
-    {
-      tui_resize_all ();
-      tui_refresh_all_win ();
-      dont_repeat ();
-      tui_set_win_resized_to (FALSE);
-      return '\n';
-    }
-  else
-    return original_ch;
-}
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 9c7a23f..095097a 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -29,6 +29,7 @@
 #include "symtab.h"
 #include "breakpoint.h"
 #include "frame.h"
+#include "event-loop.h"
 #include "cli/cli-cmds.h"
 #include "top.h"
 #include "source.h"
@@ -72,7 +73,7 @@ static void tui_scroll_right_command (char *, int);
 static void parse_scrolling_args (char *, 
 				  struct tui_win_info **, 
 				  int *);
-
+static void tui_handle_resize (void *);
 
 /***************************************
 ** DEFINITIONS
@@ -457,6 +458,31 @@ bold-standout   use extra bright or bold with standout mode"),
 			&tui_setlist, &tui_showlist);
 }
 
+/* This is called from the main event loop after we catch SIGWINCH */
+void
+tui_handle_resize (void *signal)
+{
+  char cmd[50];
+  int col, row;
+  if (tui_active)
+    {
+      tui_resize_all ();
+      tui_refresh_all_win ();
+      xsnprintf (cmd, sizeof (cmd), "set width %d", TUI_CMD_WIN->generic.width);
+      execute_command (cmd, 0);
+      xsnprintf (cmd, sizeof (cmd), "set height %d", TUI_CMD_WIN->generic.height);
+      execute_command (cmd, 0);
+    }
+  else
+    {
+      rl_get_screen_size (&row, &col);
+      xsnprintf (cmd, sizeof (cmd), "set width %d", col);
+      execute_command (cmd, 0);
+      xsnprintf (cmd, sizeof (cmd), "set height %d", row);
+      execute_command (cmd, 0);
+    }
+}
+
 /* Update gdb's knowledge of the terminal size.  */
 void
 tui_update_gdb_sizes (void)
@@ -670,7 +696,7 @@ tui_resize_all (void)
 
 #ifdef HAVE_RESIZE_TERM
       resize_term (screenheight, screenwidth);
-#endif      
+#endif
       /* Turn keypad off while we resize.  */
       if (win_with_focus != TUI_CMD_WIN)
 	keypad (TUI_CMD_WIN->generic.handle, FALSE);
@@ -818,9 +844,13 @@ tui_resize_all (void)
 static void
 tui_sigwinch_handler (int signal)
 {
-  /* Say that a resize was done so that the readline can do it later
-     when appropriate.  */
-  tui_set_win_resized_to (TRUE);
+  /* Say that a resize was done so that the we can update
+     the UI when appropriate. */
+  struct tui_translate data;
+  data.value = signal;
+  rl_cleanup_after_signal ();
+  rl_resize_terminal ();
+  mark_async_signal_handler (create_async_signal_handler (tui_handle_resize, &data));
 }
 #endif
 
diff --git a/gdb/utils.c b/gdb/utils.c
index 3915b58..ae0342a 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1686,6 +1686,8 @@ init_page_info (void)
       chars_per_line = cols;
 #else
       /* Make sure Readline has initialized its terminal settings.  */
+      rl_change_environment = 0;
+      rl_prefer_env_winsize = 0;
       rl_reset_terminal (NULL);
 
       /* Get the screen size from Readline.  */
@@ -1775,8 +1777,9 @@ set_screen_size (void)
   if (cols <= 0)
     cols = INT_MAX;
 
-  /* Update Readline's idea of the terminal size.  */
-  rl_set_screen_size (rows, cols);
+  /* Don't update with tui active or it will be too large */
+  if (!tui_active)
+      rl_set_screen_size (rows, cols);
 }
 
 /* Reinitialize WRAP_BUFFER according to the current value of

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]