complaint (_("line number info header doesn't "
"fit in `.debug_line' section"));
+ if (line_ptr != lh->statement_program_start)
+ error (_("malformed line number program header, advertised length does"
+ " not match actual length"));
+
return lh;
}
--- /dev/null
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Check handling of v3 .debug_line header advertised as v4, as produced by
+# fpc <= v3.2.4.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support the DWARF
+# assembler.
+require dwarf2_support
+
+standard_testfile main.c -dw.S
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+ declare_labels Llines
+
+ cu {} {
+ compile_unit {
+ DW_AT_language @DW_LANG_C
+ DW_AT_name $::srcfile
+ DW_AT_stmt_list $Llines DW_FORM_sec_offset
+ } {
+ }
+ }
+
+ lines {
+ version 3
+ advertised_version 4
+ } Llines {
+ include_dir "$::srcdir/$::subdir"
+ file_name "$::srcfile" 1
+ }
+}
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+ [list $srcfile $asm_file] {nodebug}] } {
+ return -1
+}
+
+gdb_test "info line 1" \
+ [string cat \
+ "malformed line number program header," \
+ " advertised length does not match actual length"]
# Current options are:
# is_64 0|1 - boolean indicating if you want to emit 64-bit DWARF
# default = 0 (32-bit)
- # version n - DWARF version number to emit
+ # version n - DWARF version to determine .debug_line format
# default = 4
+ # advertised_version n
+ # - DWARF version to emit (used only for invalid DWARF)
+ # default = value provided by <version n>
# addr_size n - the size of addresses in bytes: 4, 8, or default
# default = default
# seg_sel_size n
variable _line_header_finalized
variable _line_header_end_label
variable _line_unit_version
+ variable _line_advertised_unit_version
variable _line_is_64
variable _line_string_form
# Establish the defaults.
set _line_is_64 0
set _line_unit_version 4
+ set _line_advertised_unit_version default
set _unit_addr_size default
set _line_include_dirs {}
set _line_file_names {}
switch -exact -- $name {
is_64 { set _line_is_64 $value }
version { set _line_unit_version $value }
+ advertised_version { set _line_unit_advertised_version $value }
addr_size { set _unit_addr_size $value }
seg_sel_size { set _seg_sel_size $value }
default_is_stmt { set _default_is_stmt $value }
set _unit_addr_size 4
}
}
+ if {$_line_unit_advertised_version == "default"} {
+ set _line_unit_advertised_version $_line_unit_version
+ }
set unit_num [incr _line_count]
define_label $unit_len_label
- _op .2byte $_line_unit_version version
+ _op .2byte $_line_unit_advertised_version version
if { $_line_unit_version >= 5 } {
_op .byte $_unit_addr_size "address_size"