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