[6/6] Show column of current execution point in TUI

Message ID 20200516172632.4803-7-ssbssa@yahoo.de
State New
Headers show
Series
  • Step program considering the source column information
Related show

Commit Message

Shahab Vahedi via Gdb-patches May 16, 2020, 5:26 p.m.
---
 gdb/tui/tui-data.h      |  6 +++++-
 gdb/tui/tui-source.c    | 18 ++++++++++++------
 gdb/tui/tui-stack.c     |  2 ++
 gdb/tui/tui-stack.h     |  1 +
 gdb/tui/tui-winsource.c | 35 +++++++++++++++++++++++++++++++++--
 gdb/tui/tui-winsource.h |  9 +++++++--
 6 files changed, 60 insertions(+), 11 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 2dc73b963d..1b36b5930d 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -148,7 +148,11 @@  struct tui_line_or_address
   enum tui_line_or_address_kind loa;
   union
     {
-      int line_no;
+      struct
+	{
+	  int line_no;
+	  int column_no;
+	};
       CORE_ADDR addr;
     } u;
 };
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index fd5bd7dd96..c82647c0a4 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -93,20 +93,25 @@  tui_source_window::set_contents (struct gdbarch *arch,
     {
       struct tui_source_element *element = &m_content[cur_line];
 
-      std::string text;
-      if (*iter != '\0')
-	text = tui_copy_source_line (&iter, cur_line_no,
-				     m_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->line_or_addr.u.column_no = 0;
       element->is_exec_point
 	= (filename_cmp (locator->full_name.c_str (),
 			 symtab_to_fullname (s)) == 0
 	   && cur_line_no == locator->line_no);
+      element->exec_column = element->is_exec_point ? locator->column_no : 0;
+
+      std::string text;
+      int column = element->exec_column;
+      if (*iter != '\0')
+	text = tui_copy_source_line (&iter, cur_line_no,
+				     m_horizontal_offset,
+				     line_width, digits, &column);
+      if (element->is_exec_point)
+	element->line_or_addr.u.column_no = column;
 
       m_content[cur_line].line = std::move (text);
 
@@ -212,6 +217,7 @@  tui_source_window::maybe_update (struct frame_info *fi, symtab_and_line sal)
 
       l.loa = LOA_LINE;
       l.u.line_no = sal.line;
+      l.u.column_no = sal.column;
       set_is_exec_point_at (l);
     }
 }
diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index f1e075a3d2..052a11ec30 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -271,12 +271,14 @@  tui_locator_window::set_locator_info (struct gdbarch *gdbarch_in,
 
   locator_changed_p |= proc_name != procname;
   locator_changed_p |= sal.line != line_no;
+  locator_changed_p |= sal.column != column_no;
   locator_changed_p |= sal.pc != addr;
   locator_changed_p |= gdbarch_in != gdbarch;
   locator_changed_p |= full_name != fullname;
 
   proc_name = procname;
   line_no = sal.line;
+  column_no = sal.column;
   addr = sal.pc;
   gdbarch = gdbarch_in;
   set_locator_fullname (fullname);
diff --git a/gdb/tui/tui-stack.h b/gdb/tui/tui-stack.h
index fde7c6dd2c..13e4f9537b 100644
--- a/gdb/tui/tui-stack.h
+++ b/gdb/tui/tui-stack.h
@@ -62,6 +62,7 @@  struct tui_locator_window : public tui_gen_win_info
   std::string full_name;
   std::string proc_name;
   int line_no = 0;
+  int column_no = 0;
   CORE_ADDR addr = 0;
   /* Architecture associated with code at this location.  */
   struct gdbarch *gdbarch = nullptr;
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index db0add9968..24bacbbb18 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -66,7 +66,7 @@  tui_display_main ()
 
 std::string
 tui_copy_source_line (const char **ptr, int line_no, int first_col,
-		      int line_width, int ndigits)
+		      int line_width, int ndigits, int *exec_column)
 {
   const char *lineptr = *ptr;
 
@@ -87,6 +87,7 @@  tui_copy_source_line (const char **ptr, int line_no, int first_col,
     }
 
   int column = 0;
+  int raw_column = 0;
   char c;
   do
     {
@@ -105,6 +106,7 @@  tui_copy_source_line (const char **ptr, int line_no, int first_col,
 
       ++lineptr;
       ++column;
+      ++raw_column;
 
       auto process_tab = [&] ()
 	{
@@ -127,6 +129,12 @@  tui_copy_source_line (const char **ptr, int line_no, int first_col,
 	  continue;
 	}
 
+      if (exec_column != nullptr && *exec_column == raw_column)
+	{
+	  *exec_column = result.size ();
+	  exec_column = nullptr;
+	}
+
       if (c == '\n' || c == '\r' || c == '\0')
 	{
 	  /* Nothing.  */
@@ -152,6 +160,9 @@  tui_copy_source_line (const char **ptr, int line_no, int first_col,
     ++lineptr;
   *ptr = lineptr;
 
+  if (exec_column != nullptr)
+    *exec_column = 0;
+
   return result;
 }
 
@@ -261,7 +272,20 @@  tui_source_window_base::show_source_line (int lineno)
     tui_set_reverse_mode (handle.get (), true);
 
   wmove (handle.get (), lineno, TUI_EXECINFO_SIZE);
-  tui_puts (line->line.c_str (), handle.get ());
+  if (line->is_exec_point && line->line_or_addr.u.column_no > 0
+      && line->line_or_addr.u.column_no < line->line.size ())
+    {
+      /* Mark the column by disabling the reverse mode for the
+	 corresponding character.  */
+      int column = line->line_or_addr.u.column_no;
+      tui_puts (line->line.substr (0, column).c_str (), handle.get ());
+      tui_set_reverse_mode (handle.get (), false);
+      tui_puts (line->line.substr (column, 1).c_str (), handle.get ());
+      tui_set_reverse_mode (handle.get (), true);
+      tui_puts (line->line.substr (column + 1).c_str (), handle.get ());
+    }
+  else
+    tui_puts (line->line.c_str (), handle.get ());
   if (line->is_exec_point)
     tui_set_reverse_mode (handle.get (), false);
 
@@ -411,8 +435,15 @@  tui_source_window_base::set_is_exec_point_at (struct tui_line_or_address l)
         {
           changed = true;
           m_content[i].is_exec_point = new_state;
+          m_content[i].exec_column = l.loa == LOA_LINE ? l.u.column_no : 0;
           show_source_line (i + 1);
         }
+      else if (new_state && m_content[i].is_exec_point && l.loa == LOA_LINE
+	       && m_content[i].exec_column != l.u.column_no)
+	{
+          changed = true;
+          m_content[i].exec_column = l.u.column_no;
+	}
       i++;
     }
   if (changed)
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 501dd31ccf..8810ba1dd6 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -58,6 +58,7 @@  struct tui_source_element
     : line (std::move (other.line)),
       line_or_addr (other.line_or_addr),
       is_exec_point (other.is_exec_point),
+      exec_column (other.exec_column),
       break_mode (other.break_mode)
   {
   }
@@ -65,6 +66,7 @@  struct tui_source_element
   std::string line;
   struct tui_line_or_address line_or_addr;
   bool is_exec_point = false;
+  int exec_column = 0;
   tui_bp_flags break_mode = 0;
 };
 
@@ -250,11 +252,14 @@  extern void tui_update_source_windows_with_line (struct symtab_and_line sal);
    digits are used; otherwise the line number is formatted with 6
    digits and the text is aligned to the next tab stop.  Returns a
    string holding the desired text.  PTR is updated to point to the
-   start of the next line.  */
+   start of the next line.
+   If EXEC_COLUMN is supplied, it is updated to the position of the
+   specified colum in the returned string.  */
 
 extern std::string tui_copy_source_line (const char **ptr,
 					 int line_no, int first_col,
-					 int line_width, int ndigits);
+					 int line_width, int ndigits,
+					 int *exec_column = nullptr);
 
 /* Constant definitions. */
 #define SCROLL_THRESHOLD 2	/* Threshold for lazy scroll.  */