]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2013-2024 Free Software Foundation, Inc. |
73c1d57e YQ |
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 | ||
ba22ff86 | 20 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug nopie}]} { |
73c1d57e YQ |
21 | return -1 |
22 | } | |
23 | ||
24 | if ![runto_main] { | |
73c1d57e YQ |
25 | return -1 |
26 | } | |
27 | ||
28 | if ![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 | ||
35 | proc set_tracepoint_and_collect { } { | |
36 | global testfile srcfile | |
37 | ||
38 | # Start with a fresh gdb. | |
39 | clean_restart ${testfile} | |
40 | if ![runto_main] { | |
73c1d57e YQ |
41 | return -1 |
42 | } | |
194ed413 | 43 | gdb_breakpoint "end" qualified |
73c1d57e YQ |
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 | ||
55 | with_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 | ||
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" | |
73 | } | |
74 | ||
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" | |
80 | ||
81 | # Test read memory when changing target from remote to ${target}. | |
82 | ||
83 | proc 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" { | |
1527aea8 YQ |
103 | gdb_test "print testglob" " = <unavailable>" |
104 | gdb_test "print testglob_not_collected" " = <unavailable>" | |
73c1d57e YQ |
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 | ||
121 | test_from_remote "tfile" | |
122 | ||
123 | # Test read memory when changing target from exec to ${target} | |
124 | ||
125 | proc 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. | |
a7e727ae | 130 | clean_restart |
73c1d57e YQ |
131 | gdb_file_cmd $binfile |
132 | ||
133 | gdb_test "target ${target} ${tracefile}.${target}" ".*" \ | |
134 | "change to ${target} target" | |
135 | ||
136 | with_test_prefix "exec to ${target} w/o setting traceframe" { | |
1527aea8 YQ |
137 | gdb_test "print testglob" " = <unavailable>" |
138 | gdb_test "print testglob_not_collected" " = <unavailable>" | |
73c1d57e YQ |
139 | gdb_test "print constglob" " = 10000" |
140 | gdb_test "print constglob_not_collected" " = 100" | |
141 | } | |
142 | ||
143 | with_test_prefix "exec to ${target} w/ setting traceframe" { | |
144 | gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \ | |
145 | "tfind 0" | |
146 | gdb_test "print testglob" " = 1" | |
147 | gdb_test "print testglob_not_collected" " = <unavailable>" | |
148 | gdb_test "print constglob" " = 10000" | |
149 | gdb_test "print constglob_not_collected" " = 100" | |
150 | gdb_test "tfind" "Target failed to find requested trace frame." \ | |
151 | "tfind does not find a second frame" | |
152 | } | |
153 | } | |
154 | ||
155 | teset_from_exec "tfile" |