[binutils-gdb] [gdb/testsuite] Fix gdb.dwarf2/dw-form-strx-out-of-bounds.exp

Tom de Vries via Gdb-cvs <[email protected]> Mon, 3 Aug 2026 17:51:35 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da58e6081294f=
d3dde8fc7397f3a09f8c8a3f87aa

commit a58e6081294fd3dde8fc7397f3a09f8c8a3f87aa
Author: Tom de Vries <[email protected]>
Date:   Mon Aug 3 19:51:31 2026 +0200

    [gdb/testsuite] Fix gdb.dwarf2/dw-form-strx-out-of-bounds.exp
   =20
    With test-case gdb.dwarf2/dw-form-strx-out-of-bounds.exp, I usually get:
    ...
    (gdb) file dw-form-strx-out-of-bounds
    Reading symbols from dw-form-strx-out-of-bounds...
    (gdb) ptype global_var
    DWARF Error: Offset from DW_FORM_GNU_str_index or DW_FORM_strx pointing=
 \
      outside of .debug_str_offsets section in CU at offset 0x2d1 [in modul=
e \
      dw-form-strx-out-of-bounds]
    No symbol "global_var" in current context.
    (gdb) PASS: $exp: ptype global_var
    ...
   =20
    But I just ran into:
    ...
    (gdb) file dw-form-strx-out-of-bounds^M
    Reading symbols from dw-form-strx-out-of-bounds...
    DWARF Error: Offset from DW_FORM_GNU_str_index or DW_FORM_strx pointing=
 \
      outside of .debug_str_offsets section in CU at offset 0x2df [in modul=
e \
      dw-form-strx-out-of-bounds]^M
    (gdb) ptype global_var^M
    No symbol "global_var" in current context.^M
    (gdb) FAIL: $exp: ptype global_var
    ...
   =20
    Fix this by:
    - using "maint set dwarf synchronous on" to ensure that the error happe=
ns
      during the file command
    - updating the matching to check $gdb_file_cmd_msg
   =20
    Tested gdb.dwarf2/dw-form-strx-out-of-bounds.exp and gdb.dwarf2/dw-form=
-strx.exp
    using make-check-all.sh on x86_64-linux.

Diff:
---
 gdb/testsuite/gdb.dwarf2/dw-form-strx-out-of-bounds.exp | 7 +++----
 gdb/testsuite/gdb.dwarf2/dw-form-strx.exp.tcl           | 8 +++++++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/gdb.dwarf2/dw-form-strx-out-of-bounds.exp b/gdb/=
testsuite/gdb.dwarf2/dw-form-strx-out-of-bounds.exp
index be7323bce95..e1e28eb432f 100644
--- a/gdb/testsuite/gdb.dwarf2/dw-form-strx-out-of-bounds.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw-form-strx-out-of-bounds.exp
@@ -34,8 +34,7 @@ set re_dwarf_error \
 set re_in_module \
     {in module [^\r\n]+}
 set re_in_module [string_to_regexp {[}]$re_in_module[string_to_regexp {]}]
+gdb_assert {[regexp "$re_dwarf_error $re_in_module" $gdb_file_cmd_msg]}
+
 set re_no_symbol [string_to_regexp {No symbol "global_var" in current cont=
ext.}]
-gdb_test "ptype global_var" \
-    [multi_line \
-	 "$re_dwarf_error $re_in_module"\
-	 $re_no_symbol]
+gdb_test "ptype global_var" $re_no_symbol
diff --git a/gdb/testsuite/gdb.dwarf2/dw-form-strx.exp.tcl b/gdb/testsuite/=
gdb.dwarf2/dw-form-strx.exp.tcl
index 931c935ccae..b261dc654af 100644
--- a/gdb/testsuite/gdb.dwarf2/dw-form-strx.exp.tcl
+++ b/gdb/testsuite/gdb.dwarf2/dw-form-strx.exp.tcl
@@ -54,11 +54,17 @@ Dwarf::assemble $asm_file {
     }
 }
=20
-if { [prepare_for_testing "failed to prepare" ${testfile} \
+if { [build_executable "failed to prepare" ${testfile} \
 	  [list $srcfile $asm_file] {nodebug}] } {
     return
 }
=20
+clean_restart
+
+gdb_test_no_output "maint set dwarf synchronous on"
+
+gdb_load $binfile
+
 # Let includers know prepare_for_testing was done, without having to check
 # source return status.
 set prepare_for_testing_done 1