aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui/tui-source.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-11-12 17:26:50 -0700
committerTom Tromey <tom@tromey.com>2019-12-20 09:15:52 -0700
commit61c33f105c71d27386e5b3cc6e1c5f71efe7ed01 (patch)
tree3d61884a4c61df3cb404f931731d617fc4fe6060 /gdb/tui/tui-source.c
parent469b073133fa35b54ab4f1bc3dee42ccede84689 (diff)
downloadfsf-binutils-gdb-61c33f105c71d27386e5b3cc6e1c5f71efe7ed01.zip
fsf-binutils-gdb-61c33f105c71d27386e5b3cc6e1c5f71efe7ed01.tar.gz
fsf-binutils-gdb-61c33f105c71d27386e5b3cc6e1c5f71efe7ed01.tar.bz2
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 <tom@tromey.com> * tui/tui-winsource.h (struct tui_source_window_base) <set_contents>: Return bool. * tui/tui-winsource.c (tui_source_window_base::update_source_window_as_is): Update. * tui/tui-source.h (struct tui_source_window) <set_contents>: Return bool. * tui/tui-source.c (tui_source_window::set_contents): Return bool. Simplify. * tui/tui-disasm.h (struct tui_disasm_window) <set_contents>: Return bool. * tui/tui-disasm.c (tui_disasm_window::set_contents): Return bool. Change-Id: I8c5212400cd7aadf35760c22d5344cd3b9435674
Diffstat (limited to 'gdb/tui/tui-source.c')
-rw-r--r--gdb/tui/tui-source.c137
1 files changed, 66 insertions, 71 deletions
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 @@ tui_source_window::set_contents (struct gdbarch *arch,
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;
+ 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;
+ 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<off_t> *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;
- }
+ std::string srclines;
+ const std::vector<off_t> *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)
+ {
+ /* 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;
}