Fix regression on s390x with entry-values.exp.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / entry-values.exp
1 # Copyright 2013-2014 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 if { [istarget "arm*-*-*"] || [istarget "aarch64*-*-*"] } {
79 set call_insn "bl"
80 } elseif { [istarget "s390*-*-*"] } {
81 set call_insn "brasl"
82 } else {
83 set call_insn "call"
84 }
85
86 # Calculate the offset of the last instruction from the beginning.
87 set test "disassemble bar"
88 gdb_test_multiple $test $test {
89 -re ".*$hex <\\+$decimal>:\[ \t\]+$call_insn\[^\r\n\]+\r\n\[ \]+$hex <\\+($decimal)>:" {
90 set bar_call_foo $expect_out(1,string)
91 exp_continue
92 }
93 -re ".*$hex <\\+($decimal)>:\[^\r\n\]+\r\nEnd of assembler dump\.\r\n$gdb_prompt $" {
94 set bar_length $expect_out(1,string)
95 pass $test
96 }
97 -re ".*$gdb_prompt $" {
98 fail $test
99 }
100 }
101
102 if { [string equal $bar_call_foo ""] || [string equal $bar_length ""] } {
103 fail "Find the call or branch instruction offset in bar"
104 # The following test makes no sense if the offset is unknown. We need
105 # to update the pattern above to match call or branch instruction for
106 # the target architecture.
107 return -1
108 }
109
110 # Calculate the size of the last instruction.
111
112 set test "disassemble bar+$bar_length,+10"
113 gdb_test_multiple $test $test {
114 -re ".*($hex) <bar\\+$bar_length>:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
115 set start $expect_out(1,string)
116 set end $expect_out(2,string)
117
118 set bar_length [expr $bar_length + $end - $start]
119 pass $test
120 }
121 -re ".*$gdb_prompt $" {
122 fail $test
123 # Bail out here, because we can't do the following tests if
124 # $bar_length is unknown.
125 return -1
126 }
127 }
128
129 gdb_exit
130
131 # Make some DWARF for the test.
132 set asm_file [standard_output_file $srcfile2]
133 Dwarf::assemble $asm_file {
134 declare_labels int_label foo_label
135 global foo_length bar_length bar_call_foo
136
137 cu {} {
138 compile_unit {{language @DW_LANG_C}} {
139 int_label: base_type {
140 {name int}
141 {encoding @DW_ATE_signed}
142 {byte_size 4 DW_FORM_sdata}
143 }
144
145 foo_label: subprogram {
146 {name foo}
147 {decl_file 1}
148 {low_pc foo addr}
149 {high_pc "foo + $foo_length" addr}
150 } {
151 formal_parameter {
152 {type :$int_label}
153 {name i}
154 {location {DW_OP_reg0} SPECIAL_expr}
155 }
156 formal_parameter {
157 {type :$int_label}
158 {name j}
159 {location {DW_OP_reg1} SPECIAL_expr}
160 }
161 }
162
163 subprogram {
164 {name bar}
165 {decl_file 1}
166 {low_pc bar addr}
167 {high_pc "bar + $bar_length" addr}
168 {GNU_all_call_sites 1}
169 } {
170 formal_parameter {
171 {type :$int_label}
172 {name i}
173 }
174
175 GNU_call_site {
176 {low_pc "bar + $bar_call_foo" addr}
177 {abstract_origin :$foo_label}
178 } {
179 # Faked entry values are reference to variables 'global1'
180 # and 'global2' and faked locations are register 0 and
181 # register 1.
182 GNU_call_site_parameter {
183 {location {DW_OP_reg0} SPECIAL_expr}
184 {GNU_call_site_value {
185 addr global1
186 deref_size 4
187 } SPECIAL_expr}
188 }
189 GNU_call_site_parameter {
190 {location {DW_OP_reg1} SPECIAL_expr}
191 {GNU_call_site_value {
192 addr global2
193 deref_size 4
194 } SPECIAL_expr}
195 }
196 }
197 }
198 }
199 }
200 }
201
202 if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
203 return -1
204 }
205
206 if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
207 "${binfile}" executable {}] != ""} {
208 return -1
209 }
210
211 clean_restart ${testfile}
212
213 if ![runto_main] {
214 fail "Can't run to main"
215 return -1
216 }
217
218 gdb_breakpoint "foo"
219
220 gdb_continue_to_breakpoint "foo"
221
222 gdb_test_no_output "set print entry-values both"
223
224 gdb_test_sequence "bt" "bt (1)" {
225 "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=2, j=[-]?[0-9]+, j@entry=3\\)"
226 "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)"
227 "\[\r\n\]#2 .* main \\(\\)"
228 }
229
230 # Update global variables 'global1' and 'global2' and test that the
231 # entry values are updated too.
232
233 gdb_test_no_output "set var global1=10"
234 gdb_test_no_output "set var global2=11"
235
236 gdb_test_sequence "bt" "bt (2)" {
237 "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=10, j=[-]?[0-9]+, j@entry=11\\)"
238 "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)"
239 "\[\r\n\]#2 .* main \\(\\)"
240 }
241
242 # Restart GDB and trace.
243
244 clean_restart $binfile
245
246 load_lib "trace-support.exp"
247
248 if ![runto_main] {
249 fail "Can't run to main to check for trace support"
250 return -1
251 }
252
253 if ![gdb_target_supports_trace] {
254 unsupported "target does not support trace"
255 return -1
256 }
257
258 gdb_test "trace foo" "Tracepoint $decimal at .*"
259
260 if [is_amd64_regs_target] {
261 set spreg "\$rsp"
262 } elseif [is_x86_like_target] {
263 set spreg "\$esp"
264 } else {
265 set spreg "\$sp"
266 }
267
268 # Collect arguments i and j. Collect 'global1' which is entry value
269 # of argument i. Don't collect 'global2' to test the entry value of
270 # argument j.
271
272 gdb_trace_setactions "set action for tracepoint 1" "" \
273 "collect i, j, global1, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
274
275 gdb_test_no_output "tstart"
276
277 gdb_breakpoint "end"
278 gdb_continue_to_breakpoint "end"
279
280 gdb_test_no_output "tstop"
281
282 gdb_test "tfind" "Found trace frame 0, .*" "tfind start"
283
284 # Since 'global2' is not collected, j@entry is expected to be 'unavailable'.
285 gdb_test "bt 1" "#0 .* foo \\(i=\[-\]?$decimal, i@entry=2, j=\[-\]?$decimal, j@entry=<unavailable>\\).*"
286
287 # Test that unavailable "j@entry" is not shown when command option
288 # --skip-unavailable is used.
289 gdb_test "interpreter-exec mi \"-stack-list-arguments --skip-unavailable --simple-values\"" \
290 "\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=.*\\\].*"
291
292 gdb_test "tfind" "Target failed to find requested trace frame\..*"
This page took 0.039643 seconds and 4 git commands to generate.