xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.trace/read-memory.exp (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1#   Copyright 2013-2023 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
16load_lib "trace-support.exp"
17
18standard_testfile
19
20if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug nopie}]} {
21    return -1
22}
23
24if ![runto_main] {
25    return -1
26}
27
28if ![gdb_target_supports_trace] {
29    unsupported "target does not support trace"
30    return -1
31}
32
33# Set tracepoints, start tracing and collect data.
34
35proc set_tracepoint_and_collect { } {
36    global testfile srcfile
37
38    # Start with a fresh gdb.
39    clean_restart ${testfile}
40    if ![runto_main] {
41	return -1
42    }
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" "^$"
48
49    gdb_test_no_output "tstart"
50    gdb_test "continue" ".*Breakpoint.* end .*at.*$srcfile.*" \
51	"continue to end"
52    gdb_test_no_output "tstop"
53}
54
55with_test_prefix "live" {
56    set_tracepoint_and_collect
57
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"
62}
63
64with_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"
73}
74
75# Save trace frames to trace file.
76set tracefile [standard_output_file ${testfile}]
77gdb_test "tsave ${tracefile}.tfile" \
78    "Trace data saved to file '${tracefile}.tfile'.*" \
79    "save tfile trace"
80
81# Test read memory when changing target from remote to ${target}.
82
83proc test_from_remote { target } {
84    global gdb_prompt testfile
85    global tracefile
86
87    with_test_prefix "remote to ${target}" {
88	set_tracepoint_and_collect
89
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
96	    }
97	    -re "$gdb_prompt $" {
98		pass "$test"
99	    }
100	}
101
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"
107	}
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"
117	}
118    }
119}
120
121test_from_remote "tfile"
122
123# Test read memory when changing target from exec to ${target}
124
125proc teset_from_exec { target } {
126    global srcdir subdir binfile testfile
127    global tracefile
128
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
134
135    gdb_test "target ${target} ${tracefile}.${target}" ".*" \
136	"change to ${target} target"
137
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"
143    }
144
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"
154    }
155}
156
157teset_from_exec "tfile"
158