]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dwarf2/dwzbuildid.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dwzbuildid.exp
1 # Copyright 2013-2024 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 load_lib dwarf.exp
17
18 # This test can only be run on targets which support DWARF-2 and use gas.
19 require dwarf2_support
20
21 # No remote host testing either.
22 require {!is_remote host}
23
24
25 # Lots of source files since we test a few cases and make new files
26 # for each.
27 # The tests are:
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
36
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]
40
41 Dwarf::assemble $asm_file {
42 upvar dwzname dwzname
43 upvar buildid buildid
44
45 gnu_debugaltlink $dwzname $buildid
46
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}} {
51 }
52 }
53 aranges {} cu_start {
54 arange {} 0 0
55 }
56 }
57 }
58
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]
62
63 Dwarf::assemble $asm_file {
64 declare_labels int_label int_label2
65
66 upvar buildid buildid
67 upvar value value
68
69 build_id $buildid
70
71 cu { label cu_start } {
72 compile_unit {{language @DW_LANG_C}} {
73 int_label2: base_type {
74 {name int}
75 {byte_size 4 sdata}
76 {encoding @DW_ATE_signed}
77 }
78
79 constant {
80 {name the_int}
81 {type :$int_label2}
82 {const_value $value data1}
83 }
84 }
85 }
86
87 aranges {} cu_start {
88 arange {} 0 0
89 }
90 }
91 }
92
93 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
94 object {nodebug}] != "" } {
95 return -1
96 }
97
98 # The values don't really matter, just whether they are equal.
99 set ok_prefix 01
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]
105
106 set debugdir [standard_output_file {}]
107 set basedir $debugdir/.build-id
108 file mkdir $basedir $basedir/$ok_prefix
109
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
113
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
117
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
125
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] != ""} {
130 return -1
131 }
132 }
133
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
136
137 proc do_test {} {
138 clean_restart
139
140 gdb_test_no_output "set debug-file-directory $::debugdir" \
141 "set debug-file-directory"
142
143 gdb_load ${::binfile}-${::testname}
144
145 if {![runto_main]} {
146 return
147 }
148
149 if {$::testname == "mismatch"} {
150 gdb_test "print the_int" \
151 "(No symbol table is loaded|No symbol \"the_int\" in current context).*"
152 } else {
153 gdb_test "print the_int" " = 99"
154 }
155 }
156
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]
164 }
165
166 if {[gdb_compile $objs ${binfile}-$testname executable {quiet}] != ""} {
167 unsupported "compilation failed"
168 continue
169 }
170
171 do_test
172 }