ecd36d2d9bdca63754908e9c915dbdad07a6453c
[external/binutils.git] / gdb / testsuite / gdb.trace / tspeed.exp
1 # Copyright 2011-2018 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
16 load_lib "trace-support.exp"
17
18 standard_testfile
19 set executable $testfile
20
21 set ipalib [get_in_proc_agent]
22 gdb_load_shlib $ipalib
23
24 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
25           executable [concat {debug nowarnings c} shlib=$ipalib]] != "" } {
26     untested "failed to compile"
27     return -1
28 }
29
30 # Typically we need a little extra time for this test.
31 set timeout 180
32
33 set ws "\[\r\n\t \]+"
34 set cr "\[\r\n\]+"
35
36 #
37 # Utility procs
38 #
39
40 proc prepare_for_trace_test {} {
41     global executable
42
43     clean_restart $executable
44
45     runto_main
46
47     set testline [gdb_get_line_number "set pre-run breakpoint here"]
48
49     gdb_test "break $testline" ".*" ""
50
51     set testline [gdb_get_line_number "set post-run breakpoint here"]
52
53     gdb_test "break $testline" ".*" ""
54 }
55
56 proc run_trace_experiment {} {
57
58     gdb_test "continue" \
59         ".*Breakpoint \[0-9\]+, main .*" \
60         "advance to trace begin"
61
62     gdb_test_no_output "tstart" "start trace experiment"
63
64     gdb_test "continue" \
65         ".*Breakpoint \[0-9\]+, main .*" \
66         "advance through tracing"
67
68     gdb_test "tstatus" ".*Trace .*" "check on trace status"
69
70     gdb_test "tstop" "" ""
71 }
72
73 proc gdb_slow_trace_speed_test { } {
74
75     gdb_delete_tracepoints
76
77     gdb_test "print iters = init_iters" ".* = .*"
78
79     set testline [gdb_get_line_number "set tracepoint here"]
80
81     gdb_test "trace $testline if (globfoo != 12 && globfoo2 == 45)" \
82         "Tracepoint \[0-9\]+ at .*" \
83         "set slow tracepoint"
84
85     # Begin the test.
86     run_trace_experiment
87 }
88
89 proc gdb_fast_trace_speed_test { } {
90     global gdb_prompt
91
92     gdb_delete_tracepoints
93
94     gdb_test "print iters = init_iters" ".* = .*"
95
96     set run_ftrace 0
97
98     set testline [gdb_get_line_number "set tracepoint here"]
99
100     gdb_test_multiple "ftrace $testline if (globfoo != 12 && globfoo2 == 45)" \
101         "set conditional fast tracepoint" {
102             -re "Fast tracepoint \[0-9\]+ at .*\r\n$gdb_prompt $" {
103                 pass "set conditional fast tracepoint, done"
104                 set run_ftrace 1
105             }
106             -re "May not have a fast tracepoint at .*\r\n$gdb_prompt $" {
107                 pass "set conditional fast tracepoint, not allowed at line"
108             }
109         }
110
111     # If the fast tracepoint couldn't be set, don't bother with the run.
112     if { $run_ftrace == 1 } then {
113
114         # Begin the test.
115         run_trace_experiment
116     }
117 }
118
119 proc gdb_trace_collection_test {} {
120
121     prepare_for_trace_test
122
123     gdb_slow_trace_speed_test
124
125     gdb_fast_trace_speed_test
126 }
127
128 clean_restart $executable
129 runto_main
130
131 if { ![gdb_target_supports_trace] } then {
132     unsupported "current target does not support trace"
133     return 1
134 }
135
136 # Body of test encased in a proc so we can return prematurely.
137 gdb_trace_collection_test