[06/15] Change tui_addr_is_displayed into a method

Message ID 20190814162132.31424-7-tom@tromey.com
State New
Headers show
Series
  • Another round of TUI refactoring
Related show

Commit Message

Tom Tromey Aug. 14, 2019, 4:21 p.m.
This changes tui_addr_is_displayed to be a method on
tui_disasm_window, now that it is obvious that it can only be called
for this type.

gdb/ChangeLog
2019-08-14  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (tui_addr_is_displayed): Don't declare.
	* tui/tui-winsource.c (tui_addr_is_displayed): Move to
	tui-disasm.c.
	* tui/tui-disasm.h (struct tui_disasm_window) <addr_is_displayed>:
	Declare.
	* tui/tui-disasm.c (tui_disasm_window::addr_is_displayed): New
	method.
	(tui_disasm_window::maybe_update): Update.
---
 gdb/ChangeLog           | 11 +++++++++++
 gdb/tui/tui-disasm.c    | 20 +++++++++++++++++++-
 gdb/tui/tui-disasm.h    |  4 ++++
 gdb/tui/tui-winsource.c | 28 ----------------------------
 gdb/tui/tui-winsource.h |  3 ---
 5 files changed, 34 insertions(+), 32 deletions(-)

-- 
2.17.2

Comments

Pedro Alves Aug. 15, 2019, 4:28 p.m. | #1
On 8/14/19 5:21 PM, Tom Tromey wrote:
> diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c

> index 1b2b4393fd9..e8e7061d0f2 100644

> --- a/gdb/tui/tui-winsource.c

> +++ b/gdb/tui/tui-winsource.c

> @@ -668,31 +668,3 @@ tui_line_is_displayed (int line,

>  

>    return is_displayed;

>  }

> -

> -

> -/* Answer whether a particular line number or address is displayed

> -   in the current source window.  */

> -int

> -tui_addr_is_displayed (CORE_ADDR addr, 

> -		       struct tui_source_window_base *win_info,

> -		       int check_threshold)


That intro comment is lost.  Move it...

> --- a/gdb/tui/tui-disasm.h

> +++ b/gdb/tui/tui-disasm.h

> @@ -51,6 +51,10 @@ struct tui_disasm_window : public tui_source_window_base

>  protected:

>  

>    void do_scroll_vertical (int num_to_scroll) override;

> +

> +private:

> +  bool addr_is_displayed (CORE_ADDR addr) const;


here?

Thanks,
Pedro Alves

Patch

diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index fcb33bccfd7..e55f35da214 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -381,6 +381,24 @@  tui_disasm_window::location_matches_p (struct bp_location *loc, int line_no)
 	  && content[line_no].line_or_addr.u.addr == loc->address);
 }
 
+bool
+tui_disasm_window::addr_is_displayed (CORE_ADDR addr) const
+{
+  bool is_displayed = false;
+  int threshold = SCROLL_THRESHOLD;
+
+  int i = 0;
+  while (i < content.size () - threshold && !is_displayed)
+    {
+      is_displayed
+	= (content[i].line_or_addr.loa == LOA_ADDRESS
+	   && content[i].line_or_addr.u.addr == addr);
+      i++;
+    }
+
+  return is_displayed;
+}
+
 void
 tui_disasm_window::maybe_update (struct frame_info *fi, symtab_and_line sal,
 				 int line_no, CORE_ADDR addr)
@@ -402,7 +420,7 @@  tui_disasm_window::maybe_update (struct frame_info *fi, symtab_and_line sal,
 
   a.loa = LOA_ADDRESS;
   a.u.addr = low;
-  if (!tui_addr_is_displayed (addr, this, TRUE))
+  if (!addr_is_displayed (addr))
     tui_update_source_window (this, get_frame_arch (fi),
 			      sal.symtab, a, TRUE);
   else
diff --git a/gdb/tui/tui-disasm.h b/gdb/tui/tui-disasm.h
index 20bc4290ffc..71b911182f8 100644
--- a/gdb/tui/tui-disasm.h
+++ b/gdb/tui/tui-disasm.h
@@ -51,6 +51,10 @@  struct tui_disasm_window : public tui_source_window_base
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
+
+private:
+  bool addr_is_displayed (CORE_ADDR addr) const;
+
 };
 
 extern enum tui_status tui_set_disassem_content (tui_source_window_base *,
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 1b2b4393fd9..e8e7061d0f2 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -668,31 +668,3 @@  tui_line_is_displayed (int line,
 
   return is_displayed;
 }
-
-
-/* Answer whether a particular line number or address is displayed
-   in the current source window.  */
-int
-tui_addr_is_displayed (CORE_ADDR addr, 
-		       struct tui_source_window_base *win_info,
-		       int check_threshold)
-{
-  int is_displayed = FALSE;
-  int i, threshold;
-
-  if (check_threshold)
-    threshold = SCROLL_THRESHOLD;
-  else
-    threshold = 0;
-  i = 0;
-  while (i < win_info->content.size () - threshold
-	 && !is_displayed)
-    {
-      is_displayed
-	= win_info->content[i].line_or_addr.loa == LOA_ADDRESS
-	  && win_info->content[i].line_or_addr.u.addr == addr;
-      i++;
-    }
-
-  return is_displayed;
-}
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index ed6cbec7626..fb9c05cadc8 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -175,9 +175,6 @@  extern void tui_alloc_source_buffer (struct tui_source_window_base *);
 extern int tui_line_is_displayed (int,
 				  struct tui_source_window_base *,
 				  int);
-extern int tui_addr_is_displayed (CORE_ADDR,
-				  struct tui_source_window_base *,
-				  int);
 
 
 /* Constant definitions. */