Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / testsuite / gdb.trace / read-memory.exp
blob6c9564feb6233e38ef4918063098e5d5f970a1e8
1 # Copyright 2013-2022 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"
18 standard_testfile
20 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug nopie}]} {
21 return -1
24 if ![runto_main] {
25 return -1
28 if ![gdb_target_supports_trace] {
29 unsupported "target does not support trace"
30 return -1
33 # Set tracepoints, start tracing and collect data.
35 proc set_tracepoint_and_collect { } {
36 global testfile srcfile
38 # Start with a fresh gdb.
39 clean_restart ${testfile}
40 if ![runto_main] {
41 return -1
43 gdb_breakpoint "end" qualified
44 gdb_test "trace start" "Tracepoint \[0-9\] at .*"
45 gdb_trace_setactions "set action for tracepoint" "" \
46 "collect testglob" "^$" \
47 "collect constglob" "^$"
49 gdb_test_no_output "tstart"
50 gdb_test "continue" ".*Breakpoint.* end .*at.*$srcfile.*" \
51 "continue to end"
52 gdb_test_no_output "tstop"
55 with_test_prefix "live" {
56 set_tracepoint_and_collect
58 gdb_test "print testglob" " = 2"
59 gdb_test "print testglob_not_collected" " = 12"
60 gdb_test "print constglob" " = 10000"
61 gdb_test "print constglob_not_collected" " = 100"
64 with_test_prefix "live target tfind" {
65 gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \
66 "tfind 0"
67 gdb_test "print testglob" " = 1"
68 gdb_test "print testglob_not_collected" " = <unavailable>"
69 gdb_test "print constglob" " = 10000"
70 gdb_test "print constglob_not_collected" " = 100"
71 gdb_test "tfind" "Target failed to find requested trace frame." \
72 "tfind does not find a second frame"
75 # Save trace frames to trace file.
76 set tracefile [standard_output_file ${testfile}]
77 gdb_test "tsave ${tracefile}.tfile" \
78 "Trace data saved to file '${tracefile}.tfile'.*" \
79 "save tfile trace"
81 # Test read memory when changing target from remote to ${target}.
83 proc test_from_remote { target } {
84 global gdb_prompt testfile
85 global tracefile
87 with_test_prefix "remote to ${target}" {
88 set_tracepoint_and_collect
90 # Change target to ${target}.
91 set test "change target"
92 gdb_test_multiple "target ${target} ${tracefile}.${target}" "$test" {
93 -re "A program is being debugged already. Kill it. .y or n. " {
94 send_gdb "y\n"
95 exp_continue
97 -re "$gdb_prompt $" {
98 pass "$test"
102 with_test_prefix "w/o setting traceframe" {
103 gdb_test "print testglob" " = <unavailable>"
104 gdb_test "print testglob_not_collected" " = <unavailable>"
105 gdb_test "print constglob" " = 10000"
106 gdb_test "print constglob_not_collected" " = 100"
108 with_test_prefix "w/ setting traceframe" {
109 gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \
110 "tfind 0"
111 gdb_test "print testglob" " = 1"
112 gdb_test "print testglob_not_collected" " = <unavailable>"
113 gdb_test "print constglob" " = 10000"
114 gdb_test "print constglob_not_collected" " = 100"
115 gdb_test "tfind" "Target failed to find requested trace frame." \
116 "tfind does not find a second frame"
121 test_from_remote "tfile"
123 # Test read memory when changing target from exec to ${target}
125 proc teset_from_exec { target } {
126 global srcdir subdir binfile testfile
127 global tracefile
129 # Restart GDB and read the trace data in ${target} target.
130 gdb_exit
131 gdb_start
132 gdb_reinitialize_dir $srcdir/$subdir
133 gdb_file_cmd $binfile
135 gdb_test "target ${target} ${tracefile}.${target}" ".*" \
136 "change to ${target} target"
138 with_test_prefix "exec to ${target} w/o setting traceframe" {
139 gdb_test "print testglob" " = <unavailable>"
140 gdb_test "print testglob_not_collected" " = <unavailable>"
141 gdb_test "print constglob" " = 10000"
142 gdb_test "print constglob_not_collected" " = 100"
145 with_test_prefix "exec to ${target} w/ setting traceframe" {
146 gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \
147 "tfind 0"
148 gdb_test "print testglob" " = 1"
149 gdb_test "print testglob_not_collected" " = <unavailable>"
150 gdb_test "print constglob" " = 10000"
151 gdb_test "print constglob_not_collected" " = 100"
152 gdb_test "tfind" "Target failed to find requested trace frame." \
153 "tfind does not find a second frame"
157 teset_from_exec "tfile"