]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dwarf2/gdb-index.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / gdb-index.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.
19 require dwarf2_support
20
21 # Can't save an index with readnow.
22 require !readnow
23
24 standard_testfile main.c
25
26 if { [prepare_for_testing "failed to prepare" "${testfile}" \
27 [list ${srcfile}]] } {
28 return -1
29 }
30
31 # Add a .gdb_index section to PROGRAM.
32 # PROGRAM is assumed to be the output of standard_output_file.
33 # Returns the path of the program or "" if there is a failure.
34 # If there is a failure it will have already been logged.
35 # Use local prefix to prevent overriding add_gdb_index from lib/gdb.exp.
36
37 proc local_add_gdb_index { program } {
38 set filename [file tail ${program}]
39 set host_program [gdb_remote_download host $program]
40 set index_file [host_standard_output_file $filename.gdb-index]
41 set tmpdir [host_standard_output_file .tmp]
42 set dwz $tmpdir/$filename.dwz
43 set dwz_index_file [host_standard_output_file $filename.dwz.gdb-index]
44 verbose -log "index_file: ${index_file}"
45 remote_file host delete ${index_file}
46 remote_file host delete ${dwz_index_file}
47 gdb_test_no_output "save gdb-index [file dirname ${index_file}]" \
48 "save gdb-index for file $filename"
49
50 # No point in continuing if generating the index failed.
51 # N.B.: There are times when gdb won't create an index, and it's not a
52 # failure. However, in our case we need an index. So if you find one
53 # not being generated, you'll either have to tweak the .c file or maybe
54 # add a flag to force an index to be generated.
55 if { [remote_file host exists ${index_file}] } {
56 pass "gdb-index file created"
57 } else {
58 fail "gdb-index file created"
59 return ""
60 }
61
62 set host_program_with_index $host_program.with-index
63 set program_with_index $program.with-index
64 if {[run_on_host "objcopy" [gdb_find_objcopy] \
65 [join \
66 [list \
67 "--remove-section .gdb_index" \
68 "--add-section .gdb_index=$index_file" \
69 "--set-section-flags .gdb_index=readonly" \
70 "$host_program" \
71 "$host_program_with_index"]]]} {
72 return ""
73 }
74
75 with_test_prefix "modify dwz file" {
76 if { [remote_file host exists ${dwz_index_file}] } {
77 # We're modifying $dwz in place, otherwise we'd have to update
78 # .gnu_debugaltlink in $program.
79 set args [join [list "--remove-section .gdb_index" \
80 " --add-section .gdb_index=$dwz_index_file" \
81 " --set-section-flags .gdb_index=readonly $dwz"]]
82 if {[run_on_host "objcopy" [gdb_find_objcopy] "$args"]} {
83 return ""
84 }
85 }
86 }
87
88 return [list \
89 [remote_upload host $host_program_with_index $program_with_index] \
90 $host_program_with_index]
91 }
92
93 # Build a copy of the program with an index (.gdb_index/.debug_names).
94 # But only if the toolchain didn't already create one: gdb doesn't support
95 # building an index from a program already using one.
96
97 set test "check if index present"
98 gdb_test_multiple "mt print objfiles ${testfile}" $test {
99 -re "gdb_index.*${gdb_prompt} $" {
100 set binfile_with_index $binfile
101 set host_binfile_with_index [gdb_remote_download host $binfile]
102 }
103 -re "debug_names.*${gdb_prompt} $" {
104 set binfile_with_index $binfile
105 set host_binfile_with_index [gdb_remote_download host $binfile]
106 }
107 -re "(Psymtabs|Cooked).*${gdb_prompt} $" {
108 lassign [local_add_gdb_index $binfile] binfile_with_index host_binfile_with_index
109 if { ${binfile_with_index} == "" } {
110 return -1
111 }
112 }
113 -re ".*${gdb_prompt} $" {
114 fail "unrecognized symbol reader"
115 }
116 }
117
118 # Ok, we have a copy of $binfile with an index.
119 # Restart gdb and verify the index was used.
120
121 clean_restart ${binfile_with_index}
122 gdb_test "mt print objfiles ${testfile}" \
123 "(gdb_index|debug_names).*" \
124 "index used"
125
126 # Make gdb re-read symbols and see if .gdb_index/.debug_names still
127 # gets used. symtab/15885
128
129 # There is gdb_touch_execfile, but it doesn't handle remote hosts.
130 # Is touch portable enough?
131 # First make sure enough time has passed, file mtime resolution is seconds.
132 gdb_test_no_output "shell sleep 1"
133 if {[run_on_host "touch binary" touch $host_binfile_with_index]} {
134 return -1
135 }
136
137 if ![runto_main] {
138 return -1
139 }
140 gdb_test "mt print objfiles ${testfile}" \
141 "(gdb_index|debug_names).*" \
142 "index used after symbol reloading"