Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 4/4] [gdb/testsuite] Require DW_LNE_end_sequence
Date: Mon,  8 Apr 2024 14:04:45 +0200	[thread overview]
Message-ID: <20240408120445.12544-4-tdevries@suse.de> (raw)
In-Reply-To: <20240408120445.12544-1-tdevries@suse.de>

The dwarf standard requires that every line number program sequence ends
with a DW_LNE_end_sequence instruction.

Enforce this in the dwarf assembler for the last sequence in a line number
program (we have no means to enforce this for earlier sequences), and fix a
few test-case that don't have it.

Tested on aarch64-linux.

PR testsuite/31618
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31618
---
 gdb/testsuite/gdb.dwarf2/dw2-noloc.exp        |  3 +++
 .../gdb.dwarf2/dw2-symtab-includes-lookup.exp |  7 +++++
 .../gdb.dwarf2/dw2-symtab-includes.exp        |  7 +++++
 gdb/testsuite/lib/dwarf.exp                   | 26 +++++++++++++++++++
 4 files changed, 43 insertions(+)

diff --git a/gdb/testsuite/gdb.dwarf2/dw2-noloc.exp b/gdb/testsuite/gdb.dwarf2/dw2-noloc.exp
index 8c96ab8b0c5..bd74760e29c 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-noloc.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-noloc.exp
@@ -203,6 +203,9 @@ Dwarf::assemble $asm_file {
 	    line [gdb_get_line_number "main start"]
 	    DW_LNS_set_prologue_end
 	    DW_LNS_copy
+
+	    DW_LNE_set_address $main_end
+	    DW_LNE_end_sequence
 	}
     }
 }
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes-lookup.exp b/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes-lookup.exp
index 14bc84882be..96a528498da 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes-lookup.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes-lookup.exp
@@ -50,6 +50,8 @@ Dwarf::assemble $asm_file {
     declare_labels partial_label lines_label
     global srcdir subdir srcfile
 
+    get_func_info main
+
     cu {} {
 	partial_label: partial_unit {
 	    {stmt_list ${lines_label} DW_FORM_sec_offset}
@@ -77,7 +79,12 @@ Dwarf::assemble $asm_file {
 	include_dir "${srcdir}/${subdir}"
 	file_name "dw2-symtab-includes.h" 1
 	program {
+	    DW_LNE_set_address $main_start
 	    DW_LNS_advance_line 1
+	    DW_LNS_copy
+
+	    DW_LNE_set_address $main_end
+	    DW_LNE_end_sequence
 	}
     }
 }
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes.exp b/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes.exp
index 09007f22200..dc4a788bd70 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes.exp
@@ -29,6 +29,8 @@ Dwarf::assemble $asm_file {
     declare_labels partial_label lines_label
     global srcdir subdir srcfile
 
+    get_func_info main
+
     cu {} {
 	partial_label: partial_unit {} {
 	}
@@ -49,7 +51,12 @@ Dwarf::assemble $asm_file {
 	include_dir "${srcdir}/${subdir}"
 	file_name "dw2-symtab-includes.h" 1
 	program {
+	    DW_LNE_set_address $main_start
 	    DW_LNS_advance_line 1
+	    DW_LNS_copy
+
+	    DW_LNE_set_address $main_end
+	    DW_LNE_end_sequence
 	}
     }
 }
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 254f88f1055..c694375b534 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -2546,16 +2546,20 @@ namespace eval Dwarf {
 	    variable _line_header_end_label
 	    variable _line
 	    variable _line_address_update
+	    variable _line_program_terminated
 
 
 	    set _line 1
 	    set _line_address_update 0
+	    set _line_program_terminated 0
 
 	    _line_finalize_header
 
 	    proc DW_LNE_set_address {addr} {
 		variable _line_address_update
 		set _line_address_update 1
+		variable _line_program_terminated
+		set _line_program_terminated 0
 		_op .byte 0
 		set start [new_label "set_address_start"]
 		set end [new_label "set_address_end"]
@@ -2576,6 +2580,8 @@ namespace eval Dwarf {
 		    error "Missing address update for end_sequence"
 		}
 		set _line_address_update 0
+		variable _line_program_terminated
+		set _line_program_terminated 1
 		variable _line
 		_op .byte 0
 		_op .uleb128 1
@@ -2584,6 +2590,8 @@ namespace eval Dwarf {
 	    }
 
 	    proc DW_LNE_user { len opcode } {
+		variable _line_program_terminated
+		set _line_program_terminated 0
 		set DW_LNE_lo_usr 0x80
 		set DW_LNE_hi_usr 0xff
 		if { $DW_LNE_lo_usr <= $opcode
@@ -2605,22 +2613,32 @@ namespace eval Dwarf {
 		    error "Missing address update for copy"
 		}
 		set _line_address_update 0
+		variable _line_program_terminated
+		set _line_program_terminated 0
 		_op .byte 1
 	    }
 
 	    proc DW_LNS_negate_stmt {} {
+		variable _line_program_terminated
+		set _line_program_terminated 0
 		_op .byte 6
 	    }
 
 	    proc DW_LNS_set_prologue_end {} {
+		variable _line_program_terminated
+		set _line_program_terminated 0
 		_op .byte 0x0a
 	    }
 
 	    proc DW_LNS_set_epilogue_begin {} {
+		variable _line_program_terminated
+		set _line_program_terminated 0
 		_op .byte 0x0b
 	    }
 
 	    proc DW_LNS_advance_pc {offset} {
+		variable _line_program_terminated
+		set _line_program_terminated 0
 		variable _line_address_update
 		set _line_address_update 1
 		_op .byte 2
@@ -2628,6 +2646,8 @@ namespace eval Dwarf {
 	    }
 
 	    proc DW_LNS_advance_line {offset} {
+		variable _line_program_terminated
+		set _line_program_terminated 0
 		variable _line
 		_op .byte 3
 		_op .sleb128 ${offset}
@@ -2650,11 +2670,17 @@ namespace eval Dwarf {
 	    }
 
 	    proc DW_LNS_set_file {num} {
+		variable _line_program_terminated
+		set _line_program_terminated 0
 		_op .byte 4
 		_op .sleb128 ${num}
 	    }
 
 	    uplevel $body
+
+	    if { $_line_program_terminated == 0 } {
+		error "Missing end_seq"
+	    }
 	}
 
 	uplevel $body
-- 
2.35.3


  parent reply	other threads:[~2024-04-08 12:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08 12:04 [PATCH v2 1/4] [gdb/testsuite] Require address update for DW_LNE_end_sequence Tom de Vries
2024-04-08 12:04 ` [PATCH v2 2/4] [gdb/testsuite] Require address update for DW_LNS_copy Tom de Vries
2024-04-08 12:04 ` [PATCH v2 3/4] [gdb/testsuite] Fix end_sequence addresses Tom de Vries
2024-04-24 17:45   ` Carl Love
2024-04-24 18:07     ` Carl Love
2024-04-24 18:28     ` Carl Love
2024-04-24 21:07       ` Tom de Vries
2024-04-25 17:05         ` Carl Love
2024-04-25 20:46           ` Tom de Vries
2024-04-08 12:04 ` Tom de Vries [this message]
2024-04-17 10:58 ` [PATCH v2 1/4] [gdb/testsuite] Require address update for DW_LNE_end_sequence 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=20240408120445.12544-4-tdevries@suse.de \
    --to=tdevries@suse.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