[v3,2/5,dap,&,linetable] : Add column to maint info linetable output

Message ID 20240122133115.201205-2-simon.farre.cx@gmail.com
State New
Headers
Series [v3,1/5,dap,&,linetable] : Add column to linetable entry |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Testing failed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Simon Farre Jan. 22, 2024, 1:31 p.m. UTC
  This adds "COL" to the output of the maintenance command "info
line-table"

v2.
maint info line-table: Make display of column optional

Toggle the display (on) of column meta data by adding `-show-col`
to the command. This command is used way too much in testing to change
at this point making any feature that touches this almost impossible to
move forward due to test maintenance hell.

v3:

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31271
---
 gdb/symmisc.c | 102 +++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 76 insertions(+), 26 deletions(-)
  

Comments

Tom Tromey Feb. 7, 2024, 7:52 p.m. UTC | #1
>>>>> "Simon" == Simon Farre <simon.farre.cx@gmail.com> writes:

Simon> Toggle the display (on) of column meta data by adding `-show-col`
Simon> to the command. This command is used way too much in testing to change
Simon> at this point making any feature that touches this almost impossible to
Simon> move forward due to test maintenance hell.

When I looked it seemed like there's only a handful of spots to modify;
and since it's a "maint" command I tend to think it would be better to
just unconditionally emit the column.

Tom
  

Patch

diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 5dfb9fca8f0..b7dccb3893e 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -937,17 +937,67 @@  block_depth (const struct block *block)
     }
   return i;
 }
-
+
+static void
+output_lt_row (ui_out *uiout, int i, const linetable_entry &item,
+	       const objfile *obj)
+{
+  ui_out_emit_tuple tuple_emitter (uiout, nullptr);
+  uiout->field_signed ("index", i);
+  if (item.line > 0)
+    {
+      uiout->field_signed ("line", item.line);
+    }
+  else
+    {
+      uiout->field_string ("line", _ ("END"));
+    }
+  uiout->field_core_addr ("rel-address", obj->arch (), item.pc (obj));
+  uiout->field_core_addr ("unrel-address", obj->arch (),
+			  CORE_ADDR (item.unrelocated_pc ()));
+  uiout->field_string ("is-stmt", item.is_stmt ? "Y" : "");
+  uiout->field_string ("prologue-end", item.prologue_end ? "Y" : "");
+  uiout->field_string ("epilogue-begin", item.epilogue_begin ? "Y" : "");
+  uiout->text ("\n");
+}
+
+static auto
+output_lt_row_with_col (ui_out *uiout, int i, const linetable_entry &item,
+			const objfile *obj)
+{
+  ui_out_emit_tuple tuple_emitter (uiout, nullptr);
+  uiout->field_signed ("index", i);
+  if (item.line > 0)
+    {
+      uiout->field_signed ("line", item.line);
+      uiout->field_signed ("col", item.col);
+    }
+  else
+    {
+      uiout->field_string ("line", _ ("END"));
+      uiout->field_string ("col", _ ("END"));
+    }
+  uiout->field_core_addr ("rel-address", obj->arch (), item.pc (obj));
+  uiout->field_core_addr ("unrel-address", obj->arch (),
+			  CORE_ADDR (item.unrelocated_pc ()));
+  uiout->field_string ("is-stmt", item.is_stmt ? "Y" : "");
+  uiout->field_string ("prologue-end", item.prologue_end ? "Y" : "");
+  uiout->field_string ("epilogue-begin", item.epilogue_begin ? "Y" : "");
+  uiout->text ("\n");
+}
 
 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
    single line table.  */
 
 static int
-maintenance_print_one_line_table (struct symtab *symtab, void *data)
+maintenance_print_one_line_table (struct symtab *symtab, void *data,
+				  bool display_col)
 {
   const struct linetable *linetable;
   struct objfile *objfile;
 
+  const auto columns = display_col ? 8 : 7;
+
   objfile = symtab->compunit ()->objfile ();
   gdb_printf (_("objfile: %ps ((struct objfile *) %s)\n"),
 	      styled_string (file_name_style.style (),
@@ -973,9 +1023,11 @@  maintenance_print_one_line_table (struct symtab *symtab, void *data)
       /* Leave space for 6 digits of index and line number.  After that the
 	 tables will just not format as well.  */
       struct ui_out *uiout = current_uiout;
-      ui_out_emit_table table_emitter (uiout, 7, -1, "line-table");
+      ui_out_emit_table table_emitter (uiout, columns, -1, "line-table");
       uiout->table_header (6, ui_left, "index", _("INDEX"));
       uiout->table_header (6, ui_left, "line", _("LINE"));
+      if (display_col)
+	uiout->table_header (6, ui_left, "col", _("COL"));
       uiout->table_header (18, ui_left, "rel-address", _("REL-ADDRESS"));
       uiout->table_header (18, ui_left, "unrel-address", _("UNREL-ADDRESS"));
       uiout->table_header (7, ui_left, "is-stmt", _("IS-STMT"));
@@ -983,26 +1035,12 @@  maintenance_print_one_line_table (struct symtab *symtab, void *data)
       uiout->table_header (14, ui_left, "epilogue-begin", _("EPILOGUE-BEGIN"));
       uiout->table_body ();
 
-      for (int i = 0; i < linetable->nitems; ++i)
-	{
-	  const linetable_entry *item;
-
-	  item = &linetable->item [i];
-	  ui_out_emit_tuple tuple_emitter (uiout, nullptr);
-	  uiout->field_signed ("index", i);
-	  if (item->line > 0)
-	    uiout->field_signed ("line", item->line);
-	  else
-	    uiout->field_string ("line", _("END"));
-	  uiout->field_core_addr ("rel-address", objfile->arch (),
-				  item->pc (objfile));
-	  uiout->field_core_addr ("unrel-address", objfile->arch (),
-				  CORE_ADDR (item->unrelocated_pc ()));
-	  uiout->field_string ("is-stmt", item->is_stmt ? "Y" : "");
-	  uiout->field_string ("prologue-end", item->prologue_end ? "Y" : "");
-	  uiout->field_string ("epilogue-begin", item->epilogue_begin ? "Y" : "");
-	  uiout->text ("\n");
-	}
+      if (display_col)
+	for (int i = 0; i < linetable->nitems; ++i)
+	  output_lt_row_with_col (uiout, i, linetable->item[i], objfile);
+      else
+	for (int i = 0; i < linetable->nitems; ++i)
+	  output_lt_row (uiout, i, linetable->item[i], objfile);
     }
 
   return 0;
@@ -1011,9 +1049,20 @@  maintenance_print_one_line_table (struct symtab *symtab, void *data)
 /* Implement the 'maint info line-table' command.  */
 
 static void
-maintenance_info_line_tables (const char *regexp, int from_tty)
+maintenance_info_line_tables (const char* args, int from_tty)
 {
   dont_repeat ();
+  const char* regexp = nullptr;
+  bool show_column = false;
+  gdb_argv argv (args);
+
+  for (auto i = 0; argv != nullptr && argv[i] != nullptr; ++i)
+    {
+      if (strcmp (argv[i], "-show-col") == 0)
+	show_column = true;
+      else
+	regexp = argv[i];
+    }
 
   if (regexp != NULL)
     re_comp (regexp);
@@ -1030,7 +1079,7 @@  maintenance_info_line_tables (const char *regexp, int from_tty)
 		if (regexp == NULL
 		    || re_exec (symtab_to_filename_for_display (symtab)))
 		  {
-		    maintenance_print_one_line_table (symtab, NULL);
+		    maintenance_print_one_line_table (symtab, NULL, show_column);
 		    gdb_printf ("\n");
 		  }
 	      }
@@ -1080,7 +1129,8 @@  With an argument REGEXP, list the symbol tables with matching names."),
   add_cmd ("line-table", class_maintenance, maintenance_info_line_tables, _("\
 List the contents of all line tables, from all symbol tables.\n\
 With an argument REGEXP, list just the line tables for the symbol\n\
-tables with matching names."),
+tables with matching names.\n\
+With the argument -show-col this command also displays column information."),
 	   &maintenanceinfolist);
 
   add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,