1 # Copyright 2021-2022 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 if { [skip_shlib_tests] } {
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}
41 untested "failed to run to function foo"
45 # Invoke 'info sources EXTRA_ARGS' and extract the results.
46 # The results are then compared to the list ARGS.
48 # The list ARGS should consist of pairs of values, the first item being the
49 # path to an object file, and the second item being the name of a source file.
50 # This proc checks that source file was listed as being a source file for the
53 # If the name of the source file starts with the character "!" (exclamation
54 # character, without the quotes) then the check is inverted, that the source
55 # file is NOT listed for the given object file.
56 proc run_info_sources { extra_args args } {
57 global gdb_prompt srcdir subdir
59 with_test_prefix "args: ${extra_args}" {
61 # The results of running info sources will be placed into this local.
62 array set info_sources {}
64 # The command we are going to run.
65 set cmd "info sources ${extra_args}"
66 set command_regex [string_to_regexp $cmd]
68 # Run the command and extract the results into INFO_SOURCES.
71 gdb_test_multiple $cmd "" {
72 -re "${command_regex}\r\n" {
76 -re "^(\[^\r\n\]+):\r\n" {
77 set objfile_name $expect_out(1,string)
81 -re "^\\(Full debug information has not yet been read for this file\\.\\)\r\n" {
89 -re "^$gdb_prompt $" {
93 -re "^(\[^\r\n\]+)\r\n" {
94 if { $objfile_name == "" } {
95 fail "${gdb_test_name} (no objfile name)"
100 foreach f [split $expect_out(1,string) ,] {
101 lappend files [string trim $f]
103 set info_sources($objfile_name) $files
109 # Now check ARGS agaisnt the values held in INFO_SOURCES map.
110 foreach {objfile sourcefile} $args {
111 # First, figure out if we're expecting SOURCEFILE to be present,
115 if {[string index $sourcefile 0] == "!"} {
117 set match_type "is not"
118 set sourcefile [string range $sourcefile 1 end]
121 # Figure out the path for SOURCEFILE that we're looking for.
122 set sourcepath [file normalize ${srcdir}/${subdir}/${sourcefile}]
124 # Make sure we handle the case where there are no source files
125 # associated with a particular objfile.
127 if [info exists info_sources($objfile)] {
128 set source_list $info_sources($objfile)
131 # Now perform the search, and check the results.
132 set idx [lsearch -exact $source_list $sourcepath]
133 gdb_assert {($present && $idx >= 0) || (!$present && $idx == -1)} \
134 "source file '$sourcefile' ${match_type} present for '[file tail $objfile]'"
141 run_info_sources "" \
142 ${binfile} ${srcfile} \
143 ${binfile} ${testfile}-header.h \
144 ${solib_name} ${srcfile2} \
145 ${solib_name} ${testfile}-header.h
147 run_info_sources "-basename info_sources_2" \
148 ${binfile} ${srcfile} \
149 ${binfile} ${testfile}-header.h \
150 ${solib_name} ${srcfile2} \
151 ${solib_name} ${testfile}-header.h
153 run_info_sources "-basename \\.c" \
154 ${binfile} ${srcfile} \
155 ${binfile} !${testfile}-header.h \
156 ${solib_name} ${srcfile2} \
157 ${solib_name} !${testfile}-header.h
159 run_info_sources "-basename -- -test\\.c" \
160 ${binfile} ${srcfile} \
161 ${binfile} !${testfile}-header.h \
162 ${solib_name} !${srcfile2} \
163 ${solib_name} !${testfile}-header.h
165 run_info_sources "-basename -- -lib\\.c" \
166 ${binfile} !${srcfile} \
167 ${binfile} !${testfile}-header.h \
168 ${solib_name} ${srcfile2} \
169 ${solib_name} !${testfile}-header.h