1 # Copyright 1999-2002, 2004-2005, 2007-2012 Free Software Foundation,
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Test Machine interface (MI) operations for disassembly.
20 # The goal is not to test gdb functionality, which is done by other tests,
21 # but to verify the correct output response to MI operations.
24 load_lib mi-support.exp
32 standard_testfile basics.c
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
35 untested mi-disassemble.exp
39 proc test_disassembly_only {} {
44 set line_main_head [gdb_get_line_number "main ("]
45 set line_main_body [expr $line_main_head + 2]
47 # Test disassembly more only for the current function.
49 # -data-disassemble -s $pc -e "$pc+8" -- 0
50 # -data-disassembly -f basics.c -l $line_main_body -- 0
52 mi_gdb_test "print/x \$pc" "" ""
53 mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
54 "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
55 "data-disassemble from pc to pc+12 assembly only"
57 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 0" \
58 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
59 "data-disassemble file & line, assembly only"
62 proc test_disassembly_with_opcodes {} {
67 set line_main_head [gdb_get_line_number "main ("]
68 set line_main_body [expr $line_main_head + 2]
70 # Test disassembly with opcodes for the current function.
72 # -data-disassemble -s $pc -e "$pc+8" -- 2
73 # -data-disassembly -f basics.c -l $line_main_body -- 2
75 mi_gdb_test "print/x \$pc" "" ""
76 mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 2" \
77 "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}.*\]" \
78 "data-disassemble from pc to pc+12 assembly with opcodes"
80 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 2" \
81 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",opcodes=\".*\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]" \
82 "data-disassemble file & line, assembly with opcodes"
85 proc test_disassembly_lines_limit {} {
90 set line_main_head [gdb_get_line_number "main ("]
91 set line_main_body [expr $line_main_head + 2]
93 # Test disassembly more only for the current function.
95 # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 0
96 # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 0
97 # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 0
99 mi_gdb_test "print/x \$pc" "" ""
100 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 0" \
101 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
102 "data-disassemble file, line, number assembly only"
104 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 0" \
105 "222\\^done,asm_insns=\\\[\\\]" \
106 "data-disassemble file, line, number (zero lines) assembly only"
108 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 0" \
109 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
110 "data-disassemble file, line, number (more than main lines) assembly only"
114 proc test_disassembly_mixed {} {
118 global fullname_syntax
120 set line_callee2_head [gdb_get_line_number "callee2 ("]
121 set line_callee2_open_brace [expr $line_callee2_head + 1]
123 # Test disassembly more only for the current function.
125 # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 1
126 # -data-disassembly -s $pc -e "$pc+8" -- 1
128 mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 1" \
129 "002\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$line_callee2_open_brace\",file=\".*basics.c\",fullname=\"${fullname_syntax}basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"callee2\",offset=\"0\",inst=\".*\"\}.*\\\]\}.*,src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",fullname=\"${fullname_syntax}basics.c\",line_asm_insn=\\\[.*\{address=\"$hex\",func-name=\"callee2\",offset=\"$decimal\",inst=\".*\"\}\\\]\}\\\]" \
130 "data-disassemble file, line assembly mixed"
133 # In mixed mode, the lowest level of granularity is the source line.
134 # So we are going to get the disassembly for the source line at
135 # which we are now, even if we have specified that the range is only 2 insns.
137 mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 1" \
138 "003\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",fullname=\"${fullname_syntax}basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]\}\\\]" \
139 "data-disassemble range assembly mixed"
142 proc test_disassembly_mixed_with_opcodes {} {
146 global fullname_syntax
148 set line_callee2_head [gdb_get_line_number "callee2 ("]
149 set line_callee2_open_brace [expr $line_callee2_head + 1]
151 # Test disassembly mixed with opcodes for the current function.
153 # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 3
154 # -data-disassembly -s $pc -e "$pc+8" -- 3
156 mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 3" \
157 "002\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$line_callee2_open_brace\",file=\".*basics.c\",fullname=\"${fullname_syntax}basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"callee2\",offset=\"0\",opcodes=\".*\",inst=\".*\"\}.*\\\]\}.*,src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",fullname=\"${fullname_syntax}basics.c\",line_asm_insn=\\\[.*\{address=\"$hex\",func-name=\"callee2\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]\}\\\]" \
158 "data-disassemble file, line assembly mixed with opcodes"
161 # In mixed mode, the lowest level of granularity is the source line.
162 # So we are going to get the disassembly for the source line at
163 # which we are now, even if we have specified that the range is only 2 insns.
165 mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 3" \
166 "003\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",fullname=\"${fullname_syntax}basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}.*\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]\}\\\]" \
167 "data-disassemble range assembly mixed with opcodes"
170 proc test_disassembly_mixed_lines_limit {} {
174 global fullname_syntax
176 set line_main_head [gdb_get_line_number "main ("]
177 set line_main_open_brace [expr $line_main_head + 1]
178 set line_main_body [expr $line_main_head + 2]
180 # Test disassembly more only for the current function.
182 # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 1
183 # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 1
184 # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 1
186 mi_gdb_test "print/x \$pc" "" ""
187 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 1" \
188 "222\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",fullname=\"${fullname_syntax}basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]\}\]" \
189 "data-disassemble file, line, number assembly mixed"
191 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 1" \
192 "222\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$line_main_open_brace\",file=\".*basics.c\",fullname=\"${fullname_syntax}basics.c\",line_asm_insn=\\\[\\\]\}\\\]" \
193 "data-disassemble file, line, number (zero lines) assembly mixed"
195 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 1" \
196 "222\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",fullname=\"${fullname_syntax}basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\}.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]\}\]" \
197 "data-disassemble file, line, number (more than main lines) assembly mixed"
200 proc test_disassembly_bogus_args {} {
204 set line_main_head [gdb_get_line_number "main ("]
205 set line_main_body [expr $line_main_head + 2]
207 # Test that bogus input to disassembly command is rejected.
209 # -data-disassembly -f foo -l abc -n 0 -- 0
210 # -data-disassembly -s foo -e bar -- 0
211 # -data-disassembly -s $pc -f basics.c -- 0
212 # -data-disassembly -f basics.c -l 32 -- 9
214 mi_gdb_test "123-data-disassemble -f foo -l abc -n 0 -- 0" \
215 "123\\^error,msg=\"-data-disassemble: Invalid filename.\"" \
216 "data-disassemble bogus filename"
218 mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
219 "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
220 "data-disassemble bogus address"
222 mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
223 "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
224 "data-disassemble mix different args"
226 mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
227 "789\\^error,msg=\"-data-disassemble: Mode argument must be 0, 1, 2, or 3.\"" \
228 "data-disassemble wrong mode arg"
233 test_disassembly_only
234 test_disassembly_with_opcodes
235 test_disassembly_mixed
236 test_disassembly_mixed_with_opcodes
237 test_disassembly_bogus_args
238 test_disassembly_lines_limit
239 test_disassembly_mixed_lines_limit