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