Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-info-sources.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 the -file-list-exec-source-files command.
17
18 load_lib mi-support.exp
19 set MIFLAGS "-i=mi"
20
21 standard_testfile .c -base.c
22
23 if {[prepare_for_testing $testfile.exp $testfile \
24 [list $srcfile $srcfile2] debug]} {
25 untested $testfile.exp
26 return -1
27 }
28
29 mi_clean_restart $binfile
30
31 set readnow_p [mi_readnow]
32
33 mi_runto_main
34
35 # Unload symbols for shared libraries to prevent
36 # 'ERROR: internal buffer is full'.
37 mi_gdb_test "nosharedlibrary" ".*\\^done" "nosharedlibrary"
38
39 # Helper to build expected MI output pattern for a list. NAME is the
40 # name of the list (which can be the empty string) and args is one
41 # or more strings representing the fields of the list, which will be
42 # joined with a comma.
43 #
44 # If any of the fields in args matches ".*" then the comma before and
45 # after are dropped from the final pattern.
46 proc mi_list { name args } {
47 set str ""
48
49 if { $name != "" } {
50 set str "${name}="
51 }
52
53 set pattern ""
54 foreach a $args {
55 if { [string length $pattern] > 0 } {
56 if { [string range $pattern end-1 end] != ".*" \
57 && [string range $a 0 1] != ".*" } {
58 set pattern "${pattern},"
59 }
60 }
61 set pattern "${pattern}${a}"
62 }
63 set str "$str\\\[${pattern}\\\]"
64 return ${str}
65 }
66
67 # Helper to build expected MI output pattern for a tuple. NAME is the
68 # name of the tuple (which can be the empty string) and args is one
69 # or more strings representing the fields of the tuple, which will be
70 # joined with a comma.
71 #
72 # If any of the fields in args matches ".*" then the comma before and
73 # after are dropped from the final pattern.
74 proc mi_tuple { name args } {
75 set str ""
76
77 if { $name != "" } {
78 set str "${name}="
79 }
80
81 set pattern ""
82 foreach a $args {
83 if { [string length $pattern] > 0 } {
84 if { [string range $pattern end-1 end] != ".*" \
85 && [string range $a 0 1] != ".*" } {
86 set pattern "${pattern},"
87 }
88 }
89 set pattern "${pattern}${a}"
90 }
91 set str "$str\\{${pattern}\\}"
92 return ${str}
93 }
94
95 # Helper to build expected MI output pattern for a single field. NAME
96 # is the name of the field, and PATTERN matches the fields contents.
97 # This proc will add quotes around PATTERN.
98 proc mi_field { name pattern } {
99 set str ""
100
101 if { $name != "" } {
102 set str "${name}="
103 }
104
105 set str "$str\"${pattern}\""
106 return ${str}
107 }
108
109 # Run tests on '-file-list-exec-source-files'. DEBUG_FULLY_READ is either the string
110 # "true" or "false" and indicates if the GDB will have read all the
111 # debug for the test program or not yet.
112 proc check_info_sources { debug_fully_read } {
113
114 with_test_prefix "debug_read=${debug_fully_read}" {
115
116 if { $debug_fully_read } {
117 set p1 \
118 [mi_list "files" \
119 ".*" \
120 [mi_tuple "" \
121 [mi_field "file" "\[^\"\]+/mi-info-sources-base\\.c"] \
122 [mi_field "fullname" "\[^\"\]+/mi-info-sources-base\\.c"] \
123 [mi_field "debug-fully-read" "${debug_fully_read}"]] \
124 ".*"]
125 set p2 \
126 [mi_list "files" \
127 ".*" \
128 [mi_tuple "" \
129 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
130 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
131 [mi_field "debug-fully-read" "true"]] \
132 ".*"]
133 } else {
134 set p1 \
135 [mi_list "files" \
136 ".*" \
137 [mi_tuple "" \
138 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
139 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
140 [mi_field "debug-fully-read" "true"]] \
141 ".*"]
142 set p2 \
143 [mi_list "files" \
144 ".*" \
145 [mi_tuple "" \
146 [mi_field "file" "\[^\"\]+/mi-info-sources-base\\.c"] \
147 [mi_field "fullname" "\[^\"\]+/mi-info-sources-base\\.c"] \
148 [mi_field "debug-fully-read" "${debug_fully_read}"]] \
149 ".*"]
150 }
151
152 mi_gdb_test "-file-list-exec-source-files" ".*\\^done,${p1}" \
153 "-file-list-exec-source-files, src1"
154 mi_gdb_test "-file-list-exec-source-files" ".*\\^done,${p2}" \
155 "-file-list-exec-source-files, src2"
156
157 set p [mi_list "files" \
158 [mi_tuple "" \
159 [mi_field "file" "\[^\"\]+/mi-info-sources-base\\.c"] \
160 [mi_field "fullname" "\[^\"\]+/mi-info-sources-base\\.c"] \
161 [mi_field "debug-fully-read" "${debug_fully_read}"]]]
162 mi_gdb_test "-file-list-exec-source-files --basename -- base" ".*\\^done,${p}" \
163 "-file-list-exec-source-files --basename -- base"
164
165 # Figure out the value for the 'debug-info' field.
166 if {${debug_fully_read} == "true"} {
167 set debug_info "fully-read"
168 } else {
169 set debug_info "partially-read"
170 }
171
172 set p [mi_list "files" \
173 [mi_tuple "" \
174 [mi_field "filename" "\[^\"\]+/mi-info-sources(\.debug)?"] \
175 [mi_field "debug-info" "${debug_info}"] \
176 [mi_list "sources" \
177 ".*" \
178 [mi_tuple "" \
179 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
180 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
181 [mi_field "debug-fully-read" "true"]] \
182 ".*"]]]
183 mi_gdb_test "-file-list-exec-source-files --group-by-objfile" \
184 ".*\\^done,${p}" \
185 "-file-list-exec-source-files --group-by-objfile, look for mi-info-sources.c"
186
187 set p [mi_list "files" \
188 [mi_tuple "" \
189 [mi_field "filename" "\[^\"\]+/mi-info-sources(\.debug)?"] \
190 [mi_field "debug-info" "${debug_info}"] \
191 [mi_list "sources" \
192 ".*" \
193 [mi_tuple "" \
194 [mi_field "file" "\[^\"\]+/mi-info-sources-base\\.c"] \
195 [mi_field "fullname" "\[^\"\]+/mi-info-sources-base\\.c"] \
196 [mi_field "debug-fully-read" "${debug_fully_read}"]] \
197 ".*"]]]
198 mi_gdb_test "-file-list-exec-source-files --group-by-objfile" \
199 ".*\\^done,${p}" \
200 "-file-list-exec-source-files --group-by-objfile, look for mi-info-sources-base.c"
201 }
202 }
203
204 if { ! $readnow_p } {
205 check_info_sources "false"
206 }
207
208 mi_continue_to "some_other_func"
209
210 # Force "fully-read".
211 mi_gdb_test "maint expand-symtabs"
212
213 check_info_sources "true"
This page took 0.033915 seconds and 4 git commands to generate.