gdb/
[platform/upstream/binutils.git] / gdb / testsuite / gdb.trace / change-loc.exp
1 # Copyright 2011 Free Software Foundation, Inc.
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 3 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License
13 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
15 load_lib "trace-support.exp";
16
17 if $tracelevel then {
18     strace $tracelevel
19 }
20
21 if {[skip_shlib_tests]} {
22     return 0
23 }
24
25 set testfile "change-loc"
26 set libfile1 "change-loc-1"
27 set libfile2 "change-loc-2"
28 set srcfile $testfile.c
29 set executable $testfile
30 set libsrc1 $srcdir/$subdir/$libfile1.c
31 set libsrc2 $srcdir/$subdir/$libfile2.c
32 set binfile $objdir/$subdir/$testfile
33 set lib_sl1 $objdir/$subdir/$libfile1.sl
34 set lib_sl2 $objdir/$subdir/$libfile2.sl
35
36 set lib_opts debug
37
38 if [get_compiler_info ${binfile}] {
39     return -1
40 }
41
42 # Some targets have leading underscores on assembly symbols.
43 set additional_flags [list debug shlib=$lib_sl1 shlib_load [gdb_target_symbol_prefix_flags]]
44
45 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
46      || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""
47      || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
48     untested "Could not compile either $libsrc1 or $srcdir/$subdir/$srcfile."
49     return -1
50 }
51
52 clean_restart $executable
53
54 gdb_load_shlibs $lib_sl1
55 gdb_load_shlibs $lib_sl2
56
57 if ![runto_main] {
58     fail "Can't run to main to check for trace support"
59     return -1
60 }
61
62 if { ![gdb_target_supports_trace] } then {
63     unsupported "Current target does not support trace"
64     return -1;
65 }
66
67 if [is_amd64_regs_target] {
68     set pcreg "rip"
69 } elseif [is_x86_like_target] {
70     set pcreg "eip"
71 } else {
72     set pcreg "pc"
73 }
74
75
76 # Set tracepoint during tracing experiment.
77
78 proc tracepoint_change_loc_1 { trace_type } {
79     global testfile
80     global srcfile
81     global pcreg
82     global gdb_prompt
83     global pf_prefix
84
85     set old_pf_prefix $pf_prefix
86     set pf_prefix "$pf_prefix 1 $trace_type:"
87
88     clean_restart ${testfile}
89     if ![runto_main] {
90         fail "Can't run to main"
91         set pf_prefix $old_pf_prefix
92         return -1
93     }
94     gdb_test_no_output "delete break 1"
95
96     # Set a tracepoint we'll never meet.  Just to avoid the complain after
97     # type `tstart' later.
98     gdb_test "next" ".*"
99     gdb_test "trace main" "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
100         "set tracepoint on main"
101
102     gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
103         "breakpoint on marker"
104
105     gdb_test_no_output "tstart"
106
107     gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
108         "continue to marker 1"
109     # Set a tracepoint during tracing.
110     gdb_test "${trace_type} set_tracepoint" ".*" "set tracepoint on set_tracepoint"
111
112     gdb_trace_setactions "set action for tracepoint" "" \
113         "collect \$$pcreg" "^$"
114
115     # tracepoint has two locations after shlib change-loc-1 is loaded.
116     gdb_test "info trace" \
117         "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
118 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*" \
119         "tracepoint with two locations"
120
121     setup_kfail "gdb/13392" x86_64-*-*
122     gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
123         "continue to marker 2"
124
125     # tracepoint has three locations after shlib change-loc-2 is loaded.
126     gdb_test "info trace" \
127         "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
128 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* in func4 .*" \
129         "tracepoint with three locations"
130
131     gdb_test_no_output "tstop"
132
133     setup_kfail "gdb/13392" x86_64-*-*
134     gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" "tfind frame 0"
135     gdb_test "tfind" "Target failed to find requested trace frame\\..*"
136
137     set pf_prefix $old_pf_prefix
138 }
139
140
141 tracepoint_change_loc_1 "trace"
142
143 # Re-compile test case with IPA.
144 set libipa $objdir/../gdbserver/libinproctrace.so
145 gdb_load_shlibs $libipa
146
147 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \
148           [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } {
149     untested change-loc.exp
150     return -1
151 }
152
153 tracepoint_change_loc_1 "ftrace"