1 # Copyright 2013-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # This test can only be run on targets which support DWARF-2 and use gas.
19 require dwarf2_support
21 # No remote host testing either.
22 require {!is_remote host}
25 # Lots of source files since we test a few cases and make new files
28 # ok - the main file refers to a dwz and the buildids match
29 # mismatch - the buildids do not match
30 # fallback - the buildids do not match but a match is found via buildid
31 standard_testfile main.c \
32 dwzbuildid-ok-base.S dwzbuildid-ok-sep.S \
33 dwzbuildid-mismatch-base.S dwzbuildid-mismatch-sep.S \
34 dwzbuildid-fallback-base.S dwzbuildid-fallback-sep.S \
35 dwzbuildid-fallback-ok.S
37 # Write some assembly that just has a .gnu_debugaltlink section.
38 proc write_just_debugaltlink {filename dwzname buildid} {
39 set asm_file [standard_output_file $filename]
41 Dwarf::assemble $asm_file {
45 gnu_debugaltlink $dwzname $buildid
47 # Only the DWARF reader checks .gnu_debugaltlink, so make sure
48 # there is a bit of DWARF in here.
49 cu { label cu_start } {
50 compile_unit {{language @DW_LANG_C}} {
59 # Write some DWARF that also sets the buildid.
60 proc write_dwarf_file {filename buildid {value 99}} {
61 set asm_file [standard_output_file $filename]
63 Dwarf::assemble $asm_file {
64 declare_labels int_label int_label2
71 cu { label cu_start } {
72 compile_unit {{language @DW_LANG_C}} {
73 int_label2: base_type {
76 {encoding @DW_ATE_signed}
82 {const_value $value data1}
93 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
94 object {nodebug}] != "" } {
98 # The values don't really matter, just whether they are equal.
100 set ok_suffix 02030405060708091011121314151617181920
101 set ok_suffix2 020304050607080910111213141516171819ff
102 set ok_buildid ${ok_prefix}${ok_suffix}
103 set ok_buildid2 ${ok_prefix}${ok_suffix2}
104 set bad_buildid [string repeat ff 20]
106 set debugdir [standard_output_file {}]
107 set basedir $debugdir/.build-id
108 file mkdir $basedir $basedir/$ok_prefix
110 # Test where the separate debuginfo's buildid matches.
111 write_just_debugaltlink $srcfile2 ${binfile}3.o $ok_buildid
112 write_dwarf_file $srcfile3 $ok_buildid
114 # Test where the separate debuginfo's buildid does not match.
115 write_just_debugaltlink $srcfile4 ${binfile}5.o $ok_buildid
116 write_dwarf_file $srcfile5 $bad_buildid
118 # Test where the separate debuginfo's buildid does not match, but then
119 # we find a match in the .build-id directory.
120 write_just_debugaltlink $srcfile6 ${binfile}7.o $ok_buildid2
121 # Use 77 as the value so that if we load the bad debuginfo, we will
122 # see the wrong result.
123 write_dwarf_file $srcfile7 $bad_buildid 77
124 write_dwarf_file $srcfile8 $ok_buildid2
126 # Compile everything.
127 for {set i 2} {$i <= 8} {incr i} {
128 if {[gdb_compile [standard_output_file [set srcfile$i]] \
129 ${binfile}$i.o object nodebug] != ""} {
134 # Copy a file into the .build-id place for the "fallback" test.
135 file copy -force -- ${binfile}8.o $basedir/$ok_prefix/$ok_suffix2.debug
140 gdb_test_no_output "set debug-file-directory $::debugdir" \
141 "set debug-file-directory"
143 gdb_load ${::binfile}-${::testname}
149 if {$::testname == "mismatch"} {
150 gdb_test "print the_int" \
151 "(No symbol table is loaded|No symbol \"the_int\" in current context).*"
153 gdb_test "print the_int" " = 99"
157 foreach_with_prefix testname { ok mismatch fallback } {
158 if { $testname == "ok" } {
159 set objs [list ${binfile}1.o ${binfile}2.o]
160 } elseif { $testname == "mismatch" } {
161 set objs [list ${binfile}1.o ${binfile}4.o]
162 } elseif { $testname == "fallback" } {
163 set objs [list ${binfile}1.o ${binfile}6.o]
166 if {[gdb_compile $objs ${binfile}-$testname executable {quiet}] != ""} {
167 unsupported "compilation failed"