From patchwork Thu Nov 14 22:51:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35902 Received: (qmail 100189 invoked by alias); 14 Nov 2019 22:51:37 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 100127 invoked by uid 89); 14 Nov 2019 22:51:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=y2 X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Nov 2019 22:51:34 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id B229020E5F; Thu, 14 Nov 2019 17:51:31 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 9282020C05 for ; Thu, 14 Nov 2019 17:51:21 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 6A8CC20AF6 for ; Thu, 14 Nov 2019 17:51:21 -0500 (EST) X-Gerrit-PatchSet: 3 Date: Thu, 14 Nov 2019 17:51:20 -0500 From: "Tom Tromey (Code Review)" To: gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review v3] First use of tui_layout X-Gerrit-Change-Id: If1ee06ee58f4803e8c213f4ab0f5bb59f4650ec2 X-Gerrit-Change-Number: 368 X-Gerrit-ChangeURL: X-Gerrit-Commit: 711b316668a4b144970dc9db04a0fdf65a068742 In-Reply-To: References: Reply-To: tromey@sourceware.org, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-76-gf8b6da0ab5 Message-Id: <20191114225121.6A8CC20AF6@gnutoolchain-gerrit.osci.io> Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/368 ...................................................................... First use of tui_layout This patch introduces the first use of tui_layout, by changing show_layout to clone and use the appropriate tui_layout. This resulted in one minor layout change, and also in the unintended -- but good -- side effect that the title of each boxed window is now visible. 2019-11-12 Tom Tromey * tui/tui-layout.h (tui_apply_current_layout): Declare. * tui/tui-layout.c (standard_layouts, applied_layout): New globals. (tui_apply_current_layout): New function. (show_layout): Set applied_layout. Call tui_apply_current_layout. (show_source_command, show_disasm_command) (show_source_disasm_command, show_data) (show_source_or_disasm_and_command): Remove. (initialize_layouts): New function. (_initialize_tui_layout): Call initialize_layouts. gdb/testsuite/ChangeLog 2019-11-12 Tom Tromey * gdb.tui/basic.exp: Update. * lib/tuiterm.exp (_check_box): Don't check bottom border. Change-Id: If1ee06ee58f4803e8c213f4ab0f5bb59f4650ec2 --- M gdb/ChangeLog M gdb/testsuite/ChangeLog M gdb/testsuite/gdb.tui/basic.exp M gdb/testsuite/lib/tuiterm.exp M gdb/tui/tui-layout.c M gdb/tui/tui-layout.h 6 files changed, 75 insertions(+), 175 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ea58cbb..161cf4a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,19 @@ 2019-11-12 Tom Tromey + * tui/tui-layout.h (tui_apply_current_layout): Declare. + * tui/tui-layout.c (standard_layouts, applied_layout): New + globals. + (tui_apply_current_layout): New function. + (show_layout): Set applied_layout. Call + tui_apply_current_layout. + (show_source_command, show_disasm_command) + (show_source_disasm_command, show_data) + (show_source_or_disasm_and_command): Remove. + (initialize_layouts): New function. + (_initialize_tui_layout): Call initialize_layouts. + +2019-11-12 Tom Tromey + * tui/tui-layout.h (class tui_layout_base) (class tui_layout_window, class tui_layout_split): New. * tui/tui-layout.c (tui_get_window_by_name) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 3a4d229..ff2139e 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-11-12 Tom Tromey + + * gdb.tui/basic.exp: Update. + * lib/tuiterm.exp (_check_box): Don't check bottom border. + 2019-11-14 Tom Tromey * gdb.base/gdbvars.exp (test_convenience_variables): Add diff --git a/gdb/testsuite/gdb.tui/basic.exp b/gdb/testsuite/gdb.tui/basic.exp index 716c52f..cf61c28 100644 --- a/gdb/testsuite/gdb.tui/basic.exp +++ b/gdb/testsuite/gdb.tui/basic.exp @@ -40,7 +40,7 @@ Term::command "layout asm" Term::check_contents "asm window shows main" "$hex
" -Term::check_box "asm box" 0 0 80 15 +Term::check_box "asm box" 0 0 80 16 Term::command "layout split" Term::check_contents "split layout contents" "21 *return 0.*$hex
" diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index dcba028..81247d5 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -555,13 +555,9 @@ return "lr corner" } - for {set i [expr {$x + 1}]} {$i < $x2 - 1} {incr i} { - # Note we do not check the top border of the box, because - # it will contain a title. - if {[get_char $i $y2] != "-"} { - return "bottom border $i" - } - } + # Note we do not check the horizonal borders of the box. The + # top will contain a title, and the bottom may as well, if it + # is overlapped by some other border. for {set i [expr {$y + 1}]} {$i < $y2 - 1} {incr i} { if {[get_char $x $i] != "|"} { return "left side $i" diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 0fc2f36..097d9f6 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -41,17 +41,18 @@ #include "gdb_curses.h" static void show_layout (enum tui_layout_type); -static void show_source_or_disasm_and_command (enum tui_layout_type); -static void show_source_command (void); -static void show_disasm_command (void); -static void show_source_disasm_command (void); -static void show_data (enum tui_layout_type); static enum tui_layout_type next_layout (void); static enum tui_layout_type prev_layout (void); static void tui_layout_command (const char *, int); static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *); +/* The pre-defined layouts. */ +static tui_layout_split *standard_layouts[UNDEFINED_LAYOUT]; + +/* The layout that is currently applied. */ +static std::unique_ptr applied_layout; + static enum tui_layout_type current_layout = UNDEFINED_LAYOUT; /* Accessor for the current layout. */ @@ -61,6 +62,13 @@ return current_layout; } +/* See tui-layout.h. */ + +void +tui_apply_current_layout () +{ + applied_layout->apply (0, 0, tui_term_width (), tui_term_height ()); +} /* Show the screen layout defined. */ static void @@ -71,26 +79,8 @@ if (layout != cur_layout) { tui_make_all_invisible (); - switch (layout) - { - case SRC_DATA_COMMAND: - case DISASSEM_DATA_COMMAND: - show_data (layout); - break; - /* Now show the new layout. */ - case SRC_COMMAND: - show_source_command (); - break; - case DISASSEM_COMMAND: - show_disasm_command (); - break; - case SRC_DISASSEM_COMMAND: - show_source_disasm_command (); - break; - default: - break; - } - + applied_layout = standard_layouts[layout]->clone (); + tui_apply_current_layout (); current_layout = layout; tui_delete_invisible_windows (); } @@ -364,105 +354,6 @@ return (enum tui_layout_type) new_layout; } -/* Show the Source/Command layout. */ -static void -show_source_command (void) -{ - show_source_or_disasm_and_command (SRC_COMMAND); -} - - -/* Show the Dissassem/Command layout. */ -static void -show_disasm_command (void) -{ - show_source_or_disasm_and_command (DISASSEM_COMMAND); -} - - -/* Show the Source/Disassem/Command layout. */ -static void -show_source_disasm_command (void) -{ - int cmd_height, src_height, asm_height; - - if (TUI_CMD_WIN != NULL) - cmd_height = TUI_CMD_WIN->height; - else - cmd_height = tui_term_height () / 3; - - src_height = (tui_term_height () - cmd_height) / 2; - asm_height = tui_term_height () - (src_height + cmd_height); - - if (TUI_SRC_WIN == NULL) - tui_win_list[SRC_WIN] = new tui_source_window (); - TUI_SRC_WIN->resize (src_height, - tui_term_width (), - 0, - 0); - - struct tui_locator_window *locator = tui_locator_win_info_ptr (); - gdb_assert (locator != nullptr); - - if (TUI_DISASM_WIN == NULL) - tui_win_list[DISASSEM_WIN] = new tui_disasm_window (); - TUI_DISASM_WIN->resize (asm_height, - tui_term_width (), - 0, - src_height - 1); - locator->resize (1, tui_term_width (), - 0, (src_height + asm_height) - 1); - - if (TUI_CMD_WIN == NULL) - tui_win_list[CMD_WIN] = new tui_cmd_window (); - TUI_CMD_WIN->resize (cmd_height, - tui_term_width (), - 0, - tui_term_height () - cmd_height); -} - - -/* Show the Source/Data/Command or the Dissassembly/Data/Command - layout. */ -static void -show_data (enum tui_layout_type new_layout) -{ - int total_height = (tui_term_height () - TUI_CMD_WIN->height); - int src_height, data_height; - enum tui_win_type win_type; - - struct tui_locator_window *locator = tui_locator_win_info_ptr (); - gdb_assert (locator != nullptr); - - data_height = total_height / 2; - src_height = total_height - data_height; - if (tui_win_list[DATA_WIN] == nullptr) - tui_win_list[DATA_WIN] = new tui_data_window (); - tui_win_list[DATA_WIN]->resize (data_height, tui_term_width (), 0, 0); - - if (new_layout == SRC_DATA_COMMAND) - win_type = SRC_WIN; - else - win_type = DISASSEM_WIN; - - if (tui_win_list[win_type] == NULL) - { - if (win_type == SRC_WIN) - tui_win_list[win_type] = new tui_source_window (); - else - tui_win_list[win_type] = new tui_disasm_window (); - } - - tui_win_list[win_type]->resize (src_height, - tui_term_width (), - 0, - data_height - 1); - locator->resize (1, tui_term_width (), - 0, total_height - 1); - TUI_CMD_WIN->resize (TUI_CMD_WIN->height, tui_term_width (), - 0, total_height); -} - void tui_gen_win_info::resize (int height_, int width_, int origin_x_, int origin_y_) @@ -498,49 +389,6 @@ rerender (); } -/* Show the Source/Command or the Disassem layout. */ -static void -show_source_or_disasm_and_command (enum tui_layout_type layout_type) -{ - struct tui_source_window_base *win_info; - int src_height, cmd_height; - struct tui_locator_window *locator = tui_locator_win_info_ptr (); - gdb_assert (locator != nullptr); - - if (TUI_CMD_WIN != NULL) - cmd_height = TUI_CMD_WIN->height; - else - cmd_height = tui_term_height () / 3; - src_height = tui_term_height () - cmd_height; - - if (layout_type == SRC_COMMAND) - { - if (tui_win_list[SRC_WIN] == nullptr) - tui_win_list[SRC_WIN] = new tui_source_window (); - win_info = TUI_SRC_WIN; - } - else - { - if (tui_win_list[DISASSEM_WIN] == nullptr) - tui_win_list[DISASSEM_WIN] = new tui_disasm_window (); - win_info = TUI_DISASM_WIN; - } - - locator->resize (1, tui_term_width (), - 0, src_height - 1); - win_info->resize (src_height - 1, - tui_term_width (), - 0, - 0); - - if (TUI_CMD_WIN == NULL) - tui_win_list[CMD_WIN] = new tui_cmd_window (); - TUI_CMD_WIN->resize (cmd_height, - tui_term_width (), - 0, - src_height); -} - /* Helper function that returns a TUI window, given its name. */ @@ -888,6 +736,38 @@ m_applied = true; } +static void +initialize_layouts () +{ + standard_layouts[SRC_COMMAND] = new tui_layout_split (); + standard_layouts[SRC_COMMAND]->add_window ("src", 2); + standard_layouts[SRC_COMMAND]->add_window ("locator", 0); + standard_layouts[SRC_COMMAND]->add_window ("cmd", 1); + + standard_layouts[DISASSEM_COMMAND] = new tui_layout_split (); + standard_layouts[DISASSEM_COMMAND]->add_window ("asm", 2); + standard_layouts[DISASSEM_COMMAND]->add_window ("locator", 0); + standard_layouts[DISASSEM_COMMAND]->add_window ("cmd", 1); + + standard_layouts[SRC_DATA_COMMAND] = new tui_layout_split (); + standard_layouts[SRC_DATA_COMMAND]->add_window ("src", 1); + standard_layouts[SRC_DATA_COMMAND]->add_window ("regs", 1); + standard_layouts[SRC_DATA_COMMAND]->add_window ("locator", 0); + standard_layouts[SRC_DATA_COMMAND]->add_window ("cmd", 1); + + standard_layouts[DISASSEM_DATA_COMMAND] = new tui_layout_split (); + standard_layouts[DISASSEM_DATA_COMMAND]->add_window ("asm", 1); + standard_layouts[DISASSEM_DATA_COMMAND]->add_window ("regs", 1); + standard_layouts[DISASSEM_DATA_COMMAND]->add_window ("locator", 0); + standard_layouts[DISASSEM_DATA_COMMAND]->add_window ("cmd", 1); + + standard_layouts[SRC_DISASSEM_COMMAND] = new tui_layout_split (); + standard_layouts[SRC_DISASSEM_COMMAND]->add_window ("src", 1); + standard_layouts[SRC_DISASSEM_COMMAND]->add_window ("asm", 1); + standard_layouts[SRC_DISASSEM_COMMAND]->add_window ("locator", 0); + standard_layouts[SRC_DISASSEM_COMMAND]->add_window ("cmd", 1); +} + /* Function to initialize gdb commands, for tui window layout @@ -912,4 +792,6 @@ the register window is displayed with \n\ the window that has current logical focus.")); set_cmd_completer (cmd, layout_completer); + + initialize_layouts (); } diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h index d7f0731..a9346ef 100644 --- a/gdb/tui/tui-layout.h +++ b/gdb/tui/tui-layout.h @@ -174,4 +174,7 @@ extern void tui_add_win_to_layout (enum tui_win_type); extern void tui_set_layout (enum tui_layout_type); +/* Apply the current layout. */ +extern void tui_apply_current_layout (); + #endif /* TUI_TUI_LAYOUT_H */