Commit | Line | Data |
---|---|---|
8acc9f48 | 1 | # Copyright 1999-2013 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}] != "" } { |
b60f0898 JB |
34 | untested mi-disassemble.exp |
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 |
45f07fef | 49 | # -data-disassembly -f basics.c -l $line_main_body -- 0 |
fb40c209 AC |
50 | |
51 | mi_gdb_test "print/x \$pc" "" "" | |
e2d00831 | 52 | mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \ |
70242e8d | 53 | "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \ |
e2d00831 | 54 | "data-disassemble from pc to pc+12 assembly only" |
fb40c209 | 55 | |
45f07fef | 56 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 0" \ |
70242e8d | 57 | "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \ |
e2d00831 | 58 | "data-disassemble file & line, assembly only" |
fb40c209 AC |
59 | } |
60 | ||
b716877b AB |
61 | proc test_disassembly_with_opcodes {} { |
62 | global mi_gdb_prompt | |
63 | global hex | |
64 | global decimal | |
65 | ||
66 | set line_main_head [gdb_get_line_number "main ("] | |
67 | set line_main_body [expr $line_main_head + 2] | |
68 | ||
69 | # Test disassembly with opcodes for the current function. | |
70 | # Tests: | |
71 | # -data-disassemble -s $pc -e "$pc+8" -- 2 | |
72 | # -data-disassembly -f basics.c -l $line_main_body -- 2 | |
73 | ||
74 | mi_gdb_test "print/x \$pc" "" "" | |
75 | mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 2" \ | |
76 | "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}.*\]" \ | |
77 | "data-disassemble from pc to pc+12 assembly with opcodes" | |
78 | ||
79 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 2" \ | |
80 | "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",opcodes=\".*\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]" \ | |
81 | "data-disassemble file & line, assembly with opcodes" | |
82 | } | |
83 | ||
fb40c209 AC |
84 | proc test_disassembly_lines_limit {} { |
85 | global mi_gdb_prompt | |
86 | global hex | |
19e08fb3 | 87 | global decimal |
fb40c209 | 88 | |
45f07fef MC |
89 | set line_main_head [gdb_get_line_number "main ("] |
90 | set line_main_body [expr $line_main_head + 2] | |
91 | ||
fb40c209 AC |
92 | # Test disassembly more only for the current function. |
93 | # Tests: | |
45f07fef MC |
94 | # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 0 |
95 | # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 0 | |
96 | # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 0 | |
fb40c209 AC |
97 | |
98 | mi_gdb_test "print/x \$pc" "" "" | |
45f07fef | 99 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 0" \ |
70242e8d | 100 | "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \ |
e2d00831 | 101 | "data-disassemble file, line, number assembly only" |
fb40c209 | 102 | |
45f07fef | 103 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 0" \ |
70242e8d | 104 | "222\\^done,asm_insns=\\\[\\\]" \ |
e2d00831 | 105 | "data-disassemble file, line, number (zero lines) assembly only" |
fb40c209 | 106 | |
45f07fef | 107 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 0" \ |
70242e8d | 108 | "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \ |
e2d00831 | 109 | "data-disassemble file, line, number (more than main lines) assembly only" |
fb40c209 AC |
110 | } |
111 | ||
e2d00831 | 112 | |
fb40c209 AC |
113 | proc test_disassembly_mixed {} { |
114 | global mi_gdb_prompt | |
115 | global hex | |
116 | global decimal | |
ed8a1c2d | 117 | global fullname_syntax |
fb40c209 | 118 | |
45f07fef MC |
119 | set line_callee2_head [gdb_get_line_number "callee2 ("] |
120 | set line_callee2_open_brace [expr $line_callee2_head + 1] | |
121 | ||
fb40c209 AC |
122 | # Test disassembly more only for the current function. |
123 | # Tests: | |
45f07fef | 124 | # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 1 |
e2d00831 | 125 | # -data-disassembly -s $pc -e "$pc+8" -- 1 |
fb40c209 | 126 | |
45f07fef | 127 | mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 1" \ |
ed8a1c2d | 128 | "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 | 129 | "data-disassemble file, line assembly mixed" |
fb40c209 AC |
130 | |
131 | # | |
132 | # In mixed mode, the lowest level of granularity is the source line. | |
133 | # So we are going to get the disassembly for the source line at | |
e2d00831 | 134 | # which we are now, even if we have specified that the range is only 2 insns. |
fb40c209 | 135 | # |
e2d00831 | 136 | mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 1" \ |
ed8a1c2d | 137 | "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 | 138 | "data-disassemble range assembly mixed" |
fb40c209 AC |
139 | } |
140 | ||
b716877b AB |
141 | proc test_disassembly_mixed_with_opcodes {} { |
142 | global mi_gdb_prompt | |
143 | global hex | |
144 | global decimal | |
ed8a1c2d | 145 | global fullname_syntax |
b716877b AB |
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" \ | |
ed8a1c2d | 156 | "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 |
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" \ | |
ed8a1c2d | 165 | "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 |
166 | "data-disassemble range assembly mixed with opcodes" |
167 | } | |
168 | ||
fb40c209 AC |
169 | proc test_disassembly_mixed_lines_limit {} { |
170 | global mi_gdb_prompt | |
171 | global hex | |
172 | global decimal | |
ed8a1c2d | 173 | global fullname_syntax |
fb40c209 | 174 | |
45f07fef MC |
175 | set line_main_head [gdb_get_line_number "main ("] |
176 | set line_main_open_brace [expr $line_main_head + 1] | |
177 | set line_main_body [expr $line_main_head + 2] | |
178 | ||
fb40c209 AC |
179 | # Test disassembly more only for the current function. |
180 | # Tests: | |
45f07fef MC |
181 | # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 1 |
182 | # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 1 | |
183 | # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 1 | |
fb40c209 AC |
184 | |
185 | mi_gdb_test "print/x \$pc" "" "" | |
45f07fef | 186 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 1" \ |
ed8a1c2d | 187 | "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 | 188 | "data-disassemble file, line, number assembly mixed" |
fb40c209 | 189 | |
45f07fef | 190 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 1" \ |
ed8a1c2d | 191 | "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 | 192 | "data-disassemble file, line, number (zero lines) assembly mixed" |
fb40c209 | 193 | |
45f07fef | 194 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 1" \ |
ed8a1c2d | 195 | "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 | 196 | "data-disassemble file, line, number (more than main lines) assembly mixed" |
fb40c209 AC |
197 | } |
198 | ||
199 | proc test_disassembly_bogus_args {} { | |
200 | global mi_gdb_prompt | |
201 | global hex | |
202 | ||
45f07fef MC |
203 | set line_main_head [gdb_get_line_number "main ("] |
204 | set line_main_body [expr $line_main_head + 2] | |
205 | ||
fb40c209 AC |
206 | # Test that bogus input to disassembly command is rejected. |
207 | # Tests: | |
e2d00831 EZ |
208 | # -data-disassembly -f foo -l abc -n 0 -- 0 |
209 | # -data-disassembly -s foo -e bar -- 0 | |
210 | # -data-disassembly -s $pc -f basics.c -- 0 | |
211 | # -data-disassembly -f basics.c -l 32 -- 9 | |
fb40c209 | 212 | |
e2d00831 | 213 | mi_gdb_test "123-data-disassemble -f foo -l abc -n 0 -- 0" \ |
1b05df00 | 214 | "123\\^error,msg=\"-data-disassemble: Invalid filename.\"" \ |
e2d00831 | 215 | "data-disassemble bogus filename" |
fb40c209 | 216 | |
e2d00831 | 217 | mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \ |
a13e061a | 218 | "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \ |
e2d00831 | 219 | "data-disassemble bogus address" |
fb40c209 | 220 | |
e2d00831 | 221 | mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \ |
1b05df00 | 222 | "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \ |
e2d00831 | 223 | "data-disassemble mix different args" |
fb40c209 | 224 | |
45f07fef | 225 | mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \ |
1b05df00 | 226 | "789\\^error,msg=\"-data-disassemble: Mode argument must be 0, 1, 2, or 3.\"" \ |
e2d00831 | 227 | "data-disassemble wrong mode arg" |
fb40c209 AC |
228 | |
229 | } | |
230 | ||
6afa27b0 | 231 | mi_run_to_main |
fb40c209 | 232 | test_disassembly_only |
b716877b | 233 | test_disassembly_with_opcodes |
fb40c209 | 234 | test_disassembly_mixed |
b716877b | 235 | test_disassembly_mixed_with_opcodes |
fb40c209 AC |
236 | test_disassembly_bogus_args |
237 | test_disassembly_lines_limit | |
238 | test_disassembly_mixed_lines_limit | |
fb40c209 AC |
239 | |
240 | mi_gdb_exit | |
241 | return 0 |