gdb: Include end of sequence markers in the line table
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 5 Nov 2019 16:00:26 +0000 (16:00 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 24 Jan 2020 23:39:31 +0000 (23:39 +0000)
In this commit:

  commit d9b3de22f33e400f7f409cce3acf6c7dab07dd79
  Date:   Wed May 27 14:44:29 2015 -0700

      Add struct to record dwarf line number state machine.

I believe an unintended change was made to how we store the DWARF line
table, the end of sequence markers between sequences of lines were
lost from the line table.

This commit fixes this small oversight and restores the end of
sequence markers.

Given that we've survived this long without noticing is clearly an
indication that this isn't that serious, however, a later patch that I
am developing would benefit from having the markers in place, so I'd
like to restore them.

Having the markers also means that the output of 'maintenance info
line-table' now more closely reflects the DWARF line table.

I've taken this opportunity to improve how 'maintenance info
line-table' displays the end of sequence markers - it now uses the END
keyword, rather than just printing an entry with line number 0.  So we
see this:

  INDEX    LINE ADDRESS
  0          12 0x00000000004003b0
  1          17 0x00000000004003b0
  2          18 0x00000000004003b0
  3         END 0x00000000004003b7
  4           5 0x00000000004004a0
  5           6 0x00000000004004a0
  6         END 0x00000000004004a7

Instead of what we would have seen, which was this:

  INDEX    LINE ADDRESS
  0          12 0x00000000004003b0
  1          17 0x00000000004003b0
  2          18 0x00000000004003b0
  3           0 0x00000000004003b7
  4           5 0x00000000004004a0
  5           6 0x00000000004004a0
  6           0 0x00000000004004a7

I've added a small test that uses 'maintenance info line-table' to
ensure that we don't regress this again.

gdb/ChangeLog:

* dwarf2read.c (lnp_state_machine::record_line): Include
end_sequence parameter in debug print out.  Record the line if we
are at an end_sequence marker even if it's not the start of a
statement.
* symmisc.c (maintenance_print_one_line_table): Print end of
sequence markers with 'END' not '0'.

gdb/testsuite/ChangeLog:

* gdb.base/maint.exp: Update line table parsing test.
* gdb.dwarf2/dw2-ranges-base.exp: Add new line table parsing test.

Change-Id: I002f872248db82a1d4fefdc6b51ff5dbf932d8a8

gdb/ChangeLog
gdb/dwarf2read.c
gdb/symmisc.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/maint.exp
gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp

index 16d16ef6dcacafe0219b060e125217e31be907fe..82eea3254c4a1a5e62a6ca9830cd573e12a47d23 100644 (file)
@@ -1,3 +1,12 @@
+2020-01-24  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * dwarf2read.c (lnp_state_machine::record_line): Include
+       end_sequence parameter in debug print out.  Record the line if we
+       are at an end_sequence marker even if it's not the start of a
+       statement.
+       * symmisc.c (maintenance_print_one_line_table): Print end of
+       sequence markers with 'END' not '0'.
+
 2020-01-24  Pedro Alves  <palves@redhat.com>
 
        PR gdb/25410
index a494db790a4de976780f9cef667d3f76432d8911..a81a77aa5040309513fd9c2743463fc023c9abe8 100644 (file)
@@ -21314,10 +21314,11 @@ lnp_state_machine::record_line (bool end_sequence)
     {
       fprintf_unfiltered (gdb_stdlog,
                          "Processing actual line %u: file %u,"
-                         " address %s, is_stmt %u, discrim %u\n",
+                         " address %s, is_stmt %u, discrim %u%s\n",
                          m_line, m_file,
                          paddress (m_gdbarch, m_address),
-                         m_is_stmt, m_discriminator);
+                         m_is_stmt, m_discriminator,
+                         (end_sequence ? "\t(end sequence)" : ""));
     }
 
   file_entry *fe = current_file ();
@@ -21330,7 +21331,8 @@ lnp_state_machine::record_line (bool end_sequence)
   else if (m_op_index == 0 || end_sequence)
     {
       fe->included_p = 1;
-      if (m_record_lines_p && (producer_is_codewarrior (m_cu) || m_is_stmt))
+      if (m_record_lines_p
+         && (producer_is_codewarrior (m_cu) || m_is_stmt || end_sequence))
        {
          if (m_last_subfile != m_cu->get_builder ()->get_current_subfile ()
              || end_sequence)
index 393a0343b90bde2d9be73f5f9f962415fe372e83..a6a7e728c4a0c16b72894762b9e3fc182cba5a12 100644 (file)
@@ -999,8 +999,12 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data)
          struct linetable_entry *item;
 
          item = &linetable->item [i];
-         printf_filtered (_("%-6d %6d %s\n"), i, item->line,
-                          core_addr_to_string (item->pc));
+         printf_filtered ("%-6d ", i);
+         if (item->line > 0)
+           printf_filtered ("%6d ", item->line);
+         else
+           printf_filtered ("%6s ", _("END"));
+         printf_filtered ("%s\n", core_addr_to_string (item->pc));
        }
     }
 
index 81500c21ae71052261f533c8a545a20ec483b870..1a1bc44ccbba17fcb0d2c8e4fa257e7b63fc4807 100644 (file)
@@ -1,3 +1,8 @@
+2020-01-24  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.base/maint.exp: Update line table parsing test.
+       * gdb.dwarf2/dw2-ranges-base.exp: Add new line table parsing test.
+
 2020-01-24  Pedro Alves  <palves@redhat.com>
 
        PR gdb/25410
index f389b6aec344ce49dfcfb30b01e400eb708069a4..fe25e0fc6126f0b2b8f2809c2ce32131fcf2cbd7 100644 (file)
@@ -508,8 +508,8 @@ gdb_test "maint" \
 # Test that "main info line-table" w/o a file name shows the symtab for
 # $srcfile.
 set saw_srcfile 0
-set test "maint info line-table w/o a file name"
-gdb_test_multiple "maint info line-table" $test {
+gdb_test_multiple "maint info line-table" \
+    "maint info line-table w/o a file name" {
     -re "symtab: \[^\n\r\]+${srcfile} \\(\\(struct symtab \\*\\) $hex\\)\r\nlinetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS" {
        set saw_srcfile 1
        exp_continue
@@ -518,7 +518,11 @@ gdb_test_multiple "maint info line-table" $test {
        # Match each symtab to avoid overflowing expect's buffer.
        exp_continue
     }
-    -re "$decimal\[ \t\]+$decimal\[ \t\]+$hex\r\n" {
+    -re "symtab: \[^\n\r\]+ \\(\\(struct symtab \\*\\) $hex\\)\r\nlinetable: \\(\\(struct linetable \\*\\) 0x0\\):\r\nNo line table.\r\n" {
+       # For symtabs with no linetable.
+       exp_continue
+    }
+    -re "^$decimal\[ \t\]+$decimal\[ \t\]+$hex\r\n" {
        # Line table entries can be long too:
        #
        #  INDEX    LINE ADDRESS
@@ -531,13 +535,17 @@ gdb_test_multiple "maint info line-table" $test {
        #  6          45 0x0000000000400740
        #  (...)
        #  454       129 0x00007ffff7df1d28
-       #  455         0 0x00007ffff7df1d3f
+       #  455       END 0x00007ffff7df1d3f
        #
        # Match each line to avoid overflowing expect's buffer.
        exp_continue
     }
-    -re "$gdb_prompt $" {
-       gdb_assert $saw_srcfile $test
+    -re "^$decimal\[ \t\]+END\[ \t\]+$hex\r\n" {
+       # Matches an end marker in the above.
+       exp_continue
+    }
+    -re "^$gdb_prompt $" {
+       gdb_assert $saw_srcfile $gdb_test_name
     }
 }
 
index f46edf089592bc23e47574c752af161e85897b77..33177336f5891835c4180c5d80621117ada389a2 100644 (file)
@@ -141,3 +141,25 @@ gdb_test "info line frame2" \
     "Line 21 of .* starts at address .* and ends at .*"
 gdb_test "info line frame3" \
     "Line 31 of .* starts at address .* and ends at .*"
+
+# Ensure that the line table correctly tracks the end of sequence markers.
+set end_seq_count 0
+gdb_test_multiple "maint info line-table" \
+    "count END markers in line table" {
+       -re "^$decimal\[ \t\]+$decimal\[ \t\]+$hex\r\n" {
+           exp_continue
+       }
+       -re "^$decimal\[ \t\]+END\[ \t\]+$hex\r\n" {
+           incr end_seq_count
+           exp_continue
+       }
+       -re "^$gdb_prompt $" {
+           gdb_assert [expr $end_seq_count == 3] $gdb_test_name
+       }
+       -re ".*linetable: \\(\\(struct linetable \\*\\) 0x0\\):\r\nNo line table.\r\n" {
+           exp_continue
+       }
+       -re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS\r\n" {
+           exp_continue
+       }
+    }
This page took 0.049044 seconds and 4 git commands to generate.