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