Add options to skip unavailable locals
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / entry-values.exp
1 # Copyright 2013 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 load_lib dwarf.exp
16
17 # This test can only be run on targets which support DWARF-2 and use gas.
18 if {![dwarf2_support]} {
19 return 0
20 }
21
22 standard_testfile .c entry-values-dw.S
23
24 if {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
25 object {nodebug}] != ""} {
26 return -1
27 }
28
29 # Start GDB and load object file, compute the function length and
30 # the offset of branch instruction in function. They are needed
31 # in the Dwarf Assembler below.
32
33 gdb_exit
34 gdb_start
35 gdb_reinitialize_dir $srcdir/$subdir
36 gdb_load ${binfile}1.o
37
38 set foo_length ""
39
40 # Calculate the offset of the last instruction from the beginning.
41 set test "disassemble foo"
42 gdb_test_multiple $test $test {
43 -re ".*$hex <\\+($decimal)>:\[^\r\n\]+\r\nEnd of assembler dump\.\r\n$gdb_prompt $" {
44 set foo_length $expect_out(1,string)
45 pass $test
46 }
47 -re ".*$gdb_prompt $" {
48 fail $test
49 # Bail out here, because we can't do the following tests if
50 # $foo_length is unknown.
51 return -1
52 }
53 }
54
55 # Calculate the size of the last instruction. Single instruction
56 # shouldn't be longer than 10 bytes.
57
58 set test "disassemble foo+$foo_length,+10"
59 gdb_test_multiple $test $test {
60 -re ".*($hex) <foo\\+$foo_length>:\[^\r\n\]+\r\n\[ \]+($hex) .*\.\r\n$gdb_prompt $" {
61 set start $expect_out(1,string)
62 set end $expect_out(2,string)
63
64 set foo_length [expr $foo_length + $end - $start]
65 pass $test
66 }
67 -re ".*$gdb_prompt $" {
68 fail $test
69 # Bail out here, because we can't do the following tests if
70 # $foo_length is unknown.
71 return -1
72 }
73 }
74
75 set bar_length ""
76 set bar_call_foo ""
77
78 # Calculate the offset of the last instruction from the beginning.
79 set test "disassemble bar"
80 gdb_test_multiple $test $test {
81 -re ".*$hex <\\+$decimal>:\[ \t\]+call\[^\r\n\]+\r\n\[ \]+$hex <\\+($decimal)>:" {
82 set bar_call_foo $expect_out(1,string)
83 exp_continue
84 }
85 -re ".*$hex <\\+($decimal)>:\[^\r\n\]+\r\nEnd of assembler dump\.\r\n$gdb_prompt $" {
86 set bar_length $expect_out(1,string)
87 pass $test
88 }
89 -re ".*$gdb_prompt $" {
90 fail $test
91 }
92 }
93
94 if { [string equal $bar_call_foo ""] || [string equal $bar_length ""] } {
95 fail "Find the call or branch instruction offset in bar"
96 # The following test makes no sense if the offset is unknown. We need
97 # to update the pattern above to match call or branch instruction for
98 # the target architecture.
99 return -1
100 }
101
102 # Calculate the size of the last instruction.
103
104 set test "disassemble bar+$bar_length,+10"
105 gdb_test_multiple $test $test {
106 -re ".*($hex) <bar\\+$bar_length>:\[^\r\n\]+\r\n\[ \]+($hex) .*\.\r\n$gdb_prompt $" {
107 set start $expect_out(1,string)
108 set end $expect_out(2,string)
109
110 set bar_length [expr $bar_length + $end - $start]
111 pass $test
112 }
113 -re ".*$gdb_prompt $" {
114 fail $test
115 # Bail out here, because we can't do the following tests if
116 # $bar_length is unknown.
117 return -1
118 }
119 }
120
121 gdb_exit
122
123 # Make some DWARF for the test.
124 set asm_file [standard_output_file $srcfile2]
125 Dwarf::assemble $asm_file {
126 declare_labels int_label foo_label
127 global foo_length bar_length bar_call_foo
128
129 cu {} {
130 compile_unit {{language @DW_LANG_C}} {
131 int_label: base_type {
132 {name int}
133 {encoding @DW_ATE_signed}
134 {byte_size 4 DW_FORM_sdata}
135 }
136
137 foo_label: subprogram {
138 {name foo}
139 {decl_file 1}
140 {low_pc foo addr}
141 {high_pc "foo + $foo_length" addr}
142 } {
143 formal_parameter {
144 {type :$int_label}
145 {name i}
146 {location {DW_OP_reg0} SPECIAL_expr}
147 }
148 formal_parameter {
149 {type :$int_label}
150 {name j}
151 {location {DW_OP_reg1} SPECIAL_expr}
152 }
153 }
154
155 subprogram {
156 {name bar}
157 {decl_file 1}
158 {low_pc bar addr}
159 {high_pc "bar + $bar_length" addr}
160 {GNU_all_call_sites 1}
161 } {
162 formal_parameter {
163 {type :$int_label}
164 {name i}
165 }
166
167 GNU_call_site {
168 {low_pc "bar + $bar_call_foo" addr}
169 {abstract_origin :$foo_label}
170 } {
171 # Faked entry values are reference to variables 'global1'
172 # and 'global2' and faked locations are register 0 and
173 # register 1.
174 GNU_call_site_parameter {
175 {location {DW_OP_reg0} SPECIAL_expr}
176 {GNU_call_site_value {
177 addr global1
178 deref_size 4
179 } SPECIAL_expr}
180 }
181 GNU_call_site_parameter {
182 {location {DW_OP_reg1} SPECIAL_expr}
183 {GNU_call_site_value {
184 addr global2
185 deref_size 4
186 } SPECIAL_expr}
187 }
188 }
189 }
190 }
191 }
192 }
193
194 if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
195 return -1
196 }
197
198 if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
199 "${binfile}" executable {}] != ""} {
200 return -1
201 }
202
203 clean_restart ${testfile}
204
205 if ![runto_main] {
206 fail "Can't run to main"
207 return -1
208 }
209
210 gdb_breakpoint "foo"
211
212 gdb_continue_to_breakpoint "foo"
213
214 gdb_test_no_output "set print entry-values both"
215
216 gdb_test_sequence "bt" "bt (1)" {
217 "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=2, j=[-]?[0-9]+, j@entry=3\\)"
218 "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)"
219 "\[\r\n\]#2 .* main \\(\\)"
220 }
221
222 # Update global variables 'global1' and 'global2' and test that the
223 # entry values are updated too.
224
225 gdb_test_no_output "set var global1=10"
226 gdb_test_no_output "set var global2=11"
227
228 gdb_test_sequence "bt" "bt (2)" {
229 "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=10, j=[-]?[0-9]+, j@entry=11\\)"
230 "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)"
231 "\[\r\n\]#2 .* main \\(\\)"
232 }
233
234 # Restart GDB and trace.
235
236 clean_restart $binfile
237
238 load_lib "trace-support.exp"
239
240 if ![runto_main] {
241 fail "Can't run to main to check for trace support"
242 return -1
243 }
244
245 if ![gdb_target_supports_trace] {
246 unsupported "target does not support trace"
247 return -1
248 }
249
250 gdb_test "trace foo" "Tracepoint $decimal at .*"
251
252 if [is_amd64_regs_target] {
253 set spreg "\$rsp"
254 } elseif [is_x86_like_target] {
255 set spreg "\$esp"
256 } else {
257 set spreg "\$sp"
258 }
259
260 # Collect arguments i and j. Collect 'global1' which is entry value
261 # of argument i. Don't collect 'global2' to test the entry value of
262 # argument j.
263
264 gdb_trace_setactions "set action for tracepoint 1" "" \
265 "collect i, j, global1, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
266
267 gdb_test_no_output "tstart"
268
269 gdb_breakpoint "end"
270 gdb_continue_to_breakpoint "end"
271
272 gdb_test_no_output "tstop"
273
274 gdb_test "tfind" "Found trace frame 0, .*" "tfind start"
275
276 # Since 'global2' is not collected, j@entry is expected to be 'unavailable'.
277 gdb_test "bt 1" "#0 .* foo \\(i=\[-\]?$decimal, i@entry=2, j=\[-\]?$decimal, j@entry=<unavailable>\\).*"
278
279 # Test that unavailable "j@entry" is not shown when command option
280 # --skip-unavailable is used.
281 gdb_test "interpreter-exec mi \"-stack-list-arguments --skip-unavailable --simple-values\"" \
282 "\r\n\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"i\",type=\"int\",value=\".*\"},{name=\"i@entry\",type=\"int\",value=\"2\"},{name=\"j\",type=\"int\",value=\".*\"}\\\]},frame=.*\\\].*"
283
284 gdb_test "tfind" "Target failed to find requested trace frame\..*"
This page took 0.037385 seconds and 4 git commands to generate.