1 # Copyright (C) 1999, 2000 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
21 # Test Machine interface (MI) operations for disassembly.
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.
27 load_lib mi-support.exp
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."
42 mi_gdb_reinitialize_dir $srcdir/$subdir
43 mi_gdb_load ${binfile}
45 proc test_breakpoints_creation_and_listing {} {
50 # Insert some breakpoints and list them
51 # Also, disable some so they do not interfere with other tests
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"
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\"\}\}" \
67 proc test_running_the_program {} {
71 # Run the program without args
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"
80 # The running part has been checked already by mi_run_cmd
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$" {
85 -re ".*$mi_gdb_prompt$" {fail "run to main (2)"}
86 timeout {fail "run to main (timeout 2)"}
90 proc test_disassembly_only {} {
94 # Test disassembly more only for the current function.
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
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"
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"
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"
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"
120 proc test_disassembly_lines_limit {} {
124 # Test disassembly more only for the current function.
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
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"
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"
141 mi_gdb_test "300-data-disassemble main 0 0 0" \
142 "300\\^done,asm_insns=\{\}" \
143 "data-disassemble main zero lines - assembly only"
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"
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"
154 proc test_disassembly_mixed {} {
159 # Test disassembly more only for the current function.
161 # -data-disassembly main 0 1 -1
162 # -data-disassembly $pc $pc+8 1 -1
163 # -data-disassembly callee2 0 1 -1
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"
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
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"
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"
183 proc test_disassembly_mixed_lines_limit {} {
188 # Test disassembly more only for the current function.
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
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"
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"
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"
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"
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"
218 proc test_disassembly_bogus_args {} {
222 # Test that bogus input to disassembly command is rejected.
224 # -data-disassembly 0 0 0 0
225 # -data-disassembly 0 0 0
226 # -data-disassembly 0 0
227 # -data-disassembly 0
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"
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)"
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)"
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)"
247 proc test_disassembly_mixed_from_pc {} {
252 # Test disassembly more only for the current function.
254 # -data-disassembly $pc 0 1 -1
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"
260 send_gdb "123-exec-continue\n"
262 -re "123\\^running\r\n$mi_gdb_prompt" {
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"
267 -re ".*$mi_gdb_prompt$" {fail "run to callee2 (2)"}
268 timeout {fail "run to callee2 (timeout 2)"}
271 -re ".*$mi_gdb_prompt$" {fail "continue to callee2 (1)"}
272 timeout {fail "continue to callee2 (timeout 1)"}
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"
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
294 # change-log-default-name: "ChangeLog-mi"