1 # Copyright 2021-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 # Test 'info sources' when the test file makes use of a shared
19 require allow_shlib_tests
21 set is_remote_target [is_remote target]
23 standard_testfile -test.c -lib.c
24 set solib_name [standard_output_file ${testfile}-lib.so]
26 if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile2} ${solib_name} \
28 untested "failed to compile shared library"
32 if {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable \
33 [list debug shlib=${solib_name} ]] != ""} {
34 untested "failed to compile executable"
38 clean_restart ${binfile}
40 set solib_name [gdb_load_shlib $solib_name]
43 untested "failed to run to function foo"
47 # Invoke 'info sources EXTRA_ARGS' and extract the results.
48 # The results are then compared to the list ARGS.
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
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
62 with_test_prefix "args: ${extra_args}" {
64 # The results of running info sources will be placed into this local.
65 array set info_sources {}
67 # The command we are going to run.
68 set cmd "info sources ${extra_args}"
69 set command_regex [string_to_regexp $cmd]
71 # Run the command and extract the results into INFO_SOURCES.
75 gdb_test_multiple $cmd "" {
76 -re "${command_regex}\r\n" {
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]
88 -re "^\\(Full debug information has not yet been read for this file\\.\\)\r\n" {
91 -re "^\\(Objfile has no debug information\\.\\)\r\n" {
99 -re "^$gdb_prompt $" {
103 -re "^(\[^,\r\n\]+), " {
104 set f $expect_out(1,string)
108 -re "^(\[^\r\n\]+)\r\n" {
109 if { $objfile_name == "" } {
110 fail "${gdb_test_name} (no objfile name)"
114 set f $expect_out(1,string)
116 set info_sources($objfile_name) $files
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,
129 if {[string index $sourcefile 0] == "!"} {
131 set match_type "is not"
132 set sourcefile [string range $sourcefile 1 end]
135 # Figure out the path for SOURCEFILE that we're looking for.
136 set sourcepath [file normalize ${srcdir}/${subdir}/${sourcefile}]
138 if { $is_remote_target } {
139 set objfile [file tail $objfile]
142 # Make sure we handle the case where there are no source files
143 # associated with a particular objfile.
145 if [info exists info_sources($objfile)] {
146 set source_list $info_sources($objfile)
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]'"
159 run_info_sources "" \
160 ${binfile} ${srcfile} \
161 ${binfile} ${testfile}-header.h \
162 ${solib_name} ${srcfile2} \
163 ${solib_name} ${testfile}-header.h
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
171 run_info_sources "-basename \\.c" \
172 ${binfile} ${srcfile} \
173 ${binfile} !${testfile}-header.h \
174 ${solib_name} ${srcfile2} \
175 ${solib_name} !${testfile}-header.h
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
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