]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/info_sources_2.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / info_sources_2.exp
1 # Copyright 2021-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 'info sources' when the test file makes use of a shared
17 # library.
18
19 if { [skip_shlib_tests] } {
20 return 0
21 }
22
23 set is_remote_target [is_remote target]
24
25 standard_testfile -test.c -lib.c
26 set solib_name [standard_output_file ${testfile}-lib.so]
27
28 if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile2} ${solib_name} \
29 {debug}] != "" } {
30 untested "failed to compile shared library"
31 return -1
32 }
33
34 if {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable \
35 [list debug shlib=${solib_name} ]] != ""} {
36 untested "failed to compile executable"
37 return -1
38 }
39
40 clean_restart ${binfile}
41
42 set solib_name [gdb_load_shlib $solib_name]
43
44 if ![runto foo] {
45 untested "failed to run to function foo"
46 return -1
47 }
48
49 # Invoke 'info sources EXTRA_ARGS' and extract the results.
50 # The results are then compared to the list ARGS.
51 #
52 # The list ARGS should consist of pairs of values, the first item being the
53 # path to an object file, and the second item being the name of a source file.
54 # This proc checks that source file was listed as being a source file for the
55 # given object file.
56 #
57 # If the name of the source file starts with the character "!" (exclamation
58 # character, without the quotes) then the check is inverted, that the source
59 # file is NOT listed for the given object file.
60 proc run_info_sources { extra_args args } {
61 global gdb_prompt srcdir subdir
62 global is_remote_target
63
64 with_test_prefix "args: ${extra_args}" {
65
66 # The results of running info sources will be placed into this local.
67 array set info_sources {}
68
69 # The command we are going to run.
70 set cmd "info sources ${extra_args}"
71 set command_regex [string_to_regexp $cmd]
72
73 # Run the command and extract the results into INFO_SOURCES.
74 set objfile_name ""
75 set source_files {}
76 set files {}
77 gdb_test_multiple $cmd "" {
78 -re "${command_regex}\r\n" {
79 exp_continue
80 }
81
82 -re "^(\[^\r\n\]+):\r\n" {
83 set objfile_name $expect_out(1,string)
84 if { $is_remote_target } {
85 set objfile_name [file tail $objfile_name]
86 }
87 exp_continue
88 }
89
90 -re "^\\(Full debug information has not yet been read for this file\\.\\)\r\n" {
91 exp_continue
92 }
93 -re "^\\(Objfile has no debug information\\.\\)\r\n" {
94 exp_continue
95 }
96
97 -re "^\r\n" {
98 exp_continue
99 }
100
101 -re "^$gdb_prompt $" {
102 pass $gdb_test_name
103 }
104
105 -re "^(\[^,\r\n\]+), " {
106 set f $expect_out(1,string)
107 lappend files $f
108 exp_continue
109 }
110 -re "^(\[^\r\n\]+)\r\n" {
111 if { $objfile_name == "" } {
112 fail "${gdb_test_name} (no objfile name)"
113 return
114 }
115
116 set f $expect_out(1,string)
117 lappend files $f
118 set info_sources($objfile_name) $files
119 set $objfile_name ""
120 set files {}
121 exp_continue
122 }
123 }
124
125 # Now check ARGS agaisnt the values held in INFO_SOURCES map.
126 foreach {objfile sourcefile} $args {
127 # First, figure out if we're expecting SOURCEFILE to be present,
128 # or not.
129 set present True
130 set match_type "is"
131 if {[string index $sourcefile 0] == "!"} {
132 set present False
133 set match_type "is not"
134 set sourcefile [string range $sourcefile 1 end]
135 }
136
137 # Figure out the path for SOURCEFILE that we're looking for.
138 set sourcepath [file normalize ${srcdir}/${subdir}/${sourcefile}]
139
140 if { $is_remote_target } {
141 set objfile [file tail $objfile]
142 }
143
144 # Make sure we handle the case where there are no source files
145 # associated with a particular objfile.
146 set source_list {}
147 if [info exists info_sources($objfile)] {
148 set source_list $info_sources($objfile)
149 }
150
151 # Now perform the search, and check the results.
152 set idx [lsearch -exact $source_list $sourcepath]
153 gdb_assert {($present && $idx >= 0) || (!$present && $idx == -1)} \
154 "source file '$sourcefile' ${match_type} present for '[file tail $objfile]'"
155 }
156 }
157 }
158
159 # The actual tests.
160
161 run_info_sources "" \
162 ${binfile} ${srcfile} \
163 ${binfile} ${testfile}-header.h \
164 ${solib_name} ${srcfile2} \
165 ${solib_name} ${testfile}-header.h
166
167 run_info_sources "-basename info_sources_2" \
168 ${binfile} ${srcfile} \
169 ${binfile} ${testfile}-header.h \
170 ${solib_name} ${srcfile2} \
171 ${solib_name} ${testfile}-header.h
172
173 run_info_sources "-basename \\.c" \
174 ${binfile} ${srcfile} \
175 ${binfile} !${testfile}-header.h \
176 ${solib_name} ${srcfile2} \
177 ${solib_name} !${testfile}-header.h
178
179 run_info_sources "-basename -- -test\\.c" \
180 ${binfile} ${srcfile} \
181 ${binfile} !${testfile}-header.h \
182 ${solib_name} !${srcfile2} \
183 ${solib_name} !${testfile}-header.h
184
185 run_info_sources "-basename -- -lib\\.c" \
186 ${binfile} !${srcfile} \
187 ${binfile} !${testfile}-header.h \
188 ${solib_name} ${srcfile2} \
189 ${solib_name} !${testfile}-header.h