From patchwork Thu Jul 4 17:02:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33575 Received: (qmail 110413 invoked by alias); 4 Jul 2019 17:04:00 -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 107199 invoked by uid 89); 4 Jul 2019 17:03:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=NEXT X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.192.36) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 04 Jul 2019 17:03:30 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway36.websitewelcome.com (Postfix) with ESMTP id AB5F0400C8743 for ; Thu, 4 Jul 2019 11:26:05 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id j58rhUt1gYTGMj58rhNg3K; Thu, 04 Jul 2019 12:03:29 -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=vXmfsjQ7WrHleqt54qem3mgcNwVCG3BuOyTMEmrqVlw=; b=GSpU63PZStGqyLEjzOSQ/o+Bd0 R/y7KVe8nRD6f7Umw8OR8nKlldyp6t910wkhrALMzzVaQX5rngrz2ccJ4JdE9qL1fDa7aXQgoSU+R 8E082AFOBcV9tTR9WbO+UlxxX; Received: from 174-29-58-150.hlrn.qwest.net ([174.29.58.150]:34702 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1hj58r-002sKm-55; Thu, 04 Jul 2019 12:03:29 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 41/61] Clean up tui_layout_command Date: Thu, 4 Jul 2019 11:02:51 -0600 Message-Id: <20190704170311.15982-42-tom@tromey.com> In-Reply-To: <20190704170311.15982-1-tom@tromey.com> References: <20190704170311.15982-1-tom@tromey.com> tui_layout_command is a simple wrapper for tui_set_layout_by_name. This removes the extra layer and cleans up the resulting function a bit -- changing it to call error rather than return a result. This necessitated a small change to tui-regs.c, to avoid calling the function that is being removed. 2019-07-04 Tom Tromey * tui/tui.h (tui_set_layout_by_name): Don't declare. * tui/tui-regs.c (tui_reg_layout): New function. (tui_show_registers, tui_reg_command): Use it. * tui/tui-layout.c (LAYOUT_USAGE): Remove. (tui_layout_command): Rename from tui_set_layout_by_name. Change parameters. (tui_layout_command): Remove. --- gdb/ChangeLog | 10 +++++ gdb/tui/tui-layout.c | 94 +++++++++++++++++--------------------------- gdb/tui/tui-regs.c | 18 ++++++++- gdb/tui/tui.h | 3 -- 4 files changed, 61 insertions(+), 64 deletions(-) diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 7feadd71ece..0ed7b29ce4b 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -61,8 +61,6 @@ static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *); ** DEFINITIONS ***************************************/ -#define LAYOUT_USAGE "Usage: layout prev | next | \n" - /* Show the screen layout defined. */ static void show_layout (enum tui_layout_type layout) @@ -361,63 +359,49 @@ Layout names are:\n\ /* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, or REGS. */ -enum tui_status -tui_set_layout_by_name (const char *layout_name) +static void +tui_layout_command (const char *layout_name, int from_tty) { - enum tui_status status = TUI_SUCCESS; + int i; + enum tui_layout_type new_layout = UNDEFINED_LAYOUT; + enum tui_layout_type cur_layout = tui_current_layout (); - if (layout_name != NULL) - { - int i; - enum tui_layout_type new_layout = UNDEFINED_LAYOUT; - enum tui_layout_type cur_layout = tui_current_layout (); + if (layout_name == NULL) + error (_("Usage: layout prev | next | LAYOUT-NAME")); - std::string copy = layout_name; - for (i = 0; i < copy.size (); i++) - copy[i] = toupper (copy[i]); - const char *buf_ptr = copy.c_str (); + std::string copy = layout_name; + for (i = 0; i < copy.size (); i++) + copy[i] = toupper (copy[i]); + const char *buf_ptr = copy.c_str (); - /* First check for ambiguous input. */ - if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S') - { - warning (_("Ambiguous command input.")); - status = TUI_FAILURE; - } - else - { - if (subset_compare (buf_ptr, "SRC")) - new_layout = SRC_COMMAND; - else if (subset_compare (buf_ptr, "ASM")) - new_layout = DISASSEM_COMMAND; - else if (subset_compare (buf_ptr, "SPLIT")) - new_layout = SRC_DISASSEM_COMMAND; - else if (subset_compare (buf_ptr, "REGS")) - { - if (cur_layout == SRC_COMMAND - || cur_layout == SRC_DATA_COMMAND) - new_layout = SRC_DATA_COMMAND; - else - new_layout = DISASSEM_DATA_COMMAND; - } - else if (subset_compare (buf_ptr, "NEXT")) - new_layout = next_layout (); - else if (subset_compare (buf_ptr, "PREV")) - new_layout = prev_layout (); - else - status = TUI_FAILURE; + /* First check for ambiguous input. */ + if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S') + error (_("Ambiguous command input.")); - if (status == TUI_SUCCESS) - { - /* Make sure the curses mode is enabled. */ - tui_enable (); - tui_set_layout (new_layout); - } - } + if (subset_compare (buf_ptr, "SRC")) + new_layout = SRC_COMMAND; + else if (subset_compare (buf_ptr, "ASM")) + new_layout = DISASSEM_COMMAND; + else if (subset_compare (buf_ptr, "SPLIT")) + new_layout = SRC_DISASSEM_COMMAND; + else if (subset_compare (buf_ptr, "REGS")) + { + if (cur_layout == SRC_COMMAND + || cur_layout == SRC_DATA_COMMAND) + new_layout = SRC_DATA_COMMAND; + else + new_layout = DISASSEM_DATA_COMMAND; } + else if (subset_compare (buf_ptr, "NEXT")) + new_layout = next_layout (); + else if (subset_compare (buf_ptr, "PREV")) + new_layout = prev_layout (); else - status = TUI_FAILURE; + error (_("Unrecognized layout: %s"), layout_name); - return status; + /* Make sure the curses mode is enabled. */ + tui_enable (); + tui_set_layout (new_layout); } @@ -456,14 +440,6 @@ extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p) } -static void -tui_layout_command (const char *arg, int from_tty) -{ - /* Switch to the selected layout. */ - if (tui_set_layout_by_name (arg) != TUI_SUCCESS) - warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE); -} - /* Answer the previous layout to cycle to. */ static enum tui_layout_type next_layout (void) diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 31b252e2aa8..8ba517a6ac0 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -115,6 +115,20 @@ tui_data_window::first_reg_element_no_inline (int line_no) const return (-1); } +/* A helper function to display the register window in the appropriate + way. */ + +static void +tui_reg_layout () +{ + enum tui_layout_type cur_layout = tui_current_layout (); + enum tui_layout_type new_layout; + if (cur_layout == SRC_COMMAND || cur_layout == SRC_DATA_COMMAND) + new_layout = SRC_DATA_COMMAND; + else + new_layout = DISASSEM_DATA_COMMAND; + tui_set_layout (new_layout); +} /* Show the registers of the given group in the data window and refresh the window. */ @@ -127,7 +141,7 @@ tui_show_registers (struct reggroup *group) /* Make sure the register window is visible. If not, select an appropriate layout. */ if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible) - tui_set_layout_by_name (DATA_NAME); + tui_reg_layout (); if (group == 0) group = general_reggroup; @@ -520,7 +534,7 @@ tui_reg_command (const char *args, int from_tty) appropriate layout. We need to do this before trying to run the 'next' or 'prev' commands. */ if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible) - tui_set_layout_by_name (DATA_NAME); + tui_reg_layout (); struct reggroup *current_group = NULL; if (TUI_DATA_WIN != NULL) diff --git a/gdb/tui/tui.h b/gdb/tui/tui.h index 69ad60c98bf..76ab01443b7 100644 --- a/gdb/tui/tui.h +++ b/gdb/tui/tui.h @@ -90,7 +90,4 @@ extern int tui_active; extern void tui_show_source (const char *fullname, int line); -/* tui-layout.c */ -extern enum tui_status tui_set_layout_by_name (const char *); - #endif /* TUI_TUI_H */