Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / entry-values.exp
CommitLineData
88b9d363 1# Copyright 2013-2022 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/>.
15load_lib dwarf.exp
16
17# This test can only be run on targets which support DWARF-2 and use gas.
18if {![dwarf2_support]} {
19 return 0
20}
21
22standard_testfile .c entry-values-dw.S
23
24if {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
25 object {nodebug}] != ""} {
26 return -1
27}
28
98fa59e9
MK
29if {[gdb_compile [list ${binfile}1.o] \
30 "${binfile}1" executable {}] != ""} {
31 return -1
32}
33
34# Start GDB and load executable file, compute the offset of the
9d85a0ec
YQ
35# instruction in bar returned from foo. It is needed in the Dwarf
36# Assembler.
b39a8faf
YQ
37
38gdb_exit
39gdb_start
40gdb_reinitialize_dir $srcdir/$subdir
98fa59e9 41gdb_load ${binfile}1
b39a8faf 42
9d85a0ec 43set returned_from_foo ""
b39a8faf 44
3f983d47
YZ
45if { [istarget "arm*-*-*"] || [istarget "aarch64*-*-*"] } {
46 set call_insn "bl"
d674a709
AA
47} elseif { [istarget "s390*-*-*"] } {
48 set call_insn "brasl"
2b239efb
LM
49} elseif { [istarget "powerpc*-*-*"] } {
50 set call_insn "bl"
acc018ac
YQ
51} elseif { [istarget "mips*-*-*"] } {
52 # Skip the delay slot after the instruction used to make a call
53 # (which can be a jump or a branch) if it has one.
54 #
55 # JUMP (or BRANCH) foo
56 # insn1
57 # insn2
58 #
59 # Most MIPS instructions used to make calls have a delay slot.
60 # These include JAL, JALS, JALX, JALR, JALRS, BAL and BALS.
61 # In this case the program continues from `insn2' when `foo'
62 # returns. The only exception is JALRC, in which case execution
63 # resumes from `insn1' instead.
64 set call_insn {jalrc|[jb]al[sxr]*[ \t][^\r\n]+\r\n}
3f983d47
YZ
65} else {
66 set call_insn "call"
67}
68
9d85a0ec 69# Calculate the offset of the instruction in bar returned from foo.
b39a8faf
YQ
70set test "disassemble bar"
71gdb_test_multiple $test $test {
7337a6f2 72 -re ".*$hex <\\+$decimal>:\[ \t\]+\\y$call_insn\\y\[^\r\n\]+\r\n\[ \]+$hex <\\+($decimal)>:.*$gdb_prompt $" {
9d85a0ec 73 set returned_from_foo $expect_out(1,string)
b39a8faf
YQ
74 }
75 -re ".*$gdb_prompt $" {
76 fail $test
77 }
78}
79
9d85a0ec 80if { [string equal $returned_from_foo ""] } {
bc6c7af4 81 fail "find the call or branch instruction offset in bar"
b39a8faf
YQ
82 # The following test makes no sense if the offset is unknown. We need
83 # to update the pattern above to match call or branch instruction for
84 # the target architecture.
85 return -1
86}
87
b39a8faf
YQ
88gdb_exit
89
90# Make some DWARF for the test.
91set asm_file [standard_output_file $srcfile2]
92Dwarf::assemble $asm_file {
93 declare_labels int_label foo_label
9d85a0ec 94 global returned_from_foo
84429e27
YQ
95 global srcdir subdir srcfile
96
97 set bar_result [function_range bar ${srcdir}/${subdir}/${srcfile}]
98 set bar_start [lindex $bar_result 0]
99 set bar_length [lindex $bar_result 1]
b39a8faf
YQ
100
101 cu {} {
102 compile_unit {{language @DW_LANG_C}} {
103 int_label: base_type {
104 {name int}
105 {encoding @DW_ATE_signed}
106 {byte_size 4 DW_FORM_sdata}
107 }
108
109 foo_label: subprogram {
824eacee 110 {decl_file 0 udata}
10da644d 111 {MACRO_AT_func { foo }}
b39a8faf
YQ
112 } {
113 formal_parameter {
114 {type :$int_label}
115 {name i}
116 {location {DW_OP_reg0} SPECIAL_expr}
117 }
118 formal_parameter {
119 {type :$int_label}
120 {name j}
121 {location {DW_OP_reg1} SPECIAL_expr}
122 }
123 }
124
125 subprogram {
126 {name bar}
824eacee 127 {decl_file 0 udata}
84429e27
YQ
128 {low_pc $bar_start addr}
129 {high_pc "$bar_start + $bar_length" addr}
f2e0d4b4 130 {GNU_all_call_sites 1 sdata}
b39a8faf
YQ
131 } {
132 formal_parameter {
133 {type :$int_label}
134 {name i}
135 }
136
137 GNU_call_site {
9d85a0ec 138 {low_pc "$bar_start + $returned_from_foo" addr}
b39a8faf
YQ
139 {abstract_origin :$foo_label}
140 } {
141 # Faked entry values are reference to variables 'global1'
142 # and 'global2' and faked locations are register 0 and
143 # register 1.
144 GNU_call_site_parameter {
145 {location {DW_OP_reg0} SPECIAL_expr}
146 {GNU_call_site_value {
147 addr global1
148 deref_size 4
149 } SPECIAL_expr}
150 }
151 GNU_call_site_parameter {
152 {location {DW_OP_reg1} SPECIAL_expr}
153 {GNU_call_site_value {
154 addr global2
155 deref_size 4
156 } SPECIAL_expr}
157 }
158 }
159 }
160 }
161 }
162}
163
164if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
165 return -1
166}
167
168if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
169 "${binfile}" executable {}] != ""} {
170 return -1
171}
172
173clean_restart ${testfile}
174
175if ![runto_main] {
bc6c7af4 176 fail "can't run to main"
b39a8faf
YQ
177 return -1
178}
179
180gdb_breakpoint "foo"
181
182gdb_continue_to_breakpoint "foo"
183
184gdb_test_no_output "set print entry-values both"
185
186gdb_test_sequence "bt" "bt (1)" {
187 "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=2, j=[-]?[0-9]+, j@entry=3\\)"
188 "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)"
98fa59e9 189 "\[\r\n\]#2 .* \.?main \\(\\)"
b39a8faf
YQ
190}
191
192# Update global variables 'global1' and 'global2' and test that the
193# entry values are updated too.
194
46a4882b
PA
195gdb_test_no_output "set var *(int *) &global1=10"
196gdb_test_no_output "set var *(int *) &global2=11"
b39a8faf
YQ
197
198gdb_test_sequence "bt" "bt (2)" {
199 "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=10, j=[-]?[0-9]+, j@entry=11\\)"
200 "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)"
98fa59e9 201 "\[\r\n\]#2 .* \.?main \\(\\)"
b39a8faf 202}
b1224238
YQ
203
204# Restart GDB and trace.
205
206clean_restart $binfile
207
208load_lib "trace-support.exp"
209
210if ![runto_main] {
bc6c7af4 211 fail "can't run to main to check for trace support"
b1224238
YQ
212 return -1
213}
214
215if ![gdb_target_supports_trace] {
216 unsupported "target does not support trace"
217 return -1
218}
219
220gdb_test "trace foo" "Tracepoint $decimal at .*"
221
b1224238
YQ
222# Collect arguments i and j. Collect 'global1' which is entry value
223# of argument i. Don't collect 'global2' to test the entry value of
224# argument j.
225
226gdb_trace_setactions "set action for tracepoint 1" "" \
46a4882b 227 "collect i, j, (int) global1, \(\*\(void \*\*\) \(\$$spreg\)\) @ 128" "^$"
b1224238
YQ
228
229gdb_test_no_output "tstart"
230
231gdb_breakpoint "end"
232gdb_continue_to_breakpoint "end"
233
234gdb_test_no_output "tstop"
235
236gdb_test "tfind" "Found trace frame 0, .*" "tfind start"
237
238# Since 'global2' is not collected, j@entry is expected to be 'unavailable'.
239gdb_test "bt 1" "#0 .* foo \\(i=\[-\]?$decimal, i@entry=2, j=\[-\]?$decimal, j@entry=<unavailable>\\).*"
240
6211c335
YQ
241# Test that unavailable "j@entry" is not shown when command option
242# --skip-unavailable is used.
243gdb_test "interpreter-exec mi \"-stack-list-arguments --skip-unavailable --simple-values\"" \
244 "\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=.*\\\].*"
245
b1224238 246gdb_test "tfind" "Target failed to find requested trace frame\..*"
This page took 1.020399 seconds and 4 git commands to generate.