http://sourceware.org/ml/gdb-patches/2012-10/msg00083.html
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-disassemble.exp
CommitLineData
0b302171
JB
1# Copyright 1999-2002, 2004-2005, 2007-2012 Free Software Foundation,
2# Inc.
fb40c209
AC
3
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
fb40c209 7# (at your option) any later version.
e22f8b7c 8#
fb40c209
AC
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.
e22f8b7c 13#
fb40c209 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
fb40c209 16
fb40c209
AC
17#
18# Test Machine interface (MI) operations for disassembly.
19#
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.
22#
23
24load_lib mi-support.exp
b30bf9ee 25set MIFLAGS "-i=mi"
fb40c209
AC
26
27gdb_exit
28if [mi_gdb_start] {
29 continue
30}
31
298a9cf0
TT
32standard_testfile basics.c
33
9357e021 34if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
35 untested mi-disassemble.exp
36 return -1
fb40c209
AC
37}
38
fb40c209
AC
39proc test_disassembly_only {} {
40 global mi_gdb_prompt
41 global hex
19e08fb3 42 global decimal
fb40c209 43
45f07fef
MC
44 set line_main_head [gdb_get_line_number "main ("]
45 set line_main_body [expr $line_main_head + 2]
46
fb40c209
AC
47 # Test disassembly more only for the current function.
48 # Tests:
e2d00831 49 # -data-disassemble -s $pc -e "$pc+8" -- 0
45f07fef 50 # -data-disassembly -f basics.c -l $line_main_body -- 0
fb40c209
AC
51
52 mi_gdb_test "print/x \$pc" "" ""
e2d00831 53 mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
70242e8d 54 "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
e2d00831 55 "data-disassemble from pc to pc+12 assembly only"
fb40c209 56
45f07fef 57 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 0" \
70242e8d 58 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
e2d00831 59 "data-disassemble file & line, assembly only"
fb40c209
AC
60}
61
b716877b
AB
62proc test_disassembly_with_opcodes {} {
63 global mi_gdb_prompt
64 global hex
65 global decimal
66
67 set line_main_head [gdb_get_line_number "main ("]
68 set line_main_body [expr $line_main_head + 2]
69
70 # Test disassembly with opcodes for the current function.
71 # Tests:
72 # -data-disassemble -s $pc -e "$pc+8" -- 2
73 # -data-disassembly -f basics.c -l $line_main_body -- 2
74
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"
79
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"
83}
84
fb40c209
AC
85proc test_disassembly_lines_limit {} {
86 global mi_gdb_prompt
87 global hex
19e08fb3 88 global decimal
fb40c209 89
45f07fef
MC
90 set line_main_head [gdb_get_line_number "main ("]
91 set line_main_body [expr $line_main_head + 2]
92
fb40c209
AC
93 # Test disassembly more only for the current function.
94 # Tests:
45f07fef
MC
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
fb40c209
AC
98
99 mi_gdb_test "print/x \$pc" "" ""
45f07fef 100 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 0" \
70242e8d 101 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
e2d00831 102 "data-disassemble file, line, number assembly only"
fb40c209 103
45f07fef 104 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 0" \
70242e8d 105 "222\\^done,asm_insns=\\\[\\\]" \
e2d00831 106 "data-disassemble file, line, number (zero lines) assembly only"
fb40c209 107
45f07fef 108 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 0" \
70242e8d 109 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
e2d00831 110 "data-disassemble file, line, number (more than main lines) assembly only"
fb40c209
AC
111}
112
e2d00831 113
fb40c209
AC
114proc test_disassembly_mixed {} {
115 global mi_gdb_prompt
116 global hex
117 global decimal
ed8a1c2d 118 global fullname_syntax
fb40c209 119
45f07fef
MC
120 set line_callee2_head [gdb_get_line_number "callee2 ("]
121 set line_callee2_open_brace [expr $line_callee2_head + 1]
122
fb40c209
AC
123 # Test disassembly more only for the current function.
124 # Tests:
45f07fef 125 # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 1
e2d00831 126 # -data-disassembly -s $pc -e "$pc+8" -- 1
fb40c209 127
45f07fef 128 mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 1" \
ed8a1c2d 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=\".*\"\}\\\]\}\\\]" \
e2d00831 130 "data-disassemble file, line assembly mixed"
fb40c209
AC
131
132 #
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
e2d00831 135 # which we are now, even if we have specified that the range is only 2 insns.
fb40c209 136 #
e2d00831 137 mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 1" \
ed8a1c2d 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=\".*\"\}\\\]\}\\\]" \
fb40c209 139 "data-disassemble range assembly mixed"
fb40c209
AC
140}
141
b716877b
AB
142proc test_disassembly_mixed_with_opcodes {} {
143 global mi_gdb_prompt
144 global hex
145 global decimal
ed8a1c2d 146 global fullname_syntax
b716877b
AB
147
148 set line_callee2_head [gdb_get_line_number "callee2 ("]
149 set line_callee2_open_brace [expr $line_callee2_head + 1]
150
151 # Test disassembly mixed with opcodes for the current function.
152 # Tests:
153 # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 3
154 # -data-disassembly -s $pc -e "$pc+8" -- 3
155
156 mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 3" \
ed8a1c2d 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=\".*\"\}\\\]\}\\\]" \
b716877b
AB
158 "data-disassemble file, line assembly mixed with opcodes"
159
160 #
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.
164 #
165 mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 3" \
ed8a1c2d 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=\".*\"\}\\\]\}\\\]" \
b716877b
AB
167 "data-disassemble range assembly mixed with opcodes"
168}
169
fb40c209
AC
170proc test_disassembly_mixed_lines_limit {} {
171 global mi_gdb_prompt
172 global hex
173 global decimal
ed8a1c2d 174 global fullname_syntax
fb40c209 175
45f07fef
MC
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]
179
fb40c209
AC
180 # Test disassembly more only for the current function.
181 # Tests:
45f07fef
MC
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
fb40c209
AC
185
186 mi_gdb_test "print/x \$pc" "" ""
45f07fef 187 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 1" \
ed8a1c2d 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=\".*\"\}\\\]\}\]" \
e2d00831 189 "data-disassemble file, line, number assembly mixed"
fb40c209 190
45f07fef 191 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 1" \
ed8a1c2d 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=\\\[\\\]\}\\\]" \
e2d00831 193 "data-disassemble file, line, number (zero lines) assembly mixed"
fb40c209 194
45f07fef 195 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 1" \
ed8a1c2d 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=\".*\"\}\\\]\}\]" \
e2d00831 197 "data-disassemble file, line, number (more than main lines) assembly mixed"
fb40c209
AC
198}
199
200proc test_disassembly_bogus_args {} {
201 global mi_gdb_prompt
202 global hex
203
45f07fef
MC
204 set line_main_head [gdb_get_line_number "main ("]
205 set line_main_body [expr $line_main_head + 2]
206
fb40c209
AC
207 # Test that bogus input to disassembly command is rejected.
208 # Tests:
e2d00831
EZ
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
fb40c209 213
e2d00831 214 mi_gdb_test "123-data-disassemble -f foo -l abc -n 0 -- 0" \
1b05df00 215 "123\\^error,msg=\"-data-disassemble: Invalid filename.\"" \
e2d00831 216 "data-disassemble bogus filename"
fb40c209 217
e2d00831 218 mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
a13e061a 219 "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
e2d00831 220 "data-disassemble bogus address"
fb40c209 221
e2d00831 222 mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
1b05df00 223 "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
e2d00831 224 "data-disassemble mix different args"
fb40c209 225
45f07fef 226 mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
1b05df00 227 "789\\^error,msg=\"-data-disassemble: Mode argument must be 0, 1, 2, or 3.\"" \
e2d00831 228 "data-disassemble wrong mode arg"
fb40c209
AC
229
230}
231
6afa27b0 232mi_run_to_main
fb40c209 233test_disassembly_only
b716877b 234test_disassembly_with_opcodes
fb40c209 235test_disassembly_mixed
b716877b 236test_disassembly_mixed_with_opcodes
fb40c209
AC
237test_disassembly_bogus_args
238test_disassembly_lines_limit
239test_disassembly_mixed_lines_limit
fb40c209
AC
240
241mi_gdb_exit
242return 0
This page took 1.568686 seconds and 4 git commands to generate.