]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.mi/mi-info-sources.exp
gdb/mi: add new --group-by-objfile flag for -file-list-exec-source-files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-info-sources.exp
CommitLineData
0e350a05
AB
1# Copyright 2021 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
18load_lib mi-support.exp
19set MIFLAGS "-i=mi"
20
21standard_testfile .c -base.c
22
23if {[prepare_for_testing $testfile.exp $testfile \
24 [list $srcfile $srcfile2] debug]} {
25 untested $testfile.exp
26 return -1
27}
28
29mi_clean_restart $binfile
30
31mi_runto_main
32
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.
37#
38# If any of the fields in args matches ".*" then the comma before and
39# after are dropped from the final pattern.
40proc mi_list { name args } {
41 set str ""
42
43 if { $name != "" } {
44 set str "${name}="
45 }
46
47 set pattern ""
48 foreach a $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},"
53 }
54 }
55 set pattern "${pattern}${a}"
56 }
57 set str "$str\\\[${pattern}\\\]"
58 return ${str}
59}
60
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.
65#
66# If any of the fields in args matches ".*" then the comma before and
67# after are dropped from the final pattern.
68proc mi_tuple { name args } {
69 set str ""
70
71 if { $name != "" } {
72 set str "${name}="
73 }
74
75 set pattern ""
76 foreach a $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},"
81 }
82 }
83 set pattern "${pattern}${a}"
84 }
85 set str "$str\\{${pattern}\\}"
86 return ${str}
87}
88
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.
92proc mi_field { name pattern } {
93 set str ""
94
95 if { $name != "" } {
96 set str "${name}="
97 }
98
99 set str "$str\"${pattern}\""
100 return ${str}
101}
102
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.
106proc check_info_sources { debug_fully_read } {
107
108 with_test_prefix "debug_read=${debug_fully_read}" {
109
110 if { $debug_fully_read } {
111 set p [mi_list "files" \
112 [mi_tuple "" \
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}"]] \
116 [mi_tuple "" \
117 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
118 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
119 [mi_field "debug-fully-read" "true"]]]
120 } else {
121 set p [mi_list "files" \
122 [mi_tuple "" \
123 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
124 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
125 [mi_field "debug-fully-read" "true"]] \
126 [mi_tuple "" \
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}"]]]
130 }
131 mi_gdb_test "-file-list-exec-source-files" ".*\\^done,${p}" "-file-list-exec-source-files"
132
133 set p [mi_list "files" \
134 [mi_tuple "" \
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"
1fb1ce02
AB
140
141 # Figure out the value for the 'debug-info' field.
142 if {${debug_fully_read} == "true"} {
143 set debug_info "fully-read"
144 } else {
145 set debug_info "partially-read"
146 }
147
148 set p [mi_list "files" \
149 [mi_tuple "" \
150 [mi_field "filename" "\[^\"\]+/mi-info-sources"] \
151 [mi_field "debug-info" "${debug_info}"] \
152 [mi_list "sources" \
153 ".*" \
154 [mi_tuple "" \
155 [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
156 [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
157 [mi_field "debug-fully-read" "true"]] \
158 ".*"]]]
159 mi_gdb_test "-file-list-exec-source-files --group-by-objfile" \
160 ".*\\^done,${p}" \
161 "-file-list-exec-source-files --group-by-objfile, look for mi-info-sources.c"
162
163 set p [mi_list "files" \
164 [mi_tuple "" \
165 [mi_field "filename" "\[^\"\]+/mi-info-sources"] \
166 [mi_field "debug-info" "${debug_info}"] \
167 [mi_list "sources" \
168 ".*" \
169 [mi_tuple "" \
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}"]] \
173 ".*"]]]
174 mi_gdb_test "-file-list-exec-source-files --group-by-objfile" \
175 ".*\\^done,${p}" \
176 "-file-list-exec-source-files --group-by-objfile, look for mi-info-sources-base.c"
0e350a05
AB
177 }
178}
179
180check_info_sources "false"
181
182mi_continue_to "some_other_func"
183
184check_info_sources "true"