diff --git a/gdb/testsuite/gdb.base/until-trailing-insns.exp b/gdb/testsuite/gdb.base/until-trailing-insns.exp
index aed36814809..baa5f1fa32c 100644
--- a/gdb/testsuite/gdb.base/until-trailing-insns.exp
+++ b/gdb/testsuite/gdb.base/until-trailing-insns.exp
@@ -147,9 +147,8 @@ Dwarf::assemble $asm_file {
 	    line [gdb_get_line_number "TAG: main return"]
 	    DW_LNS_negate_stmt
 	    DW_LNS_copy
+
 	    DW_LNE_set_address $main_end
-	    line [expr [gdb_get_line_number "TAG: main return"] + 1]
-	    DW_LNS_copy
 	    DW_LNE_end_sequence
 	}
     }
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp b/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp
index 71c5bf9014d..63d83fb9416 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp
@@ -128,9 +128,12 @@ Dwarf::assemble $asm_file {
 	    DW_LNE_set_address [lindex $main_result 0]
 	    DW_LNS_advance_line 10
 	    DW_LNS_copy
+
 	    DW_LNS_advance_pc [lindex $main_result 1]
 	    DW_LNS_advance_line 19
 	    DW_LNS_copy
+
+	    DW_LNS_advance_pc 0
 	    DW_LNE_end_sequence
 	}
     }
@@ -144,9 +147,12 @@ Dwarf::assemble $asm_file {
 	    DW_LNE_set_address some_func
 	    DW_LNS_advance_line 5
 	    DW_LNS_copy
+
 	    DW_LNS_advance_pc 64
 	    DW_LNS_advance_line 8
 	    DW_LNS_copy
+
+	    DW_LNS_advance_pc 0
 	    DW_LNE_end_sequence
 	}
     }
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-disasm-over-non-stmt.exp b/gdb/testsuite/gdb.dwarf2/dw2-disasm-over-non-stmt.exp
index 425dd971333..aa84a20b09c 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-disasm-over-non-stmt.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-disasm-over-non-stmt.exp
@@ -87,7 +87,6 @@ Dwarf::assemble $asm_file {
 	    DW_LNS_copy
 
 	    DW_LNE_set_address $main_end
-	    DW_LNS_copy
 	    DW_LNE_end_sequence
 	}
     }
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp
index f646e23da62..7ae14fa9b5a 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp
@@ -134,6 +134,7 @@ Dwarf::assemble $asm_file {
 	    DW_LNS_set_epilogue_begin
 	    DW_LNS_copy
 
+	    DW_LNE_set_address "$main_start + $main_len"
 	    DW_LNE_end_sequence
 	}
     }
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-small-func.exp b/gdb/testsuite/gdb.dwarf2/dw2-inline-small-func.exp
index 1ba346b9758..b117c8910f0 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-inline-small-func.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-small-func.exp
@@ -108,6 +108,8 @@ Dwarf::assemble $asm_file {
 
 	    DW_LNE_set_address line_label_3
 	    DW_LNS_copy
+
+	    DW_LNE_set_address "$main_start + $main_len"
 	    DW_LNE_end_sequence
 	}
     }
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-prologue-end.exp b/gdb/testsuite/gdb.dwarf2/dw2-prologue-end.exp
index 8d85464a826..caa40861f87 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-prologue-end.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-prologue-end.exp
@@ -72,6 +72,7 @@ Dwarf::assemble $asm_file {
 	    line [gdb_get_line_number "main end"]
 	    DW_LNS_copy
 
+	    DW_LNE_set_address "$main_start + $main_len"
 	    DW_LNE_end_sequence
 	}
     }
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
index 13e7c98dcf1..1a3d53c2116 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
@@ -79,24 +79,18 @@ Dwarf::assemble $asm_file {
 	    DW_LNS_advance_line 10
 	    DW_LNS_copy
 	    DW_LNS_advance_pc [lindex $main_func 1]
-	    DW_LNS_advance_line 19
-	    DW_LNS_copy
 	    DW_LNE_end_sequence
 
 	    DW_LNE_set_address [lindex $frame2_func 0]
 	    DW_LNS_advance_line 20
 	    DW_LNS_copy
 	    DW_LNS_advance_pc [lindex $frame2_func 1]
-	    DW_LNS_advance_line 29
-	    DW_LNS_copy
 	    DW_LNE_end_sequence
 
 	    DW_LNE_set_address [lindex $frame3_func 0]
 	    DW_LNS_advance_line 30
 	    DW_LNS_copy
 	    DW_LNS_advance_pc [lindex $frame3_func 1]
-	    DW_LNS_advance_line 39
-	    DW_LNS_copy
 	    DW_LNE_end_sequence
 	}
     }
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-func.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges-func.exp
index ea69af44601..c952e82b335 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-func.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-func.exp
@@ -133,9 +133,8 @@ proc do_test {suffix} {
 		DW_LNE_set_address main_label2
 		line [gdb_get_line_number "main return"]
 		DW_LNS_copy
+
 		DW_LNE_set_address $main_end
-		line [expr [gdb_get_line_number "main end"] + 1]
-		DW_LNS_copy
 		DW_LNE_end_sequence
 
 		DW_LNE_set_address $foo_start
@@ -150,25 +149,22 @@ proc do_test {suffix} {
 		DW_LNE_set_address foo_label3
 		line [gdb_get_line_number "foo end"]
 		DW_LNS_copy
+
 		DW_LNE_set_address $foo_end
-		DW_LNS_advance_line 1
-		DW_LNS_copy
 		DW_LNE_end_sequence
 
 		DW_LNE_set_address $bar_start
 		line [gdb_get_line_number "bar end"]
 		DW_LNS_copy
+
 		DW_LNS_advance_pc $bar_len
-		DW_LNS_advance_line 1
-		DW_LNS_copy
 		DW_LNE_end_sequence
 
 		DW_LNE_set_address $baz_start
 		line [gdb_get_line_number "baz end"]
 		DW_LNS_copy
+
 		DW_LNS_advance_pc $baz_len
-		DW_LNS_advance_line 1
-		DW_LNS_copy
 		DW_LNE_end_sequence
 
 		DW_LNE_set_address $foo_cold_start
@@ -180,9 +176,8 @@ proc do_test {suffix} {
 		DW_LNE_set_address foo_cold_label2
 		line [gdb_get_line_number "foo_cold end"]
 		DW_LNS_copy
+
 		DW_LNE_set_address $foo_cold_end
-		DW_LNS_advance_line 1
-		DW_LNS_copy
 		DW_LNE_end_sequence
 	    }
 	}
diff --git a/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp b/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
index d2ea91e2d3d..567049adc87 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
@@ -93,8 +93,6 @@ Dwarf::assemble $asm_file_1 {
 	    DW_LNS_copy
 
 	    DW_LNE_set_address $func_end
-	    DW_LNS_advance_line 1
-	    DW_LNS_copy
 	    DW_LNE_end_sequence
 	}
     }
@@ -177,8 +175,6 @@ Dwarf::assemble $asm_file_2 {
 	    DW_LNS_copy
 
 	    DW_LNE_set_address $main_end
-	    DW_LNS_advance_line 2
-	    DW_LNS_copy
 	    DW_LNE_end_sequence
 	}
     }
diff --git a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp
index ca597aaaa3e..a1c0e7705b3 100644
--- a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp
+++ b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp
@@ -283,11 +283,11 @@ Dwarf::assemble ${asm_file} {
 	    DW_LNS_copy
 	    line [gdb_get_line_number "foo end" $libsrc]
 	    DW_LNS_copy
+
 	    DW_LNE_set_address $foo_end
-	    DW_LNS_advance_line 1
-	    DW_LNS_copy
 	    DW_LNE_end_sequence
 
+
 	    DW_LNE_set_address $bar_start
 	    line [gdb_get_line_number "bar prologue" $libsrc]
 	    DW_LNS_copy
@@ -296,9 +296,8 @@ Dwarf::assemble ${asm_file} {
 	    DW_LNS_copy
 	    line [gdb_get_line_number "bar end" $libsrc]
 	    DW_LNS_copy
+
 	    DW_LNE_set_address $bar_end
-	    DW_LNS_advance_line 1
-	    DW_LNS_copy
 	    DW_LNE_end_sequence
 	}
     }
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index d085f835f07..816440f975f 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -2545,13 +2545,17 @@ namespace eval Dwarf {
 	proc program { body } {
 	    variable _line_header_end_label
 	    variable _line
+	    variable _line_address_update
 
 
 	    set _line 1
+	    set _line_address_update 0
 
 	    _line_finalize_header
 
 	    proc DW_LNE_set_address {addr} {
+		variable _line_address_update
+		set _line_address_update 1
 		_op .byte 0
 		set start [new_label "set_address_start"]
 		set end [new_label "set_address_end"]
@@ -2567,6 +2571,11 @@ namespace eval Dwarf {
 	    }
 
 	    proc DW_LNE_end_sequence {} {
+		variable _line_address_update
+		if { $_line_address_update == 0 } {
+		    error "Missing address update for end_sequence"
+		}
+		set _line_address_update 0
 		variable _line
 		_op .byte 0
 		_op .uleb128 1
@@ -2591,6 +2600,8 @@ namespace eval Dwarf {
 	    }
 
 	    proc DW_LNS_copy {} {
+		variable _line_address_update
+		set _line_address_update 0
 		_op .byte 1
 	    }
 
@@ -2607,6 +2618,8 @@ namespace eval Dwarf {
 	    }
 
 	    proc DW_LNS_advance_pc {offset} {
+		variable _line_address_update
+		set _line_address_update 1
 		_op .byte 2
 		_op .uleb128 ${offset}
 	    }
