1 # Copyright 2021-2023 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 the -file-list-exec-source-files command.
18 load_lib mi-support.exp
21 standard_testfile .c -base.c
23 if {[build_executable $testfile.exp $testfile \
24 [list $srcfile $srcfile2] debug]} {
25 untested $testfile.exp
29 mi_clean_restart $binfile
31 set readnow_p [mi_readnow]
35 # Unload symbols for shared libraries to prevent
36 # 'ERROR: internal buffer is full'.
37 mi_gdb_test "nosharedlibrary" ".*\\^done" "nosharedlibrary"
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.
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 } {
55 if { [string length $pattern] > 0 } {
56 if { [string range $pattern end-1 end] != ".*" \
57 && [string range $a 0 1] != ".*" } {
58 set pattern "${pattern},"
61 set pattern "${pattern}${a}"
63 set str "$str\\\[${pattern}\\\]"
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.
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 } {
83 if { [string length $pattern] > 0 } {
84 if { [string range $pattern end-1 end] != ".*" \
85 && [string range $a 0 1] != ".*" } {
86 set pattern "${pattern},"
89 set pattern "${pattern}${a}"
91 set str "$str\\{${pattern}\\}"
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 } {
105 set str "$str\"${pattern}\""
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 } {
114 with_test_prefix "debug_read=${debug_fully_read}" {
116 if { $debug_fully_read } {
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}"]] \
129 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
130 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
131 [mi_field "debug-fully-read" "true"]] \
138 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
139 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
140 [mi_field "debug-fully-read" "true"]] \
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}"]] \
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"
157 set p [mi_list "files" \
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"
165 # Figure out the value for the 'debug-info' field.
166 if {${debug_fully_read} == "true"} {
167 set debug_info "fully-read"
169 set debug_info "partially-read"
172 set p [mi_list "files" \
174 [mi_field "filename" "\[^\"\]+/mi-info-sources(\.debug)?"] \
175 [mi_field "debug-info" "${debug_info}"] \
179 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
180 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
181 [mi_field "debug-fully-read" "true"]] \
183 mi_gdb_test "-file-list-exec-source-files --group-by-objfile" \
185 "-file-list-exec-source-files --group-by-objfile, look for mi-info-sources.c"
187 set p [mi_list "files" \
189 [mi_field "filename" "\[^\"\]+/mi-info-sources(\.debug)?"] \
190 [mi_field "debug-info" "${debug_info}"] \
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}"]] \
198 mi_gdb_test "-file-list-exec-source-files --group-by-objfile" \
200 "-file-list-exec-source-files --group-by-objfile, look for mi-info-sources-base.c"
204 if { ! $readnow_p } {
205 check_info_sources "false"
208 mi_continue_to "some_other_func"
210 # Force "fully-read".
211 mi_gdb_test "maint expand-symtabs"
213 check_info_sources "true"