Patchwork [review] Use symtab_and_line when updating TUI windows

login
register
mail settings
Submitter Simon Marchi (Code Review)
Date Nov. 14, 2019, 11:35 p.m.
Message ID <gerrit.1573774548000.I6974a03589930a0f910c657ef50b7f6f7397c87d@gnutoolchain-gerrit.osci.io>
Download mbox | patch
Permalink /patch/35914/
State New
Headers show

Comments

Simon Marchi (Code Review) - Nov. 14, 2019, 11:35 p.m.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/640
......................................................................

Use symtab_and_line when updating TUI windows

This changes a few TUI source window methods to take a symtab_and_line
rather than separate symtab and tui_line_or_address parameters.  A
symtab_and_line already incorporates the same information, so this
seemed simpler.  Also, it helps avoid the problem that the source and
disassembly windows need different information -- both forms are
present in the SAL.

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

	* tui/tui-winsource.h (struct tui_source_window_base)
	<set_contents, update_source_window_as_is, update_source_window>:
	Take a sal, not a separate symtab and tui_line_or_address.
	* tui/tui-winsource.c (tui_source_window_base::update_source_window)
	(tui_source_window_base::update_source_window_as_is): Take a sal,
	not a separate symtab and tui_line_or_address.
	(tui_update_source_windows_with_addr)
	(tui_update_source_windows_with_line)
	(tui_source_window_base::rerender)
	(tui_source_window_base::refill): Update.
	* tui/tui-source.h (struct tui_source_window) <set_contents>: Take
	a sal, not a separate symtab and tui_line_or_address.
	* tui/tui-source.c (tui_source_window::set_contents): Take a sal,
	not a separate symtab and tui_line_or_address.
	(tui_source_window::maybe_update): Update.
	* tui/tui-disasm.h (struct tui_disasm_window) <set_contents>: Take
	a sal, not a separate symtab and tui_line_or_address.
	* tui/tui-disasm.c (tui_disasm_window::set_contents): Take a sal,
	not a separate symtab and tui_line_or_address.
	(tui_disasm_window::do_scroll_vertical)
	(tui_disasm_window::maybe_update): Update.

Change-Id: I6974a03589930a0f910c657ef50b7f6f7397c87d
---
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, 83 insertions(+), 81 deletions(-)

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0709e39..1bc528d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,29 @@ 
 2019-11-14  Tom Tromey  <tom@tromey.com>
 
+	* tui/tui-winsource.h (struct tui_source_window_base)
+	<set_contents, update_source_window_as_is, update_source_window>:
+	Take a sal, not a separate symtab and tui_line_or_address.
+	* tui/tui-winsource.c (tui_source_window_base::update_source_window)
+	(tui_source_window_base::update_source_window_as_is): Take a sal,
+	not a separate symtab and tui_line_or_address.
+	(tui_update_source_windows_with_addr)
+	(tui_update_source_windows_with_line)
+	(tui_source_window_base::rerender)
+	(tui_source_window_base::refill): Update.
+	* tui/tui-source.h (struct tui_source_window) <set_contents>: Take
+	a sal, not a separate symtab and tui_line_or_address.
+	* tui/tui-source.c (tui_source_window::set_contents): Take a sal,
+	not a separate symtab and tui_line_or_address.
+	(tui_source_window::maybe_update): Update.
+	* tui/tui-disasm.h (struct tui_disasm_window) <set_contents>: Take
+	a sal, not a separate symtab and tui_line_or_address.
+	* tui/tui-disasm.c (tui_disasm_window::set_contents): Take a sal,
+	not a separate symtab and tui_line_or_address.
+	(tui_disasm_window::do_scroll_vertical)
+	(tui_disasm_window::maybe_update): Update.
+
+2019-11-14  Tom Tromey  <tom@tromey.com>
+
 	* tui/tui-winsource.c (tui_source_window_base::refill): Use
 	start_line_or_addr.
 	* tui/tui-source.c (tui_source_window::do_scroll_vertical): Use
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index da5519f..35165bf 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -200,8 +200,7 @@ 
 /* Function to set the disassembly window's content.  */
 bool
 tui_disasm_window::set_contents (struct gdbarch *arch,
-				 struct symtab *s,
-				 struct tui_line_or_address line_or_addr)
+				 const struct symtab_and_line &sal)
 {
   int i;
   int offset = horizontal_offset;
@@ -211,8 +210,7 @@ 
   int tab_len = tui_tab_width;
   int insn_pos;
 
-  gdb_assert (line_or_addr.loa == LOA_ADDRESS);
-  CORE_ADDR pc = line_or_addr.u.addr;
+  CORE_ADDR pc = sal.pc;
   if (pc == 0)
     return false;
 
@@ -323,7 +321,6 @@ 
   if (!content.empty ())
     {
       CORE_ADDR pc;
-      struct tui_line_or_address val;
 
       pc = start_line_or_addr.u.addr;
       if (num_to_scroll >= 0)
@@ -331,9 +328,9 @@ 
       else
 	--num_to_scroll;
 
-      val.loa = LOA_ADDRESS;
-      val.u.addr = tui_find_disassembly_address (gdbarch, pc, num_to_scroll);
-      update_source_window_as_is (gdbarch, NULL, val);
+      symtab_and_line sal {};
+      sal.pc = tui_find_disassembly_address (gdbarch, pc, num_to_scroll);
+      update_source_window_as_is (gdbarch, sal);
     }
 }
 
@@ -379,7 +376,10 @@ 
     low = tui_get_low_disassembly_address (frame_arch, low, sal.pc);
 
   if (!addr_is_displayed (sal.pc))
-    update_source_window (frame_arch, sal.symtab, a);
+    {
+      sal.pc = low;
+      update_source_window (frame_arch, sal);
+    }
   else
     {
       struct tui_line_or_address a;
diff --git a/gdb/tui/tui-disasm.h b/gdb/tui/tui-disasm.h
index ec8d7f1..e46cf1a 100644
--- a/gdb/tui/tui-disasm.h
+++ b/gdb/tui/tui-disasm.h
@@ -56,8 +56,7 @@ 
   void do_scroll_vertical (int num_to_scroll) override;
 
   bool set_contents (struct gdbarch *gdbarch,
-		     struct symtab *s,
-		     struct tui_line_or_address line_or_addr) override;
+		     const struct symtab_and_line &sal) 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 d527e91..695eed6 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -40,11 +40,10 @@ 
 /* Function to display source in the source window.  */
 bool
 tui_source_window::set_contents (struct gdbarch *arch,
-				 struct symtab *s, 
-				 struct tui_line_or_address line_or_addr)
+				 const struct symtab_and_line &sal)
 {
-  gdb_assert (line_or_addr.loa == LOA_LINE);
-  int line_no = line_or_addr.u.line_no;
+  struct symtab *s = sal.symtab;
+  int line_no = sal.line;
 
   if (s == NULL)
     return false;
@@ -188,14 +187,16 @@ 
   bool source_already_displayed = (sal.symtab != 0
 				   && showing_source_p (m_fullname.get ()));
 
-  struct tui_line_or_address l;
-
-  l.loa = LOA_LINE;
-  l.u.line_no = start_line;
   if (!(source_already_displayed && line_is_displayed (sal.line)))
-    update_source_window (get_frame_arch (fi), sal.symtab, l);
+    {
+      sal.line = start_line;
+      update_source_window (get_frame_arch (fi), sal);
+    }
   else
     {
+      struct tui_line_or_address l;
+
+      l.loa = LOA_LINE;
       l.u.line_no = sal.line;
       set_is_exec_point_at (l);
     }
diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h
index 36515e7..beff9bc 100644
--- a/gdb/tui/tui-source.h
+++ b/gdb/tui/tui-source.h
@@ -61,8 +61,7 @@ 
   void do_scroll_vertical (int num_to_scroll) override;
 
   bool set_contents (struct gdbarch *gdbarch,
-		     struct symtab *s,
-		     struct tui_line_or_address line_or_addr) override;
+		     const struct symtab_and_line &sal) override;
 
 private:
 
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 942c4d1..0039f96 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -160,11 +160,10 @@ 
 void
 tui_source_window_base::update_source_window
   (struct gdbarch *gdbarch,
-   struct symtab *s,
-   struct tui_line_or_address line_or_addr)
+   const struct symtab_and_line &sal)
 {
   horizontal_offset = 0;
-  update_source_window_as_is (gdbarch, s, line_or_addr);
+  update_source_window_as_is (gdbarch, sal);
 }
 
 
@@ -173,10 +172,9 @@ 
 void
 tui_source_window_base::update_source_window_as_is
   (struct gdbarch *gdbarch,
-   struct symtab *s,
-   struct tui_line_or_address line_or_addr)
+   const struct symtab_and_line &sal)
 {
-  bool ret = set_contents (gdbarch, s, line_or_addr);
+  bool ret = set_contents (gdbarch, sal);
 
   if (!ret)
     erase_source_content ();
@@ -187,12 +185,10 @@ 
       update_exec_info ();
       if (type == SRC_WIN)
 	{
-	  symtab_and_line sal;
+	  symtab_and_line new_sal = sal;
 
-	  sal.line = line_or_addr.u.line_no + (content.size () - 2);
-	  sal.symtab = s;
-	  sal.pspace = SYMTAB_PSPACE (s);
-	  set_current_source_symtab_and_line (sal);
+	  new_sal.line = sal.line + (content.size () - 2);
+	  set_current_source_symtab_and_line (new_sal);
 	}
     }
 }
@@ -206,21 +202,12 @@ 
   if (addr != 0)
     {
       struct symtab_and_line sal = find_pc_line (addr, 0);
-      struct tui_line_or_address l;
       
       if (TUI_DISASM_WIN != nullptr)
-	{
-	  l.loa = LOA_ADDRESS;
-	  l.u.addr = addr;
-	  TUI_DISASM_WIN->update_source_window (gdbarch, sal.symtab, l);
-	}
+	TUI_DISASM_WIN->update_source_window (gdbarch, sal);
 
       if (TUI_SRC_WIN != nullptr)
-	{
-	  l.loa = LOA_LINE;
-	  l.u.line_no = sal.line;
-	  TUI_SRC_WIN->update_source_window (gdbarch, sal.symtab, l);
-	}
+	TUI_SRC_WIN->update_source_window (gdbarch, sal);
     }
   else
     {
@@ -236,11 +223,14 @@ 
 {
   struct gdbarch *gdbarch;
   CORE_ADDR pc;
-  struct tui_line_or_address l;
+  struct symtab_and_line sal;
 
   if (!s)
     return;
 
+  sal.symtab = s;
+  sal.line = line;
+
   gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
 
   switch (tui_current_layout ())
@@ -251,16 +241,11 @@ 
       tui_update_source_windows_with_addr (gdbarch, pc);
       break;
     default:
-      l.loa = LOA_LINE;
-      l.u.line_no = line;
-      TUI_SRC_WIN->update_source_window (gdbarch, s, l);
+      find_line_pc (s, line, &pc);
+      sal.pc = pc;
+      TUI_SRC_WIN->update_source_window (gdbarch, sal);
       if (tui_current_layout () == SRC_DISASSEM_COMMAND)
-	{
-	  find_line_pc (s, line, &pc);
-	  l.loa = LOA_ADDRESS;
-	  l.u.addr = pc;
-	  TUI_DISASM_WIN->update_source_window (gdbarch, s, l);
-	}
+	TUI_DISASM_WIN->update_source_window (gdbarch, sal);
       break;
     }
 }
@@ -359,33 +344,26 @@ 
 {
   if (!content.empty ())
     {
-      struct tui_line_or_address line_or_addr;
       struct symtab_and_line cursal
 	= get_current_source_symtab_and_line ();
 
-      line_or_addr = start_line_or_addr;
-      update_source_window (gdbarch, cursal.symtab, line_or_addr);
+      if (start_line_or_addr.loa == LOA_LINE)
+	cursal.line = start_line_or_addr.u.line_no;
+      else
+	cursal.pc = start_line_or_addr.u.addr;
+      update_source_window (gdbarch, cursal);
     }
   else if (deprecated_safe_get_selected_frame () != NULL)
     {
-      struct tui_line_or_address line;
       struct symtab_and_line cursal
 	= get_current_source_symtab_and_line ();
       struct frame_info *frame = deprecated_safe_get_selected_frame ();
       struct gdbarch *gdbarch = get_frame_arch (frame);
 
       struct symtab *s = find_pc_line_symtab (get_frame_pc (frame));
-      if (type == SRC_WIN)
-	{
-	  line.loa = LOA_LINE;
-	  line.u.line_no = cursal.line;
-	}
-      else
-	{
-	  line.loa = LOA_ADDRESS;
-	  find_line_pc (s, cursal.line, &line.u.addr);
-	}
-      update_source_window (gdbarch, s, line);
+      if (type != SRC_WIN)
+	find_line_pc (s, cursal.line, &cursal.pc);
+      update_source_window (gdbarch, cursal);
     }
   else
     erase_source_content ();
@@ -396,17 +374,21 @@ 
 void
 tui_source_window_base::refill ()
 {
-  symtab *s = nullptr;
+  symtab_and_line sal {};
 
   if (type == SRC_WIN)
     {
-      symtab_and_line cursal = get_current_source_symtab_and_line ();
-      s = (cursal.symtab == NULL
-	   ? find_pc_line_symtab (get_frame_pc (get_selected_frame (NULL)))
-	   : cursal.symtab);
+      sal = get_current_source_symtab_and_line ();
+      if (sal.symtab == NULL)
+	sal = find_pc_line (get_frame_pc (get_selected_frame (NULL)), 0);
     }
 
-  update_source_window_as_is (gdbarch, s, start_line_or_addr);
+  if (start_line_or_addr.loa == LOA_LINE)
+    sal.line = start_line_or_addr.u.line_no;
+  else
+    sal.pc = start_line_or_addr.u.addr;
+
+  update_source_window_as_is (gdbarch, sal);
 }
 
 /* Scroll the source forward or backward horizontally.  */
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 830b547..c66ea42 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -88,8 +88,7 @@ 
   void rerender () override;
 
   virtual bool set_contents (struct gdbarch *gdbarch,
-			     struct symtab *s,
-			     struct tui_line_or_address line_or_addr) = 0;
+			     const struct symtab_and_line &sal) = 0;
 
 public:
 
@@ -111,11 +110,9 @@ 
   virtual void maybe_update (struct frame_info *fi, symtab_and_line sal) = 0;
 
   void update_source_window_as_is  (struct gdbarch *gdbarch,
-				    struct symtab *s,
-				    struct tui_line_or_address line_or_addr);
+				    const struct symtab_and_line &sal);
   void update_source_window (struct gdbarch *gdbarch,
-			     struct symtab *s,
-			     struct tui_line_or_address line_or_addr);
+			     const struct symtab_and_line &sal);
 
   /* Scan the source window and the breakpoints to update the
      break_mode information for each line.  Returns true if something