1 # Copyright
1999, 2000, 2001, 2002, 2003, 2004, 2005
2 # Free Software Foundation
, Inc.
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.
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.
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.
19 # Test Machine interface
(MI
) operations
for disassembly.
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.
25 load_lib mi
-support.exp
34 set srcfile $
{testfile
}.c
35 set binfile $
{objdir
}/$
{subdir
}/$
{testfile
}
36 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
37 gdb_suppress_entire_file
"Testcase compile failed, so all tests in this file will automatically fail."
41 mi_gdb_reinitialize_dir $srcdir
/$subdir
42 mi_gdb_load $
{binfile
}
44 proc test_disassembly_only
{} {
49 set line_main_head
[gdb_get_line_number
"main ("]
50 set line_main_body
[expr $line_main_head
+ 2]
52 # Test disassembly more only
for the current function.
54 #
-data
-disassemble
-s $pc
-e
"$pc+8" -- 0
55 #
-data
-disassembly
-f basics.c
-l $line_main_body
-- 0
57 mi_gdb_test
"print/x \$pc" "" ""
58 mi_gdb_test
"111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
59 "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
60 "data-disassemble from pc to pc+12 assembly only"
62 mi_gdb_test
"222-data-disassemble -f basics.c -l $line_main_body -- 0" \
63 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
64 "data-disassemble file & line, assembly only"
67 proc test_disassembly_lines_limit
{} {
72 set line_main_head
[gdb_get_line_number
"main ("]
73 set line_main_body
[expr $line_main_head
+ 2]
75 # Test disassembly more only
for the current function.
77 #
-data
-disassembly
-f basics.c
-l $line_main_body
-n
20 -- 0
78 #
-data
-disassembly
-f basics.c
-l $line_main_body
-n
0 -- 0
79 #
-data
-disassembly
-f basics.c
-l $line_main_body
-n
50 -- 0
81 mi_gdb_test
"print/x \$pc" "" ""
82 mi_gdb_test
"222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 0" \
83 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
84 "data-disassemble file, line, number assembly only"
86 mi_gdb_test
"222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 0" \
87 "222\\^done,asm_insns=\\\[\\\]" \
88 "data-disassemble file, line, number (zero lines) assembly only"
90 mi_gdb_test
"222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 0" \
91 "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
92 "data-disassemble file, line, number (more than main lines) assembly only"
96 proc test_disassembly_mixed
{} {
101 set line_callee2_head
[gdb_get_line_number
"callee2 ("]
102 set line_callee2_open_brace
[expr $line_callee2_head
+ 1]
104 # Test disassembly more only
for the current function.
106 #
-data
-disassembly
-f basics.c
-l $line_callee2_open_brace
-- 1
107 #
-data
-disassembly
-s $pc
-e
"$pc+8" -- 1
109 mi_gdb_test
"002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 1" \
110 "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=\".*\"\}\\\]\}\\\]" \
111 "data-disassemble file, line assembly mixed"
114 # In mixed
mode, the lowest level of granularity is the source line.
115 # So we are going to
get the disassembly
for the source line at
116 # which we are now
, even
if we have specified that the range is only
2 insns.
118 mi_gdb_test
"003-data-disassemble -s \$pc -e \"\$pc+4\" -- 1" \
119 "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=\".*\"\}\\\]\}\\\]" \
120 "data-disassemble range assembly mixed"
123 proc test_disassembly_mixed_lines_limit
{} {
128 set line_main_head
[gdb_get_line_number
"main ("]
129 set line_main_open_brace
[expr $line_main_head
+ 1]
130 set line_main_body
[expr $line_main_head
+ 2]
132 # Test disassembly more only
for the current function.
134 #
-data
-disassembly
-f basics.c
-l $line_main_body
-n
20 -- 1
135 #
-data
-disassembly
-f basics.c
-l $line_main_body
-n
0 -- 1
136 #
-data
-disassembly
-f basics.c
-l $line_main_body
-n
50 -- 1
138 mi_gdb_test
"print/x \$pc" "" ""
139 mi_gdb_test
"222-data-disassemble -f basics.c -l $line_main_body -n 20 -- 1" \
140 "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=\".*\"\}\\\]\}\]" \
141 "data-disassemble file, line, number assembly mixed"
143 mi_gdb_test
"222-data-disassemble -f basics.c -l $line_main_body -n 0 -- 1" \
144 "222\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$line_main_open_brace\",file=\".*basics.c\",line_asm_insn=\\\[\\\]\}\\\]" \
145 "data-disassemble file, line, number (zero lines) assembly mixed"
147 mi_gdb_test
"222-data-disassemble -f basics.c -l $line_main_body -n 50 -- 1" \
148 "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=\".*\"\}\\\]\}\]" \
149 "data-disassemble file, line, number (more than main lines) assembly mixed"
152 proc test_disassembly_bogus_args
{} {
156 set line_main_head
[gdb_get_line_number
"main ("]
157 set line_main_body
[expr $line_main_head
+ 2]
159 # Test that bogus input to disassembly command is rejected.
161 #
-data
-disassembly
-f foo
-l abc
-n
0 -- 0
162 #
-data
-disassembly
-s foo
-e bar
-- 0
163 #
-data
-disassembly
-s $pc
-f basics.c
-- 0
164 #
-data
-disassembly
-f basics.c
-l
32 -- 9
166 mi_gdb_test
"123-data-disassemble -f foo -l abc -n 0 -- 0" \
167 "&.*123\\^error,msg=\"mi_cmd_disassemble: Invalid filename.\"" \
168 "data-disassemble bogus filename"
170 mi_gdb_test
"321-data-disassemble -s foo -e bar -- 0" \
171 "&.*321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
172 "data-disassemble bogus address"
174 mi_gdb_test
"456-data-disassemble -s \$pc -f basics.c -- 0" \
175 "&.*456\\^error,msg=\"mi_cmd_disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mixed_mode.\"" \
176 "data-disassemble mix different args"
178 mi_gdb_test
"789-data-disassemble -f basics.c -l $line_main_body -- 9" \
179 "&.*789\\^error,msg=\"mi_cmd_disassemble: Mixed_mode argument must be 0 or 1.\"" \
180 "data-disassemble wrong mode arg"
185 test_disassembly_only
186 test_disassembly_mixed
187 test_disassembly_bogus_args
188 test_disassembly_lines_limit
189 test_disassembly_mixed_lines_limit