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