]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / per-bfd-sharing.exp
CommitLineData
213516ef 1# Copyright 2020-2023 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
19standard_testfile
20
60be64b3 21if { [build_executable "failed to prepare" $testfile $srcfile \
21f507ef 22 {debug ldflags=-Wl,--build-id}] == -1 } {
60be64b3
BE
23 return
24}
25
1df42e90
TV
26set has_index_section [exec_has_index_section $binfile]
27set uses_readnow [expr [string first "-readnow" $GDBFLAGS] != -1]
28set expecting_index_cache_use [expr !$has_index_section && !$uses_readnow]
29
8a91fbdf
SM
30lassign [remote_exec host mktemp -d] ret cache_dir
31
32# The output of mktemp contains an end of line, remove it.
33set cache_dir [string trimright $cache_dir \r\n]
34
35if { $ret != 0 } {
36 fail "couldn't create temporary cache dir"
37 return
38}
39
40verbose -log "Index cache dir: $cache_dir"
41
8a91fbdf
SM
42# Populate the index-cache.
43with_test_prefix "populate index cache" {
44 clean_restart
45
46 gdb_test_no_output "set index-cache directory $cache_dir" \
47 "set index-cache directory"
7bc5c369 48 gdb_test_no_output "set index-cache enabled on"
8a91fbdf
SM
49 gdb_test "file $binfile" "Reading symbols from .*" "file"
50}
51
52proc load_binary { method } {
53 global binfile
54 global hex
55
56 if { $method == "standard" } {
57 gdb_test "file $binfile" "Reading symbols from .*" "file"
58 } elseif { $method == "index" } {
7bc5c369 59 gdb_test_no_output "set index-cache enabled on"
8a91fbdf 60 gdb_test "file $binfile" "Reading symbols from .*" "file index"
7bc5c369 61 gdb_test_no_output "set index-cache enabled off"
8a91fbdf
SM
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"
68 }
69
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>"
73}
74
75set methods {standard index readnow}
76
77foreach_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
82
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"
88
89 # Avoid GDB asking whether we really want to load a new binary.
90 gdb_test_no_output "set confirm off"
91
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 }
95 }
96 }
97}
f8eec398
BE
98
99lassign [remote_exec host sh "-c \"rm $cache_dir/*.gdb-index\""] ret
1df42e90 100if { $ret != 0 && $expecting_index_cache_use } {
f8eec398
BE
101 fail "couldn't remove files in temporary cache dir"
102 return
103}
104
105lassign [remote_exec host rmdir "$cache_dir"] ret
106if { $ret != 0 } {
107 fail "couldn't remove temporary cache dir"
108 return
109}