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