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