Fix column alignment in "maint info line-table"

Message ID 20200318182947.21438-1-tromey@adacore.com
State New
Headers show
Series
  • Fix column alignment in "maint info line-table"
Related show

Commit Message

Tom Tromey March 18, 2020, 6:29 p.m.
Andrew Burgess pointed out on irc that "maint info line-table" doesn't
properly align the table headers.  This patch fixes the problem by
switching the table to use ui-out.

This required a small tweak to one test case, as ui-out will pad a
field using spaces, even at the end of a line.

gdb/ChangeLog
2020-03-18  Tom Tromey  <tromey@adacore.com>

	* symmisc.c (maintenance_print_one_line_table): Use ui_out.

gdb/testsuite/ChangeLog
2020-03-18  Tom Tromey  <tromey@adacore.com>

	* gdb.dwarf2/dw2-ranges-base.exp: Update regular expressions.
---
 gdb/ChangeLog                                |  4 +++
 gdb/symmisc.c                                | 29 ++++++++++++--------
 gdb/testsuite/ChangeLog                      |  4 +++
 gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp |  6 ++--
 4 files changed, 28 insertions(+), 15 deletions(-)

-- 
2.21.1

Comments

Andrew Burgess March 19, 2020, 11:31 p.m. | #1
* Tom Tromey <tromey@adacore.com> [2020-03-18 12:29:47 -0600]:

> Andrew Burgess pointed out on irc that "maint info line-table" doesn't

> properly align the table headers.  This patch fixes the problem by

> switching the table to use ui-out.

> 

> This required a small tweak to one test case, as ui-out will pad a

> field using spaces, even at the end of a line.

> 

> gdb/ChangeLog

> 2020-03-18  Tom Tromey  <tromey@adacore.com>

> 

> 	* symmisc.c (maintenance_print_one_line_table): Use ui_out.

> 

> gdb/testsuite/ChangeLog

> 2020-03-18  Tom Tromey  <tromey@adacore.com>

> 

> 	* gdb.dwarf2/dw2-ranges-base.exp: Update regular expressions.


I didn't test this, just skimmed the code, and it looks like a good
improvement, I just had one question...

> ---

>  gdb/ChangeLog                                |  4 +++

>  gdb/symmisc.c                                | 29 ++++++++++++--------

>  gdb/testsuite/ChangeLog                      |  4 +++

>  gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp |  6 ++--

>  4 files changed, 28 insertions(+), 15 deletions(-)

> 

> diff --git a/gdb/symmisc.c b/gdb/symmisc.c

> index 4bf1f08849f..5b51f168e52 100644

> --- a/gdb/symmisc.c

> +++ b/gdb/symmisc.c

> @@ -985,26 +985,31 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data)

>      printf_filtered (_("Line table has no lines.\n"));

>    else

>      {

> -      int i;

> -

>        /* Leave space for 6 digits of index and line number.  After that the

>  	 tables will just not format as well.  */

> -      printf_filtered (_("%-6s %6s %s %s\n"),

> -		       _("INDEX"), _("LINE"), _("ADDRESS"), _("IS-STMT"));

> -

> -      for (i = 0; i < linetable->nitems; ++i)

> +      struct ui_out *uiout = current_uiout;

> +      ui_out_emit_table table_emitter (uiout, 4, -1, "line-table");

> +      uiout->table_header (6, ui_left, "index", _("INDEX"));

> +      uiout->table_header (6, ui_left, "line", _("LINE"));

> +      uiout->table_header (18, ui_left, "address", _("ADDRESS"));

> +      uiout->table_header (1, ui_left, "is-stmt", _("IS-STMT"));

> +      uiout->table_body ();

> +

> +      for (int i = 0; i < linetable->nitems; ++i)

>  	{

>  	  struct linetable_entry *item;

>  

>  	  item = &linetable->item [i];

> -	  printf_filtered ("%-6d ", i);

> +	  ui_out_emit_tuple tuple_emitter (uiout, nullptr);

> +	  uiout->field_signed ("index", i);

>  	  if (item->line > 0)

> -	    printf_filtered ("%6d ", item->line);

> +	    uiout->field_signed ("line", item->line);

>  	  else

> -	    printf_filtered ("%6s ", _("END"));

> -	  printf_filtered ("%s%s\n",

> -			   core_addr_to_string (item->pc),

> -			   (item->is_stmt ? " Y" : ""));

> +	    uiout->field_string ("line", _("END"));

> +	  uiout->field_core_addr ("address", get_objfile_arch (objfile),

> +				  item->pc);

> +	  uiout->field_string ("is-stmt", item->is_stmt ? " Y" : "");


Is the whitespace in " Y" still needed? I'm guessing this is a hang
over from the previous manual formatting.  But like I said, I didn't
actually test this.

Otherwise, looks good.

Thanks,
Andrew


> +	  uiout->text ("\n");

>  	}

>      }

>  

> diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp

> index c1a3ab155fd..92f8f6cecbe 100644

> --- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp

> +++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp

> @@ -146,10 +146,10 @@ gdb_test "info line frame3" \

>  set end_seq_count 0

>  gdb_test_multiple "maint info line-table gdb.dwarf2/dw2-ranges-base.c" \

>      "count END markers in line table" {

> -	-re "^$decimal\[ \t\]+$decimal\[ \t\]+$hex\(\[ \t\]+Y\)?\r\n" {

> +	-re "^$decimal\[ \t\]+$decimal\[ \t\]+$hex\(\[ \t\]+Y\)? *\r\n" {

>  	    exp_continue

>  	}

> -	-re "^$decimal\[ \t\]+END\[ \t\]+$hex\(\[ \t\]+Y\)?\r\n" {

> +	-re "^$decimal\[ \t\]+END\[ \t\]+$hex\(\[ \t\]+Y\)? *\r\n" {

>  	    incr end_seq_count

>  	    exp_continue

>  	}

> @@ -159,7 +159,7 @@ gdb_test_multiple "maint info line-table gdb.dwarf2/dw2-ranges-base.c" \

>  	-re ".*linetable: \\(\\(struct linetable \\*\\) 0x0\\):\r\nNo line table.\r\n" {

>  	    exp_continue

>  	}

> -	-re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS\[ \t\]+IS-STMT\r\n" {

> +	-re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS\[ \t\]+IS-STMT *\r\n" {

>  	    exp_continue

>  	}

>      }

> -- 

> 2.21.1

>
Tom Tromey March 20, 2020, 2:29 p.m. | #2
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:


>> +	  uiout->field_string ("is-stmt", item->is_stmt ? " Y" : "");


Andrew> Is the whitespace in " Y" still needed? I'm guessing this is a hang
Andrew> over from the previous manual formatting.  But like I said, I didn't
Andrew> actually test this.

Thanks, I hadn't noticed this.
I've removed the space.

Andrew> Otherwise, looks good.

I'm checking it in with that change.

Tom

Patch

diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 4bf1f08849f..5b51f168e52 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -985,26 +985,31 @@  maintenance_print_one_line_table (struct symtab *symtab, void *data)
     printf_filtered (_("Line table has no lines.\n"));
   else
     {
-      int i;
-
       /* Leave space for 6 digits of index and line number.  After that the
 	 tables will just not format as well.  */
-      printf_filtered (_("%-6s %6s %s %s\n"),
-		       _("INDEX"), _("LINE"), _("ADDRESS"), _("IS-STMT"));
-
-      for (i = 0; i < linetable->nitems; ++i)
+      struct ui_out *uiout = current_uiout;
+      ui_out_emit_table table_emitter (uiout, 4, -1, "line-table");
+      uiout->table_header (6, ui_left, "index", _("INDEX"));
+      uiout->table_header (6, ui_left, "line", _("LINE"));
+      uiout->table_header (18, ui_left, "address", _("ADDRESS"));
+      uiout->table_header (1, ui_left, "is-stmt", _("IS-STMT"));
+      uiout->table_body ();
+
+      for (int i = 0; i < linetable->nitems; ++i)
 	{
 	  struct linetable_entry *item;
 
 	  item = &linetable->item [i];
-	  printf_filtered ("%-6d ", i);
+	  ui_out_emit_tuple tuple_emitter (uiout, nullptr);
+	  uiout->field_signed ("index", i);
 	  if (item->line > 0)
-	    printf_filtered ("%6d ", item->line);
+	    uiout->field_signed ("line", item->line);
 	  else
-	    printf_filtered ("%6s ", _("END"));
-	  printf_filtered ("%s%s\n",
-			   core_addr_to_string (item->pc),
-			   (item->is_stmt ? " Y" : ""));
+	    uiout->field_string ("line", _("END"));
+	  uiout->field_core_addr ("address", get_objfile_arch (objfile),
+				  item->pc);
+	  uiout->field_string ("is-stmt", item->is_stmt ? " Y" : "");
+	  uiout->text ("\n");
 	}
     }
 
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
index c1a3ab155fd..92f8f6cecbe 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
@@ -146,10 +146,10 @@  gdb_test "info line frame3" \
 set end_seq_count 0
 gdb_test_multiple "maint info line-table gdb.dwarf2/dw2-ranges-base.c" \
     "count END markers in line table" {
-	-re "^$decimal\[ \t\]+$decimal\[ \t\]+$hex\(\[ \t\]+Y\)?\r\n" {
+	-re "^$decimal\[ \t\]+$decimal\[ \t\]+$hex\(\[ \t\]+Y\)? *\r\n" {
 	    exp_continue
 	}
-	-re "^$decimal\[ \t\]+END\[ \t\]+$hex\(\[ \t\]+Y\)?\r\n" {
+	-re "^$decimal\[ \t\]+END\[ \t\]+$hex\(\[ \t\]+Y\)? *\r\n" {
 	    incr end_seq_count
 	    exp_continue
 	}
@@ -159,7 +159,7 @@  gdb_test_multiple "maint info line-table gdb.dwarf2/dw2-ranges-base.c" \
 	-re ".*linetable: \\(\\(struct linetable \\*\\) 0x0\\):\r\nNo line table.\r\n" {
 	    exp_continue
 	}
-	-re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS\[ \t\]+IS-STMT\r\n" {
+	-re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS\[ \t\]+IS-STMT *\r\n" {
 	    exp_continue
 	}
     }