]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Add missing terminator in Dwarf::_macro_unit
authorTom de Vries <tdevries@suse.de>
Thu, 16 May 2024 20:28:07 +0000 (22:28 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 16 May 2024 20:28:07 +0000 (22:28 +0200)
When printing complaints with one of the execs from test-case
gdb.dwarf2/macro-source-path.exp, we run into:
...
$ gdb -q -batch \
    -iex "set complaints 100" \
    macro-source-path-clang14-dw4-absolute-cwd-32 \
    -ex "p main"
During symbol reading: debug info runs off end of .debug_macro section \
  [in module macro-source-path-clang14-dw4-absolute-cwd-32]
$1 = {int ()} 0x4004b7 <main>
...
and readelf complains more specifically:
...
Contents of the .debug_macro section:

  Offset:                      0
  Version:                     5
  Offset size:                 4
  Offset into .debug_line:     0xe3

 DW_MACRO_define - lineno : 0 macro : ONE 1
 DW_MACRO_define_strp - lineno : 0 macro : THREE 3
 DW_MACRO_start_file - lineno: 0 filenum: 1 filename: test.c
 DW_MACRO_define - lineno : 1 macro : TWO 2
 DW_MACRO_end_file
readelf: Error: .debug_macro section not zero terminated
...

Fix this by adding the missing terminator in Dwarf::_macro_unit.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/gdb.dwarf2/macro-source-path.exp
gdb/testsuite/lib/dwarf.exp

index b6b7b0bd2fd373a92c55796c4ece7d376de7947e..fccfabdebb19f7a5f669f6ed3dc91936827fc2a2 100644 (file)
@@ -139,6 +139,17 @@ proc do_test { test_name lines_version DW_AT_name main_file_idx directories
                return
            }
 
+           with_complaints 5 {
+               gdb_test_multiple "print main" "no complaints" {
+                   -wrap -re "During symbol reading: .*" {
+                       fail $gdb_test_name
+                   }
+                   -wrap -re "" {
+                       pass $gdb_test_name
+                   }
+               }
+           }
+
            if ![runto_main] {
                return
            }
index 5b23a60af8eb24022a1a4387547473a0679a5e8c..995cdcac9414507a07dbb63656ef8bb96c65c572 100644 (file)
@@ -2252,6 +2252,8 @@ namespace eval Dwarf {
        with_override Dwarf::end_file Dwarf::_macro_unit_end_file {
            uplevel $body
        }}}}
+
+       _op .byte 0x0 "# End macro unit"
     }
 
     # Emit a DW_MACRO_define entry.