aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.trace/entry-values.exp
blob: f10ffa6b6e032bd3155a9a9264552417f37a54b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# Copyright 2013-2014 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
load_lib dwarf.exp

# This test can only be run on targets which support DWARF-2 and use gas.
if {![dwarf2_support]} {
    return 0
}

standard_testfile .c entry-values-dw.S

if  {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
	  object {nodebug}] != ""} {
    return -1
}

# Start GDB and load object file, compute the function length and
# the offset of branch instruction in function.  They are needed
# in the Dwarf Assembler below.

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}1.o

set foo_length ""

# Calculate the offset of the last instruction from the beginning.
set test "disassemble foo"
gdb_test_multiple $test $test {
    -re ".*$hex <\\+($decimal)>:\[^\r\n\]+\r\nEnd of assembler dump\.\r\n$gdb_prompt $" {
	set foo_length $expect_out(1,string)
	pass $test
    }
    -re ".*$gdb_prompt $" {
	fail $test
	# Bail out here, because we can't do the following tests if
	# $foo_length is unknown.
	return -1
    }
}

# Calculate the size of the last instruction.  Single instruction
# shouldn't be longer than 10 bytes.

set test "disassemble foo+$foo_length,+10"
gdb_test_multiple $test $test {
    -re ".*($hex) <foo\\+$foo_length>:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
	set start $expect_out(1,string)
	set end $expect_out(2,string)

	set foo_length [expr $foo_length + $end - $start]
	pass $test
    }
    -re ".*$gdb_prompt $" {
	fail $test
	# Bail out here, because we can't do the following tests if
	# $foo_length is unknown.
	return -1
    }
}

set bar_length ""
set bar_call_foo ""

if { [istarget "arm*-*-*"] || [istarget "aarch64*-*-*"] } {
    set call_insn "bl"
} elseif { [istarget "s390*-*-*"] } {
    set call_insn "brasl"
} else {
    set call_insn "call"
}

# Calculate the offset of the last instruction from the beginning.
set test "disassemble bar"
gdb_test_multiple $test $test {
    -re ".*$hex <\\+$decimal>:\[ \t\]+$call_insn\[^\r\n\]+\r\n\[ \]+$hex <\\+($decimal)>:" {
	set bar_call_foo $expect_out(1,string)
	exp_continue
    }
    -re ".*$hex <\\+($decimal)>:\[^\r\n\]+\r\nEnd of assembler dump\.\r\n$gdb_prompt $" {
	set bar_length $expect_out(1,string)
	pass $test
    }
    -re ".*$gdb_prompt $" {
	fail $test
    }
}

if { [string equal $bar_call_foo ""] || [string equal $bar_length ""] } {
    fail "Find the call or branch instruction offset in bar"
    # The following test makes no sense if the offset is unknown.  We need
    # to update the pattern above to match call or branch instruction for
    # the target architecture.
    return -1
}

# Calculate the size of the last instruction.

set test "disassemble bar+$bar_length,+10"
gdb_test_multiple $test $test {
    -re ".*($hex) <bar\\+$bar_length>:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
	set start $expect_out(1,string)
	set end $expect_out(2,string)

	set bar_length [expr $bar_length + $end - $start]
	pass $test
    }
    -re ".*$gdb_prompt $" {
	fail $test
	# Bail out here, because we can't do the following tests if
	# $bar_length is unknown.
	return -1
    }
}

gdb_exit

# Make some DWARF for the test.
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
    declare_labels int_label foo_label
    global foo_length bar_length bar_call_foo

    cu {} {
	compile_unit {{language @DW_LANG_C}} {
	    int_label: base_type {
		{name int}
		{encoding @DW_ATE_signed}
		{byte_size 4 DW_FORM_sdata}
	    }

	    foo_label: subprogram {
		{name foo}
		{decl_file 1}
		{low_pc foo addr}
		{high_pc "foo + $foo_length" addr}
	    } {
		formal_parameter {
		    {type :$int_label}
		    {name i}
		    {location {DW_OP_reg0} SPECIAL_expr}
		}
		formal_parameter {
		    {type :$int_label}
		    {name j}
		    {location {DW_OP_reg1} SPECIAL_expr}
		}
	    }

	    subprogram {
		{name bar}
		{decl_file 1}
		{low_pc bar addr}
		{high_pc "bar + $bar_length" addr}
		{GNU_all_call_sites 1}
	    } {
		formal_parameter {
		    {type :$int_label}
		    {name i}
		}

		GNU_call_site {
		    {low_pc "bar + $bar_call_foo" addr}
		    {abstract_origin :$foo_label}
		} {
		    # Faked entry values are reference to variables 'global1'
		    # and 'global2' and faked locations are register 0 and
		    # register 1.
		    GNU_call_site_parameter {
			{location {DW_OP_reg0} SPECIAL_expr}
			{GNU_call_site_value {
			    addr global1
			    deref_size 4
			} SPECIAL_expr}
		    }
		    GNU_call_site_parameter {
			{location {DW_OP_reg1} SPECIAL_expr}
			{GNU_call_site_value {
			    addr global2
			    deref_size 4
			} SPECIAL_expr}
		    }
		}
	    }
	}
    }
}

if  {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
    return -1
}

if  {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
	  "${binfile}" executable {}] != ""} {
    return -1
}

clean_restart ${testfile}

if ![runto_main] {
    fail "Can't run to main"
    return -1
}

gdb_breakpoint "foo"

gdb_continue_to_breakpoint "foo"

gdb_test_no_output "set print entry-values both"

gdb_test_sequence "bt" "bt (1)" {
    "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=2, j=[-]?[0-9]+, j@entry=3\\)"
    "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)"
    "\[\r\n\]#2 .* main \\(\\)"
}

# Update global variables 'global1' and 'global2' and test that the
# entry values are updated too.

gdb_test_no_output "set var global1=10"
gdb_test_no_output "set var global2=11"

gdb_test_sequence "bt" "bt (2)" {
    "\[\r\n\]#0 .* foo \\(i=[-]?[0-9]+, i@entry=10, j=[-]?[0-9]+, j@entry=11\\)"
    "\[\r\n\]#1 .* bar \\(i=<optimized out>, i@entry=<optimized out>\\)"
    "\[\r\n\]#2 .* main \\(\\)"
}

# Restart GDB and trace.

clean_restart $binfile

load_lib "trace-support.exp"

if ![runto_main] {
    fail "Can't run to main to check for trace support"
    return -1
}

if ![gdb_target_supports_trace] {
    unsupported "target does not support trace"
    return -1
}

gdb_test "trace foo" "Tracepoint $decimal at .*"

if [is_amd64_regs_target] {
    set spreg "\$rsp"
} elseif [is_x86_like_target] {
    set spreg "\$esp"
} else {
    set spreg "\$sp"
}

# Collect arguments i and j.  Collect 'global1' which is entry value
# of argument i.  Don't collect 'global2' to test the entry value of
# argument j.

gdb_trace_setactions "set action for tracepoint 1" "" \
    "collect i, j, global1, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"

gdb_test_no_output "tstart"

gdb_breakpoint "end"
gdb_continue_to_breakpoint "end"

gdb_test_no_output "tstop"

gdb_test "tfind" "Found trace frame 0, .*" "tfind start"

# Since 'global2' is not collected, j@entry is expected to be 'unavailable'.
gdb_test "bt 1" "#0 .* foo \\(i=\[-\]?$decimal, i@entry=2, j=\[-\]?$decimal, j@entry=<unavailable>\\).*"

# Test that unavailable "j@entry" is not shown when command option
# --skip-unavailable is used.
gdb_test "interpreter-exec mi \"-stack-list-arguments --skip-unavailable --simple-values\"" \
    "\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=.*\\\].*"

gdb_test "tfind" "Target failed to find requested trace frame\..*"