daily update
[external/binutils.git] / gdb / testsuite / gdb.mi / mi-disassemble.exp
1 # Copyright 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
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.
13 #
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/>.
16
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
24 load_lib mi-support.exp
25 set MIFLAGS "-i=mi"
26
27 gdb_exit
28 if [mi_gdb_start] {
29     continue
30 }
31
32 set testfile "basics"
33 set srcfile ${testfile}.c
34 set binfile ${objdir}/${subdir}/mi-disassemble
35 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
36      untested mi-disassemble.exp
37      return -1
38 }
39
40 proc test_disassembly_only {} {
41     global mi_gdb_prompt
42     global hex
43     global decimal
44
45     set line_main_head [gdb_get_line_number "main ("]
46     set line_main_body [expr $line_main_head + 2]
47
48     # Test disassembly more only for the current function.
49     # Tests:
50     # -data-disassemble -s $pc -e "$pc+8" -- 0
51     # -data-disassembly -f basics.c -l $line_main_body -- 0
52
53     mi_gdb_test "print/x \$pc" "" ""
54     mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
55             "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
56              "data-disassemble from pc to pc+12 assembly only"
57
58     mi_gdb_test "222-data-disassemble  -f basics.c -l $line_main_body -- 0" \
59             "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
60               "data-disassemble file & line, assembly only"
61 }
62
63 proc test_disassembly_with_opcodes {} {
64     global mi_gdb_prompt
65     global hex
66     global decimal
67
68     set line_main_head [gdb_get_line_number "main ("]
69     set line_main_body [expr $line_main_head + 2]
70
71     # Test disassembly with opcodes for the current function.
72     # Tests:
73     # -data-disassemble -s $pc -e "$pc+8" -- 2
74     # -data-disassembly -f basics.c -l $line_main_body -- 2
75
76     mi_gdb_test "print/x \$pc" "" ""
77     mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 2" \
78            "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}.*\]" \
79              "data-disassemble from pc to pc+12 assembly with opcodes"
80
81     mi_gdb_test "222-data-disassemble  -f basics.c -l $line_main_body -- 2" \
82            "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",opcodes=\".*\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]" \
83               "data-disassemble file & line, assembly with opcodes"
84 }
85
86 proc test_disassembly_lines_limit {} {
87     global mi_gdb_prompt
88     global hex
89     global decimal
90
91     set line_main_head [gdb_get_line_number "main ("]
92     set line_main_body [expr $line_main_head + 2]
93
94     # Test disassembly more only for the current function.
95     # Tests:
96     # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 0
97     # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 0
98     # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 0
99
100     mi_gdb_test "print/x \$pc" "" ""
101     mi_gdb_test "222-data-disassemble  -f basics.c -l $line_main_body -n 20 -- 0" \
102             "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
103               "data-disassemble file, line, number assembly only"
104
105     mi_gdb_test "222-data-disassemble  -f basics.c -l $line_main_body -n 0 -- 0" \
106             "222\\^done,asm_insns=\\\[\\\]" \
107               "data-disassemble file, line, number (zero lines) assembly only"
108
109     mi_gdb_test "222-data-disassemble  -f basics.c -l $line_main_body -n 50 -- 0" \
110             "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
111               "data-disassemble file, line, number (more than main lines) assembly only"
112 }
113
114
115 proc test_disassembly_mixed {} {
116     global mi_gdb_prompt
117     global hex
118     global decimal
119
120     set line_callee2_head       [gdb_get_line_number "callee2 ("]
121     set line_callee2_open_brace [expr $line_callee2_head + 1]
122
123     # Test disassembly more only for the current function.
124     # Tests:
125     # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 1
126     # -data-disassembly -s $pc -e "$pc+8" -- 1
127
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\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"callee2\",offset=\"0\",inst=\".*\"\}.*\\\]\}.*,src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\\\[.*\{address=\"$hex\",func-name=\"callee2\",offset=\"$decimal\",inst=\".*\"\}\\\]\}\\\]" \
130              "data-disassemble file, line assembly mixed"
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
135     # which we are now, even if we have specified that the range is only 2 insns.
136     #
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\",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"
140 }
141
142 proc test_disassembly_mixed_with_opcodes {} {
143     global mi_gdb_prompt
144     global hex
145     global decimal
146
147     set line_callee2_head       [gdb_get_line_number "callee2 ("]
148     set line_callee2_open_brace [expr $line_callee2_head + 1]
149
150     # Test disassembly mixed with opcodes for the current function.
151     # Tests:
152     # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 3
153     # -data-disassembly -s $pc -e "$pc+8" -- 3
154
155     mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 3" \
156            "002\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$line_callee2_open_brace\",file=\".*basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"callee2\",offset=\"0\",opcodes=\".*\",inst=\".*\"\}.*\\\]\}.*,src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\\\[.*\{address=\"$hex\",func-name=\"callee2\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]\}\\\]" \
157              "data-disassemble file, line assembly mixed with opcodes"
158
159     #
160     # In mixed mode, the lowest level of granularity is the source line.
161     # So we are going to get the disassembly for the source line at
162     # which we are now, even if we have specified that the range is only 2 insns.
163     #
164     mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 3" \
165            "003\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}.*\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]\}\\\]" \
166              "data-disassemble range assembly mixed with opcodes"
167 }
168
169 proc test_disassembly_mixed_lines_limit {} {
170     global mi_gdb_prompt
171     global hex
172     global decimal
173
174     set line_main_head       [gdb_get_line_number "main ("]
175     set line_main_open_brace [expr $line_main_head + 1]
176     set line_main_body       [expr $line_main_head + 2]
177
178     # Test disassembly more only for the current function.
179     # Tests:
180     # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 1
181     # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 1
182     # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 1
183
184     mi_gdb_test "print/x \$pc" "" ""
185     mi_gdb_test "222-data-disassemble  -f basics.c -l $line_main_body -n 20 -- 1" \
186             "222\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]\}\]" \
187               "data-disassemble file, line, number assembly mixed"
188
189     mi_gdb_test "222-data-disassemble  -f basics.c -l $line_main_body -n 0 -- 1" \
190             "222\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$line_main_open_brace\",file=\".*basics.c\",line_asm_insn=\\\[\\\]\}\\\]" \
191               "data-disassemble file, line, number (zero lines) assembly mixed"
192
193     mi_gdb_test "222-data-disassemble  -f basics.c -l $line_main_body -n 50 -- 1" \
194             "222\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\}.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]\}\]" \
195               "data-disassemble file, line, number (more than main lines) assembly mixed"
196 }
197
198 proc test_disassembly_bogus_args {} {
199     global mi_gdb_prompt
200     global hex
201
202     set line_main_head [gdb_get_line_number "main ("]
203     set line_main_body [expr $line_main_head + 2]
204
205     # Test that bogus input to disassembly command is rejected.
206     # Tests:
207     # -data-disassembly -f foo -l abc -n 0 -- 0
208     # -data-disassembly -s foo -e bar -- 0
209     # -data-disassembly -s $pc -f basics.c -- 0
210     # -data-disassembly -f basics.c -l 32 -- 9
211
212     mi_gdb_test "123-data-disassemble -f foo -l abc -n 0 -- 0" \
213              "123\\^error,msg=\"-data-disassemble: Invalid filename.\"" \
214              "data-disassemble bogus filename"
215
216     mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
217              "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
218              "data-disassemble bogus address"
219
220     mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
221              "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
222              "data-disassemble mix different args"
223
224     mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
225              "789\\^error,msg=\"-data-disassemble: Mode argument must be 0, 1, 2, or 3.\"" \
226              "data-disassemble wrong mode arg"
227
228 }
229
230 mi_run_to_main
231 test_disassembly_only
232 test_disassembly_with_opcodes
233 test_disassembly_mixed
234 test_disassembly_mixed_with_opcodes
235 test_disassembly_bogus_args
236 test_disassembly_lines_limit
237 test_disassembly_mixed_lines_limit
238
239 mi_gdb_exit
240 return 0