xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/info_sources.exp (revision 4ac76180e904e771b9d522c7e57296d371f06499)
1# Copyright 2019-2020 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 [-d | -b] [--] [REGEX]'
17
18standard_testfile .c info_sources_base.c
19
20if {[prepare_for_testing $testfile.exp $testfile \
21	 [list $srcfile $srcfile2] debug]} {
22    untested $testfile.exp
23    return -1
24}
25
26# Executes "info sources " $args.
27# EXPECT_SEEN_INFO_SOURCES 1 indicates that the source file info_sources.c must be seen
28# in the output.  Similarly, EXPECT_SEEN_INFO_SOURCES_BASE indicates that the source file
29# info_sources_base.c must be seen in the output.
30proc test_info_sources {args expect_seen_info_sources expect_seen_info_sources_base} {
31    global gdb_prompt
32
33    set seen_info_sources 0
34    set seen_info_sources_base 0
35    set cmd [concat "info sources " $args]
36    gdb_test_multiple $cmd $cmd {
37	-re "^\[^,\]*info_sources.c(, |\[\r\n\]+)" {
38	    set seen_info_sources 1
39	    exp_continue
40	}
41	-re "^\[^,\]*info_sources_base.c(, |\[\r\n\]+)" {
42	    set seen_info_sources_base 1
43	    exp_continue
44	}
45	-re ", " {
46	    exp_continue
47	}
48	-re "$gdb_prompt $" {
49	    if {$seen_info_sources == $expect_seen_info_sources \
50		    && $seen_info_sources_base == $expect_seen_info_sources_base} {
51		pass $cmd
52	    } else {
53		fail $cmd
54	    }
55	}
56    }
57}
58
59if ![runto_main] {
60    untested $testfile.exp
61    return -1
62}
63gdb_test "break some_other_func" ""
64
65gdb_test "continue"
66
67# List both files with no regexp:
68test_info_sources "" 1 1
69# Same but with option terminator:
70test_info_sources "--" 1 1
71
72# List both files with regexp matching anywhere in the filenames:
73test_info_sources "info_sources" 1 1
74if { ! [is_remote host] } {
75    test_info_sources "gdb.base" 1 1
76}
77
78# List both files with regexp matching the filename basenames,
79# using various parts of the -basename option:
80test_info_sources "-b info_sources" 1 1
81test_info_sources "-basename info_sources" 1 1
82test_info_sources "-b -- info_sources" 1 1
83test_info_sources "-ba info_sources" 1 1
84test_info_sources "-base -- info_sources" 1 1
85test_info_sources "-basena info_sources" 1 1
86test_info_sources "-basename -- info_sources" 1 1
87
88# List only the file with basename matching regexp:
89test_info_sources "-b base" 0 1
90
91# List the files with dirname matching regexp,
92# using various part of the -dirname option:
93if { ! [is_remote host] } {
94    test_info_sources "-d base" 1 1
95    test_info_sources "-dirname base" 1 1
96}
97
98# Test non matching regexp, with option terminator:
99test_info_sources "-b -- -d" 0 0
100test_info_sources "-d -- -d" 0 0
101