1 # Copyright 2021 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 {[prepare_for_testing $testfile.exp $testfile \
24 [list $srcfile $srcfile2] debug]} {
25 untested $testfile.exp
29 mi_clean_restart $binfile
33 # Helper to build expected MI output pattern for a list. NAME is the
34 # name of the list (which can be the empty string) and args is one
35 # or more strings representing the fields of the list, which will be
36 # joined with a comma.
38 # If any of the fields in args matches ".*" then the comma before and
39 # after are dropped from the final pattern.
40 proc mi_list { name args } {
49 if { [string length $pattern] > 0 } {
50 if { [string range $pattern end-1 end] != ".*" \
51 && [string range $a 0 1] != ".*" } {
52 set pattern "${pattern},"
55 set pattern "${pattern}${a}"
57 set str "$str\\\[${pattern}\\\]"
61 # Helper to build expected MI output pattern for a tuple. NAME is the
62 # name of the tuple (which can be the empty string) and args is one
63 # or more strings representing the fields of the tuple, which will be
64 # joined with a comma.
66 # If any of the fields in args matches ".*" then the comma before and
67 # after are dropped from the final pattern.
68 proc mi_tuple { name args } {
77 if { [string length $pattern] > 0 } {
78 if { [string range $pattern end-1 end] != ".*" \
79 && [string range $a 0 1] != ".*" } {
80 set pattern "${pattern},"
83 set pattern "${pattern}${a}"
85 set str "$str\\{${pattern}\\}"
89 # Helper to build expected MI output pattern for a single field. NAME
90 # is the name of the field, and PATTERN matches the fields contents.
91 # This proc will add quotes around PATTERN.
92 proc mi_field { name pattern } {
99 set str "$str\"${pattern}\""
103 # Run tests on '-file-list-exec-source-files'. DEBUG_FULLY_READ is either the string
104 # "true" or "false" and indicates if the GDB will have read all the
105 # debug for the test program or not yet.
106 proc check_info_sources { debug_fully_read } {
108 with_test_prefix "debug_read=${debug_fully_read}" {
110 if { $debug_fully_read } {
111 set p [mi_list "files" \
113 [mi_field "file" "\[^\"\]+/mi-info-sources-base\\.c"] \
114 [mi_field "fullname" "\[^\"\]+/mi-info-sources-base\\.c"] \
115 [mi_field "debug-fully-read" "${debug_fully_read}"]] \
117 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
118 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
119 [mi_field "debug-fully-read" "true"]]]
121 set p [mi_list "files" \
123 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
124 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
125 [mi_field "debug-fully-read" "true"]] \
127 [mi_field "file" "\[^\"\]+/mi-info-sources-base\\.c"] \
128 [mi_field "fullname" "\[^\"\]+/mi-info-sources-base\\.c"] \
129 [mi_field "debug-fully-read" "${debug_fully_read}"]]]
131 mi_gdb_test "-file-list-exec-source-files" ".*\\^done,${p}" "-file-list-exec-source-files"
133 set p [mi_list "files" \
135 [mi_field "file" "\[^\"\]+/mi-info-sources-base\\.c"] \
136 [mi_field "fullname" "\[^\"\]+/mi-info-sources-base\\.c"] \
137 [mi_field "debug-fully-read" "${debug_fully_read}"]]]
138 mi_gdb_test "-file-list-exec-source-files --basename -- base" ".*\\^done,${p}" \
139 "-file-list-exec-source-files --basename -- base"
141 # Figure out the value for the 'debug-info' field.
142 if {${debug_fully_read} == "true"} {
143 set debug_info "fully-read"
145 set debug_info "partially-read"
148 set p [mi_list "files" \
150 [mi_field "filename" "\[^\"\]+/mi-info-sources"] \
151 [mi_field "debug-info" "${debug_info}"] \
155 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
156 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
157 [mi_field "debug-fully-read" "true"]] \
159 mi_gdb_test "-file-list-exec-source-files --group-by-objfile" \
161 "-file-list-exec-source-files --group-by-objfile, look for mi-info-sources.c"
163 set p [mi_list "files" \
165 [mi_field "filename" "\[^\"\]+/mi-info-sources"] \
166 [mi_field "debug-info" "${debug_info}"] \
170 [mi_field "file" "\[^\"\]+/mi-info-sources-base\\.c"] \
171 [mi_field "fullname" "\[^\"\]+/mi-info-sources-base\\.c"] \
172 [mi_field "debug-fully-read" "${debug_fully_read}"]] \
174 mi_gdb_test "-file-list-exec-source-files --group-by-objfile" \
176 "-file-list-exec-source-files --group-by-objfile, look for mi-info-sources-base.c"
180 check_info_sources "false"
182 mi_continue_to "some_other_func"
184 check_info_sources "true"