]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2013-2024 Free Software Foundation, Inc. |
779bd270 DE |
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. | |
ce8d533e | 19 | require dwarf2_support |
779bd270 | 20 | |
a653ec1f TV |
21 | # Can't save an index with readnow. |
22 | require !readnow | |
23 | ||
779bd270 DE |
24 | standard_testfile main.c |
25 | ||
5b362f04 | 26 | if { [prepare_for_testing "failed to prepare" "${testfile}" \ |
779bd270 DE |
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. | |
e453275c | 35 | # Use local prefix to prevent overriding add_gdb_index from lib/gdb.exp. |
779bd270 | 36 | |
e453275c | 37 | proc local_add_gdb_index { program } { |
0df0352a | 38 | set filename [file tail ${program}] |
a653ec1f TV |
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] | |
779bd270 DE |
44 | verbose -log "index_file: ${index_file}" |
45 | remote_file host delete ${index_file} | |
c4973306 | 46 | remote_file host delete ${dwz_index_file} |
7893c162 | 47 | gdb_test_no_output "save gdb-index [file dirname ${index_file}]" \ |
a653ec1f | 48 | "save gdb-index for file $filename" |
779bd270 DE |
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 | ||
a653ec1f TV |
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"]]]} { | |
779bd270 DE |
72 | return "" |
73 | } | |
c4973306 | 74 | |
73d9a918 TV |
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 | } | |
c4973306 SM |
85 | } |
86 | } | |
87 | ||
a653ec1f TV |
88 | return [list \ |
89 | [remote_upload host $host_program_with_index $program_with_index] \ | |
90 | $host_program_with_index] | |
779bd270 DE |
91 | } |
92 | ||
927aa2e7 | 93 | # Build a copy of the program with an index (.gdb_index/.debug_names). |
779bd270 DE |
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 | |
a653ec1f | 101 | set host_binfile_with_index [gdb_remote_download host $binfile] |
779bd270 | 102 | } |
927aa2e7 JK |
103 | -re "debug_names.*${gdb_prompt} $" { |
104 | set binfile_with_index $binfile | |
a653ec1f | 105 | set host_binfile_with_index [gdb_remote_download host $binfile] |
927aa2e7 | 106 | } |
6dd7aa90 | 107 | -re "(Psymtabs|Cooked).*${gdb_prompt} $" { |
a653ec1f | 108 | lassign [local_add_gdb_index $binfile] binfile_with_index host_binfile_with_index |
779bd270 DE |
109 | if { ${binfile_with_index} == "" } { |
110 | return -1 | |
111 | } | |
112 | } | |
6dd7aa90 TT |
113 | -re ".*${gdb_prompt} $" { |
114 | fail "unrecognized symbol reader" | |
115 | } | |
779bd270 DE |
116 | } |
117 | ||
927aa2e7 | 118 | # Ok, we have a copy of $binfile with an index. |
779bd270 DE |
119 | # Restart gdb and verify the index was used. |
120 | ||
121 | clean_restart ${binfile_with_index} | |
122 | gdb_test "mt print objfiles ${testfile}" \ | |
927aa2e7 JK |
123 | "(gdb_index|debug_names).*" \ |
124 | "index used" | |
779bd270 | 125 | |
927aa2e7 JK |
126 | # Make gdb re-read symbols and see if .gdb_index/.debug_names still |
127 | # gets used. symtab/15885 | |
779bd270 DE |
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" | |
a653ec1f | 133 | if {[run_on_host "touch binary" touch $host_binfile_with_index]} { |
779bd270 DE |
134 | return -1 |
135 | } | |
136 | ||
137 | if ![runto_main] { | |
138 | return -1 | |
139 | } | |
140 | gdb_test "mt print objfiles ${testfile}" \ | |
927aa2e7 JK |
141 | "(gdb_index|debug_names).*" \ |
142 | "index used after symbol reloading" |