1 # Copyright 2013-2020 Free Software Foundation, Inc.
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.
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.
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/>.
16 load_lib "trace-support.exp"
20 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug nopie}]} {
25 fail "can't run to main to check for trace support"
29 if ![gdb_target_supports_trace] {
30 unsupported "target does not support trace"
34 # Set tracepoints, start tracing and collect data.
36 proc set_tracepoint_and_collect { } {
37 global testfile srcfile
39 # Start with a fresh gdb.
40 clean_restart ${testfile}
42 fail "can't run to main"
45 gdb_breakpoint "end" qualified
46 gdb_test "trace start" "Tracepoint \[0-9\] at .*"
47 gdb_trace_setactions "set action for tracepoint" "" \
48 "collect testglob" "^$" \
49 "collect constglob" "^$"
51 gdb_test_no_output "tstart"
52 gdb_test "continue" ".*Breakpoint.* end .*at.*$srcfile.*" \
54 gdb_test_no_output "tstop"
57 with_test_prefix "live" {
58 set_tracepoint_and_collect
60 gdb_test "print testglob" " = 2"
61 gdb_test "print testglob_not_collected" " = 12"
62 gdb_test "print constglob" " = 10000"
63 gdb_test "print constglob_not_collected" " = 100"
66 with_test_prefix "live target tfind" {
67 gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \
69 gdb_test "print testglob" " = 1"
70 gdb_test "print testglob_not_collected" " = <unavailable>"
71 gdb_test "print constglob" " = 10000"
72 gdb_test "print constglob_not_collected" " = 100"
73 gdb_test "tfind" "Target failed to find requested trace frame." \
74 "tfind does not find a second frame"
77 # Save trace frames to trace file.
78 set tracefile [standard_output_file ${testfile}]
79 gdb_test "tsave ${tracefile}.tfile" \
80 "Trace data saved to file '${tracefile}.tfile'.*" \
83 # Test read memory when changing target from remote to ${target}.
85 proc test_from_remote { target } {
86 global gdb_prompt testfile
89 with_test_prefix "remote to ${target}" {
90 set_tracepoint_and_collect
92 # Change target to ${target}.
93 set test "change target"
94 gdb_test_multiple "target ${target} ${tracefile}.${target}" "$test" {
95 -re "A program is being debugged already. Kill it. .y or n. " {
104 with_test_prefix "w/o setting traceframe" {
105 gdb_test "print testglob" " = <unavailable>"
106 gdb_test "print testglob_not_collected" " = <unavailable>"
107 gdb_test "print constglob" " = 10000"
108 gdb_test "print constglob_not_collected" " = 100"
110 with_test_prefix "w/ setting traceframe" {
111 gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \
113 gdb_test "print testglob" " = 1"
114 gdb_test "print testglob_not_collected" " = <unavailable>"
115 gdb_test "print constglob" " = 10000"
116 gdb_test "print constglob_not_collected" " = 100"
117 gdb_test "tfind" "Target failed to find requested trace frame." \
118 "tfind does not find a second frame"
123 test_from_remote "tfile"
125 # Test read memory when changing target from exec to ${target}
127 proc teset_from_exec { target } {
128 global srcdir subdir binfile testfile
131 # Restart GDB and read the trace data in ${target} target.
134 gdb_reinitialize_dir $srcdir/$subdir
135 gdb_file_cmd $binfile
137 gdb_test "target ${target} ${tracefile}.${target}" ".*" \
138 "change to ${target} target"
140 with_test_prefix "exec to ${target} w/o setting traceframe" {
141 gdb_test "print testglob" " = <unavailable>"
142 gdb_test "print testglob_not_collected" " = <unavailable>"
143 gdb_test "print constglob" " = 10000"
144 gdb_test "print constglob_not_collected" " = 100"
147 with_test_prefix "exec to ${target} w/ setting traceframe" {
148 gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \
150 gdb_test "print testglob" " = 1"
151 gdb_test "print testglob_not_collected" " = <unavailable>"
152 gdb_test "print constglob" " = 10000"
153 gdb_test "print constglob_not_collected" " = 100"
154 gdb_test "tfind" "Target failed to find requested trace frame." \
155 "tfind does not find a second frame"
159 teset_from_exec "tfile"