]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/mi2-stack.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi2-stack.exp
1 # Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2007
2 # Free Software Foundation, Inc.
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
18 #
19 # Test essential Machine interface (MI) operations
20 #
21 # Verify that stack commands work.
22
23 # The goal is not to test gdb functionality, which is done by other tests,
24 # but to verify the correct output response to MI operations.
25 #
26
27 load_lib mi-support.exp
28 set MIFLAGS "-i=mi2"
29
30 gdb_exit
31 if [mi_gdb_start] {
32 continue
33 }
34
35 set testfile "basics"
36 set srcfile ${testfile}.c
37 set binfile ${objdir}/${subdir}/${testfile}
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
39 untested mi2-stack.exp
40 return -1
41 }
42
43 mi_delete_breakpoints
44 mi_gdb_reinitialize_dir $srcdir/$subdir
45 mi_gdb_reinitialize_dir $srcdir/$subdir
46 mi_gdb_load ${binfile}
47
48 proc test_stack_frame_listing {} {
49 global mi_gdb_prompt
50 global hex fullname_syntax srcfile
51
52 set line_callee4_head [gdb_get_line_number "callee4 ("]
53 set line_callee4_body [expr $line_callee4_head + 2]
54
55 # Obtain a stack trace
56 # Tests:
57 # -stack-list-frames
58 # -stack-list-frames 1 1
59 # -stack-list-frames 1 3
60 # -stack-info-frame
61
62 mi_gdb_test "231-stack-list-frames" \
63 "231\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$line_callee4_body\"\},frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\},frame=\{level=\"4\",addr=\"$hex\",func=\"main\",.*\}\\\]" \
64 "stack frame listing"
65 mi_gdb_test "232-stack-list-frames 1 1" \
66 "232\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\}\\\]" \
67 "stack frame listing 1 1"
68 mi_gdb_test "233-stack-list-frames 1 3" \
69 "233\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\}\\\]" \
70 "stack frame listing 1 3"
71
72 mi_gdb_test "234-stack-list-frames 1" \
73 "&.*234\\^error,msg=\"mi_cmd_stack_list_frames: Usage.*FRAME_LOW FRAME_HIGH.*\"" \
74 "stack frame listing wrong"
75
76 mi_gdb_test "235-stack-info-frame" \
77 "235\\^done,frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$line_callee4_body\"\}" \
78 "selected frame listing"
79 }
80
81 proc test_stack_args_listing {} {
82 global mi_gdb_prompt
83 global hex
84
85 # Obtain lists for args for the stack frames
86 # Tests:
87 # -stack-list-arguments 0
88 # -stack-list-arguments 0 1 1
89 # -stack-list-arguments 0 1 3
90 # -stack-list-arguments 1
91 # -stack-list-arguments 1 1 1
92 # -stack-list-arguments 1 1 3
93 # -stack-list-arguments
94
95 mi_gdb_test "231-stack-list-arguments 0" \
96 "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
97 "stack args listing 0"
98
99 mi_gdb_test "232-stack-list-arguments 0 1 1" \
100 "232\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\}\\\]" \
101 "stack args listing 0 1 1"
102
103 mi_gdb_test "233-stack-list-arguments 0 1 3" \
104 "233\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\}\\\]" \
105 "stack args listing 0 1 3"
106
107 mi_gdb_test "231-stack-list-arguments 1" \
108 "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
109 "stack args listing 1"
110
111 mi_gdb_test "232-stack-list-arguments 1 1 1" \
112 "232\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
113 "stack args listing 1 1 1"
114
115 mi_gdb_test "233-stack-list-arguments 1 1 3" \
116 "233\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\}\\\]" \
117 "stack args listing 1 1 3"
118
119 mi_gdb_test "234-stack-list-arguments" \
120 "&.*234\\^error,msg=\"mi_cmd_stack_list_args: Usage.*PRINT_VALUES.*FRAME_LOW FRAME_HIGH.*\"" \
121 "stack args listing wrong"
122 }
123
124 proc test_stack_info_depth {} {
125 global mi_gdb_prompt
126 global hex
127
128 # Obtain depth of stack
129 # Tests:
130 # -stack-info-depth
131 # -stack-info-depth 3
132 # -stack-info-depth 99
133
134 mi_gdb_test "231-stack-info-depth" \
135 "231\\^done,depth=\"5\"" \
136 "stack info-depth"
137
138 mi_gdb_test "231-stack-info-depth 3" \
139 "231\\^done,depth=\"3\"" \
140 "stack info-depth 3"
141
142 mi_gdb_test "231-stack-info-depth 99" \
143 "231\\^done,depth=\"5\"" \
144 "stack info-depth 99"
145
146 mi_gdb_test "231-stack-info-depth 99 99" \
147 "&.*231\\^error,msg=\"mi_cmd_stack_info_depth: Usage: .MAX_DEPTH.\"" \
148 "stack info-depth wrong usage"
149 }
150
151 proc test_stack_locals_listing {} {
152 global mi_gdb_prompt
153 global hex fullname_syntax srcfile
154
155 # Obtain lists for locals for the stack frames
156 # Tests:
157 # -stack-list-locals 0
158 # -stack-list-locals 1
159 # -stack-list-arguments
160
161 mi_gdb_test "232-stack-list-locals 0" \
162 "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\"\\\]" \
163 "stack locals listing 0"
164
165 set line_callee4_return_0 [gdb_get_line_number "return 0;"]
166
167 # step until A, B, C, have some reasonable values.
168 send_gdb "-exec-next 3\n"
169 gdb_expect {
170 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"\[01\]\",frame=\{addr=\"$hex\",func=\"callee4\",args=\\\[\\\],file=\".*basics.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$line_callee4_return_0\"\}\r\n$mi_gdb_prompt$" {
171 pass "next's in callee4"
172 }
173 timeout { fail "next in callee4 (timeout)" }
174 }
175
176 mi_gdb_test "232-stack-list-locals 1" \
177 "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\}\\\]" \
178 "stack locals listing 1"
179
180 mi_gdb_test "234-stack-list-locals" \
181 "&.*234\\^error,msg=\"mi_cmd_stack_list_locals: Usage.*PRINT_VALUES.*\"" \
182 "stack locals listing wrong"
183
184 mi_gdb_test "232-stack-select-frame 1" \
185 "232\\^done" \
186 "stack select frame 1"
187
188 mi_gdb_test "232-stack-list-locals 1" \
189 "232\\^done,locals=\\\[\\\]" \
190 "stack locals listing for new frame"
191
192 mi_gdb_test "232-stack-list-locals 1" \
193 "232\\^done,locals=\\\[\\\]" \
194 "stack locals for same frame (level 1)"
195 }
196
197 mi_runto callee4
198 test_stack_frame_listing
199 test_stack_args_listing
200 test_stack_locals_listing
201 test_stack_info_depth
202
203
204 mi_gdb_exit
205 return 0