More type safety for TUI source window functions
authorTom Tromey <tom@tromey.com>
Sun, 23 Jun 2019 18:21:34 +0000 (12:21 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 25 Jun 2019 13:48:50 +0000 (07:48 -0600)
A few functions can only operate on a source or disassembly window.
This patch adds a bit more type safety to a few of these functions.
This simplifies a subsequent patch.

gdb/ChangeLog
2019-06-25  Tom Tromey  <tom@tromey.com>

* tui/tui-winsource.h (tui_clear_source_content)
(tui_erase_source_content, tui_show_source_content): Change type
of win_info.
* tui/tui-winsource.c (tui_clear_source_content)
(tui_erase_source_content, tui_show_source_content): Change type
of win_info.
* tui/tui-win.c (tui_resize_all, tui_adjust_win_heights): Update.
* tui/tui-source.h (tui_set_source_content_nil): Change type of
win_info.
* tui/tui-source.c (tui_set_source_content_nil): Change type of
win_info.
* tui/tui-layout.c (show_source_or_disasm_and_command): Update.

gdb/ChangeLog
gdb/tui/tui-layout.c
gdb/tui/tui-source.c
gdb/tui/tui-source.h
gdb/tui/tui-win.c
gdb/tui/tui-winsource.c
gdb/tui/tui-winsource.h

index 02d96d106b495a441fcf563d4b0756beb2c17e6c..ee4b3d0c9b43823a266d6e088b11992d47e5d88b 100644 (file)
@@ -1,3 +1,18 @@
+2019-06-25  Tom Tromey  <tom@tromey.com>
+
+       * tui/tui-winsource.h (tui_clear_source_content)
+       (tui_erase_source_content, tui_show_source_content): Change type
+       of win_info.
+       * tui/tui-winsource.c (tui_clear_source_content)
+       (tui_erase_source_content, tui_show_source_content): Change type
+       of win_info.
+       * tui/tui-win.c (tui_resize_all, tui_adjust_win_heights): Update.
+       * tui/tui-source.h (tui_set_source_content_nil): Change type of
+       win_info.
+       * tui/tui-source.c (tui_set_source_content_nil): Change type of
+       win_info.
+       * tui/tui-layout.c (show_source_or_disasm_and_command): Update.
+
 2019-06-25  Tom Tromey  <tom@tromey.com>
 
        * tui/tui-winsource.c (tui_clear_source_content)
index 9fffba779a9a1c79e012641a82c094a3f6fe742c..ad99ec9abd914d574f7c0f96636c1967888eece3 100644 (file)
@@ -921,7 +921,7 @@ show_source_or_disasm_and_command (enum tui_layout_type layout_type)
       base->m_has_locator = true;
       tui_make_visible (locator);
       tui_show_locator_content ();
-      tui_show_source_content (*win_info_ptr);
+      tui_show_source_content (base);
 
       if (TUI_CMD_WIN == NULL)
        {
index 54e4e1be903efdcd9a5cc8399f4be985d78b29e3..fd89d98ba16dd1caa5d22375a0424e53612cb4be 100644 (file)
@@ -222,7 +222,7 @@ tui_set_source_content (struct symtab *s,
    source files cannot be accessed.  */
 
 void
-tui_set_source_content_nil (struct tui_win_info *win_info, 
+tui_set_source_content_nil (struct tui_source_window_base *win_info,
                            const char *warning_string)
 {
   int line_width;
index 7757373a2a2b1cbea3afbe7f68e9c0f82048b184..9e1dc1a6e109bf4a81f7997fc7284a18924a847c 100644 (file)
@@ -27,7 +27,7 @@
 struct symtab;
 struct tui_win_info;
 
-extern void tui_set_source_content_nil (struct tui_win_info *, 
+extern void tui_set_source_content_nil (struct tui_source_window_base *,
                                        const char *);
 
 extern enum tui_status tui_set_source_content (struct symtab *, 
index dac3996ce5b3b0567c2188d59a89d62b6d107391..2f862c1a2f08b581e89ae8941c066a64e6576464 100644 (file)
@@ -556,6 +556,7 @@ tui_resize_all (void)
       struct tui_win_info *win_with_focus = tui_win_with_focus ();
       struct tui_win_info *first_win;
       struct tui_win_info *second_win;
+      tui_source_window_base *src_win;
       struct tui_locator_window *locator = tui_locator_win_info_ptr ();
       int win_type;
       int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2;
@@ -592,7 +593,8 @@ tui_resize_all (void)
        {
        case SRC_COMMAND:
        case DISASSEM_COMMAND:
-         first_win = tui_source_windows ()[0];
+         src_win = tui_source_windows ()[0];
+         first_win = src_win;
          first_win->width += width_diff;
          locator->width += width_diff;
          /* Check for invalid heights.  */
@@ -614,13 +616,14 @@ tui_resize_all (void)
          make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
          first_win->make_visible_with_new_height ();
          TUI_CMD_WIN->make_visible_with_new_height ();
-         if (first_win->content_size <= 0)
-           tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
+         if (src_win->content_size <= 0)
+           tui_erase_source_content (src_win, EMPTY_SOURCE_PROMPT);
          break;
        default:
          if (cur_layout == SRC_DISASSEM_COMMAND)
            {
-             first_win = TUI_SRC_WIN;
+             src_win = TUI_SRC_WIN;
+             first_win = src_win;
              first_win->width += width_diff;
              second_win = TUI_DISASM_WIN;
              second_win->width += width_diff;
@@ -629,7 +632,8 @@ tui_resize_all (void)
            {
              first_win = TUI_DATA_WIN;
              first_win->width += width_diff;
-             second_win = tui_source_windows ()[0];
+             src_win = tui_source_windows ()[0];
+             second_win = src_win;
              second_win->width += width_diff;
            }
          /* Change the first window's height/width.  */
@@ -677,10 +681,8 @@ tui_resize_all (void)
          first_win->make_visible_with_new_height ();
          second_win->make_visible_with_new_height ();
          TUI_CMD_WIN->make_visible_with_new_height ();
-         if (first_win->content_size <= 0)
-           tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
-         if (second_win->content_size <= 0)
-           tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
+         if (src_win->content_size <= 0)
+           tui_erase_source_content (src_win, EMPTY_SOURCE_PROMPT);
          break;
        }
       /* Now remove all invisible windows, and their content so that
@@ -1124,21 +1126,28 @@ tui_adjust_win_heights (struct tui_win_info *primary_win_info,
              TUI_CMD_WIN->origin.y = locator->origin.y + 1;
              win_info->make_visible_with_new_height ();
              primary_win_info->make_visible_with_new_height ();
-             if (src_win_info->content_size <= 0)
-               tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT);
+             if ((src_win_info->type == SRC_WIN
+                  || src_win_info->type == DISASSEM_WIN)
+                 && src_win_info->content_size <= 0)
+               tui_erase_source_content
+                 ((tui_source_window_base *) src_win_info,
+                  EMPTY_SOURCE_PROMPT);
            }
          else
            {
              struct tui_win_info *first_win;
-             struct tui_win_info *second_win;
+             struct tui_source_window_base *second_win;
+             tui_source_window_base *src1;
 
              if (cur_layout == SRC_DISASSEM_COMMAND)
                {
-                 first_win = TUI_SRC_WIN;
+                 src1 = TUI_SRC_WIN;
+                 first_win = src1;
                  second_win = TUI_DISASM_WIN;
                }
              else
                {
+                 src1 = nullptr;
                  first_win = TUI_DATA_WIN;
                  second_win = tui_source_windows ()[0];
                }
@@ -1227,8 +1236,8 @@ tui_adjust_win_heights (struct tui_win_info *primary_win_info,
              TUI_CMD_WIN->make_visible_with_new_height ();
              second_win->make_visible_with_new_height ();
              first_win->make_visible_with_new_height ();
-             if (first_win->content_size <= 0)
-               tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
+             if (src1 != nullptr && src1->content_size <= 0)
+               tui_erase_source_content (src1, EMPTY_SOURCE_PROMPT);
              if (second_win->content_size <= 0)
                tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
            }
index f30c3d67632d942b7545cb13dfdce6c280a3f69e..b11feff2a4d7f11eb43cd9be52ec10eae076d426 100644 (file)
@@ -204,7 +204,7 @@ tui_update_source_windows_with_line (struct symtab *s, int line)
 }
 
 void
-tui_clear_source_content (struct tui_win_info *win_info, 
+tui_clear_source_content (struct tui_source_window_base *win_info,
                          int display_prompt)
 {
   if (win_info != NULL)
@@ -225,7 +225,7 @@ tui_clear_source_content (struct tui_win_info *win_info,
 
 
 void
-tui_erase_source_content (struct tui_win_info *win_info, 
+tui_erase_source_content (struct tui_source_window_base *win_info,
                          int display_prompt)
 {
   int x_pos;
@@ -291,7 +291,7 @@ tui_show_source_line (struct tui_win_info *win_info, int lineno)
 }
 
 void
-tui_show_source_content (struct tui_win_info *win_info)
+tui_show_source_content (struct tui_source_window_base *win_info)
 {
   if (win_info->content_size > 0)
     {
index 09a9d5abf4a0bb6826b4f125b22daa1475ecfa8c..f914c0aaf14af389574a3d2a0c5b933a2a9fa85e 100644 (file)
@@ -50,9 +50,9 @@ extern void tui_update_source_window_as_is (struct tui_source_window_base *,
 extern void tui_update_source_windows_with_addr (struct gdbarch *, CORE_ADDR);
 extern void tui_update_source_windows_with_line (struct symtab *, 
                                                 int);
-extern void tui_clear_source_content (struct tui_win_info *, int);
-extern void tui_erase_source_content (struct tui_win_info *, int);
-extern void tui_show_source_content (struct tui_win_info *);
+extern void tui_clear_source_content (struct tui_source_window_base *, int);
+extern void tui_erase_source_content (struct tui_source_window_base *, int);
+extern void tui_show_source_content (struct tui_source_window_base *);
 extern void tui_set_exec_info_content (struct tui_source_window_base *);
 extern void tui_show_exec_info_content (struct tui_source_window_base *);
 extern void tui_erase_exec_info_content (struct tui_source_window_base *);