Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hannes Domani <ssbssa@yahoo.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 5/6][PR gdb/25911] Show column of current execution point in frame info
Date: Sat, 16 May 2020 19:26:32 +0200	[thread overview]
Message-ID: <20200516172632.4803-6-ssbssa@yahoo.de> (raw)
In-Reply-To: <20200516172632.4803-1-ssbssa@yahoo.de>

---
 gdb/source.c | 37 ++++++++++++++++++++++++++++++++++++-
 gdb/source.h |  6 ++++++
 gdb/stack.c  | 21 +++++++++++++++++----
 3 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/gdb/source.c b/gdb/source.c
index b94c6af487..bf9ec71464 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1243,7 +1243,8 @@ symtab_to_filename_for_display (struct symtab *symtab)
 
 static void
 print_source_lines_base (struct symtab *s, int line, int stopline,
-			 print_source_lines_flags flags)
+			 print_source_lines_flags flags,
+			 int *column_pos = nullptr)
 {
   bool noprint = false;
   int nlines = stopline - line;
@@ -1356,8 +1357,11 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
           uiout->text (":");
         }
       xsnprintf (buf, sizeof (buf), "%d\t", new_lineno++);
+      int printed = strlen (buf);
+      printed = ((printed >> 3) + 1) << 3;
       uiout->text (buf);
 
+      int column = 0;
       while (*iter != '\0')
 	{
 	  /* Find a run of characters that can be emitted at once.
@@ -1369,6 +1373,24 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
 	      int skip_bytes;
 
 	      char c = *iter;
+	      if (c != '\033')
+		{
+		  column++;
+		  if (column_pos != nullptr && *column_pos == column)
+		    {
+		      *column_pos = printed;
+		      column_pos = nullptr;
+		    }
+
+		  if (c == '\t')
+		    printed = ((printed >> 3) + 1) << 3;
+		  else if (c >= 0 && c < 040)
+		    printed += 2;
+		  else if (c == 0177)
+		    printed += 2;
+		  else
+		    printed++;
+		}
 	      if (c == '\033' && skip_ansi_escape (iter, &skip_bytes))
 		iter += skip_bytes;
 	      else if (c >= 0 && c < 040 && c != '\t')
@@ -1408,6 +1430,11 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
 	      ++iter;
 	    }
 	}
+      if (column_pos != nullptr && *column_pos == column)
+	{
+	  *column_pos = printed;
+	  column_pos = nullptr;
+	}
       uiout->text ("\n");
     }
 
@@ -1434,6 +1461,14 @@ print_source_lines (struct symtab *s, source_lines_range line_range,
 			   line_range.stopline (), flags);
 }
 
+/* See source.h.  */
+
+void
+print_source_line_column (struct symtab *s, int line, int &column)
+{
+  print_source_lines_base (s, line, line + 1, 0, &column);
+}
+
 
 \f
 /* Print info on range of pc's in a specified line.  */
diff --git a/gdb/source.h b/gdb/source.h
index 6273a2cc18..5535964e3c 100644
--- a/gdb/source.h
+++ b/gdb/source.h
@@ -140,6 +140,12 @@ DEF_ENUM_FLAGS_TYPE (enum print_source_lines_flag, print_source_lines_flags);
 extern void print_source_lines (struct symtab *s, int line, int stopline,
 				print_source_lines_flags flags);
 
+/* Show source line with number LINE from the file of symtab S.
+   The column number COLUMN is updated to the real number of characters
+   printed until the specified column was reached.  */
+extern void print_source_line_column (struct symtab *s, int line,
+				      int &column);
+
 /* Wrap up the logic to build a line number range for passing to
    print_source_lines when using get_lines_to_list.  An instance of this
    class can be built from a single line number and a direction (forward or
diff --git a/gdb/stack.c b/gdb/stack.c
index f67a151aee..055c4bbe29 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -989,13 +989,15 @@ print_frame_info_to_print_what (const char *print_frame_info)
 		  print_frame_info);
 }
 
-/* Print the PC from FRAME, plus any flags, to UIOUT.  */
+/* Print the PC from FRAME, plus any flags, to UIOUT.
+   Returns number of characters printed.  */
 
-static void
+static int
 print_pc (struct ui_out *uiout, struct gdbarch *gdbarch, frame_info *frame,
 	  CORE_ADDR pc)
 {
   uiout->field_core_addr ("addr", gdbarch, pc);
+  int printed = 2 + (gdbarch_addr_bit (gdbarch) <= 32 ? 8 : 16);
 
   std::string flags = gdbarch_get_pc_address_flags (gdbarch, frame, pc);
   if (!flags.empty ())
@@ -1003,7 +1005,10 @@ print_pc (struct ui_out *uiout, struct gdbarch *gdbarch, frame_info *frame,
     uiout->text (" [");
     uiout->field_string ("addr_flags", flags);
     uiout->text ("]");
+    printed += 3 + flags.size ();
   }
+
+  return printed;
 }
 
 /* See stack.h.  */
@@ -1135,6 +1140,7 @@ print_frame_info (const frame_print_options &fp_opts,
       else
 	{
 	  struct value_print_options opts;
+	  int printed = 0;
 
 	  get_user_print_options (&opts);
 	  /* We used to do this earlier, but that is clearly
@@ -1147,11 +1153,18 @@ print_frame_info (const frame_print_options &fp_opts,
 	     ability to decide for themselves if it is desired.  */
 	  if (opts.addressprint && mid_statement)
 	    {
-	      print_pc (uiout, gdbarch, frame, get_frame_pc (frame));
+	      printed = print_pc (uiout, gdbarch, frame, get_frame_pc (frame));
 	      uiout->text ("\t");
+	      printed = ((printed >> 3) + 1) << 3;
 	    }
 
-	  print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
+	  int column = sal.column;
+	  print_source_line_column (sal.symtab, sal.line, column);
+	  if (column > 0)
+	    {
+	      uiout->spaces (printed + column);
+	      uiout->text ("^\n");
+	    }
 	}
 
       /* If disassemble-next-line is set to on and there is line debug
-- 
2.26.2



  parent reply	other threads:[~2020-05-16 17:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200516172632.4803-1-ssbssa.ref@yahoo.de>
2020-05-16 17:26 ` [RFC][PATCH 0/6] Step program considering the source column information Hannes Domani
2020-05-16 17:26   ` [PATCH 1/6] Add column information of dwarf to the symbol information Hannes Domani
2020-05-18 16:17     ` Tom Tromey
2020-05-19 12:23       ` Luis Machado
2020-05-16 17:26   ` [PATCH 2/6][PR gdb/25913] Implement nextc and stepc commands Hannes Domani
2020-05-16 17:26   ` [PATCH 3/6] Add column information to maint info line-table Hannes Domani
2020-05-16 17:26   ` [PATCH 4/6] Add LineTableEntry.column to python line table interface Hannes Domani
2020-05-27 13:50     ` Tom de Vries
2020-05-27 14:36       ` Tom Tromey
2020-05-16 17:26   ` Hannes Domani [this message]
2020-05-18 16:20     ` [PATCH 5/6][PR gdb/25911] Show column of current execution point in frame info Tom Tromey
2020-05-18 16:37       ` Hannes Domani
2020-05-19 14:51         ` Tom Tromey
2020-05-16 17:26   ` [PATCH 6/6] Show column of current execution point in TUI Hannes Domani
2020-05-16 18:45   ` [RFC][PATCH 0/6] Step program considering the source column information Pedro Alves
2020-05-17  0:08     ` Hannes Domani
2020-05-18 16:21   ` Tom Tromey
2020-05-18 16:28     ` Hannes Domani
2020-05-19 12:27   ` Luis Machado
2020-05-19 16:02     ` Hannes Domani
2020-05-27 15:33   ` Tom de Vries
2020-05-27 16:04     ` Hannes Domani
2020-06-02  9:08       ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200516172632.4803-6-ssbssa@yahoo.de \
    --to=ssbssa@yahoo.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox