aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/info_sources.exp
blob: 6ef711f39e0e61c9e1e26a3e827a223d9ea6c521 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Copyright 2019-2024 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Test 'info sources [-d | -b] [--] [REGEX]'

standard_testfile .c info_sources_base.c

if {[prepare_for_testing $testfile.exp $testfile \
	 [list $srcfile $srcfile2] debug]} {
    untested $testfile.exp
    return -1
}

# Executes "info sources ARGS".
#
# EXPECT_SEEN_INFO_SOURCES 1 indicates that the source file info_sources.c
# must be seen in the output.  Similarly, EXPECT_SEEN_INFO_SOURCES_BASE
# indicates that the source file info_sources_base.c must be seen in the
# output.
#
# If TESTNAME is not the empty string then this is the test name, otherwise
# uses "info sources ARGS" as the test name.
proc test_info_sources {args expect_seen_info_sources \
			    expect_seen_info_sources_base \
			    {testname ""}} {
    global gdb_prompt srcfile srcfile2

    set seen_info_sources 0
    set seen_info_sources_base 0
    set cmd [concat "info sources " $args]

    if { $testname eq "" } {
	set $testname $cmd
    }

    gdb_test_multiple $cmd $testname {
	-re "^\[^,\]*${srcfile}(, |\[\r\n\]+)" {
	    incr seen_info_sources
	    exp_continue
	}
	-re "^\[^,\]*${srcfile2}(, |\[\r\n\]+)" {
	    incr seen_info_sources_base 1
	    exp_continue
	}
	-re ", " {
	    exp_continue
	}
	-re "$gdb_prompt $" {
	    if {$seen_info_sources == $expect_seen_info_sources \
		    && $seen_info_sources_base == $expect_seen_info_sources_base} {
		pass $gdb_test_name
	    } else {
		fail $gdb_test_name
	    }
	}
    }
}

if ![runto_main] {
    return -1
}

# List both files with no regexp:
with_test_prefix "in main" {
    test_info_sources "" 1 1
}

gdb_test "break some_other_func" ""
gdb_test "continue"

# List both files with no regexp:
test_info_sources "" 1 1
# Same but with option terminator:
test_info_sources "--" 1 1

# List both files with regexp matching anywhere in the filenames:
test_info_sources "info_sources" 1 1
if { ! [is_remote host] } {
    test_info_sources "gdb.base" 1 1
}

# List both files with regexp matching the filename basenames,
# using various parts of the -basename option:
test_info_sources "-b info_sources" 1 1
test_info_sources "-basename info_sources" 1 1
test_info_sources "-b -- info_sources" 1 1
test_info_sources "-ba info_sources" 1 1
test_info_sources "-base -- info_sources" 1 1
test_info_sources "-basena info_sources" 1 1
test_info_sources "-basename -- info_sources" 1 1

# List only the file with basename matching regexp:
test_info_sources "-b base" 0 1

# List the files with dirname matching regexp,
# using various part of the -dirname option:
if { ! [is_remote host] } {
    test_info_sources "-d base" 1 1
    test_info_sources "-dirname base" 1 1
}

# Test non matching regexp against the basename, with option
# terminator:
test_info_sources "-b -- -d" 0 0

# The following tests relies on using a regexp which will not match
# either the directory name of the source files.  Unlike the basename
# test above we need to be more careful picking the regexp as the
# source filename might contain any simple character patterns, and so
# could unexpectedly match the regexp.
#
# Loop through all the characters a-z trying regexp '-C' (where 'C' is
# each character), looking for a regexp which doesn't match the
# directory name.
set re ""
for {set i [scan a %c]} {$i <= [scan z %c]} {incr i} {
    set tmp_re -[format %c $i]

    if {$re eq "" && ![regexp $tmp_re $srcdir/$subdir/]} {
	set re $tmp_re
    }
}

# If we found a suitable regexp then test non matching regexp against
# the directory name, with option terminator:
if { $re ne "" } {
    test_info_sources "-d -- $re" 0 0 \
	"info sources -d -- <non matching regexp>"
} else {
    unresolved \
	"info sources -d -- <non matching regexp> (failed to find regexp)"
}