Update copyright year range in all GDB files.
[external/binutils.git] / gdb / testsuite / gdb.trace / read-memory.exp
1 #   Copyright 2013-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 standard_testfile
19
20 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
21     return -1
22 }
23
24 if ![runto_main] {
25     fail "can't run to main to check for trace support"
26     return -1
27 }
28
29 if ![gdb_target_supports_trace] {
30     unsupported "target does not support trace"
31     return -1
32 }
33
34 # Set tracepoints, start tracing and collect data.
35
36 proc set_tracepoint_and_collect { } {
37     global testfile srcfile
38
39     # Start with a fresh gdb.
40     clean_restart ${testfile}
41     if ![runto_main] {
42         fail "can't run to main"
43         return -1
44     }
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" "^$"
50
51     gdb_test_no_output "tstart"
52     gdb_test "continue" ".*Breakpoint.* end .*at.*$srcfile.*" \
53         "continue to end"
54     gdb_test_no_output "tstop"
55 }
56
57 with_test_prefix "live" {
58     set_tracepoint_and_collect
59
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"
64 }
65
66 with_test_prefix "live target tfind" {
67     gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \
68         "tfind 0"
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"
75 }
76
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'.*" \
81     "save tfile trace"
82
83 # Test read memory when changing target from remote to ${target}.
84
85 proc test_from_remote { target } {
86     global gdb_prompt testfile
87     global tracefile
88
89     with_test_prefix "remote to ${target}" {
90         set_tracepoint_and_collect
91
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. " {
96                 send_gdb "y\n"
97                 exp_continue
98             }
99             -re "$gdb_prompt $" {
100                 pass "$test"
101             }
102         }
103
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"
109         }
110         with_test_prefix "w/ setting traceframe" {
111             gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \
112                 "tfind 0"
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"
119         }
120     }
121 }
122
123 test_from_remote "tfile"
124
125 # Test read memory when changing target from exec to ${target}
126
127 proc teset_from_exec { target } {
128     global srcdir subdir binfile testfile
129     global tracefile
130
131     # Restart GDB and read the trace data in ${target} target.
132     gdb_exit
133     gdb_start
134     gdb_reinitialize_dir $srcdir/$subdir
135     gdb_file_cmd $binfile
136
137     gdb_test "target ${target} ${tracefile}.${target}" ".*" \
138         "change to ${target} target"
139
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"
145     }
146
147     with_test_prefix "exec to ${target} w/ setting traceframe" {
148         gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \
149             "tfind 0"
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"
156     }
157 }
158
159 teset_from_exec "tfile"