Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / info_sources_2.exp
1 # Copyright 2021-2022 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 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 if ![runto foo] {
41 untested "failed to run to function foo"
42 return -1
43 }
44
45 # Invoke 'info sources EXTRA_ARGS' and extract the results.
46 # The results are then compared to the list ARGS.
47 #
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
51 # given object file.
52 #
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
58
59 with_test_prefix "args: ${extra_args}" {
60
61 # The results of running info sources will be placed into this local.
62 array set info_sources {}
63
64 # The command we are going to run.
65 set cmd "info sources ${extra_args}"
66 set command_regex [string_to_regexp $cmd]
67
68 # Run the command and extract the results into INFO_SOURCES.
69 set objfile_name ""
70 set source_files {}
71 gdb_test_multiple $cmd "" {
72 -re "${command_regex}\r\n" {
73 exp_continue
74 }
75
76 -re "^(\[^\r\n\]+):\r\n" {
77 set objfile_name $expect_out(1,string)
78 exp_continue
79 }
80
81 -re "^\\(Full debug information has not yet been read for this file\\.\\)\r\n" {
82 exp_continue
83 }
84
85 -re "^\r\n" {
86 exp_continue
87 }
88
89 -re "^$gdb_prompt $" {
90 pass $gdb_test_name
91 }
92
93 -re "^(\[^\r\n\]+)\r\n" {
94 if { $objfile_name == "" } {
95 fail "${gdb_test_name} (no objfile name)"
96 return
97 }
98
99 set files {}
100 foreach f [split $expect_out(1,string) ,] {
101 lappend files [string trim $f]
102 }
103 set info_sources($objfile_name) $files
104 set $objfile_name ""
105 exp_continue
106 }
107 }
108
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,
112 # or not.
113 set present True
114 set match_type "is"
115 if {[string index $sourcefile 0] == "!"} {
116 set present False
117 set match_type "is not"
118 set sourcefile [string range $sourcefile 1 end]
119 }
120
121 # Figure out the path for SOURCEFILE that we're looking for.
122 set sourcepath [file normalize ${srcdir}/${subdir}/${sourcefile}]
123
124 # Make sure we handle the case where there are no source files
125 # associated with a particular objfile.
126 set source_list {}
127 if [info exists info_sources($objfile)] {
128 set source_list $info_sources($objfile)
129 }
130
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]'"
135 }
136 }
137 }
138
139 # The actual tests.
140
141 run_info_sources "" \
142 ${binfile} ${srcfile} \
143 ${binfile} ${testfile}-header.h \
144 ${solib_name} ${srcfile2} \
145 ${solib_name} ${testfile}-header.h
146
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
152
153 run_info_sources "-basename \\.c" \
154 ${binfile} ${srcfile} \
155 ${binfile} !${testfile}-header.h \
156 ${solib_name} ${srcfile2} \
157 ${solib_name} !${testfile}-header.h
158
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
164
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
This page took 0.042323 seconds and 4 git commands to generate.