]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/mi-disassemble.exp
Add mi/ and testsuite/gdb.mi/ subdirectories.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-disassemble.exp
1 # Copyright (C) 1999, 2000 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 #
21 # Test Machine interface (MI) operations for disassembly.
22 #
23 # The goal is not to test gdb functionality, which is done by other tests,
24 # but to verify the correct output response to MI operations.
25 #
26
27 load_lib mi-support.exp
28
29 gdb_exit
30 if [mi_gdb_start] {
31 continue
32 }
33
34 set testfile "basics"
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
38 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
39 }
40
41 mi_delete_breakpoints
42 mi_gdb_reinitialize_dir $srcdir/$subdir
43 mi_gdb_load ${binfile}
44
45 proc test_breakpoints_creation_and_listing {} {
46 global mi_gdb_prompt
47 global srcfile
48 global hex
49
50 # Insert some breakpoints and list them
51 # Also, disable some so they do not interfere with other tests
52 # Tests:
53 # -break-insert
54 # -break-list
55 # -break-disable
56 # -break-info
57
58 mi_gdb_test "200-break-insert main" \
59 "200\\^done,bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"main\",file=\".*basics.c\",line=\"32\",times=\"0\"\}" \
60 "break-insert operation"
61
62 mi_gdb_test "204-break-list" \
63 "204\\^done,BreakpointTable=\{hdr=\{.*\},bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"main\",file=\".*basics.c\",line=\"32\",times=\"0\"\}\}" \
64 "list of breakpoints"
65 }
66
67 proc test_running_the_program {} {
68 global mi_gdb_prompt
69 global hex
70
71 # Run the program without args
72 # Tests:
73 # -exec-run
74
75 # mi_gdb_test cannot be used for asynchronous commands because there are
76 # two prompts involved and this can lead to a race condition.
77 # FIXME: We are accepting a duplicate file and line info temporarely.
78 # The following is equivalent to a send_gdb "000-exec-run\n"
79 mi_run_cmd
80 # The running part has been checked already by mi_run_cmd
81 gdb_expect {
82 -re "\[\r\n\]*000\\*stopped,reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"main\",args=\{\},file=\".*basics.c\",line=\"32\"\}\r\n$mi_gdb_prompt$" {
83 pass "run to main"
84 }
85 -re ".*$mi_gdb_prompt$" {fail "run to main (2)"}
86 timeout {fail "run to main (timeout 2)"}
87 }
88 }
89
90 proc test_disassembly_only {} {
91 global mi_gdb_prompt
92 global hex
93
94 # Test disassembly more only for the current function.
95 # Tests:
96 # -data-disassembly $pc 0 0 -1
97 # -data-disassembly main 0 0 -1
98 # -data-disassembly $pc $pc+8 0 -1
99 # -data-disassembly callee2 0 0 -1
100
101 mi_gdb_test "print/x \$pc" "" ""
102 mi_gdb_test "111-data-disassemble \$pc 0 0 -1" \
103 "111\\^done,asm_insns=\{\{address=\"$hex <main>\",inst=\".*\"\},\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\},\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\},.*\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}\}" \
104 "data-disassemble from pc assembly only"
105
106 mi_gdb_test "222-data-disassemble main 0 0 -1" \
107 "222\\^done,asm_insns=\{\{address=\"$hex <main>\",inst=\".*\"\},\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}\}" \
108 "data-disassemble main assembly only"
109
110 mi_gdb_test "333-data-disassemble \$pc \$pc+8 0 -1" \
111 "333\\^done,asm_insns=\{\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\},\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}\}" \
112 "data-disassemble range assembly only"
113
114 mi_gdb_test "444-data-disassemble callee2 0 0 -1" \
115 "444\\^done,asm_insns=\{\{address=\"$hex <callee2\[0-9\]*>\",inst=\".*\"\},.*\{address=\"$hex <callee2\\+\[0-9\]*>\",inst=\".*\"\}\}" \
116 "data-disassemble callee2 assembly only"
117
118 }
119
120 proc test_disassembly_lines_limit {} {
121 global mi_gdb_prompt
122 global hex
123
124 # Test disassembly more only for the current function.
125 # Tests:
126 # -data-disassembly $pc 0 0 2
127 # -data-disassembly main 0 0 1
128 # -data-disassembly main 0 0 0
129 # -data-disassembly $pc $pc+8 0 99
130 # -data-disassembly $pc $pc+12 0 2
131
132 mi_gdb_test "print/x \$pc" "" ""
133 mi_gdb_test "100-data-disassemble \$pc 0 0 2" \
134 "100\\^done,asm_insns=\{\{address=\"$hex <main\[0-9\]*>\",inst=\".*\"\},\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}\}" \
135 "data-disassemble from pc two lines - assembly only"
136
137 mi_gdb_test "200-data-disassemble main 0 0 1" \
138 "200\\^done,asm_insns=\{\{address=\"$hex <main\[0-9\]*>\",inst=\".*\"\}\}" \
139 "data-disassemble main 1 line - assembly only"
140
141 mi_gdb_test "300-data-disassemble main 0 0 0" \
142 "300\\^done,asm_insns=\{\}" \
143 "data-disassemble main zero lines - assembly only"
144
145 mi_gdb_test "400-data-disassemble \$pc \$pc+8 0 99" \
146 "400\\^done,asm_insns=\{\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\},\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}\}" \
147 "data-disassemble lines bigger than range - assembly only"
148
149 mi_gdb_test "500-data-disassemble \$pc \$pc+12 0 2" \
150 "500\\^done,asm_insns=\{\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\},\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}\}" \
151 "data-disassemble lines less than range - assembly only"
152 }
153
154 proc test_disassembly_mixed {} {
155 global mi_gdb_prompt
156 global hex
157 global decimal
158
159 # Test disassembly more only for the current function.
160 # Tests:
161 # -data-disassembly main 0 1 -1
162 # -data-disassembly $pc $pc+8 1 -1
163 # -data-disassembly callee2 0 1 -1
164
165 mi_gdb_test "002-data-disassemble callee2 0 1 -1" \
166 "002\\^done,asm_insns=\{src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{\{address=\"$hex <callee2\[0-9\]*>\",inst=\".*\"\}\}\},src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{.*\{address=\"$hex <callee2\\+\[0-9\]*>\",inst=\".*\"\}\}\}\}" \
167 "data-disassemble callee2 assembly mixed"
168
169 #
170 # In mixed mode, the lowest level of granularity is the source line.
171 # So we are going to get the disassembly for the source line at
172 # which we are now.
173 #
174 mi_gdb_test "003-data-disassemble \$pc \$pc+8 1 -1" \
175 "003\\^done,asm_insns=\{src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}.*\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}\}\}\}" \
176 "data-disassemble range assembly mixed"
177
178 mi_gdb_test "004-data-disassemble callee2 0 1 -1" \
179 "004\\^done,asm_insns=\{src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{\{address=\"$hex <callee2\[0-9\]*>\",inst=\".*\"\}\}\},.*src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{.*\{address=\"$hex <callee2\\+\[0-9\]*>\",inst=\".*\"\}\}\}\}" \
180 "data-disassemble callee2 assembly mixed"
181 }
182
183 proc test_disassembly_mixed_lines_limit {} {
184 global mi_gdb_prompt
185 global hex
186 global decimal
187
188 # Test disassembly more only for the current function.
189 # Tests:
190 # -data-disassembly $pc 0 1 2
191 # -data-disassembly main 0 1 1
192 # -data-disassembly main 0 1 0
193 # -data-disassembly $pc $pc+4 1 99
194 # -data-disassembly $pc $pc+12 1 2
195
196 mi_gdb_test "print/x \$pc" "" ""
197 mi_gdb_test "100-data-disassemble \$pc 0 1 2" \
198 "100\\^done,asm_insns=\{src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{\{address=\"$hex <main\[0-9\]*>\",inst=\".*\"\}\}\},src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}\}\}\}" \
199 "data-disassemble from pc two lines - assembly mixed"
200
201 mi_gdb_test "200-data-disassemble main 0 1 1" \
202 "200\\^done,asm_insns=\{src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{\{address=\"$hex <main\[0-9\]*>\",inst=\".*\"\}\}\}\}" \
203 "data-disassemble main 1 line - assembly mixed"
204
205 mi_gdb_test "300-data-disassemble main 0 1 0" \
206 "300\\^done,asm_insns=\{src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{\}\}\}" \
207 "data-disassemble main zero lines - assembly mixed"
208
209 mi_gdb_test "400-data-disassemble \$pc \$pc+4 1 99" \
210 "400\\^done,asm_insns=\{src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}.*\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}\}\}\}" \
211 "data-disassemble lines bigger than range - assembly mixed"
212
213 mi_gdb_test "500-data-disassemble \$pc \$pc+12 1 2" \
214 "500\\^done,asm_insns=\{src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\},\{address=\"$hex <main\\+\[0-9\]*>\",inst=\".*\"\}\}\}\}" \
215 "data-disassemble lines less than range - assembly mixed"
216 }
217
218 proc test_disassembly_bogus_args {} {
219 global mi_gdb_prompt
220 global hex
221
222 # Test that bogus input to disassembly command is rejected.
223 # Tests:
224 # -data-disassembly 0 0 0 0
225 # -data-disassembly 0 0 0
226 # -data-disassembly 0 0
227 # -data-disassembly 0
228
229 mi_gdb_test "123-data-disassemble 0 0 0 0" \
230 ".*123\\^error,msg=\"No function contains specified address\"" \
231 "data-disassemble bogus arguments"
232
233 mi_gdb_test "321-data-disassemble 0 0 0" \
234 "321\\^error,msg=\"mi_cmd_disassemble: Usage: start_address end_address mixed_mode num_of_lines.\"" \
235 "data-disassemble wrong num of args (3)"
236
237 mi_gdb_test "456-data-disassemble 0 0" \
238 "456\\^error,msg=\"mi_cmd_disassemble: Usage: start_address end_address mixed_mode num_of_lines.\"" \
239 "data-disassemble wrong num of args (2)"
240
241 mi_gdb_test "789-data-disassemble 0" \
242 "789\\^error,msg=\"mi_cmd_disassemble: Usage: start_address end_address mixed_mode num_of_lines.\"" \
243 "data-disassemble wrong num of args (1)"
244
245 }
246
247 proc test_disassembly_mixed_from_pc {} {
248 global mi_gdb_prompt
249 global hex
250 global decimal
251
252 # Test disassembly more only for the current function.
253 # Tests:
254 # -data-disassembly $pc 0 1 -1
255
256 mi_gdb_test "200-break-insert callee2" \
257 "200\\^done,bkpt=\{number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee2\",file=\".*basics.c\",line=\"22\",times=\"0\"\}" \
258 "break-insert operation for mixed"
259
260 send_gdb "123-exec-continue\n"
261 gdb_expect {
262 -re "123\\^running\r\n$mi_gdb_prompt" {
263 gdb_expect {
264 -re "\[\r\n\]*123\\*stopped,reason=\"breakpoint-hit\",bkptno=\"2\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"callee2\",args=\{.*\},file=\".*basics.c\",line=\"22\"\}\r\n$mi_gdb_prompt$" {
265 pass "run to callee2"
266 }
267 -re ".*$mi_gdb_prompt$" {fail "run to callee2 (2)"}
268 timeout {fail "run to callee2 (timeout 2)"}
269 }
270 }
271 -re ".*$mi_gdb_prompt$" {fail "continue to callee2 (1)"}
272 timeout {fail "continue to callee2 (timeout 1)"}
273 }
274
275 mi_gdb_test "001-data-disassemble \$pc 0 1 -1" \
276 "001\\^done,asm_insns=\{src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{\{address=\"$hex <callee2\[0-9\]*>\",inst=\".*\"\}\}\},src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\{.*\{address=\"$hex <callee2\\+\[0-9\]*>\",inst=\".*\"\}\}\}\}" \
277 "data-disassemble from pc assembly mixed"
278
279 }
280
281 test_breakpoints_creation_and_listing
282 test_running_the_program
283 test_disassembly_only
284 test_disassembly_mixed
285 test_disassembly_bogus_args
286 test_disassembly_lines_limit
287 test_disassembly_mixed_lines_limit
288 test_disassembly_mixed_from_pc
289
290 mi_gdb_exit
291 return 0
292
293 # Local variables:
294 # change-log-default-name: "ChangeLog-mi"
295 # End: