[gdb/testsuite] Fix quoting issue in gdb.base/index-cache.exp
[binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / per-bfd-sharing.exp
blob6574f65df9136ba7467116d962989165f9b7c7e1
1 # Copyright 2020-2023 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This test checks that loading a file with different methods (partial symtabs,
17 # index, readnow) does not crash.
19 standard_testfile
21 if { [build_executable "failed to prepare" $testfile $srcfile \
22 {debug ldflags=-Wl,--build-id}] == -1 } {
23 return
26 set has_index_section [exec_has_index_section $binfile]
27 set uses_readnow [expr [string first "-readnow" $GDBFLAGS] != -1]
28 set expecting_index_cache_use [expr !$has_index_section && !$uses_readnow]
30 lassign [remote_exec host mktemp -d] ret cache_dir
32 # The output of mktemp contains an end of line, remove it.
33 set cache_dir [string trimright $cache_dir \r\n]
35 if { $ret != 0 } {
36 fail "couldn't create temporary cache dir"
37 return
40 verbose -log "Index cache dir: $cache_dir"
42 # Populate the index-cache.
43 with_test_prefix "populate index cache" {
44 clean_restart
46 gdb_test_no_output "set index-cache directory $cache_dir" \
47 "set index-cache directory"
48 gdb_test_no_output "set index-cache enabled on"
49 gdb_test "file $binfile" "Reading symbols from .*" "file"
52 proc load_binary { method } {
53 global binfile
54 global hex
56 if { $method == "standard" } {
57 gdb_test "file $binfile" "Reading symbols from .*" "file"
58 } elseif { $method == "index" } {
59 gdb_test_no_output "set index-cache enabled on"
60 gdb_test "file $binfile" "Reading symbols from .*" "file index"
61 gdb_test_no_output "set index-cache enabled off"
62 } elseif { $method == "readnow" } {
63 gdb_test "file -readnow $binfile" \
64 "Reading symbols from .*Expanding full symbols from .*" \
65 "file readnow"
66 } else {
67 error "unknown method"
70 # Print a static function: seeing it and its signature confirms GDB
71 # sees some symbols.
72 gdb_test "print foo" " = {int \\(int, int\\)} $hex <foo>"
75 set methods {standard index readnow}
77 foreach_with_prefix first $methods {
78 foreach_with_prefix second $methods {
79 foreach_with_prefix third $methods {
80 # Start with a clean GDB.
81 clean_restart
83 # Set the index cache dir, but don't enable the index-cache, it will
84 # be enabled only when needed, when loading a file with the "index"
85 # method.
86 gdb_test_no_output "set index-cache directory $cache_dir" \
87 "set index-cache directory"
89 # Avoid GDB asking whether we really want to load a new binary.
90 gdb_test_no_output "set confirm off"
92 with_test_prefix "load first" { load_binary $first }
93 with_test_prefix "load second" { load_binary $second }
94 with_test_prefix "load third" { load_binary $third }
99 lassign [remote_exec host "sh -c" [quote_for_host rm $cache_dir/*.gdb-index]] ret
100 if { $ret != 0 && $expecting_index_cache_use } {
101 fail "couldn't remove files in temporary cache dir"
102 return
105 lassign [remote_exec host rmdir "$cache_dir"] ret
106 if { $ret != 0 } {
107 fail "couldn't remove temporary cache dir"
108 return