1 # Copyright 2013-2014 Free Software Foundation, Inc.
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.
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.
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/>.
17 # This test can only be run on targets which support DWARF-2 and use gas.
18 if {![dwarf2_support]} {
22 standard_testfile .c entry-values-dw.S
24 if {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
25 object {nodebug}] != ""} {
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.
35 gdb_reinitialize_dir $srcdir/$subdir
36 gdb_load ${binfile}1.o
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)
47 -re ".*$gdb_prompt $" {
49 # Bail out here, because we can't do the following tests if
50 # $foo_length is unknown.
55 # Calculate the size of the last instruction. Single instruction
56 # shouldn't be longer than 10 bytes.
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)
64 set foo_length [expr $foo_length + $end - $start]
67 -re ".*$gdb_prompt $" {
69 # Bail out here, because we can't do the following tests if
70 # $foo_length is unknown.
78 if { [istarget "arm*-*-*"] || [istarget "aarch64*-*-*"] } {
80 } elseif { [istarget "s390*-*-*"] } {
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)
93 -re ".*$hex <\\+($decimal)>:\[^\r\n\]+\r\nEnd of assembler dump\.\r\n$gdb_prompt $" {
94 set bar_length $expect_out(1,string)
97 -re ".*$gdb_prompt $" {
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.
110 # Calculate the size of the last instruction.
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)
118 set bar_length [expr $bar_length + $end - $start]
121 -re ".*$gdb_prompt $" {
123 # Bail out here, because we can't do the following tests if
124 # $bar_length is unknown.
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
138 compile_unit {{language @DW_LANG_C}} {
139 int_label: base_type {
141 {encoding @DW_ATE_signed}
142 {byte_size 4 DW_FORM_sdata}
145 foo_label: subprogram {
149 {high_pc "foo + $foo_length" addr}
154 {location {DW_OP_reg0} SPECIAL_expr}
159 {location {DW_OP_reg1} SPECIAL_expr}
167 {high_pc "bar + $bar_length" addr}
168 {GNU_all_call_sites 1}
176 {low_pc "bar + $bar_call_foo" addr}
177 {abstract_origin :$foo_label}
179 # Faked entry values are reference to variables 'global1'
180 # and 'global2' and faked locations are register 0 and
182 GNU_call_site_parameter {
183 {location {DW_OP_reg0} SPECIAL_expr}
184 {GNU_call_site_value {
189 GNU_call_site_parameter {
190 {location {DW_OP_reg1} SPECIAL_expr}
191 {GNU_call_site_value {
202 if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
206 if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
207 "${binfile}" executable {}] != ""} {
211 clean_restart ${testfile}
214 fail "Can't run to main"
220 gdb_continue_to_breakpoint "foo"
222 gdb_test_no_output "set print entry-values both"
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 \\(\\)"
230 # Update global variables 'global1' and 'global2' and test that the
231 # entry values are updated too.
233 gdb_test_no_output "set var global1=10"
234 gdb_test_no_output "set var global2=11"
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 \\(\\)"
242 # Restart GDB and trace.
244 clean_restart $binfile
246 load_lib "trace-support.exp"
249 fail "Can't run to main to check for trace support"
253 if ![gdb_target_supports_trace] {
254 unsupported "target does not support trace"
258 gdb_test "trace foo" "Tracepoint $decimal at .*"
260 if [is_amd64_regs_target] {
262 } elseif [is_x86_like_target] {
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
272 gdb_trace_setactions "set action for tracepoint 1" "" \
273 "collect i, j, global1, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
275 gdb_test_no_output "tstart"
278 gdb_continue_to_breakpoint "end"
280 gdb_test_no_output "tstop"
282 gdb_test "tfind" "Found trace frame 0, .*" "tfind start"
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>\\).*"
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=.*\\\].*"
292 gdb_test "tfind" "Target failed to find requested trace frame\..*"