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