1 # Copyright 2020-2024 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.
21 if { [build_executable "failed to prepare" $testfile $srcfile \
22 {debug build-id}] == -1 } {
25 set host_binfile [gdb_remote_download host $binfile]
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]
31 lassign [remote_exec host mktemp -d] ret cache_dir
33 # The output of mktemp contains an end of line, remove it.
34 set cache_dir [string trimright $cache_dir \r\n]
37 fail "couldn't create temporary cache dir"
41 verbose -log "Index cache dir: $cache_dir"
43 # Populate the index-cache.
44 with_test_prefix "populate index cache" {
47 gdb_test_no_output "set index-cache directory $cache_dir" \
48 "set index-cache directory"
49 gdb_test_no_output "set index-cache enabled on"
50 gdb_test "file $host_binfile" "Reading symbols from .*" "file"
51 gdb_test_no_output "maint wait-for-index-cache"
54 proc load_binary { method } {
58 if { $method == "standard" } {
59 gdb_test "file $::host_binfile" "Reading symbols from .*" "file"
60 } elseif { $method == "index" } {
61 gdb_test_no_output "set index-cache enabled on"
62 gdb_test "file $::host_binfile" "Reading symbols from .*" "file index"
63 gdb_test_no_output "set index-cache enabled off"
64 } elseif { $method == "readnow" } {
65 gdb_test "file -readnow $::host_binfile" \
66 "Reading symbols from .*Expanding full symbols from .*" \
69 error "unknown method"
72 # Print a static function: seeing it and its signature confirms GDB
74 gdb_test "print foo" " = {int \\(int, int\\)} $hex <foo>"
77 set methods {standard index readnow}
79 foreach_with_prefix first $methods {
80 foreach_with_prefix second $methods {
81 foreach_with_prefix third $methods {
82 # Start with a clean GDB.
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"
88 gdb_test_no_output "set index-cache directory $cache_dir" \
89 "set index-cache directory"
91 # Avoid GDB asking whether we really want to load a new binary.
92 gdb_test_no_output "set confirm off"
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 }
101 lassign [remote_exec host "sh -c" [quote_for_host rm $cache_dir/*.gdb-index]] ret
102 if { $ret != 0 && $expecting_index_cache_use } {
103 fail "couldn't remove files in temporary cache dir"
107 lassign [remote_exec host rmdir "$cache_dir"] ret
109 fail "couldn't remove temporary cache dir"