1 # Copyright 2015-2024 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 require allow_shlib_tests 18 19 standard_testfile 20 set executable $testfile 21 set expfile $testfile.exp 22 23 # Some targets have leading underscores on assembly symbols. 24 set options [list debug [gdb_target_symbol_prefix_flags]] 25 26 # Check that the target supports trace. 27 require gdb_trace_common_supports_arch 28 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } { 29 untested "failed to compile" 30 return -1 31 } 32 33 clean_restart ${testfile} 34 35 if ![runto_main] { 36 return -1 37 } 38 39 if ![gdb_target_supports_trace] { 40 unsupported "target does not support trace" 41 return -1 42 } 43 44 # Compile the test case with the in-process agent library. 45 require allow_in_proc_agent 46 set libipa [get_in_proc_agent] 47 gdb_load_shlib $libipa 48 49 lappend options shlib=$libipa 50 51 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } { 52 untested "failed to compile with in-process agent library" 53 return -1 54 } 55 56 # This test makes sure that disabling and enabling tracepoints works 57 # correctly. TRACEPOINT_CMD is the command used to set tracepoints 58 # (e.g. trace or ftrace). 59 60 proc test_tracepoint_enable_disable { tracepoint_cmd } { 61 with_test_prefix "test_tracepoint_enable_disable $tracepoint_cmd" { 62 global executable 63 clean_restart ${executable} 64 65 set expected 0 66 67 if ![runto_main] { 68 return -1 69 } 70 71 gdb_test "$tracepoint_cmd point_a" "(Tracepoint|Fast tracepoint) 2.*" 72 gdb_test "$tracepoint_cmd point_b" "(Tracepoint|Fast tracepoint) 3.*" 73 gdb_breakpoint "break_here" 74 gdb_test_no_output "tstart" 75 76 # Test that tracepoints start enabled 77 with_test_prefix "start" { 78 gdb_continue "break_here" 79 incr expected 2 80 gdb_test "tstatus" "Collected $expected trace frames.*" 81 } 82 83 # Test that disabling works 84 with_test_prefix "disable #1" { 85 gdb_test_no_output "disable 2" 86 gdb_continue "break_here" 87 incr expected 1 88 gdb_test "tstatus" "Collected $expected trace frames.*" 89 } 90 91 with_test_prefix "disable #2" { 92 gdb_test_no_output "disable 3" 93 gdb_continue "break_here" 94 gdb_test "tstatus" "Collected $expected trace frames.*" 95 } 96 97 # Test that disabling an already disabled tracepoint works 98 with_test_prefix "disable #3" { 99 gdb_test_no_output "disable 2" 100 gdb_continue "break_here" 101 gdb_test "tstatus" "Collected $expected trace frames.*" 102 } 103 104 # Test that enabling works 105 with_test_prefix "enable #1" { 106 gdb_test_no_output "enable 2" 107 gdb_continue "break_here" 108 incr expected 1 109 gdb_test "tstatus" "Collected $expected trace frames.*" 110 } 111 112 with_test_prefix "enable #2" { 113 gdb_test_no_output "enable 3" 114 gdb_continue "break_here" 115 incr expected 2 116 gdb_test "tstatus" "Collected $expected trace frames.*" 117 } 118 119 # Test that enabling an already enabled tracepoint works 120 with_test_prefix "enable #3" { 121 gdb_test_no_output "enable 3" 122 gdb_continue "break_here" 123 incr expected 2 124 gdb_test "tstatus" "Collected $expected trace frames.*" 125 } 126 } 127 } 128 129 test_tracepoint_enable_disable trace 130 test_tracepoint_enable_disable ftrace 131