From patchwork Fri Dec 20 16:20:07 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: 37018 Received: (qmail 109876 invoked by alias); 20 Dec 2019 16:29:03 -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 109336 invoked by uid 89); 20 Dec 2019 16:28:59 -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= 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; Fri, 20 Dec 2019 16:28:56 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 926AA20A8B; Fri, 20 Dec 2019 11:20:22 -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 DAFC620A6F; Fri, 20 Dec 2019 11:20:10 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id B42C82816F; Fri, 20 Dec 2019 11:20:10 -0500 (EST) X-Gerrit-PatchSet: 3 Date: Fri, 20 Dec 2019 11:20:07 -0500 From: "Sourceware to Gerrit sync (Code Review)" To: Tom Tromey , gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [pushed] Change tui_source_window_base::set_contents to return bool X-Gerrit-Change-Id: I8c5212400cd7aadf35760c22d5344cd3b9435674 X-Gerrit-Change-Number: 638 X-Gerrit-ChangeURL: X-Gerrit-Commit: 61c33f105c71d27386e5b3cc6e1c5f71efe7ed01 In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, tromey@sourceware.org, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Message-Id: <20191220162010.B42C82816F@gnutoolchain-gerrit.osci.io> The original change was created by Tom Tromey. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/638 ...................................................................... Change tui_source_window_base::set_contents to return bool This changes tui_source_window_base::set_contents to return bool, rather than tui_status. It also changes one implementation of set_contents to use early returns rather than a variable, which IMO makes it easier to follow. gdb/ChangeLog 2019-12-20 Tom Tromey * tui/tui-winsource.h (struct tui_source_window_base) : Return bool. * tui/tui-winsource.c (tui_source_window_base::update_source_window_as_is): Update. * tui/tui-source.h (struct tui_source_window) : Return bool. * tui/tui-source.c (tui_source_window::set_contents): Return bool. Simplify. * tui/tui-disasm.h (struct tui_disasm_window) : Return bool. * tui/tui-disasm.c (tui_disasm_window::set_contents): Return bool. Change-Id: I8c5212400cd7aadf35760c22d5344cd3b9435674 --- M gdb/ChangeLog M gdb/tui/tui-disasm.c M gdb/tui/tui-disasm.h M gdb/tui/tui-source.c M gdb/tui/tui-source.h M gdb/tui/tui-winsource.c M gdb/tui/tui-winsource.h 7 files changed, 96 insertions(+), 90 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5125089..2994728 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,20 @@ 2019-12-20 Tom Tromey + * tui/tui-winsource.h (struct tui_source_window_base) + : Return bool. + * tui/tui-winsource.c + (tui_source_window_base::update_source_window_as_is): Update. + * tui/tui-source.h (struct tui_source_window) : + Return bool. + * tui/tui-source.c (tui_source_window::set_contents): Return + bool. Simplify. + * tui/tui-disasm.h (struct tui_disasm_window) : + Return bool. + * tui/tui-disasm.c (tui_disasm_window::set_contents): Return + bool. + +2019-12-20 Tom Tromey + * tui/tui-winsource.c (tui_update_source_windows_with_addr) (tui_update_source_windows_with_line): Call update_source_window. * tui/tui-source.h (struct tui_source_window) diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index c49369a..080253c 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -198,7 +198,7 @@ } /* Function to set the disassembly window's content. */ -enum tui_status +bool tui_disasm_window::set_contents (struct gdbarch *arch, struct symtab *s, struct tui_line_or_address line_or_addr) @@ -214,7 +214,7 @@ gdb_assert (line_or_addr.loa == LOA_ADDRESS); CORE_ADDR pc = line_or_addr.u.addr; if (pc == 0) - return TUI_FAILURE; + return false; gdbarch = arch; start_line_or_addr.loa = LOA_ADDRESS; @@ -251,7 +251,7 @@ src->line_or_addr.u.addr = asm_lines[i].addr; src->is_exec_point = asm_lines[i].addr == cur_pc; } - return TUI_SUCCESS; + return true; } diff --git a/gdb/tui/tui-disasm.h b/gdb/tui/tui-disasm.h index f5cc373..ec8d7f1 100644 --- a/gdb/tui/tui-disasm.h +++ b/gdb/tui/tui-disasm.h @@ -55,10 +55,9 @@ void do_scroll_vertical (int num_to_scroll) override; - enum tui_status set_contents - (struct gdbarch *gdbarch, - struct symtab *s, - struct tui_line_or_address line_or_addr) override; + bool set_contents (struct gdbarch *gdbarch, + struct symtab *s, + struct tui_line_or_address line_or_addr) override; private: /* Answer whether a particular line number or address is displayed diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 062f26f..78afc62 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -40,7 +40,7 @@ #include "gdb_curses.h" /* Function to display source in the source window. */ -enum tui_status +bool tui_source_window::set_contents (struct gdbarch *arch, struct symtab *s, struct tui_line_or_address line_or_addr) @@ -48,80 +48,75 @@ gdb_assert (line_or_addr.loa == LOA_LINE); int line_no = line_or_addr.u.line_no; - enum tui_status ret = TUI_FAILURE; + if (s == NULL) + return false; - if (s != NULL) + int line_width, nlines; + + line_width = width - TUI_EXECINFO_SIZE - 1; + /* Take hilite (window border) into account, when + calculating the number of lines. */ + nlines = (line_no + (height - 2)) - line_no; + + std::string srclines; + const std::vector *offsets; + if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines, + &srclines) + || !g_source_cache.get_line_charpos (s, &offsets)) + return false; + + int cur_line_no, cur_line; + struct tui_locator_window *locator + = tui_locator_win_info_ptr (); + const char *s_filename = symtab_to_filename_for_display (s); + + title = s_filename; + + m_fullname = make_unique_xstrdup (symtab_to_fullname (s)); + + cur_line = 0; + gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s)); + start_line_or_addr.loa = LOA_LINE; + cur_line_no = start_line_or_addr.u.line_no = line_no; + + int digits = 0; + if (compact_source) { - int line_width, nlines; - - ret = TUI_SUCCESS; - line_width = width - TUI_EXECINFO_SIZE - 1; - /* Take hilite (window border) into account, when - calculating the number of lines. */ - nlines = (line_no + (height - 2)) - line_no; - - std::string srclines; - const std::vector *offsets; - if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines, - &srclines) - || !g_source_cache.get_line_charpos (s, &offsets)) - ret = TUI_FAILURE; - else - { - int cur_line_no, cur_line; - struct tui_locator_window *locator - = tui_locator_win_info_ptr (); - const char *s_filename = symtab_to_filename_for_display (s); - - title = s_filename; - - m_fullname = make_unique_xstrdup (symtab_to_fullname (s)); - - cur_line = 0; - gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s)); - start_line_or_addr.loa = LOA_LINE; - cur_line_no = start_line_or_addr.u.line_no = line_no; - - int digits = 0; - if (compact_source) - { - /* Solaris 11+gcc 5.5 has ambiguous overloads of log10, so we - cast to double to get the right one. */ - double l = log10 ((double) offsets->size ()); - digits = 1 + (int) l; - } - - const char *iter = srclines.c_str (); - content.resize (nlines); - while (cur_line < nlines) - { - struct tui_source_element *element - = &content[cur_line]; - - std::string text; - if (*iter != '\0') - text = tui_copy_source_line (&iter, cur_line_no, - horizontal_offset, - line_width, digits); - - /* Set whether element is the execution point - and whether there is a break point on it. */ - element->line_or_addr.loa = LOA_LINE; - element->line_or_addr.u.line_no = cur_line_no; - element->is_exec_point - = (filename_cmp (locator->full_name.c_str (), - symtab_to_fullname (s)) == 0 - && cur_line_no == locator->line_no); - - content[cur_line].line = std::move (text); - - cur_line++; - cur_line_no++; - } - ret = TUI_SUCCESS; - } + /* Solaris 11+gcc 5.5 has ambiguous overloads of log10, so we + cast to double to get the right one. */ + double l = log10 ((double) offsets->size ()); + digits = 1 + (int) l; } - return ret; + + const char *iter = srclines.c_str (); + content.resize (nlines); + while (cur_line < nlines) + { + struct tui_source_element *element + = &content[cur_line]; + + std::string text; + if (*iter != '\0') + text = tui_copy_source_line (&iter, cur_line_no, + horizontal_offset, + line_width, digits); + + /* Set whether element is the execution point + and whether there is a break point on it. */ + element->line_or_addr.loa = LOA_LINE; + element->line_or_addr.u.line_no = cur_line_no; + element->is_exec_point + = (filename_cmp (locator->full_name.c_str (), + symtab_to_fullname (s)) == 0 + && cur_line_no == locator->line_no); + + content[cur_line].line = std::move (text); + + cur_line++; + cur_line_no++; + } + + return true; } diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h index a573ce4..36515e7 100644 --- a/gdb/tui/tui-source.h +++ b/gdb/tui/tui-source.h @@ -60,10 +60,9 @@ void do_scroll_vertical (int num_to_scroll) override; - enum tui_status set_contents - (struct gdbarch *gdbarch, - struct symtab *s, - struct tui_line_or_address line_or_addr) override; + bool set_contents (struct gdbarch *gdbarch, + struct symtab *s, + struct tui_line_or_address line_or_addr) override; private: diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 9274678..fad8d7b 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -183,10 +183,9 @@ struct symtab *s, struct tui_line_or_address line_or_addr) { - enum tui_status ret - = set_contents (gdbarch, s, line_or_addr); + bool ret = set_contents (gdbarch, s, line_or_addr); - if (ret == TUI_FAILURE) + if (!ret) erase_source_content (); else { diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index 1ba967c..1991d04 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -87,10 +87,9 @@ void rerender () override; - virtual enum tui_status set_contents - (struct gdbarch *gdbarch, - struct symtab *s, - struct tui_line_or_address line_or_addr) = 0; + virtual bool set_contents (struct gdbarch *gdbarch, + struct symtab *s, + struct tui_line_or_address line_or_addr) = 0; public: