2004-08-15 Michael Chastain <mec.gnu@mindspring.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-disassemble.exp
CommitLineData
45f07fef 1# Copyright 1999, 2000, 2001, 2002, 2004 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
5# the Free Software Foundation; either version 2 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, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
fb40c209
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
24load_lib mi-support.exp
b30bf9ee 25set MIFLAGS "-i=mi"
fb40c209
AC
26
27gdb_exit
28if [mi_gdb_start] {
29 continue
30}
31
32set testfile "basics"
33set srcfile ${testfile}.c
34set binfile ${objdir}/${subdir}/${testfile}
35if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
36 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
37}
38
39mi_delete_breakpoints
40mi_gdb_reinitialize_dir $srcdir/$subdir
41mi_gdb_load ${binfile}
42
fb40c209
AC
43proc test_disassembly_only {} {
44 global mi_gdb_prompt
45 global hex
19e08fb3 46 global decimal
fb40c209 47
45f07fef
MC
48 set line_main_head [gdb_get_line_number "main ("]
49 set line_main_body [expr $line_main_head + 2]
50
fb40c209
AC
51 # Test disassembly more only for the current function.
52 # Tests:
e2d00831 53 # -data-disassemble -s $pc -e "$pc+8" -- 0
45f07fef 54 # -data-disassembly -f basics.c -l $line_main_body -- 0
fb40c209
AC
55
56 mi_gdb_test "print/x \$pc" "" ""
e2d00831 57 mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
70242e8d 58 "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
e2d00831 59 "data-disassemble from pc to pc+12 assembly only"
fb40c209 60
45f07fef 61 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 0" \
70242e8d 62 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
e2d00831 63 "data-disassemble file & line, assembly only"
fb40c209
AC
64}
65
66proc test_disassembly_lines_limit {} {
67 global mi_gdb_prompt
68 global hex
19e08fb3 69 global decimal
fb40c209 70
45f07fef
MC
71 set line_main_head [gdb_get_line_number "main ("]
72 set line_main_body [expr $line_main_head + 2]
73
fb40c209
AC
74 # Test disassembly more only for the current function.
75 # Tests:
45f07fef
MC
76 # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 0
77 # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 0
78 # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 0
fb40c209
AC
79
80 mi_gdb_test "print/x \$pc" "" ""
45f07fef 81 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 0" \
70242e8d 82 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
e2d00831 83 "data-disassemble file, line, number assembly only"
fb40c209 84
45f07fef 85 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 0" \
70242e8d 86 "222\\^done,asm_insns=\\\[\\\]" \
e2d00831 87 "data-disassemble file, line, number (zero lines) assembly only"
fb40c209 88
45f07fef 89 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 0" \
70242e8d 90 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
e2d00831 91 "data-disassemble file, line, number (more than main lines) assembly only"
fb40c209
AC
92}
93
e2d00831 94
fb40c209
AC
95proc test_disassembly_mixed {} {
96 global mi_gdb_prompt
97 global hex
98 global decimal
99
45f07fef
MC
100 set line_callee2_head [gdb_get_line_number "callee2 ("]
101 set line_callee2_open_brace [expr $line_callee2_head + 1]
102
fb40c209
AC
103 # Test disassembly more only for the current function.
104 # Tests:
45f07fef 105 # -data-disassembly -f basics.c -l $line_callee2_open_brace -- 1
e2d00831 106 # -data-disassembly -s $pc -e "$pc+8" -- 1
fb40c209 107
45f07fef
MC
108 mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 1" \
109 "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=\".*\"\}\\\]\}\\\]" \
e2d00831 110 "data-disassemble file, line assembly mixed"
fb40c209
AC
111
112 #
113 # In mixed mode, the lowest level of granularity is the source line.
114 # So we are going to get the disassembly for the source line at
e2d00831 115 # which we are now, even if we have specified that the range is only 2 insns.
fb40c209 116 #
e2d00831 117 mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 1" \
70242e8d 118 "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=\".*\"\}\\\]\}\\\]" \
fb40c209 119 "data-disassemble range assembly mixed"
fb40c209
AC
120}
121
122proc test_disassembly_mixed_lines_limit {} {
123 global mi_gdb_prompt
124 global hex
125 global decimal
126
45f07fef
MC
127 set line_main_head [gdb_get_line_number "main ("]
128 set line_main_open_brace [expr $line_main_head + 1]
129 set line_main_body [expr $line_main_head + 2]
130
fb40c209
AC
131 # Test disassembly more only for the current function.
132 # Tests:
45f07fef
MC
133 # -data-disassembly -f basics.c -l $line_main_body -n 20 -- 1
134 # -data-disassembly -f basics.c -l $line_main_body -n 0 -- 1
135 # -data-disassembly -f basics.c -l $line_main_body -n 50 -- 1
fb40c209
AC
136
137 mi_gdb_test "print/x \$pc" "" ""
45f07fef 138 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 1" \
70242e8d 139 "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=\".*\"\}\\\]\}\]" \
e2d00831 140 "data-disassemble file, line, number assembly mixed"
fb40c209 141
45f07fef
MC
142 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 1" \
143 "222\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$line_main_open_brace\",file=\".*basics.c\",line_asm_insn=\\\[\\\]\}\\\]" \
e2d00831 144 "data-disassemble file, line, number (zero lines) assembly mixed"
fb40c209 145
45f07fef 146 mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 1" \
70242e8d 147 "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=\".*\"\}\\\]\}\]" \
e2d00831 148 "data-disassemble file, line, number (more than main lines) assembly mixed"
fb40c209
AC
149}
150
151proc test_disassembly_bogus_args {} {
152 global mi_gdb_prompt
153 global hex
154
45f07fef
MC
155 set line_main_head [gdb_get_line_number "main ("]
156 set line_main_body [expr $line_main_head + 2]
157
fb40c209
AC
158 # Test that bogus input to disassembly command is rejected.
159 # Tests:
e2d00831
EZ
160 # -data-disassembly -f foo -l abc -n 0 -- 0
161 # -data-disassembly -s foo -e bar -- 0
162 # -data-disassembly -s $pc -f basics.c -- 0
163 # -data-disassembly -f basics.c -l 32 -- 9
fb40c209 164
e2d00831
EZ
165 mi_gdb_test "123-data-disassemble -f foo -l abc -n 0 -- 0" \
166 ".*123\\^error,msg=\"mi_cmd_disassemble: Invalid filename.\"" \
167 "data-disassemble bogus filename"
fb40c209 168
e2d00831
EZ
169 mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
170 "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
171 "data-disassemble bogus address"
fb40c209 172
e2d00831
EZ
173 mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
174 "456\\^error,msg=\"mi_cmd_disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. | .-s startaddr -e endaddr.\\) .--. mixed_mode.\"" \
175 "data-disassemble mix different args"
fb40c209 176
45f07fef 177 mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
e2d00831
EZ
178 "789\\^error,msg=\"mi_cmd_disassemble: Mixed_mode argument must be 0 or 1.\"" \
179 "data-disassemble wrong mode arg"
fb40c209
AC
180
181}
182
6afa27b0 183mi_run_to_main
fb40c209
AC
184test_disassembly_only
185test_disassembly_mixed
186test_disassembly_bogus_args
187test_disassembly_lines_limit
188test_disassembly_mixed_lines_limit
fb40c209
AC
189
190mi_gdb_exit
191return 0
This page took 0.746901 seconds and 4 git commands to generate.