Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.trace / entry-values.exp
blob82ae5a8b2736c839e306da9b87240b18db5c32b0
1 # Copyright 2013-2024 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/>.
15 load_lib dwarf.exp
17 # This test can only be run on targets which support DWARF-2 and use gas.
18 require dwarf2_support
20 standard_testfile .c entry-values-dw.S
22 if  {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
23           object {nodebug}] != ""} {
24     return -1
27 if  {[gdb_compile [list ${binfile}1.o] \
28           "${binfile}1" executable {}] != ""} {
29     return -1
32 clean_restart ${binfile}1
34 set returned_from_foo ""
36 if { [istarget "arm*-*-*"] || [istarget "aarch64*-*-*"] } {
37     set call_insn "bl"
38 } elseif { [istarget "s390*-*-*"] } {
39     set call_insn "brasl"
40 } elseif { [istarget "powerpc*-*-*"] } {
41     set call_insn "bl"
42 } elseif { [istarget "mips*-*-*"] } {
43     # Skip the delay slot after the instruction used to make a call
44     # (which can be a jump or a branch) if it has one.
45     #
46     #  JUMP (or BRANCH) foo
47     #  insn1
48     #  insn2
49     #
50     # Most MIPS instructions used to make calls have a delay slot.
51     # These include JAL, JALS, JALX, JALR, JALRS, BAL and BALS.
52     # In this case the program continues from `insn2' when `foo'
53     # returns.  The only exception is JALRC, in which case execution
54     # resumes from `insn1' instead.
55     set call_insn {jalrc|[jb]al[sxr]*[ \t][^\r\n]+\r\n}
56 } elseif { [istarget "riscv64*-*-*"] } {
57     set call_insn jal
58 } else {
59     set call_insn "call"
62 # Calculate the offset of the instruction in bar returned from foo.
63 set test "disassemble bar"
64 gdb_test_multiple $test $test {
65     -re ".*$hex <\\+$decimal>:\[ \t\]+\\y$call_insn\\y\[^\r\n\]+\r\n\[ \]+$hex <\\+($decimal)>:.*$gdb_prompt $" {
66         set returned_from_foo $expect_out(1,string)
67     }
68     -re ".*$gdb_prompt $" {
69         fail $test
70     }
73 if { [string equal $returned_from_foo ""] } {
74     fail "find the call or branch instruction offset in bar"
75     # The following test makes no sense if the offset is unknown.  We need
76     # to update the pattern above to match call or branch instruction for
77     # the target architecture.
78     return -1
81 # Make some DWARF for the test.
82 set asm_file [standard_output_file $srcfile2]
83 Dwarf::assemble $asm_file {
84     declare_labels int_label foo_label
85     global returned_from_foo
86     global srcdir subdir srcfile
88     set bar_result [function_range bar ${srcdir}/${subdir}/${srcfile}]
89     set bar_start [lindex $bar_result 0]
90     set bar_length [lindex $bar_result 1]
92     cu {} {
93         compile_unit {{language @DW_LANG_C}} {
94             int_label: base_type {
95                 {name int}
96                 {encoding @DW_ATE_signed}
97                 {byte_size 4 DW_FORM_sdata}
98             }
100             foo_label: subprogram {
101                 {decl_file 0 udata}
102                 {MACRO_AT_func { foo }}
103             } {
104                 formal_parameter {
105                     {type :$int_label}
106                     {name i}
107                     {location {DW_OP_reg0} SPECIAL_expr}
108                 }
109                 formal_parameter {
110                     {type :$int_label}
111                     {name j}
112                     {location {DW_OP_reg1} SPECIAL_expr}
113                 }
114             }
116             subprogram {
117                 {name bar}
118                 {decl_file 0 udata}
119                 {low_pc $bar_start addr}
120                 {high_pc "$bar_start + $bar_length" addr}
121                 {GNU_all_call_sites 1 sdata}
122             } {
123                 formal_parameter {
124                     {type :$int_label}
125                     {name i}
126                 }
128                 GNU_call_site {
129                     {low_pc "$bar_start + $returned_from_foo" addr}
130                     {abstract_origin :$foo_label}
131                 } {
132                     # Faked entry values are reference to variables 'global1'
133                     # and 'global2' and faked locations are register 0 and
134                     # register 1.
135                     GNU_call_site_parameter {
136                         {location {DW_OP_reg0} SPECIAL_expr}
137                         {GNU_call_site_value {
138                             addr global1
139                             deref_size 4
140                         } SPECIAL_expr}
141                     }
142                     GNU_call_site_parameter {
143                         {location {DW_OP_reg1} SPECIAL_expr}
144                         {GNU_call_site_value {
145                             addr global2
146                             deref_size 4
147                         } SPECIAL_expr}
148                     }
149                 }
150             }
151         }
152     }
155 if  {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
156     return -1
159 if  {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
160           "${binfile}" executable {}] != ""} {
161     return -1
164 clean_restart ${testfile}
166 if ![runto_main] {
167     return -1
170 gdb_breakpoint "foo"
172 gdb_continue_to_breakpoint "foo"
174 gdb_test_no_output "set print entry-values both"
176 gdb_test_sequence "bt" "bt, 1" {
177     "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=2, j=[-]?[0-9]+, j@entry=3\\)"
178     "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)"
179     "\[\r\n\]#2 .* \.?main \\(\\)"
182 # Update global variables 'global1' and 'global2' and test that the
183 # entry values are updated too.
185 gdb_test_no_output "set var *(int *) &global1=10"
186 gdb_test_no_output "set var *(int *) &global2=11"
188 gdb_test_sequence "bt" "bt, 2" {
189     "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=10, j=[-]?[0-9]+, j@entry=11\\)"
190     "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)"
191     "\[\r\n\]#2 .* \.?main \\(\\)"
194 # Restart GDB and trace.
196 clean_restart $binfile
198 load_lib "trace-support.exp"
200 if ![runto_main] {
201     return -1
204 if ![gdb_target_supports_trace] {
205     unsupported "target does not support trace"
206     return -1
209 gdb_test "trace foo" "Tracepoint $decimal at .*"
211 # Collect arguments i and j.  Collect 'global1' which is entry value
212 # of argument i.  Don't collect 'global2' to test the entry value of
213 # argument j.
215 gdb_trace_setactions "set action for tracepoint 1" "" \
216     "collect i, j, (int) global1, \(\*\(void \*\*\) \(\$$spreg\)\) @ 128" "^$"
218 gdb_test_no_output "tstart"
220 gdb_breakpoint "end"
221 gdb_continue_to_breakpoint "end"
223 gdb_test_no_output "tstop"
225 gdb_test "tfind" "Found trace frame 0, .*" "tfind start"
227 # Since 'global2' is not collected, j@entry is expected to be 'unavailable'.
228 gdb_test "bt 1" "#0 .* foo \\(i=\[-\]?$decimal, i@entry=2, j=\[-\]?$decimal, j@entry=<unavailable>\\).*"
230 # Test that unavailable "j@entry" is not shown when command option
231 # --skip-unavailable is used.
232 gdb_test "interpreter-exec mi \"-stack-list-arguments --skip-unavailable --simple-values\"" \
233     "\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=.*\\\].*"
235 gdb_test "tfind" "Target failed to find requested trace frame\..*"