1 # Copyright 2019-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 [-d | -b] [--] [REGEX]'
18 standard_testfile .c info_sources_base.c
20 if {[prepare_for_testing $testfile.exp $testfile \
21 [list $srcfile $srcfile2] debug]} {
22 untested $testfile.exp
26 # Executes "info sources ARGS".
28 # EXPECT_SEEN_INFO_SOURCES 1 indicates that the source file info_sources.c
29 # must be seen in the output. Similarly, EXPECT_SEEN_INFO_SOURCES_BASE
30 # indicates that the source file info_sources_base.c must be seen in the
33 # If TESTNAME is not the empty string then this is the test name, otherwise
34 # uses "info sources ARGS" as the test name.
35 proc test_info_sources {args expect_seen_info_sources \
36 expect_seen_info_sources_base \
38 global gdb_prompt srcfile srcfile2
40 set seen_info_sources 0
41 set seen_info_sources_base 0
42 set cmd [concat "info sources " $args]
44 if { $testname eq "" } {
48 gdb_test_multiple $cmd $testname {
49 -re "^\[^,\]*${srcfile}(, |\[\r\n\]+)" {
50 incr seen_info_sources
53 -re "^\[^,\]*${srcfile2}(, |\[\r\n\]+)" {
54 incr seen_info_sources_base 1
61 if {$seen_info_sources == $expect_seen_info_sources \
62 && $seen_info_sources_base == $expect_seen_info_sources_base} {
75 # List both files with no regexp:
76 with_test_prefix "in main" {
77 test_info_sources "" 1 1
80 gdb_test "break some_other_func" ""
83 # List both files with no regexp:
84 test_info_sources "" 1 1
85 # Same but with option terminator:
86 test_info_sources "--" 1 1
88 # List both files with regexp matching anywhere in the filenames:
89 test_info_sources "info_sources" 1 1
90 if { ! [is_remote host] } {
91 test_info_sources "gdb.base" 1 1
94 # List both files with regexp matching the filename basenames,
95 # using various parts of the -basename option:
96 test_info_sources "-b info_sources" 1 1
97 test_info_sources "-basename info_sources" 1 1
98 test_info_sources "-b -- info_sources" 1 1
99 test_info_sources "-ba info_sources" 1 1
100 test_info_sources "-base -- info_sources" 1 1
101 test_info_sources "-basena info_sources" 1 1
102 test_info_sources "-basename -- info_sources" 1 1
104 # List only the file with basename matching regexp:
105 test_info_sources "-b base" 0 1
107 # List the files with dirname matching regexp,
108 # using various part of the -dirname option:
109 if { ! [is_remote host] } {
110 test_info_sources "-d base" 1 1
111 test_info_sources "-dirname base" 1 1
114 # Test non matching regexp against the basename, with option
116 test_info_sources "-b -- -d" 0 0
118 # The following tests relies on using a regexp which will not match
119 # either the directory name of the source files. Unlike the basename
120 # test above we need to be more careful picking the regexp as the
121 # source filename might contain any simple character patterns, and so
122 # could unexpectedly match the regexp.
124 # Loop through all the characters a-z trying regexp '-C' (where 'C' is
125 # each character), looking for a regexp which doesn't match the
128 for {set i [scan a %c]} {$i <= [scan z %c]} {incr i} {
129 set tmp_re -[format %c $i]
131 if {$re eq "" && ![regexp $tmp_re $srcdir/$subdir/]} {
136 # If we found a suitable regexp then test non matching regexp against
137 # the directory name, with option terminator:
139 test_info_sources "-d -- $re" 0 0 \
140 "info sources -d -- <non matching regexp>"
143 "info sources -d -- <non matching regexp> (failed to find regexp)"