Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-stack.exp
1 # Copyright 2000-2022 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
15
16 #
17 # Test essential Machine interface (MI) operations
18 #
19 # Verify that stack commands work.
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
25 load_lib mi-support.exp
26 set MIFLAGS "-i=mi"
27
28 gdb_exit
29 if [mi_gdb_start] {
30 continue
31 }
32
33 standard_testfile
34
35 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
36 untested "failed to compile"
37 return -1
38 }
39
40 mi_delete_breakpoints
41 mi_gdb_reinitialize_dir $srcdir/$subdir
42 mi_gdb_reinitialize_dir $srcdir/$subdir
43 mi_gdb_load ${binfile}
44
45 proc test_stack_frame_listing {} {
46 global mi_gdb_prompt
47 global hex fullname_syntax srcfile
48
49 set any "\[^\"\]+"
50
51 set callee4_begin [gdb_get_line_number "callee4 begin"]
52 mi_continue_to_line $callee4_begin "continue to callee4 begin"
53
54 # Obtain a stack trace
55 # Tests:
56 # -stack-list-frames
57 # -stack-list-frames 1 1
58 # -stack-list-frames 1 3
59 # -stack-info-frame
60 mi_gdb_test "231-stack-list-frames" \
61 "231\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*${srcfile}\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$callee4_begin\",arch=\"$any\"\},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\",.*\}\\\]" \
62 "stack frame listing"
63 mi_gdb_test "232-stack-list-frames 1 1" \
64 "232\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\}\\\]" \
65 "stack frame listing 1 1"
66 mi_gdb_test "233-stack-list-frames 1 3" \
67 "233\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\}\\\]" \
68 "stack frame listing 1 3"
69
70 mi_gdb_test "234-stack-list-frames 1" \
71 "234\\^error,msg=\"-stack-list-frames: Usage.*FRAME_LOW FRAME_HIGH.*\"" \
72 "stack frame listing wrong"
73
74 mi_gdb_test "235-stack-info-frame" \
75 "235\\^done,frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*${srcfile}\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$callee4_begin\",arch=\"$any\"\}" \
76 "selected frame listing"
77
78 mi_gdb_test "236-stack-list-frames 1 300" \
79 "236\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\}\\\]" \
80 "stack frame listing 1 300"
81 }
82
83 proc test_stack_args_listing {} {
84 global mi_gdb_prompt
85 global hex
86
87 # Obtain lists for args for the stack frames
88 # Tests:
89 # -stack-list-arguments 0
90 # -stack-list-arguments 0 1 1
91 # -stack-list-arguments 0 1 3
92 # -stack-list-arguments 1
93 # -stack-list-arguments 1 1 1
94 # -stack-list-arguments 1 1 3
95 # -stack-list-arguments
96
97 mi_gdb_test "231-stack-list-arguments 0" \
98 "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=\\\[\\\]\}\\\]" \
99 "stack args listing 0"
100
101 mi_gdb_test "232-stack-list-arguments 0 1 1" \
102 "232\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\}\\\]" \
103 "stack args listing 0 1 1"
104
105 mi_gdb_test "233-stack-list-arguments 0 1 3" \
106 "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\"\\\]\}\\\]" \
107 "stack args listing 0 1 3"
108
109 mi_gdb_test "231-stack-list-arguments 1" \
110 "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=\\\[\\\]\}\\\]" \
111 "stack args listing 1"
112
113 mi_gdb_test "232-stack-list-arguments 1 1 1" \
114 "232\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
115 "stack args listing 1 1 1"
116
117 mi_gdb_test "233-stack-list-arguments --all-values 1 3" \
118 "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\"\}\\\]\}\\\]" \
119 "stack args listing 1 1 3"
120
121 mi_gdb_test "234-stack-list-arguments" \
122 "234\\^error,msg=\"-stack-list-arguments: Usage.*PRINT_VALUES.*FRAME_LOW FRAME_HIGH.*\"" \
123 "stack args listing wrong"
124
125 mi_gdb_test "235-stack-list-arguments 1 1 300" \
126 "235\\^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\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
127 "stack args listing 1 1 300"
128 }
129
130 proc test_stack_info_depth {} {
131 global mi_gdb_prompt
132 global hex
133
134 # Obtain depth of stack
135 # Tests:
136 # -stack-info-depth
137 # -stack-info-depth 3
138 # -stack-info-depth 99
139
140 mi_gdb_test "231-stack-info-depth" \
141 "231\\^done,depth=\"5\"" \
142 "stack info-depth"
143
144 mi_gdb_test "231-stack-info-depth 3" \
145 "231\\^done,depth=\"3\"" \
146 "stack info-depth 3"
147
148 mi_gdb_test "231-stack-info-depth 99" \
149 "231\\^done,depth=\"5\"" \
150 "stack info-depth 99"
151
152 mi_gdb_test "231-stack-info-depth 99 99" \
153 "231\\^error,msg=\"-stack-info-depth: Usage: .MAX_DEPTH.\"" \
154 "stack info-depth wrong usage"
155 }
156
157 proc test_stack_locals_listing {} {
158 global mi_gdb_prompt
159 global hex fullname_syntax srcfile
160
161 # Obtain lists for locals for the stack frames
162 # Tests:
163 # -stack-list-locals 0 (--no-values)
164 # -stack-list-locals 1 (--all-values)
165 # -stack-list-locals 2 (--simple-values)
166 # -stack-list-arguments
167
168 mi_gdb_test "232-stack-list-locals 0" \
169 "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
170 "stack locals listing of names"
171
172 set line_callee4_return_0 [gdb_get_line_number "return 0;"]
173
174 # step until A, B, C, D have some reasonable values.
175 mi_execute_to "exec-next 4" "end-stepping-range" "callee4" "" ".*${srcfile}" $line_callee4_return_0 ""\
176 "next's in callee4"
177
178 mi_gdb_test "232-stack-list-locals 1" \
179 "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
180 "stack locals listing of names and values"
181
182 mi_gdb_test "232-stack-list-locals --simple-values" \
183 "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
184 "stack locals listing, simple types: names and values, complex type: names and types"
185
186 mi_gdb_test "234-stack-list-locals" \
187 "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
188 "stack locals listing wrong"
189
190 mi_gdb_test "232-stack-select-frame 1" \
191 "232\\^done" \
192 "stack select frame 1"
193
194 mi_gdb_test "232-stack-list-locals 1" \
195 "232\\^done,locals=\\\[\\\]" \
196 "stack locals listing for new frame"
197
198 mi_gdb_test "232-stack-list-locals 1" \
199 "232\\^done,locals=\\\[\\\]" \
200 "stack locals for same frame (level 1)"
201 }
202
203 mi_runto callee4
204 test_stack_frame_listing
205 test_stack_args_listing
206 test_stack_locals_listing
207 test_stack_info_depth
208
209
210 mi_gdb_exit
211 return 0
This page took 0.033036 seconds and 4 git commands to generate.