]>
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 | ||
b39a8faf YQ |
38 | set bar_call_foo "" |
39 | ||
3f983d47 YZ |
40 | if { [istarget "arm*-*-*"] || [istarget "aarch64*-*-*"] } { |
41 | set call_insn "bl" | |
d674a709 AA |
42 | } elseif { [istarget "s390*-*-*"] } { |
43 | set call_insn "brasl" | |
2b239efb LM |
44 | } elseif { [istarget "powerpc*-*-*"] } { |
45 | set call_insn "bl" | |
3f983d47 YZ |
46 | } else { |
47 | set call_insn "call" | |
48 | } | |
49 | ||
84429e27 | 50 | # Calculate the offset of the instruction bar calls foo. |
b39a8faf YQ |
51 | set test "disassemble bar" |
52 | gdb_test_multiple $test $test { | |
84429e27 | 53 | -re ".*$hex <\\+$decimal>:\[ \t\]+$call_insn\[^\r\n\]+\r\n\[ \]+$hex <\\+($decimal)>:.*$gdb_prompt $" { |
b39a8faf | 54 | set bar_call_foo $expect_out(1,string) |
b39a8faf YQ |
55 | } |
56 | -re ".*$gdb_prompt $" { | |
57 | fail $test | |
58 | } | |
59 | } | |
60 | ||
84429e27 | 61 | if { [string equal $bar_call_foo ""] } { |
b39a8faf YQ |
62 | fail "Find the call or branch instruction offset in bar" |
63 | # The following test makes no sense if the offset is unknown. We need | |
64 | # to update the pattern above to match call or branch instruction for | |
65 | # the target architecture. | |
66 | return -1 | |
67 | } | |
68 | ||
b39a8faf YQ |
69 | gdb_exit |
70 | ||
71 | # Make some DWARF for the test. | |
72 | set asm_file [standard_output_file $srcfile2] | |
73 | Dwarf::assemble $asm_file { | |
74 | declare_labels int_label foo_label | |
84429e27 YQ |
75 | global bar_call_foo |
76 | global srcdir subdir srcfile | |
77 | ||
78 | set bar_result [function_range bar ${srcdir}/${subdir}/${srcfile}] | |
79 | set bar_start [lindex $bar_result 0] | |
80 | set bar_length [lindex $bar_result 1] | |
b39a8faf YQ |
81 | |
82 | cu {} { | |
83 | compile_unit {{language @DW_LANG_C}} { | |
84 | int_label: base_type { | |
85 | {name int} | |
86 | {encoding @DW_ATE_signed} | |
87 | {byte_size 4 DW_FORM_sdata} | |
88 | } | |
89 | ||
90 | foo_label: subprogram { | |
b39a8faf | 91 | {decl_file 1} |
84429e27 | 92 | {MACRO_AT_func { foo ${srcdir}/${subdir}/${srcfile} }} |
b39a8faf YQ |
93 | } { |
94 | formal_parameter { | |
95 | {type :$int_label} | |
96 | {name i} | |
97 | {location {DW_OP_reg0} SPECIAL_expr} | |
98 | } | |
99 | formal_parameter { | |
100 | {type :$int_label} | |
101 | {name j} | |
102 | {location {DW_OP_reg1} SPECIAL_expr} | |
103 | } | |
104 | } | |
105 | ||
106 | subprogram { | |
107 | {name bar} | |
108 | {decl_file 1} | |
84429e27 YQ |
109 | {low_pc $bar_start addr} |
110 | {high_pc "$bar_start + $bar_length" addr} | |
b39a8faf YQ |
111 | {GNU_all_call_sites 1} |
112 | } { | |
113 | formal_parameter { | |
114 | {type :$int_label} | |
115 | {name i} | |
116 | } | |
117 | ||
118 | GNU_call_site { | |
84429e27 | 119 | {low_pc "$bar_start + $bar_call_foo" addr} |
b39a8faf YQ |
120 | {abstract_origin :$foo_label} |
121 | } { | |
122 | # Faked entry values are reference to variables 'global1' | |
123 | # and 'global2' and faked locations are register 0 and | |
124 | # register 1. | |
125 | GNU_call_site_parameter { | |
126 | {location {DW_OP_reg0} SPECIAL_expr} | |
127 | {GNU_call_site_value { | |
128 | addr global1 | |
129 | deref_size 4 | |
130 | } SPECIAL_expr} | |
131 | } | |
132 | GNU_call_site_parameter { | |
133 | {location {DW_OP_reg1} SPECIAL_expr} | |
134 | {GNU_call_site_value { | |
135 | addr global2 | |
136 | deref_size 4 | |
137 | } SPECIAL_expr} | |
138 | } | |
139 | } | |
140 | } | |
141 | } | |
142 | } | |
143 | } | |
144 | ||
145 | if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} { | |
146 | return -1 | |
147 | } | |
148 | ||
149 | if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \ | |
150 | "${binfile}" executable {}] != ""} { | |
151 | return -1 | |
152 | } | |
153 | ||
154 | clean_restart ${testfile} | |
155 | ||
156 | if ![runto_main] { | |
157 | fail "Can't run to main" | |
158 | return -1 | |
159 | } | |
160 | ||
161 | gdb_breakpoint "foo" | |
162 | ||
163 | gdb_continue_to_breakpoint "foo" | |
164 | ||
165 | gdb_test_no_output "set print entry-values both" | |
166 | ||
167 | gdb_test_sequence "bt" "bt (1)" { | |
168 | "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=2, j=[-]?[0-9]+, j@entry=3\\)" | |
169 | "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)" | |
170 | "\[\r\n\]#2 .* main \\(\\)" | |
171 | } | |
172 | ||
173 | # Update global variables 'global1' and 'global2' and test that the | |
174 | # entry values are updated too. | |
175 | ||
176 | gdb_test_no_output "set var global1=10" | |
177 | gdb_test_no_output "set var global2=11" | |
178 | ||
179 | gdb_test_sequence "bt" "bt (2)" { | |
180 | "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=10, j=[-]?[0-9]+, j@entry=11\\)" | |
181 | "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)" | |
182 | "\[\r\n\]#2 .* main \\(\\)" | |
183 | } | |
b1224238 YQ |
184 | |
185 | # Restart GDB and trace. | |
186 | ||
187 | clean_restart $binfile | |
188 | ||
189 | load_lib "trace-support.exp" | |
190 | ||
191 | if ![runto_main] { | |
192 | fail "Can't run to main to check for trace support" | |
193 | return -1 | |
194 | } | |
195 | ||
196 | if ![gdb_target_supports_trace] { | |
197 | unsupported "target does not support trace" | |
198 | return -1 | |
199 | } | |
200 | ||
201 | gdb_test "trace foo" "Tracepoint $decimal at .*" | |
202 | ||
203 | if [is_amd64_regs_target] { | |
204 | set spreg "\$rsp" | |
205 | } elseif [is_x86_like_target] { | |
206 | set spreg "\$esp" | |
207 | } else { | |
208 | set spreg "\$sp" | |
209 | } | |
210 | ||
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. | |
214 | ||
215 | gdb_trace_setactions "set action for tracepoint 1" "" \ | |
216 | "collect i, j, global1, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$" | |
217 | ||
218 | gdb_test_no_output "tstart" | |
219 | ||
220 | gdb_breakpoint "end" | |
221 | gdb_continue_to_breakpoint "end" | |
222 | ||
223 | gdb_test_no_output "tstop" | |
224 | ||
225 | gdb_test "tfind" "Found trace frame 0, .*" "tfind start" | |
226 | ||
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>\\).*" | |
229 | ||
6211c335 YQ |
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=.*\\\].*" | |
234 | ||
b1224238 | 235 | gdb_test "tfind" "Target failed to find requested trace frame\..*" |