Commit | Line | Data |
---|---|---|
9b254dd1 | 1 | # Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008 |
39fb8e9e | 2 | # Free Software Foundation, Inc. |
2fcf52f0 AC |
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 | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
2fcf52f0 | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
2fcf52f0 AC |
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. | |
e22f8b7c | 13 | # |
2fcf52f0 | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
2fcf52f0 | 16 | |
2fcf52f0 AC |
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=mi2" | |
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}/${testfile} | |
35 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } { | |
b60f0898 JB |
36 | untested mi2-disassemble.exp |
37 | return -1 | |
2fcf52f0 AC |
38 | } |
39 | ||
2fcf52f0 AC |
40 | proc test_disassembly_only {} { |
41 | global mi_gdb_prompt | |
42 | global hex | |
43 | global decimal | |
44 | ||
45f07fef MC |
45 | set line_main_head [gdb_get_line_number "main ("] |
46 | set line_main_body [expr $line_main_head + 2] | |
47 | ||
2fcf52f0 AC |
48 | # Test disassembly more only for the current function. |
49 | # Tests: | |
50 | # -data-disassemble -s $pc -e "$pc+8" -- 0 | |
45f07fef | 51 | # -data-disassembly -f basics.c -l $line_main_body -- 0 |
2fcf52f0 AC |
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 | ||
45f07fef | 58 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 0" \ |
2fcf52f0 AC |
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_lines_limit {} { | |
64 | global mi_gdb_prompt | |
65 | global hex | |
66 | global decimal | |
67 | ||
45f07fef MC |
68 | set line_main_head [gdb_get_line_number "main ("] |
69 | set line_main_body [expr $line_main_head + 2] | |
70 | ||
2fcf52f0 AC |
71 | # Test disassembly more only for the current function. |
72 | # Tests: | |
45f07fef MC |
73 | # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 0 |
74 | # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 0 | |
75 | # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 0 | |
2fcf52f0 AC |
76 | |
77 | mi_gdb_test "print/x \$pc" "" "" | |
45f07fef | 78 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 0" \ |
2fcf52f0 AC |
79 | "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \ |
80 | "data-disassemble file, line, number assembly only" | |
81 | ||
45f07fef | 82 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 0" \ |
2fcf52f0 AC |
83 | "222\\^done,asm_insns=\\\[\\\]" \ |
84 | "data-disassemble file, line, number (zero lines) assembly only" | |
85 | ||
45f07fef | 86 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 0" \ |
2fcf52f0 AC |
87 | "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \ |
88 | "data-disassemble file, line, number (more than main lines) assembly only" | |
89 | } | |
90 | ||
91 | ||
92 | proc test_disassembly_mixed {} { | |
93 | global mi_gdb_prompt | |
94 | global hex | |
95 | global decimal | |
96 | ||
45f07fef MC |
97 | set line_callee2_head [gdb_get_line_number "callee2 ("] |
98 | set line_callee2_open_brace [expr $line_callee2_head + 1] | |
99 | ||
2fcf52f0 AC |
100 | # Test disassembly more only for the current function. |
101 | # Tests: | |
45f07fef | 102 | # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 1 |
2fcf52f0 AC |
103 | # -data-disassembly -s $pc -e "$pc+8" -- 1 |
104 | ||
45f07fef MC |
105 | mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 1" \ |
106 | "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=\".*\"\}\\\]\}\\\]" \ | |
2fcf52f0 AC |
107 | "data-disassemble file, line assembly mixed" |
108 | ||
109 | # | |
110 | # In mixed mode, the lowest level of granularity is the source line. | |
111 | # So we are going to get the disassembly for the source line at | |
112 | # which we are now, even if we have specified that the range is only 2 insns. | |
113 | # | |
114 | mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 1" \ | |
115 | "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=\".*\"\}\\\]\}\\\]" \ | |
116 | "data-disassemble range assembly mixed" | |
117 | } | |
118 | ||
119 | proc test_disassembly_mixed_lines_limit {} { | |
120 | global mi_gdb_prompt | |
121 | global hex | |
122 | global decimal | |
123 | ||
45f07fef MC |
124 | set line_main_head [gdb_get_line_number "main ("] |
125 | set line_main_open_brace [expr $line_main_head + 1] | |
126 | set line_main_body [expr $line_main_head + 2] | |
127 | ||
2fcf52f0 AC |
128 | # Test disassembly more only for the current function. |
129 | # Tests: | |
45f07fef MC |
130 | # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 1 |
131 | # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 1 | |
132 | # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 1 | |
2fcf52f0 AC |
133 | |
134 | mi_gdb_test "print/x \$pc" "" "" | |
45f07fef | 135 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 1" \ |
2fcf52f0 AC |
136 | "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=\".*\"\}\\\]\}\]" \ |
137 | "data-disassemble file, line, number assembly mixed" | |
138 | ||
45f07fef MC |
139 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 1" \ |
140 | "222\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$line_main_open_brace\",file=\".*basics.c\",line_asm_insn=\\\[\\\]\}\\\]" \ | |
2fcf52f0 AC |
141 | "data-disassemble file, line, number (zero lines) assembly mixed" |
142 | ||
45f07fef | 143 | mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 1" \ |
2fcf52f0 AC |
144 | "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=\".*\"\}\\\]\}\]" \ |
145 | "data-disassemble file, line, number (more than main lines) assembly mixed" | |
146 | } | |
147 | ||
148 | proc test_disassembly_bogus_args {} { | |
149 | global mi_gdb_prompt | |
150 | global hex | |
151 | ||
45f07fef MC |
152 | set line_main_head [gdb_get_line_number "main ("] |
153 | set line_main_body [expr $line_main_head + 2] | |
154 | ||
2fcf52f0 AC |
155 | # Test that bogus input to disassembly command is rejected. |
156 | # Tests: | |
157 | # -data-disassembly -f foo -l abc -n 0 -- 0 | |
158 | # -data-disassembly -s foo -e bar -- 0 | |
159 | # -data-disassembly -s $pc -f basics.c -- 0 | |
160 | # -data-disassembly -f basics.c -l 32 -- 9 | |
161 | ||
162 | mi_gdb_test "123-data-disassemble -f foo -l abc -n 0 -- 0" \ | |
39fb8e9e | 163 | "&.*123\\^error,msg=\"mi_cmd_disassemble: Invalid filename.\"" \ |
2fcf52f0 AC |
164 | "data-disassemble bogus filename" |
165 | ||
166 | mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \ | |
39fb8e9e | 167 | "&.*321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \ |
2fcf52f0 AC |
168 | "data-disassemble bogus address" |
169 | ||
170 | mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \ | |
39fb8e9e | 171 | "&.*456\\^error,msg=\"mi_cmd_disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mixed_mode.\"" \ |
2fcf52f0 AC |
172 | "data-disassemble mix different args" |
173 | ||
45f07fef | 174 | mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \ |
39fb8e9e | 175 | "&.*789\\^error,msg=\"mi_cmd_disassemble: Mixed_mode argument must be 0 or 1.\"" \ |
2fcf52f0 AC |
176 | "data-disassemble wrong mode arg" |
177 | ||
178 | } | |
179 | ||
180 | mi_run_to_main | |
181 | test_disassembly_only | |
182 | test_disassembly_mixed | |
183 | test_disassembly_bogus_args | |
184 | test_disassembly_lines_limit | |
185 | test_disassembly_mixed_lines_limit | |
186 | ||
187 | mi_gdb_exit | |
188 | return 0 |