From patchwork Sat Aug 3 13:29:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33935 Received: (qmail 95249 invoked by alias); 3 Aug 2019 13:29:35 -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 95096 invoked by uid 89); 3 Aug 2019 13:29:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SEMBLACK, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=Unify, unify X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.144.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 03 Aug 2019 13:29:31 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 7F0F0D5134 for ; Sat, 3 Aug 2019 08:29:30 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id tu6Ehsg8ziQertu6EhGra1; Sat, 03 Aug 2019 08:29:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=fFrQWyQ++rzA13uPs3ONzmqU3IwLYqp2SUEdgoqVDds=; b=dVnOdc9Qjdhr1v2AGLMjuv43i+ +ycpZjbxoYX9sCiB8PFQ3TCv/X3rzwyCmhB0xR8SFbT+RU98LFjh3AFl0htySEXiu0MicQ2wPuD5E HEbJ3CDpRKsv0rB2xg5SnE9Do; Received: from 97-122-178-82.hlrn.qwest.net ([97.122.178.82]:36980 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1htu6E-003nqS-9H; Sat, 03 Aug 2019 08:29:30 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 06/19] Two simplifications in tui-layout.c Date: Sat, 3 Aug 2019 07:29:12 -0600 Message-Id: <20190803132925.25074-7-tom@tromey.com> In-Reply-To: <20190803132925.25074-1-tom@tromey.com> References: <20190803132925.25074-1-tom@tromey.com> This patch simplifies some code in tui-layout.c. In show_layout, all the layout settings can be handled by a single switch statement. In show_source_disasm_command and show_source_or_disasm_and_command, there is no need to check the current layout, as the caller has already done so. gdb/ChangeLog 2019-08-03 Tom Tromey * tui/tui-layout.c (show_layout): Unify all layout cases into a single switch. (show_source_disasm_command, show_source_or_disasm_and_command): Don't check current layout. --- gdb/ChangeLog | 7 ++ gdb/tui/tui-layout.c | 228 +++++++++++++++++++++---------------------- 2 files changed, 116 insertions(+), 119 deletions(-) diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 3ee3354b2ff..91db38404b3 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -83,33 +83,29 @@ show_layout (enum tui_layout_type layout) /* First make the current layout be invisible. */ tui_make_all_invisible (); tui_locator_win_info_ptr ()->make_visible (false); - if (layout == SRC_DATA_COMMAND - || layout == DISASSEM_DATA_COMMAND) + switch (layout) { + case SRC_DATA_COMMAND: + case DISASSEM_DATA_COMMAND: show_data (layout); tui_refresh_all (); - } - else - { - switch (layout) - { - /* Now show the new layout. */ - case SRC_COMMAND: - show_source_command (); - tui_add_to_source_windows (TUI_SRC_WIN); - break; - case DISASSEM_COMMAND: - show_disasm_command (); - tui_add_to_source_windows (TUI_DISASM_WIN); - break; - case SRC_DISASSEM_COMMAND: - show_source_disasm_command (); - tui_add_to_source_windows (TUI_SRC_WIN); - tui_add_to_source_windows (TUI_DISASM_WIN); - break; - default: - break; - } + break; + /* Now show the new layout. */ + case SRC_COMMAND: + show_source_command (); + tui_add_to_source_windows (TUI_SRC_WIN); + break; + case DISASSEM_COMMAND: + show_disasm_command (); + tui_add_to_source_windows (TUI_DISASM_WIN); + break; + case SRC_DISASSEM_COMMAND: + show_source_disasm_command (); + tui_add_to_source_windows (TUI_SRC_WIN); + tui_add_to_source_windows (TUI_DISASM_WIN); + break; + default: + break; } } } @@ -500,59 +496,56 @@ show_disasm_command (void) static void show_source_disasm_command (void) { - if (tui_current_layout () != SRC_DISASSEM_COMMAND) - { - int cmd_height, src_height, asm_height; + 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; + 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); + 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->reset (src_height, - tui_term_width (), - 0, - 0); - TUI_SRC_WIN->make_visible (true); - TUI_SRC_WIN->m_has_locator = false; - - struct tui_locator_window *locator = tui_locator_win_info_ptr (); - gdb_assert (locator != nullptr); - - tui_show_source_content (TUI_SRC_WIN); - if (TUI_DISASM_WIN == NULL) - tui_win_list[DISASSEM_WIN] = new tui_disasm_window (); - TUI_DISASM_WIN->reset (asm_height, - tui_term_width (), - 0, - src_height - 1); - TUI_DISASM_WIN->make_visible (true); - locator->reset (2 /* 1 */ , + if (TUI_SRC_WIN == NULL) + tui_win_list[SRC_WIN] = new tui_source_window (); + TUI_SRC_WIN->reset (src_height, tui_term_width (), 0, - (src_height + asm_height) - 1); - TUI_SRC_WIN->m_has_locator = false; - TUI_DISASM_WIN->m_has_locator = true; - locator->make_visible (true); - tui_show_locator_content (); - tui_show_source_content (TUI_DISASM_WIN); - - if (TUI_CMD_WIN == NULL) - tui_win_list[CMD_WIN] = new tui_cmd_window (); - TUI_CMD_WIN->reset (cmd_height, - tui_term_width (), - 0, - tui_term_height () - cmd_height); - /* FIXME tui_cmd_window won't recreate the handle on - make_visible, so we need this instead. */ - tui_make_window (TUI_CMD_WIN, DONT_BOX_WINDOW); - current_layout = SRC_DISASSEM_COMMAND; - } + 0); + TUI_SRC_WIN->make_visible (true); + TUI_SRC_WIN->m_has_locator = false; + + struct tui_locator_window *locator = tui_locator_win_info_ptr (); + gdb_assert (locator != nullptr); + + tui_show_source_content (TUI_SRC_WIN); + if (TUI_DISASM_WIN == NULL) + tui_win_list[DISASSEM_WIN] = new tui_disasm_window (); + TUI_DISASM_WIN->reset (asm_height, + tui_term_width (), + 0, + src_height - 1); + TUI_DISASM_WIN->make_visible (true); + locator->reset (2 /* 1 */ , + tui_term_width (), + 0, + (src_height + asm_height) - 1); + TUI_SRC_WIN->m_has_locator = false; + TUI_DISASM_WIN->m_has_locator = true; + locator->make_visible (true); + tui_show_locator_content (); + tui_show_source_content (TUI_DISASM_WIN); + + if (TUI_CMD_WIN == NULL) + tui_win_list[CMD_WIN] = new tui_cmd_window (); + TUI_CMD_WIN->reset (cmd_height, + tui_term_width (), + 0, + tui_term_height () - cmd_height); + /* FIXME tui_cmd_window won't recreate the handle on + make_visible, so we need this instead. */ + tui_make_window (TUI_CMD_WIN, DONT_BOX_WINDOW); + current_layout = SRC_DISASSEM_COMMAND; } @@ -630,57 +623,54 @@ tui_gen_win_info::reset (int height_, int width_, static void show_source_or_disasm_and_command (enum tui_layout_type layout_type) { - if (tui_current_layout () != 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) { - 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_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; + } - 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; + locator->reset (2 /* 1 */ , + tui_term_width (), + 0, + src_height - 1); + win_info->reset (src_height - 1, + tui_term_width (), + 0, + 0); + win_info->make_visible (true); - 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->reset (2 /* 1 */ , + win_info->m_has_locator = true; + locator->make_visible (true); + tui_show_locator_content (); + tui_show_source_content (win_info); + + if (TUI_CMD_WIN == NULL) + tui_win_list[CMD_WIN] = new tui_cmd_window (); + TUI_CMD_WIN->reset (cmd_height, tui_term_width (), 0, - src_height - 1); - win_info->reset (src_height - 1, - tui_term_width (), - 0, - 0); - win_info->make_visible (true); - - - win_info->m_has_locator = true; - locator->make_visible (true); - tui_show_locator_content (); - tui_show_source_content (win_info); - - if (TUI_CMD_WIN == NULL) - tui_win_list[CMD_WIN] = new tui_cmd_window (); - TUI_CMD_WIN->reset (cmd_height, - tui_term_width (), - 0, - src_height); - /* FIXME tui_cmd_window won't recreate the handle on - make_visible, so we need this instead. */ - tui_make_window (TUI_CMD_WIN, DONT_BOX_WINDOW); - current_layout = layout_type; - } + src_height); + /* FIXME tui_cmd_window won't recreate the handle on + make_visible, so we need this instead. */ + tui_make_window (TUI_CMD_WIN, DONT_BOX_WINDOW); + current_layout = layout_type; }