xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/info_sources.exp (revision c9055873d0546e63388f027d3d7f85381cde0545)
1# Copyright 2019-2023 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 srcfile srcfile2
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 "^\[^,\]*${srcfile}(, |\[\r\n\]+)" {
38	    incr seen_info_sources
39	    exp_continue
40	}
41	-re "^\[^,\]*${srcfile2}(, |\[\r\n\]+)" {
42	    incr 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    return -1
61}
62
63# List both files with no regexp:
64with_test_prefix "in main" {
65    test_info_sources "" 1 1
66}
67
68gdb_test "break some_other_func" ""
69gdb_test "continue"
70
71# List both files with no regexp:
72test_info_sources "" 1 1
73# Same but with option terminator:
74test_info_sources "--" 1 1
75
76# List both files with regexp matching anywhere in the filenames:
77test_info_sources "info_sources" 1 1
78if { ! [is_remote host] } {
79    test_info_sources "gdb.base" 1 1
80}
81
82# List both files with regexp matching the filename basenames,
83# using various parts of the -basename option:
84test_info_sources "-b info_sources" 1 1
85test_info_sources "-basename info_sources" 1 1
86test_info_sources "-b -- info_sources" 1 1
87test_info_sources "-ba info_sources" 1 1
88test_info_sources "-base -- info_sources" 1 1
89test_info_sources "-basena info_sources" 1 1
90test_info_sources "-basename -- info_sources" 1 1
91
92# List only the file with basename matching regexp:
93test_info_sources "-b base" 0 1
94
95# List the files with dirname matching regexp,
96# using various part of the -dirname option:
97if { ! [is_remote host] } {
98    test_info_sources "-d base" 1 1
99    test_info_sources "-dirname base" 1 1
100}
101
102# Test non matching regexp, with option terminator:
103test_info_sources "-b -- -d" 0 0
104test_info_sources "-d -- -d" 0 0
105