From: Tom Tromey Date: Sat, 22 Feb 2020 18:48:26 +0000 (-0700) Subject: Make some tui_source_window_base members "protected" X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=432b5c40220d80d539284f0ee8f6d081d39f0578;p=binutils-gdb.git Make some tui_source_window_base members "protected" This renames a few members of tui_source_window_base, and makes them "protected". 2020-02-22 Tom Tromey * tui/tui-layout.c (extract_display_start_addr): Rewrite. * tui/tui-disasm.h (struct tui_disasm_window) : Declare. * tui/tui-source.h (struct tui_source_window) : Declare. * tui/tui-winsource.h (struct tui_source_window_base) : New methods. : Rename and move to protected section. * tui/tui-winsource.c (tui_source_window_base::update_source_window) (tui_source_window_base::do_erase_source_content): Update. (tui_source_window_base::show_source_line): Now a method. (tui_source_window_base::show_source_content) (tui_source_window_base::tui_source_window_base) (tui_source_window_base::rerender) (tui_source_window_base::refill) (tui_source_window_base::do_scroll_horizontal) (tui_source_window_base::set_is_exec_point_at) (tui_source_window_base::update_breakpoint_info) (tui_source_window_base::update_exec_info): Update. * tui/tui-source.c (tui_source_window::set_contents) (tui_source_window::showing_source_p) (tui_source_window::do_scroll_vertical) (tui_source_window::location_matches_p) (tui_source_window::line_is_displayed): Update. (tui_source_window::display_start_addr): New method. * tui/tui-disasm.c (tui_disasm_window::set_contents) (tui_disasm_window::do_scroll_vertical) (tui_disasm_window::location_matches_p): Update. (tui_disasm_window::display_start_addr): New method. Change-Id: I74d72b9da5f458664427db643a108634690c6e19 --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a83d3e76af3..a644ea78398 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,36 @@ +2020-02-22 Tom Tromey + + * tui/tui-layout.c (extract_display_start_addr): Rewrite. + * tui/tui-disasm.h (struct tui_disasm_window) + : Declare. + * tui/tui-source.h (struct tui_source_window) + : Declare. + * tui/tui-winsource.h (struct tui_source_window_base) + : New methods. + : + Rename and move to protected section. + * tui/tui-winsource.c (tui_source_window_base::update_source_window) + (tui_source_window_base::do_erase_source_content): Update. + (tui_source_window_base::show_source_line): Now a method. + (tui_source_window_base::show_source_content) + (tui_source_window_base::tui_source_window_base) + (tui_source_window_base::rerender) + (tui_source_window_base::refill) + (tui_source_window_base::do_scroll_horizontal) + (tui_source_window_base::set_is_exec_point_at) + (tui_source_window_base::update_breakpoint_info) + (tui_source_window_base::update_exec_info): Update. + * tui/tui-source.c (tui_source_window::set_contents) + (tui_source_window::showing_source_p) + (tui_source_window::do_scroll_vertical) + (tui_source_window::location_matches_p) + (tui_source_window::line_is_displayed): Update. + (tui_source_window::display_start_addr): New method. + * tui/tui-disasm.c (tui_disasm_window::set_contents) + (tui_disasm_window::do_scroll_vertical) + (tui_disasm_window::location_matches_p): Update. + (tui_disasm_window::display_start_addr): New method. + 2020-02-22 Tom Tromey * NEWS: Add entry for gdb.register_window_type. diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index b0b53d64a68..d684b02fd12 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -318,7 +318,7 @@ tui_disasm_window::set_contents (struct gdbarch *arch, const struct symtab_and_line &sal) { int i; - int offset = horizontal_offset; + int offset = m_horizontal_offset; int max_lines, line_width; CORE_ADDR cur_pc; struct tui_locator_window *locator = tui_locator_win_info_ptr (); @@ -329,9 +329,9 @@ tui_disasm_window::set_contents (struct gdbarch *arch, if (pc == 0) return false; - gdbarch = arch; - start_line_or_addr.loa = LOA_ADDRESS; - start_line_or_addr.u.addr = pc; + m_gdbarch = arch; + m_start_line_or_addr.loa = LOA_ADDRESS; + m_start_line_or_addr.u.addr = pc; cur_pc = locator->addr; /* Window size, excluding highlight box. */ @@ -341,16 +341,16 @@ tui_disasm_window::set_contents (struct gdbarch *arch, /* Get temporary table that will hold all strings (addr & insn). */ std::vector asm_lines; size_t addr_size = 0; - tui_disassemble (gdbarch, asm_lines, pc, max_lines, &addr_size); + tui_disassemble (m_gdbarch, asm_lines, pc, max_lines, &addr_size); /* Align instructions to the same column. */ insn_pos = (1 + (addr_size / tab_len)) * tab_len; /* Now construct each line. */ - content.resize (max_lines); + m_content.resize (max_lines); for (i = 0; i < max_lines; i++) { - tui_source_element *src = &content[i]; + tui_source_element *src = &m_content[i]; std::string line; CORE_ADDR addr; @@ -448,36 +448,36 @@ tui_get_low_disassembly_address (struct gdbarch *gdbarch, void tui_disasm_window::do_scroll_vertical (int num_to_scroll) { - if (!content.empty ()) + if (!m_content.empty ()) { CORE_ADDR pc; - pc = start_line_or_addr.u.addr; + pc = m_start_line_or_addr.u.addr; symtab_and_line sal {}; sal.pspace = current_program_space; - sal.pc = tui_find_disassembly_address (gdbarch, pc, num_to_scroll); - update_source_window_as_is (gdbarch, sal); + sal.pc = tui_find_disassembly_address (m_gdbarch, pc, num_to_scroll); + update_source_window_as_is (m_gdbarch, sal); } } bool tui_disasm_window::location_matches_p (struct bp_location *loc, int line_no) { - return (content[line_no].line_or_addr.loa == LOA_ADDRESS - && content[line_no].line_or_addr.u.addr == loc->address); + return (m_content[line_no].line_or_addr.loa == LOA_ADDRESS + && m_content[line_no].line_or_addr.u.addr == loc->address); } bool tui_disasm_window::addr_is_displayed (CORE_ADDR addr) const { - if (content.size () < SCROLL_THRESHOLD) + if (m_content.size () < SCROLL_THRESHOLD) return false; - for (size_t i = 0; i < content.size () - SCROLL_THRESHOLD; ++i) + for (size_t i = 0; i < m_content.size () - SCROLL_THRESHOLD; ++i) { - if (content[i].line_or_addr.loa == LOA_ADDRESS - && content[i].line_or_addr.u.addr == addr) + if (m_content[i].line_or_addr.loa == LOA_ADDRESS + && m_content[i].line_or_addr.u.addr == addr) return true; } @@ -515,3 +515,11 @@ tui_disasm_window::maybe_update (struct frame_info *fi, symtab_and_line sal) set_is_exec_point_at (a); } } + +void +tui_disasm_window::display_start_addr (struct gdbarch **gdbarch_p, + CORE_ADDR *addr_p) +{ + *gdbarch_p = m_gdbarch; + *addr_p = m_start_line_or_addr.u.addr; +} diff --git a/gdb/tui/tui-disasm.h b/gdb/tui/tui-disasm.h index dd020310746..0eb6c9e7290 100644 --- a/gdb/tui/tui-disasm.h +++ b/gdb/tui/tui-disasm.h @@ -48,6 +48,9 @@ struct tui_disasm_window : public tui_source_window_base do_erase_source_content (_("[ No Assembly Available ]")); } + void display_start_addr (struct gdbarch **gdbarch_p, + CORE_ADDR *addr_p) override; + protected: void do_scroll_vertical (int num_to_scroll) override; diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 66c74494d17..b2c47c018c1 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -274,27 +274,15 @@ tui_remove_some_windows () static void extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p) { - struct gdbarch *gdbarch = nullptr; - CORE_ADDR addr = 0; - CORE_ADDR pc; - struct symtab_and_line cursal = get_current_source_symtab_and_line (); - if (TUI_SRC_WIN != nullptr) - { - gdbarch = TUI_SRC_WIN->gdbarch; - find_line_pc (cursal.symtab, - TUI_SRC_WIN->start_line_or_addr.u.line_no, - &pc); - addr = pc; - } + TUI_SRC_WIN->display_start_addr (gdbarch_p, addr_p); else if (TUI_DISASM_WIN != nullptr) + TUI_DISASM_WIN->display_start_addr (gdbarch_p, addr_p); + else { - gdbarch = TUI_DISASM_WIN->gdbarch; - addr = TUI_DISASM_WIN->start_line_or_addr.u.addr; + *gdbarch_p = nullptr; + *addr_p = 0; } - - *gdbarch_p = gdbarch; - *addr_p = addr; } void diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 3c7a8e10008..7bc1220a876 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -74,9 +74,9 @@ tui_source_window::set_contents (struct gdbarch *arch, 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; + m_gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s)); + m_start_line_or_addr.loa = LOA_LINE; + cur_line_no = m_start_line_or_addr.u.line_no = line_no; int digits = 0; if (compact_source) @@ -88,16 +88,15 @@ tui_source_window::set_contents (struct gdbarch *arch, } const char *iter = srclines.c_str (); - content.resize (nlines); + m_content.resize (nlines); while (cur_line < nlines) { - struct tui_source_element *element - = &content[cur_line]; + struct tui_source_element *element = &m_content[cur_line]; std::string text; if (*iter != '\0') text = tui_copy_source_line (&iter, cur_line_no, - horizontal_offset, + m_horizontal_offset, line_width, digits); /* Set whether element is the execution point @@ -109,7 +108,7 @@ tui_source_window::set_contents (struct gdbarch *arch, symtab_to_fullname (s)) == 0 && cur_line_no == locator->line_no); - content[cur_line].line = std::move (text); + m_content[cur_line].line = std::move (text); cur_line++; cur_line_no++; @@ -124,7 +123,7 @@ tui_source_window::set_contents (struct gdbarch *arch, bool tui_source_window::showing_source_p (const char *fullname) const { - return (!content.empty () + return (!m_content.empty () && (filename_cmp (tui_locator_win_info_ptr ()->full_name.c_str (), fullname) == 0)); } @@ -134,11 +133,11 @@ tui_source_window::showing_source_p (const char *fullname) const void tui_source_window::do_scroll_vertical (int num_to_scroll) { - if (!content.empty ()) + if (!m_content.empty ()) { struct symtab *s; struct symtab_and_line cursal = get_current_source_symtab_and_line (); - struct gdbarch *arch = gdbarch; + struct gdbarch *arch = m_gdbarch; if (cursal.symtab == NULL) { @@ -149,11 +148,11 @@ tui_source_window::do_scroll_vertical (int num_to_scroll) else s = cursal.symtab; - int line_no = start_line_or_addr.u.line_no + num_to_scroll; + int line_no = m_start_line_or_addr.u.line_no + num_to_scroll; const std::vector *offsets; if (g_source_cache.get_line_charpos (s, &offsets) && line_no > offsets->size ()) - line_no = start_line_or_addr.u.line_no; + line_no = m_start_line_or_addr.u.line_no; if (line_no <= 0) line_no = 1; @@ -167,8 +166,8 @@ tui_source_window::do_scroll_vertical (int num_to_scroll) bool tui_source_window::location_matches_p (struct bp_location *loc, int line_no) { - return (content[line_no].line_or_addr.loa == LOA_LINE - && content[line_no].line_or_addr.u.line_no == loc->line_number + return (m_content[line_no].line_or_addr.loa == LOA_LINE + && m_content[line_no].line_or_addr.u.line_no == loc->line_number && loc->symtab != NULL && filename_cmp (m_fullname.get (), symtab_to_fullname (loc->symtab)) == 0); @@ -179,13 +178,13 @@ tui_source_window::location_matches_p (struct bp_location *loc, int line_no) bool tui_source_window::line_is_displayed (int line) const { - if (content.size () < SCROLL_THRESHOLD) + if (m_content.size () < SCROLL_THRESHOLD) return false; - for (size_t i = 0; i < content.size () - SCROLL_THRESHOLD; ++i) + for (size_t i = 0; i < m_content.size () - SCROLL_THRESHOLD; ++i) { - if (content[i].line_or_addr.loa == LOA_LINE - && content[i].line_or_addr.u.line_no == line) + if (m_content[i].line_or_addr.loa == LOA_LINE + && m_content[i].line_or_addr.u.line_no == line) return true; } @@ -216,3 +215,13 @@ tui_source_window::maybe_update (struct frame_info *fi, symtab_and_line sal) set_is_exec_point_at (l); } } + +void +tui_source_window::display_start_addr (struct gdbarch **gdbarch_p, + CORE_ADDR *addr_p) +{ + struct symtab_and_line cursal = get_current_source_symtab_and_line (); + + *gdbarch_p = m_gdbarch; + find_line_pc (cursal.symtab, m_start_line_or_addr.u.line_no, addr_p); +} diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h index 58dc5e88cf7..1df84cf304c 100644 --- a/gdb/tui/tui-source.h +++ b/gdb/tui/tui-source.h @@ -53,6 +53,9 @@ struct tui_source_window : public tui_source_window_base do_erase_source_content (_("[ No Source Available ]")); } + void display_start_addr (struct gdbarch **gdbarch_p, + CORE_ADDR *addr_p) override; + protected: void do_scroll_vertical (int num_to_scroll) override; diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 9ec05ae7c3d..b5ba59e2f7a 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -169,7 +169,7 @@ tui_source_window_base::update_source_window (struct gdbarch *gdbarch, const struct symtab_and_line &sal) { - horizontal_offset = 0; + m_horizontal_offset = 0; update_source_window_as_is (gdbarch, sal); } @@ -229,7 +229,7 @@ tui_source_window_base::do_erase_source_content (const char *str) int x_pos; int half_width = (width - 2) / 2; - content.clear (); + m_content.clear (); if (handle != NULL) { werase (handle.get ()); @@ -250,37 +250,37 @@ tui_source_window_base::do_erase_source_content (const char *str) /* Redraw the complete line of a source or disassembly window. */ -static void -tui_show_source_line (struct tui_source_window_base *win_info, int lineno) +void +tui_source_window_base::show_source_line (int lineno) { struct tui_source_element *line; int x; - line = &win_info->content[lineno - 1]; + line = &m_content[lineno - 1]; if (line->is_exec_point) - tui_set_reverse_mode (win_info->handle.get (), true); + tui_set_reverse_mode (handle.get (), true); - wmove (win_info->handle.get (), lineno, TUI_EXECINFO_SIZE); - tui_puts (line->line.c_str (), win_info->handle.get ()); + wmove (handle.get (), lineno, TUI_EXECINFO_SIZE); + tui_puts (line->line.c_str (), handle.get ()); if (line->is_exec_point) - tui_set_reverse_mode (win_info->handle.get (), false); + tui_set_reverse_mode (handle.get (), false); /* Clear to end of line but stop before the border. */ - x = getcurx (win_info->handle.get ()); - while (x + 1 < win_info->width) + x = getcurx (handle.get ()); + while (x + 1 < width) { - waddch (win_info->handle.get (), ' '); - x = getcurx (win_info->handle.get ()); + waddch (handle.get (), ' '); + x = getcurx (handle.get ()); } } void tui_source_window_base::show_source_content () { - gdb_assert (!content.empty ()); + gdb_assert (!m_content.empty ()); - for (int lineno = 1; lineno <= content.size (); lineno++) - tui_show_source_line (this, lineno); + for (int lineno = 1; lineno <= m_content.size (); lineno++) + show_source_line (lineno); check_and_display_highlight_if_needed (); refresh_window (); @@ -288,8 +288,8 @@ tui_source_window_base::show_source_content () tui_source_window_base::tui_source_window_base () { - start_line_or_addr.loa = LOA_ADDRESS; - start_line_or_addr.u.addr = 0; + m_start_line_or_addr.loa = LOA_ADDRESS; + m_start_line_or_addr.u.addr = 0; gdb::observers::source_styling_changed.attach (std::bind (&tui_source_window::style_changed, this), @@ -313,16 +313,16 @@ tui_source_window_base::update_tab_width () void tui_source_window_base::rerender () { - if (!content.empty ()) + if (!m_content.empty ()) { struct symtab_and_line cursal = get_current_source_symtab_and_line (); - if (start_line_or_addr.loa == LOA_LINE) - cursal.line = start_line_or_addr.u.line_no; + if (m_start_line_or_addr.loa == LOA_LINE) + cursal.line = m_start_line_or_addr.u.line_no; else - cursal.pc = start_line_or_addr.u.addr; - update_source_window (gdbarch, cursal); + cursal.pc = m_start_line_or_addr.u.addr; + update_source_window (m_gdbarch, cursal); } else if (deprecated_safe_get_selected_frame () != NULL) { @@ -361,12 +361,12 @@ tui_source_window_base::refill () if (sal.pspace == nullptr) sal.pspace = current_program_space; - if (start_line_or_addr.loa == LOA_LINE) - sal.line = start_line_or_addr.u.line_no; + if (m_start_line_or_addr.loa == LOA_LINE) + sal.line = m_start_line_or_addr.u.line_no; else - sal.pc = start_line_or_addr.u.addr; + sal.pc = m_start_line_or_addr.u.addr; - update_source_window_as_is (gdbarch, sal); + update_source_window_as_is (m_gdbarch, sal); } /* Scroll the source forward or backward horizontally. */ @@ -374,12 +374,12 @@ tui_source_window_base::refill () void tui_source_window_base::do_scroll_horizontal (int num_to_scroll) { - if (!content.empty ()) + if (!m_content.empty ()) { - int offset = horizontal_offset + num_to_scroll; + int offset = m_horizontal_offset + num_to_scroll; if (offset < 0) offset = 0; - horizontal_offset = offset; + m_horizontal_offset = offset; refill (); } } @@ -395,11 +395,11 @@ tui_source_window_base::set_is_exec_point_at (struct tui_line_or_address l) int i; i = 0; - while (i < content.size ()) + while (i < m_content.size ()) { bool new_state; struct tui_line_or_address content_loa = - content[i].line_or_addr; + m_content[i].line_or_addr; if (content_loa.loa == l.loa && ((l.loa == LOA_LINE && content_loa.u.line_no == l.u.line_no) @@ -407,11 +407,11 @@ tui_source_window_base::set_is_exec_point_at (struct tui_line_or_address l) new_state = true; else new_state = false; - if (new_state != content[i].is_exec_point) + if (new_state != m_content[i].is_exec_point) { changed = true; - content[i].is_exec_point = new_state; - tui_show_source_line (this, i + 1); + m_content[i].is_exec_point = new_state; + show_source_line (i + 1); } i++; } @@ -445,11 +445,11 @@ tui_source_window_base::update_breakpoint_info int i; bool need_refresh = false; - for (i = 0; i < content.size (); i++) + for (i = 0; i < m_content.size (); i++) { struct tui_source_element *line; - line = &content[i]; + line = &m_content[i]; if (current_only && !line->is_exec_point) continue; @@ -498,9 +498,9 @@ void tui_source_window_base::update_exec_info () { update_breakpoint_info (nullptr, true); - for (int i = 0; i < content.size (); i++) + for (int i = 0; i < m_content.size (); i++) { - struct tui_source_element *src_element = &content[i]; + struct tui_source_element *src_element = &m_content[i]; char element[TUI_EXECINFO_SIZE] = " "; /* Now update the exec info content based upon the state diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index 4ac20d80502..501dd31ccfd 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -90,6 +90,18 @@ protected: virtual bool set_contents (struct gdbarch *gdbarch, const struct symtab_and_line &sal) = 0; + /* Redraw the complete line of a source or disassembly window. */ + void show_source_line (int lineno); + + /* Used for horizontal scroll. */ + int m_horizontal_offset = 0; + struct tui_line_or_address m_start_line_or_addr; + + /* Architecture associated with code at this location. */ + struct gdbarch *m_gdbarch = nullptr; + + std::vector m_content; + public: /* Refill the source window's source cache and update it. If this @@ -125,14 +137,9 @@ public: /* Erase the source content. */ virtual void erase_source_content () = 0; - /* Used for horizontal scroll. */ - int horizontal_offset = 0; - struct tui_line_or_address start_line_or_addr; - - /* Architecture associated with code at this location. */ - struct gdbarch *gdbarch = nullptr; - - std::vector content; + /* Return the start address and gdbarch. */ + virtual void display_start_addr (struct gdbarch **gdbarch_p, + CORE_ADDR *addr_p) = 0; private: