Remove some TUI static allocations
authorTom Tromey <tom@tromey.com>
Mon, 17 Jun 2019 21:45:14 +0000 (15:45 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 25 Jun 2019 13:48:42 +0000 (07:48 -0600)
The TUI statically allocates the "execution_info" for the source and
disassembly windows.  However, there's no deep reason to do this, and
this approach makes it harder to allow multiple such windows.

This patch removes the static data and changes the code to simply
allocate these windows as needed.  This required pushing some code
into the tui_gen_win_info destructor, but that seems like a good idea
anyhow.

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

* tui/tui-layout.c (make_source_or_disasm_window): Always use
init_and_make_win for EXEC_INFO_WIN.
* tui/tui-data.h (struct tui_gen_win_info) <~tui_gen_win_info>: No
longer inline.
(struct tui_win_info) <~tui_win_info>: Inline.
(tui_source_exec_info_win_ptr, tui_disassem_exec_info_win_ptr):
Don't declare.
* tui/tui-data.c (source_win, disasm_win): Remove globals.
(tui_source_exec_info_win_ptr, tui_disassem_exec_info_win_ptr):
Remove.
(tui_initialize_static_data): Update.
(~tui_gen_win_info): Handle more cleanup here.
(~tui_source_window_base): Delete "execution_info".
(~tui_win_info): Move code to ~tui_gen_win_info; remove.

gdb/ChangeLog
gdb/tui/tui-data.c
gdb/tui/tui-data.h
gdb/tui/tui-layout.c

index 4f6f26a..db76928 100644 (file)
@@ -1,5 +1,22 @@
 2019-06-25  Tom Tromey  <tom@tromey.com>
 
+       * tui/tui-layout.c (make_source_or_disasm_window): Always use
+       init_and_make_win for EXEC_INFO_WIN.
+       * tui/tui-data.h (struct tui_gen_win_info) <~tui_gen_win_info>: No
+       longer inline.
+       (struct tui_win_info) <~tui_win_info>: Inline.
+       (tui_source_exec_info_win_ptr, tui_disassem_exec_info_win_ptr):
+       Don't declare.
+       * tui/tui-data.c (source_win, disasm_win): Remove globals.
+       (tui_source_exec_info_win_ptr, tui_disassem_exec_info_win_ptr):
+       Remove.
+       (tui_initialize_static_data): Update.
+       (~tui_gen_win_info): Handle more cleanup here.
+       (~tui_source_window_base): Delete "execution_info".
+       (~tui_win_info): Move code to ~tui_gen_win_info; remove.
+
+2019-06-25  Tom Tromey  <tom@tromey.com>
+
        * tui/tui-layout.c (make_command_window): Don't set
        can_highlight.
        (show_source_disasm_command): Call the reset method.
index 79990b8..3d1e0e6 100644 (file)
@@ -37,8 +37,6 @@ struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
 static enum tui_layout_type current_layout = UNDEFINED_LAYOUT;
 static int term_height, term_width;
 static struct tui_gen_win_info _locator (LOCATOR_WIN);
-static struct tui_gen_win_info source_win (EXEC_INFO_WIN);
-static struct tui_gen_win_info disasm_win (EXEC_INFO_WIN);
 static std::vector<tui_source_window_base *> source_windows;
 static struct tui_win_info *win_with_focus = NULL;
 static struct tui_layout_def layout_def = {
@@ -185,22 +183,6 @@ tui_data_window::clear_detail ()
   display_regs = false;
 }
 
-/* Accessor for the source execution info ptr.  */
-struct tui_gen_win_info *
-tui_source_exec_info_win_ptr (void)
-{
-  return &source_win;
-}
-
-
-/* Accessor for the disassem execution info ptr.  */
-struct tui_gen_win_info *
-tui_disassem_exec_info_win_ptr (void)
-{
-  return &disasm_win;
-}
-
-
 /* Accessor for the locator win info.  Answers a pointer to the static
    locator win info struct.  */
 struct tui_gen_win_info *
@@ -354,8 +336,6 @@ tui_partial_win_by_name (const char *name)
 void
 tui_initialize_static_data (void)
 {
-  tui_init_generic_part (tui_source_exec_info_win_ptr ());
-  tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
   tui_init_generic_part (tui_locator_win_info_ptr ());
 }
 
@@ -525,16 +505,21 @@ tui_add_content_elements (struct tui_gen_win_info *win_info,
   return index_start;
 }
 
-tui_source_window_base::~tui_source_window_base ()
+tui_gen_win_info::~tui_gen_win_info ()
 {
-  xfree (fullname);
-  struct tui_gen_win_info *generic_win = execution_info;
-  if (generic_win != NULL)
+  if (handle != NULL)
     {
-      tui_delete_win (generic_win->handle);
-      generic_win->handle = NULL;
-      tui_free_win_content (generic_win);
+      tui_delete_win (handle);
+      handle = NULL;
+      tui_free_win_content (this);
     }
+  xfree (title);
+}
+
+tui_source_window_base::~tui_source_window_base ()
+{
+  xfree (fullname);
+  delete execution_info;
 }  
 
 tui_data_window::~tui_data_window ()
@@ -554,19 +539,6 @@ tui_data_window::~tui_data_window ()
     }
 }  
 
-tui_win_info::~tui_win_info ()
-{
-  if (handle != NULL)
-    {
-      tui_delete_win (handle);
-      handle = NULL;
-      tui_free_win_content (this);
-    }
-  if (title)
-    xfree (title);
-}
-
-
 void
 tui_free_all_source_wins_content ()
 {
index fdde302..9c45d6f 100644 (file)
@@ -44,9 +44,7 @@ struct tui_gen_win_info
   {
   }
 
-  virtual ~tui_gen_win_info ()
-  {
-  }
+  virtual ~tui_gen_win_info ();
 
   /* Call to refresh this window.  */
   virtual void refresh_window ();
@@ -272,7 +270,9 @@ protected:
 
 public:
 
-  ~tui_win_info () override;
+  ~tui_win_info () override
+  {
+  }
 
   /* Clear the pertinent detail in the window.  */
   virtual void clear_detail () = 0;
@@ -524,8 +524,6 @@ extern void tui_set_term_height_to (int);
 extern int tui_term_width (void);
 extern void tui_set_term_width_to (int);
 extern struct tui_gen_win_info *tui_locator_win_info_ptr (void);
-extern struct tui_gen_win_info *tui_source_exec_info_win_ptr (void);
-extern struct tui_gen_win_info *tui_disassem_exec_info_win_ptr (void);
 extern std::vector<tui_source_window_base *> &tui_source_windows ();
 extern void tui_clear_source_windows (void);
 extern void tui_clear_source_windows_detail (void);
index f586d70..695fa35 100644 (file)
@@ -814,22 +814,14 @@ static struct tui_win_info *
 make_source_or_disasm_window (enum tui_win_type type,
                              int height, int origin_y)
 {
-  struct tui_gen_win_info *execution_info = NULL;
-
-  /* Create the exeuction info window.  */
-  if (type == SRC_WIN)
-    execution_info = tui_source_exec_info_win_ptr ();
-  else
-    execution_info = tui_disassem_exec_info_win_ptr ();
-  execution_info
-    = ((struct tui_gen_win_info *)
-       init_and_make_win (execution_info,
-                         EXEC_INFO_WIN,
-                         height,
-                         3,
-                         0,
-                         origin_y,
-                         DONT_BOX_WINDOW));
+  struct tui_gen_win_info *execution_info
+    = init_and_make_win (nullptr,
+                        EXEC_INFO_WIN,
+                        height,
+                        3,
+                        0,
+                        origin_y,
+                        DONT_BOX_WINDOW);
 
   /* Now create the source window.  */
   struct tui_source_window_base *result