Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / entry-values.exp
1 # Copyright 2013-2022 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 if {[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
35 # instruction in bar returned from foo. It is needed in the Dwarf
36 # Assembler.
37
38 gdb_exit
39 gdb_start
40 gdb_reinitialize_dir $srcdir/$subdir
41 gdb_load ${binfile}1
42
43 set returned_from_foo ""
44
45 if { [istarget "arm*-*-*"] || [istarget "aarch64*-*-*"] } {
46 set call_insn "bl"
47 } elseif { [istarget "s390*-*-*"] } {
48 set call_insn "brasl"
49 } elseif { [istarget "powerpc*-*-*"] } {
50 set call_insn "bl"
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}
65 } else {
66 set call_insn "call"
67 }
68
69 # Calculate the offset of the instruction in bar returned from foo.
70 set test "disassemble bar"
71 gdb_test_multiple $test $test {
72 -re ".*$hex <\\+$decimal>:\[ \t\]+\\y$call_insn\\y\[^\r\n\]+\r\n\[ \]+$hex <\\+($decimal)>:.*$gdb_prompt $" {
73 set returned_from_foo $expect_out(1,string)
74 }
75 -re ".*$gdb_prompt $" {
76 fail $test
77 }
78 }
79
80 if { [string equal $returned_from_foo ""] } {
81 fail "find the call or branch instruction offset in bar"
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
88 gdb_exit
89
90 # Make some DWARF for the test.
91 set asm_file [standard_output_file $srcfile2]
92 Dwarf::assemble $asm_file {
93 declare_labels int_label foo_label
94 global returned_from_foo
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]
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 {
110 {decl_file 0 udata}
111 {MACRO_AT_func { foo }}
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}
127 {decl_file 0 udata}
128 {low_pc $bar_start addr}
129 {high_pc "$bar_start + $bar_length" addr}
130 {GNU_all_call_sites 1 sdata}
131 } {
132 formal_parameter {
133 {type :$int_label}
134 {name i}
135 }
136
137 GNU_call_site {
138 {low_pc "$bar_start + $returned_from_foo" addr}
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
164 if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
165 return -1
166 }
167
168 if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
169 "${binfile}" executable {}] != ""} {
170 return -1
171 }
172
173 clean_restart ${testfile}
174
175 if ![runto_main] {
176 fail "can't run to main"
177 return -1
178 }
179
180 gdb_breakpoint "foo"
181
182 gdb_continue_to_breakpoint "foo"
183
184 gdb_test_no_output "set print entry-values both"
185
186 gdb_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>\\)"
189 "\[\r\n\]#2 .* \.?main \\(\\)"
190 }
191
192 # Update global variables 'global1' and 'global2' and test that the
193 # entry values are updated too.
194
195 gdb_test_no_output "set var *(int *) &global1=10"
196 gdb_test_no_output "set var *(int *) &global2=11"
197
198 gdb_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>\\)"
201 "\[\r\n\]#2 .* \.?main \\(\\)"
202 }
203
204 # Restart GDB and trace.
205
206 clean_restart $binfile
207
208 load_lib "trace-support.exp"
209
210 if ![runto_main] {
211 fail "can't run to main to check for trace support"
212 return -1
213 }
214
215 if ![gdb_target_supports_trace] {
216 unsupported "target does not support trace"
217 return -1
218 }
219
220 gdb_test "trace foo" "Tracepoint $decimal at .*"
221
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
226 gdb_trace_setactions "set action for tracepoint 1" "" \
227 "collect i, j, (int) global1, \(\*\(void \*\*\) \(\$$spreg\)\) @ 128" "^$"
228
229 gdb_test_no_output "tstart"
230
231 gdb_breakpoint "end"
232 gdb_continue_to_breakpoint "end"
233
234 gdb_test_no_output "tstop"
235
236 gdb_test "tfind" "Found trace frame 0, .*" "tfind start"
237
238 # Since 'global2' is not collected, j@entry is expected to be 'unavailable'.
239 gdb_test "bt 1" "#0 .* foo \\(i=\[-\]?$decimal, i@entry=2, j=\[-\]?$decimal, j@entry=<unavailable>\\).*"
240
241 # Test that unavailable "j@entry" is not shown when command option
242 # --skip-unavailable is used.
243 gdb_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
246 gdb_test "tfind" "Target failed to find requested trace frame\..*"
This page took 0.037797 seconds and 4 git commands to generate.