Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-info-sources.exp
blobf639f3cdef9bc5155975e3ba022061a1c412a776
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
19 set MIFLAGS "-i=mi"
21 standard_testfile .c -base.c
23 if {[build_executable $testfile.exp $testfile \
24          [list $srcfile $srcfile2] debug]} {
25     untested $testfile.exp
26     return -1
29 mi_clean_restart $binfile
31 set readnow_p [mi_readnow]
33 mi_runto_main
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 } {
47     set str ""
49     if { $name != "" } {
50         set str "${name}="
51     }
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}
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 } {
75     set str ""
77     if { $name != "" } {
78         set str "${name}="
79     }
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}
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 ""
101     if { $name != "" } {
102         set str "${name}="
103     }
105     set str "$str\"${pattern}\""
106     return ${str}
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 } {
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         }
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" \
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"
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         }
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"
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     }
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"