From 29d2c474f5a397017455da82e6dbc72629186359 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 16 Jun 2019 17:49:41 -0600 Subject: [PATCH] Change tui_alloc_source_buffer return type to void tui_alloc_source_buffer can't actually fail, so change its return type to void and update the callers. gdb/ChangeLog 2019-06-25 Tom Tromey * tui/tui-winsource.h (tui_alloc_source_buffer): Change return type to void. * tui/tui-winsource.c (tui_alloc_source_buffer): Change return type to void. * tui/tui-source.c (tui_set_source_content): Update. * tui/tui-disasm.c (tui_set_disassem_content): Update. --- gdb/ChangeLog | 9 +++ gdb/tui/tui-disasm.c | 5 +- gdb/tui/tui-source.c | 149 ++++++++++++++++++++-------------------- gdb/tui/tui-winsource.c | 4 +- gdb/tui/tui-winsource.h | 2 +- 5 files changed, 86 insertions(+), 83 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fd95f6e2e2d..a97cfde736d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2019-06-25 Tom Tromey + + * tui/tui-winsource.h (tui_alloc_source_buffer): Change return + type to void. + * tui/tui-winsource.c (tui_alloc_source_buffer): Change return + type to void. + * tui/tui-source.c (tui_set_source_content): Update. + * tui/tui-disasm.c (tui_set_disassem_content): Update. + 2019-06-25 Tom Tromey * tui/tui-win.c (window_name_completer, tui_set_focus) diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index a9d827f5b78..0bc7c642bcd 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -165,7 +165,6 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from) enum tui_status tui_set_disassem_content (struct gdbarch *gdbarch, CORE_ADDR pc) { - enum tui_status ret = TUI_FAILURE; int i; int offset = TUI_DISASM_WIN->horizontal_offset; int max_lines, line_width; @@ -180,9 +179,7 @@ tui_set_disassem_content (struct gdbarch *gdbarch, CORE_ADDR pc) if (pc == 0) return TUI_FAILURE; - ret = tui_alloc_source_buffer (TUI_DISASM_WIN); - if (ret != TUI_SUCCESS) - return ret; + tui_alloc_source_buffer (TUI_DISASM_WIN); tui_source_window_base *base = TUI_DISASM_WIN; base->gdbarch = gdbarch; diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index c6367765d67..39abe81a870 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -133,86 +133,85 @@ tui_set_source_content (struct symtab *s, { int line_width, nlines; - if ((ret = tui_alloc_source_buffer (TUI_SRC_WIN)) == TUI_SUCCESS) + ret = TUI_SUCCESS; + tui_alloc_source_buffer (TUI_SRC_WIN); + line_width = TUI_SRC_WIN->width - 1; + /* Take hilite (window border) into account, when + calculating the number of lines. */ + nlines = (line_no + (TUI_SRC_WIN->height - 2)) - line_no; + + std::string srclines; + if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines, + &srclines)) { - line_width = TUI_SRC_WIN->width - 1; - /* Take hilite (window border) into account, when - calculating the number of lines. */ - nlines = (line_no + (TUI_SRC_WIN->height - 2)) - line_no; - - std::string srclines; - if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines, - &srclines)) + if (!noerror) { - if (!noerror) - { - const char *filename = symtab_to_filename_for_display (s); - char *name = (char *) alloca (strlen (filename) + 100); - - sprintf (name, "%s:%d", filename, line_no); - print_sys_errmsg (name, errno); - } - ret = TUI_FAILURE; + const char *filename = symtab_to_filename_for_display (s); + char *name = (char *) alloca (strlen (filename) + 100); + + sprintf (name, "%s:%d", filename, line_no); + print_sys_errmsg (name, errno); } - else + ret = TUI_FAILURE; + } + else + { + int cur_line_no, cur_line; + struct tui_gen_win_info *locator + = tui_locator_win_info_ptr (); + struct tui_source_window_base *src + = (struct tui_source_window_base *) TUI_SRC_WIN; + const char *s_filename = symtab_to_filename_for_display (s); + + if (TUI_SRC_WIN->title) + xfree (TUI_SRC_WIN->title); + TUI_SRC_WIN->title = xstrdup (s_filename); + + xfree (src->fullname); + src->fullname = xstrdup (symtab_to_fullname (s)); + + cur_line = 0; + src->gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s)); + src->start_line_or_addr.loa = LOA_LINE; + cur_line_no = src->start_line_or_addr.u.line_no = line_no; + + const char *iter = srclines.c_str (); + while (cur_line < nlines) { - int cur_line_no, cur_line; - struct tui_gen_win_info *locator - = tui_locator_win_info_ptr (); - struct tui_source_window_base *src - = (struct tui_source_window_base *) TUI_SRC_WIN; - const char *s_filename = symtab_to_filename_for_display (s); - - if (TUI_SRC_WIN->title) - xfree (TUI_SRC_WIN->title); - TUI_SRC_WIN->title = xstrdup (s_filename); - - xfree (src->fullname); - src->fullname = xstrdup (symtab_to_fullname (s)); - - cur_line = 0; - src->gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s)); - src->start_line_or_addr.loa = LOA_LINE; - cur_line_no = src->start_line_or_addr.u.line_no = line_no; - - const char *iter = srclines.c_str (); - while (cur_line < nlines) - { - struct tui_win_element *element - = TUI_SRC_WIN->content[cur_line]; - - std::string text; - if (*iter != '\0') - text = copy_source_line (&iter, cur_line_no, - src->horizontal_offset, - line_width); - - /* Set whether element is the execution point - and whether there is a break point on it. */ - element->which_element.source.line_or_addr.loa = - LOA_LINE; - element->which_element.source.line_or_addr.u.line_no = - cur_line_no; - element->which_element.source.is_exec_point = - (filename_cmp (locator->content[0] - ->which_element.locator.full_name, - symtab_to_fullname (s)) == 0 - && cur_line_no - == locator->content[0] - ->which_element.locator.line_no); - - xfree (TUI_SRC_WIN->content[cur_line] - ->which_element.source.line); - TUI_SRC_WIN->content[cur_line] - ->which_element.source.line - = xstrdup (text.c_str ()); - - cur_line++; - cur_line_no++; - } - TUI_SRC_WIN->content_size = nlines; - ret = TUI_SUCCESS; + struct tui_win_element *element + = TUI_SRC_WIN->content[cur_line]; + + std::string text; + if (*iter != '\0') + text = copy_source_line (&iter, cur_line_no, + src->horizontal_offset, + line_width); + + /* Set whether element is the execution point + and whether there is a break point on it. */ + element->which_element.source.line_or_addr.loa = + LOA_LINE; + element->which_element.source.line_or_addr.u.line_no = + cur_line_no; + element->which_element.source.is_exec_point = + (filename_cmp (locator->content[0] + ->which_element.locator.full_name, + symtab_to_fullname (s)) == 0 + && cur_line_no + == locator->content[0] + ->which_element.locator.line_no); + + xfree (TUI_SRC_WIN->content[cur_line] + ->which_element.source.line); + TUI_SRC_WIN->content[cur_line] + ->which_element.source.line + = xstrdup (text.c_str ()); + + cur_line++; + cur_line_no++; } + TUI_SRC_WIN->content_size = nlines; + ret = TUI_SUCCESS; } } return ret; diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 1ec9cecdc9c..209d33d6c99 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -589,7 +589,7 @@ tui_update_exec_info (struct tui_win_info *win_info) tui_show_exec_info_content (win_info); } -enum tui_status +void tui_alloc_source_buffer (struct tui_win_info *win_info) { int i, line_width, max_lines; @@ -608,8 +608,6 @@ tui_alloc_source_buffer (struct tui_win_info *win_info) win_info->content[i]->which_element.source.line = (char *) xmalloc (line_width); } - - return TUI_SUCCESS; } diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index 6f2dc3533f7..ccc9ae5f68a 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -59,7 +59,7 @@ extern void tui_erase_exec_info_content (struct tui_win_info *); extern void tui_clear_exec_info_content (struct tui_win_info *); extern void tui_update_exec_info (struct tui_win_info *); -extern enum tui_status tui_alloc_source_buffer (struct tui_win_info *); +extern void tui_alloc_source_buffer (struct tui_win_info *); extern int tui_line_is_displayed (int, struct tui_win_info *, int); -- 2.30.2