public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug symtab/26092] New: Complain about contradictory DW_LNE_end_sequence marker
@ 2020-06-08  8:34 vries at gcc dot gnu.org
  2020-06-08  8:59 ` [Bug symtab/26092] " vries at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2020-06-08  8:34 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26092

            Bug ID: 26092
           Summary: Complain about contradictory DW_LNE_end_sequence
                    marker
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: symtab
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider test-case gdb.dwarf2/dw2-ranges-base.exp.  It has a line-table for
dw2-ranges-base.c like this:
...
     Line Number Statements:
      [0x0000014e]  Extended opcode 2: set Address to 0x4004ba
      [0x00000159]  Advance Line by 10 to 11
      [0x0000015b]  Copy
      [0x0000015c]  Advance PC by 12 to 0x4004c6
      [0x0000015e]  Advance Line by 19 to 30
      [0x00000160]  Copy
      [0x00000161]  Extended opcode 1: End of Sequence

      [0x00000164]  Extended opcode 2: set Address to 0x4004ae
      [0x0000016f]  Advance Line by 20 to 21
      [0x00000171]  Copy
      [0x00000172]  Advance PC by 12 to 0x4004ba
      [0x00000174]  Advance Line by 29 to 50
      [0x00000176]  Copy
      [0x00000177]  Extended opcode 1: End of Sequence

      [0x0000017a]  Extended opcode 2: set Address to 0x4004a7
      [0x00000185]  Advance Line by 30 to 31
      [0x00000187]  Copy
      [0x00000188]  Advance PC by 7 to 0x4004ae
      [0x0000018a]  Advance Line by 39 to 70
      [0x0000018c]  Copy
      [0x0000018d]  Extended opcode 1: End of Sequence
...

The Copy followed by End-of-Sequence is as specified in the dwarf assembly, but
incorrect.  F.i., consider:
 ...
      [0x0000015c]  Advance PC by 12 to 0x4004c6
      [0x0000015e]  Advance Line by 19 to 30
      [0x00000160]  Copy
      [0x00000161]  Extended opcode 1: End of Sequence
 ...

Both the Copy and the End-of-Sequence append a row to the matrix using the same
addres: 0x4004c6.

The Copy declares a target instruction at that address.

The End-of-Sequence declares that the sequence ends before that address.

It's a contradiction that the target instruction is both part of the sequence
(according to Copy) and not part of the sequence (according to
End-of-Sequence).

[ Relevant dwarf standard bits:

DW_LNS_copy

The DW_LNS_copy opcode takes no operands. It appends a row to the matrix using
the current values of the state machine registers. Then it sets the
discriminator register to 0, and sets the basic_block, prologue_end and
epilogue_begin registers to “false.”

end_sequence:

A boolean indicating that the current address is that of the first byte
after the end of a sequence of target machine instructions. end_sequence
terminates a sequence of lines; therefore other information in the same
row is not meaningful.

DW_LNE_end_sequence:

The DW_LNE_end_sequence opcode takes no operands. It sets the
end_sequence register of the state machine to “true” and appends a row
to the matrix using the current values of the state-machine registers.
Then it resets the registers to the initial values specified above (see
Section 6.2.2). Every line number program sequence must end with a
DW_LNE_end_sequence instruction which creates a row whose address is
that of the byte after the last target machine instruction of the sequence.

]

The offending Copy is currently silently skipped by
buildsym_compunit::record_line.

It would be good to warn about this invalid use of dwarf, through the
complaints mechanism, or some such.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug symtab/26092] Complain about contradictory DW_LNE_end_sequence marker
  2020-06-08  8:34 [Bug symtab/26092] New: Complain about contradictory DW_LNE_end_sequence marker vries at gcc dot gnu.org
@ 2020-06-08  8:59 ` vries at gcc dot gnu.org
  2020-06-08  9:38 ` vries at gcc dot gnu.org
  2020-06-08 10:04 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2020-06-08  8:59 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26092

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
I wrote a tentative patch detecting this problem using a gdb_assert:
...
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 477c382b81..1219cc58be 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -20045,6 +20045,7 @@ class lnp_state_machine
   /* These are initialized in the constructor.  */

   CORE_ADDR m_address;
+  CORE_ADDR m_prev_line_address = 0;
   bool m_is_stmt;
   unsigned int m_discriminator;

@@ -20235,6 +20236,19 @@ dwarf_finish_line (struct gdbarch *gdbarch, struct
subfile *subfile,
 void
 lnp_state_machine::record_line (bool end_sequence)
 {
+  if (end_sequence)
+    {
+      if (m_prev_line_address != 0)
+       {
+         gdb_assert (m_prev_line_address != m_address);
+         m_prev_line_address = 0;
+       }
+    }
+  else
+    {
+      m_prev_line_address = m_address;
+    }
+
   if (dwarf_line_debug)
     {
       fprintf_unfiltered (gdb_stdlog,
...

I did a gdb.dwarf2 testsuite run, hoping to find that the problem is only
detected in the dwarf assembly test-cases.

However, it also triggered on this bit in libgcc:
...
  [0x0000064a]  Special opcode 75: advance Address by 5 to 0x300a and Line by 0
to 246
  [0x0000064b]  Advance PC by 0 to 0x300a
  [0x0000064d]  Extended opcode 1: End of Sequence
...
So it looks like we also got compilers/assemblers generating this.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug symtab/26092] Complain about contradictory DW_LNE_end_sequence marker
  2020-06-08  8:34 [Bug symtab/26092] New: Complain about contradictory DW_LNE_end_sequence marker vries at gcc dot gnu.org
  2020-06-08  8:59 ` [Bug symtab/26092] " vries at gcc dot gnu.org
@ 2020-06-08  9:38 ` vries at gcc dot gnu.org
  2020-06-08 10:04 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2020-06-08  9:38 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26092

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #1)
> However, it also triggered on this bit in libgcc:
> ...
>   [0x0000064a]  Special opcode 75: advance Address by 5 to 0x300a and Line
> by 0 to 246
>   [0x0000064b]  Advance PC by 0 to 0x300a
>   [0x0000064d]  Extended opcode 1: End of Sequence
> ...
> So it looks like we also got compilers/assemblers generating this.

Filed a gcc PR, PR95574 - "line table entry in sequence with address after
sequence" ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95574 ).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug symtab/26092] Complain about contradictory DW_LNE_end_sequence marker
  2020-06-08  8:34 [Bug symtab/26092] New: Complain about contradictory DW_LNE_end_sequence marker vries at gcc dot gnu.org
  2020-06-08  8:59 ` [Bug symtab/26092] " vries at gcc dot gnu.org
  2020-06-08  9:38 ` vries at gcc dot gnu.org
@ 2020-06-08 10:04 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2020-06-08 10:04 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26092

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
Apart from the warning, we want to fix the dwarf assembly test-cases, to
prevent people coming across this construct while testing patches, and
mistakenly getting the impression that this is valid dwarf.

OTOH, we do want a dwarf assembly test-case called
dw2-bad-dw-lne-end-sequence.exp or some such containing this construct, to make
sure it's handled in the current fashion (ignore).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-08 10:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-08  8:34 [Bug symtab/26092] New: Complain about contradictory DW_LNE_end_sequence marker vries at gcc dot gnu.org
2020-06-08  8:59 ` [Bug symtab/26092] " vries at gcc dot gnu.org
2020-06-08  9:38 ` vries at gcc dot gnu.org
2020-06-08 10:04 ` vries at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).