Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-disassemble.exp
CommitLineData
88b9d363 1# Copyright 1999-2022 Free Software Foundation, Inc.
fb40c209
AC
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
fb40c209 6# (at your option) any later version.
e22f8b7c 7#
fb40c209
AC
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.
e22f8b7c 12#
fb40c209 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
fb40c209 15
fb40c209
AC
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
23load_lib mi-support.exp
b30bf9ee 24set MIFLAGS "-i=mi"
fb40c209 25
298a9cf0
TT
26standard_testfile basics.c
27
9357e021 28if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
5b362f04 29 untested "failed to compile"
b60f0898 30 return -1
fb40c209
AC
31}
32
fb40c209
AC
33proc test_disassembly_only {} {
34 global mi_gdb_prompt
35 global hex
19e08fb3 36 global decimal
fb40c209 37
45f07fef
MC
38 set line_main_head [gdb_get_line_number "main ("]
39 set line_main_body [expr $line_main_head + 2]
40
fb40c209
AC
41 # Test disassembly more only for the current function.
42 # Tests:
e2d00831 43 # -data-disassemble -s $pc -e "$pc+8" -- 0
26fb3983
JV
44 # -data-disassemble -a $pc -- 0
45 # -data-disassemble -a callee4 -- 0
45f07fef 46 # -data-disassembly -f basics.c -l $line_main_body -- 0
fb40c209 47
26fb3983 48
fb40c209 49 mi_gdb_test "print/x \$pc" "" ""
e2d00831 50 mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
70242e8d 51 "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
e2d00831 52 "data-disassemble from pc to pc+12 assembly only"
fb40c209 53
26fb3983
JV
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
45f07fef 62 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 0" \
70242e8d 63 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
e2d00831 64 "data-disassemble file & line, assembly only"
fb40c209
AC
65}
66
b716877b
AB
67proc 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
fb40c209
AC
90proc test_disassembly_lines_limit {} {
91 global mi_gdb_prompt
92 global hex
19e08fb3 93 global decimal
fb40c209 94
45f07fef
MC
95 set line_main_head [gdb_get_line_number "main ("]
96 set line_main_body [expr $line_main_head + 2]
97
fb40c209
AC
98 # Test disassembly more only for the current function.
99 # Tests:
45f07fef
MC
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
fb40c209
AC
103
104 mi_gdb_test "print/x \$pc" "" ""
45f07fef 105 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 0" \
70242e8d 106 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
e2d00831 107 "data-disassemble file, line, number assembly only"
fb40c209 108
45f07fef 109 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 0" \
70242e8d 110 "222\\^done,asm_insns=\\\[\\\]" \
e2d00831 111 "data-disassemble file, line, number (zero lines) assembly only"
fb40c209 112
45f07fef 113 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 0" \
70242e8d 114 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
e2d00831 115 "data-disassemble file, line, number (more than main lines) assembly only"
fb40c209
AC
116}
117
e2d00831 118
fb40c209
AC
119proc test_disassembly_mixed {} {
120 global mi_gdb_prompt
121 global hex
122 global decimal
ed8a1c2d 123 global fullname_syntax
fb40c209 124
45f07fef
MC
125 set line_callee2_head [gdb_get_line_number "callee2 ("]
126 set line_callee2_open_brace [expr $line_callee2_head + 1]
127
fb40c209
AC
128 # Test disassembly more only for the current function.
129 # Tests:
45f07fef 130 # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 1
e2d00831 131 # -data-disassembly -s $pc -e "$pc+8" -- 1
fb40c209 132
45f07fef 133 mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 1" \
ed8a1c2d 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=\".*\"\}\\\]\}\\\]" \
e2d00831 135 "data-disassemble file, line assembly mixed"
fb40c209
AC
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
e2d00831 140 # which we are now, even if we have specified that the range is only 2 insns.
fb40c209 141 #
e2d00831 142 mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 1" \
ed8a1c2d 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=\".*\"\}\\\]\}\\\]" \
fb40c209 144 "data-disassemble range assembly mixed"
fb40c209
AC
145}
146
b716877b
AB
147proc test_disassembly_mixed_with_opcodes {} {
148 global mi_gdb_prompt
149 global hex
150 global decimal
ed8a1c2d 151 global fullname_syntax
b716877b
AB
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" \
ed8a1c2d 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=\".*\"\}\\\]\}\\\]" \
b716877b
AB
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" \
ed8a1c2d 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=\".*\"\}\\\]\}\\\]" \
b716877b
AB
172 "data-disassemble range assembly mixed with opcodes"
173}
174
fb40c209
AC
175proc test_disassembly_mixed_lines_limit {} {
176 global mi_gdb_prompt
177 global hex
178 global decimal
ed8a1c2d 179 global fullname_syntax
fb40c209 180
45f07fef
MC
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
fb40c209
AC
185 # Test disassembly more only for the current function.
186 # Tests:
45f07fef
MC
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
fb40c209
AC
190
191 mi_gdb_test "print/x \$pc" "" ""
45f07fef 192 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 1" \
ed8a1c2d 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=\".*\"\}\\\]\}\]" \
e2d00831 194 "data-disassemble file, line, number assembly mixed"
fb40c209 195
45f07fef 196 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 1" \
ed8a1c2d 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=\\\[\\\]\}\\\]" \
e2d00831 198 "data-disassemble file, line, number (zero lines) assembly mixed"
fb40c209 199
45f07fef 200 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 1" \
ed8a1c2d 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=\".*\"\}\\\]\}\]" \
e2d00831 202 "data-disassemble file, line, number (more than main lines) assembly mixed"
fb40c209
AC
203}
204
205proc test_disassembly_bogus_args {} {
206 global mi_gdb_prompt
207 global hex
208
45f07fef
MC
209 set line_main_head [gdb_get_line_number "main ("]
210 set line_main_body [expr $line_main_head + 2]
211
fb40c209
AC
212 # Test that bogus input to disassembly command is rejected.
213 # Tests:
e2d00831
EZ
214 # -data-disassembly -f foo -l abc -n 0 -- 0
215 # -data-disassembly -s foo -e bar -- 0
26fb3983 216 # -data-disassembly -a foo -- 0
e2d00831
EZ
217 # -data-disassembly -s $pc -f basics.c -- 0
218 # -data-disassembly -f basics.c -l 32 -- 9
fb40c209 219
e2d00831 220 mi_gdb_test "123-data-disassemble -f foo -l abc -n 0 -- 0" \
1b05df00 221 "123\\^error,msg=\"-data-disassemble: Invalid filename.\"" \
e2d00831 222 "data-disassemble bogus filename"
fb40c209 223
e2d00831 224 mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
a13e061a 225 "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
26fb3983
JV
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"
fb40c209 231
e2d00831 232 mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
26fb3983 233 "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
e2d00831 234 "data-disassemble mix different args"
fb40c209 235
45f07fef 236 mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
6ff0ba5f 237 "789\\^error,msg=\"-data-disassemble: Mode argument must be in the range 0-5.\"" \
e2d00831 238 "data-disassemble wrong mode arg"
fb40c209
AC
239
240}
241
b75d55d4
PA
242mi_clean_restart $binfile
243mi_runto_main
fb40c209 244test_disassembly_only
b716877b 245test_disassembly_with_opcodes
fb40c209 246test_disassembly_mixed
b716877b 247test_disassembly_mixed_with_opcodes
fb40c209
AC
248test_disassembly_bogus_args
249test_disassembly_lines_limit
250test_disassembly_mixed_lines_limit
fb40c209
AC
251
252mi_gdb_exit
253return 0
This page took 2.950762 seconds and 4 git commands to generate.