Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-disassemble.exp
1 # Copyright 1999-2022 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 3 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, see <http://www.gnu.org/licenses/>.
15
16 #
17 # Test Machine interface (MI) operations for disassembly.
18 #
19 # The goal is not to test gdb functionality, which is done by other tests,
20 # but to verify the correct output response to MI operations.
21 #
22
23 load_lib mi-support.exp
24 set MIFLAGS "-i=mi"
25
26 standard_testfile basics.c
27
28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
29 untested "failed to compile"
30 return -1
31 }
32
33 proc test_disassembly_only {} {
34 global mi_gdb_prompt
35 global hex
36 global decimal
37
38 set line_main_head [gdb_get_line_number "main ("]
39 set line_main_body [expr $line_main_head + 2]
40
41 # Test disassembly more only for the current function.
42 # Tests:
43 # -data-disassemble -s $pc -e "$pc+8" -- 0
44 # -data-disassemble -a $pc -- 0
45 # -data-disassemble -a callee4 -- 0
46 # -data-disassembly -f basics.c -l $line_main_body -- 0
47
48
49 mi_gdb_test "print/x \$pc" "" ""
50 mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
51 "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
52 "data-disassemble from pc to pc+12 assembly only"
53
54 mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
55 "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
56 "data-disassemble function around pc assembly only"
57
58 mi_gdb_test "113-data-disassemble -a callee4 -- 0" \
59 "113\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
60 "data-disassemble function callee4 assembly only"
61
62 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 0" \
63 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
64 "data-disassemble file & line, assembly only"
65 }
66
67 proc test_disassembly_with_opcodes {} {
68 global mi_gdb_prompt
69 global hex
70 global decimal
71
72 set line_main_head [gdb_get_line_number "main ("]
73 set line_main_body [expr $line_main_head + 2]
74
75 # Test disassembly with opcodes for the current function.
76 # Tests:
77 # -data-disassemble -s $pc -e "$pc+8" -- 2
78 # -data-disassembly -f basics.c -l $line_main_body -- 2
79
80 mi_gdb_test "print/x \$pc" "" ""
81 mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 2" \
82 "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}.*\]" \
83 "data-disassemble from pc to pc+12 assembly with opcodes"
84
85 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 2" \
86 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",opcodes=\".*\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]" \
87 "data-disassemble file & line, assembly with opcodes"
88 }
89
90 proc test_disassembly_lines_limit {} {
91 global mi_gdb_prompt
92 global hex
93 global decimal
94
95 set line_main_head [gdb_get_line_number "main ("]
96 set line_main_body [expr $line_main_head + 2]
97
98 # Test disassembly more only for the current function.
99 # Tests:
100 # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 0
101 # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 0
102 # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 0
103
104 mi_gdb_test "print/x \$pc" "" ""
105 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 0" \
106 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
107 "data-disassemble file, line, number assembly only"
108
109 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 0" \
110 "222\\^done,asm_insns=\\\[\\\]" \
111 "data-disassemble file, line, number (zero lines) assembly only"
112
113 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 0" \
114 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
115 "data-disassemble file, line, number (more than main lines) assembly only"
116 }
117
118
119 proc test_disassembly_mixed {} {
120 global mi_gdb_prompt
121 global hex
122 global decimal
123 global fullname_syntax
124
125 set line_callee2_head [gdb_get_line_number "callee2 ("]
126 set line_callee2_open_brace [expr $line_callee2_head + 1]
127
128 # Test disassembly more only for the current function.
129 # Tests:
130 # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 1
131 # -data-disassembly -s $pc -e "$pc+8" -- 1
132
133 mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 1" \
134 "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=\".*\"\}\\\]\}\\\]" \
135 "data-disassemble file, line assembly mixed"
136
137 #
138 # In mixed mode, the lowest level of granularity is the source line.
139 # So we are going to get the disassembly for the source line at
140 # which we are now, even if we have specified that the range is only 2 insns.
141 #
142 mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 1" \
143 "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=\".*\"\}\\\]\}\\\]" \
144 "data-disassemble range assembly mixed"
145 }
146
147 proc test_disassembly_mixed_with_opcodes {} {
148 global mi_gdb_prompt
149 global hex
150 global decimal
151 global fullname_syntax
152
153 set line_callee2_head [gdb_get_line_number "callee2 ("]
154 set line_callee2_open_brace [expr $line_callee2_head + 1]
155
156 # Test disassembly mixed with opcodes for the current function.
157 # Tests:
158 # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 3
159 # -data-disassembly -s $pc -e "$pc+8" -- 3
160
161 mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 3" \
162 "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=\".*\"\}\\\]\}\\\]" \
163 "data-disassemble file, line assembly mixed with opcodes"
164
165 #
166 # In mixed mode, the lowest level of granularity is the source line.
167 # So we are going to get the disassembly for the source line at
168 # which we are now, even if we have specified that the range is only 2 insns.
169 #
170 mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 3" \
171 "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=\".*\"\}\\\]\}\\\]" \
172 "data-disassemble range assembly mixed with opcodes"
173 }
174
175 proc test_disassembly_mixed_lines_limit {} {
176 global mi_gdb_prompt
177 global hex
178 global decimal
179 global fullname_syntax
180
181 set line_main_head [gdb_get_line_number "main ("]
182 set line_main_open_brace [expr $line_main_head + 1]
183 set line_main_body [expr $line_main_head + 2]
184
185 # Test disassembly more only for the current function.
186 # Tests:
187 # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 1
188 # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 1
189 # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 1
190
191 mi_gdb_test "print/x \$pc" "" ""
192 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 1" \
193 "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=\".*\"\}\\\]\}\]" \
194 "data-disassemble file, line, number assembly mixed"
195
196 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 1" \
197 "222\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$line_main_open_brace\",file=\".*basics.c\",fullname=\"${fullname_syntax}basics.c\",line_asm_insn=\\\[\\\]\}\\\]" \
198 "data-disassemble file, line, number (zero lines) assembly mixed"
199
200 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 1" \
201 "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=\".*\"\}\\\]\}\]" \
202 "data-disassemble file, line, number (more than main lines) assembly mixed"
203 }
204
205 proc test_disassembly_bogus_args {} {
206 global mi_gdb_prompt
207 global hex
208
209 set line_main_head [gdb_get_line_number "main ("]
210 set line_main_body [expr $line_main_head + 2]
211
212 # Test that bogus input to disassembly command is rejected.
213 # Tests:
214 # -data-disassembly -f foo -l abc -n 0 -- 0
215 # -data-disassembly -s foo -e bar -- 0
216 # -data-disassembly -a foo -- 0
217 # -data-disassembly -s $pc -f basics.c -- 0
218 # -data-disassembly -f basics.c -l 32 -- 9
219
220 mi_gdb_test "123-data-disassemble -f foo -l abc -n 0 -- 0" \
221 "123\\^error,msg=\"-data-disassemble: Invalid filename.\"" \
222 "data-disassemble bogus filename"
223
224 mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
225 "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
226 "data-disassemble bogus address, -s -e"
227
228 mi_gdb_test "322-data-disassemble -a foo -- 0" \
229 "322\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
230 "data-disassemble bogus address, -a"
231
232 mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
233 "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
234 "data-disassemble mix different args"
235
236 mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
237 "789\\^error,msg=\"-data-disassemble: Mode argument must be in the range 0-5.\"" \
238 "data-disassemble wrong mode arg"
239
240 }
241
242 mi_clean_restart $binfile
243 mi_runto_main
244 test_disassembly_only
245 test_disassembly_with_opcodes
246 test_disassembly_mixed
247 test_disassembly_mixed_with_opcodes
248 test_disassembly_bogus_args
249 test_disassembly_lines_limit
250 test_disassembly_mixed_lines_limit
251
252 mi_gdb_exit
253 return 0
This page took 0.035694 seconds and 4 git commands to generate.