]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2020-2024 Free Software Foundation, Inc. |
8a91fbdf SM |
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 | # This test checks that loading a file with different methods (partial symtabs, | |
17 | # index, readnow) does not crash. | |
18 | ||
19 | standard_testfile | |
20 | ||
60be64b3 | 21 | if { [build_executable "failed to prepare" $testfile $srcfile \ |
21f507ef | 22 | {debug ldflags=-Wl,--build-id}] == -1 } { |
60be64b3 BE |
23 | return |
24 | } | |
8eef5130 | 25 | set host_binfile [gdb_remote_download host $binfile] |
60be64b3 | 26 | |
1df42e90 TV |
27 | set has_index_section [exec_has_index_section $binfile] |
28 | set uses_readnow [expr [string first "-readnow" $GDBFLAGS] != -1] | |
29 | set expecting_index_cache_use [expr !$has_index_section && !$uses_readnow] | |
30 | ||
8a91fbdf SM |
31 | lassign [remote_exec host mktemp -d] ret cache_dir |
32 | ||
33 | # The output of mktemp contains an end of line, remove it. | |
34 | set cache_dir [string trimright $cache_dir \r\n] | |
35 | ||
36 | if { $ret != 0 } { | |
37 | fail "couldn't create temporary cache dir" | |
38 | return | |
39 | } | |
40 | ||
41 | verbose -log "Index cache dir: $cache_dir" | |
42 | ||
8a91fbdf SM |
43 | # Populate the index-cache. |
44 | with_test_prefix "populate index cache" { | |
45 | clean_restart | |
46 | ||
47 | gdb_test_no_output "set index-cache directory $cache_dir" \ | |
48 | "set index-cache directory" | |
7bc5c369 | 49 | gdb_test_no_output "set index-cache enabled on" |
8eef5130 | 50 | gdb_test "file $host_binfile" "Reading symbols from .*" "file" |
743d3f09 | 51 | gdb_test_no_output "maint wait-for-index-cache" |
8a91fbdf SM |
52 | } |
53 | ||
54 | proc load_binary { method } { | |
55 | global binfile | |
56 | global hex | |
57 | ||
58 | if { $method == "standard" } { | |
8eef5130 | 59 | gdb_test "file $::host_binfile" "Reading symbols from .*" "file" |
8a91fbdf | 60 | } elseif { $method == "index" } { |
7bc5c369 | 61 | gdb_test_no_output "set index-cache enabled on" |
8eef5130 | 62 | gdb_test "file $::host_binfile" "Reading symbols from .*" "file index" |
7bc5c369 | 63 | gdb_test_no_output "set index-cache enabled off" |
8a91fbdf | 64 | } elseif { $method == "readnow" } { |
8eef5130 | 65 | gdb_test "file -readnow $::host_binfile" \ |
8a91fbdf SM |
66 | "Reading symbols from .*Expanding full symbols from .*" \ |
67 | "file readnow" | |
68 | } else { | |
69 | error "unknown method" | |
70 | } | |
71 | ||
72 | # Print a static function: seeing it and its signature confirms GDB | |
73 | # sees some symbols. | |
74 | gdb_test "print foo" " = {int \\(int, int\\)} $hex <foo>" | |
75 | } | |
76 | ||
77 | set methods {standard index readnow} | |
78 | ||
79 | foreach_with_prefix first $methods { | |
80 | foreach_with_prefix second $methods { | |
81 | foreach_with_prefix third $methods { | |
82 | # Start with a clean GDB. | |
83 | clean_restart | |
84 | ||
85 | # Set the index cache dir, but don't enable the index-cache, it will | |
86 | # be enabled only when needed, when loading a file with the "index" | |
87 | # method. | |
88 | gdb_test_no_output "set index-cache directory $cache_dir" \ | |
89 | "set index-cache directory" | |
90 | ||
91 | # Avoid GDB asking whether we really want to load a new binary. | |
92 | gdb_test_no_output "set confirm off" | |
93 | ||
94 | with_test_prefix "load first" { load_binary $first } | |
95 | with_test_prefix "load second" { load_binary $second } | |
96 | with_test_prefix "load third" { load_binary $third } | |
97 | } | |
98 | } | |
99 | } | |
f8eec398 | 100 | |
0ecbda2f | 101 | lassign [remote_exec host "sh -c" [quote_for_host rm $cache_dir/*.gdb-index]] ret |
1df42e90 | 102 | if { $ret != 0 && $expecting_index_cache_use } { |
f8eec398 BE |
103 | fail "couldn't remove files in temporary cache dir" |
104 | return | |
105 | } | |
106 | ||
107 | lassign [remote_exec host rmdir "$cache_dir"] ret | |
108 | if { $ret != 0 } { | |
109 | fail "couldn't remove temporary cache dir" | |
110 | return | |
111 | } |