]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/gdb-index-err.exp
cefd708f5ab3409c95b51a823b01f5d160a367dd
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / gdb-index-err.exp
1 # Copyright 2023 Free Software Foundation, Inc.
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 # Test some error messages that can arise from the 'save gdb-index'
17 # command.
18
19 standard_testfile
20
21 if {[prepare_for_testing "prepare for test" $testfile $srcfile] == -1} {
22 return -1
23 }
24
25 # This test isn't going to work when the board file automatically adds
26 # an index section, or if the debug information is split into a
27 # separate objfile.
28 set index_type [get_index_type $binfile "check debug style"]
29 if { $index_type ne "cooked" } {
30 unsupported "cannot test without a cooked index"
31 return -1
32 }
33
34
35 # The name of a directory that doesn't exist.
36 set bad_dir [standard_output_file "non-existent"]
37
38 # Try to write the index into a non-existent directory.
39 foreach_with_prefix flag { "" "-dwarf-5" } {
40 gdb_test "save gdb-index ${flag} ${bad_dir}" \
41 "Error while writing index for `[string_to_regexp $binfile]': `[string_to_regexp $bad_dir]': No such file or directory\\." \
42 "try to write index to non-existent directory"
43 }
44
45 # Create a text-file.
46 set text_file [standard_output_file "text-file"]
47 set fd [open $text_file w]
48 puts $fd "A line of text.\n"
49 close $fd
50
51 # Try to write the index into something that is not a directory.
52 foreach_with_prefix flag { "" "-dwarf-5" } {
53 gdb_test "save gdb-index ${flag} ${text_file}" \
54 "Error while writing index for `[string_to_regexp $binfile]': `[string_to_regexp $text_file]': Is not a directory\\." \
55 "try to write index to something that's not a directory"
56 }
57
58 # Create a directory which can't be written too.
59 set non_writable_dir [standard_output_file "private"]
60 remote_exec host "mkdir -p ${non_writable_dir}"
61 remote_exec host "chmod u-w,g-w ${non_writable_dir}"
62
63 # Try to write the index into a non-writable directory.
64 foreach_with_prefix flag { "" "-dwarf-5" } {
65 set test "try to write index to a non-writable directory"
66 if { [root_user] } {
67 unsupported $test
68 continue
69 }
70
71 gdb_test "save gdb-index ${flag} ${non_writable_dir}" \
72 "Error while writing index for `[string_to_regexp $binfile]': couldn't open `[string_to_regexp $non_writable_dir]/${gdb_test_file_name}.*': Permission denied\\." \
73 $test
74 }
75
76 # Create copies of the executable, we will add an index section to
77 # each of these.
78 remote_exec host "cp $binfile ${binfile}.gdb_index"
79 remote_exec host "cp $binfile ${binfile}.dwarf_5"
80
81 # Create a directory in which we can try to generate the index files.
82 set already_indexed_dir [standard_output_file "already_indexed"]
83 remote_exec host "mkdir -p $already_indexed_dir"
84
85 foreach_with_prefix flag { "" "-dwarf-5" } {
86 if { $flag eq "" } {
87 set extension "gdb_index"
88 } else {
89 set extension "dwarf_5"
90 }
91
92 # Add the index section to the executable.
93 clean_restart ${binfile}.${extension}
94 gdb_assert {[ensure_gdb_index ${binfile}.${extension} ${flag}] == 1} \
95 "add index to executable"
96
97 # Reload the executable (which now has an index), and try to
98 # generate and index from it. This will fail.
99 clean_restart ${binfile}.${extension}
100 gdb_test "save gdb-index ${flag} $already_indexed_dir" \
101 "Error while writing index for `[string_to_regexp $binfile.$extension]': Cannot use an index to create the index" \
102 "try to generate an index from a binary with an index"
103 }