From f936bca26dd7593a3b792e76eba37c5de2374961 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 17 Jun 2019 15:45:14 -0600 Subject: [PATCH] Remove some TUI static allocations 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 * 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 | 17 +++++++++++++++ gdb/tui/tui-data.c | 52 ++++++++++---------------------------------- gdb/tui/tui-data.h | 10 ++++----- gdb/tui/tui-layout.c | 24 +++++++------------- 4 files changed, 41 insertions(+), 62 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4f6f26adb3..db769282a2 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,20 @@ +2019-06-25 Tom Tromey + + * 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 * tui/tui-layout.c (make_command_window): Don't set diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c index 79990b8a0d..3d1e0e6ff0 100644 --- a/gdb/tui/tui-data.c +++ b/gdb/tui/tui-data.c @@ -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 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 () { diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h index fdde302659..9c45d6f637 100644 --- a/gdb/tui/tui-data.h +++ b/gdb/tui/tui-data.h @@ -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_windows (); extern void tui_clear_source_windows (void); extern void tui_clear_source_windows_detail (void); diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index f586d703d4..695fa3560b 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -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 -- 2.34.1