Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 2013-2016 Free Software Foundation, Inc. |
aaff8d73 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 actions.c | |
19 | ||
20 | if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug}] } { | |
21 | return -1 | |
22 | } | |
23 | ||
24 | if ![runto_main] { | |
bc6c7af4 | 25 | fail "can't run to main to check for trace support" |
aaff8d73 YQ |
26 | return -1 |
27 | } | |
28 | ||
29 | if ![gdb_target_supports_trace] { | |
bc6c7af4 | 30 | unsupported "current target does not support trace" |
aaff8d73 YQ |
31 | return -1 |
32 | } | |
33 | ||
34 | gdb_exit | |
35 | ||
36 | load_lib mi-support.exp | |
37 | set MIFLAGS "-i=mi" | |
38 | ||
39 | if [mi_gdb_start] { | |
40 | return | |
41 | } | |
42 | mi_run_to_main | |
43 | ||
44 | mi_gdb_test "-break-insert end" \ | |
45 | "\\^done,bkpt=\{number=\"${decimal}\",type=\"breakpoint\".*\"\}" \ | |
46 | "insert tracepoint on end" | |
47 | mi_gdb_test "-break-insert -a gdb_recursion_test" \ | |
48 | "\\^done,bkpt=\{number=\"${decimal}\",type=\"tracepoint\".*\"\}" \ | |
49 | "insert tracepoint on gdb_recursion_test" | |
50 | ||
51 | mi_gdb_test "-trace-define-variable \$tsv 1" {.*\^done} \ | |
52 | "-trace-define-variable" | |
53 | ||
aaff8d73 YQ |
54 | mi_gdb_test "-break-commands 3 \"collect gdb_char_test\" \"collect gdb_union1_test\" \"collect gdb_struct1_test.l\" \"collect gdb_arr_test\[0\]\" \"collect $${pcreg}\" \"teval \$tsv += 1\" \"collect \$tsv\" \"end\" " \ |
55 | {\^done} "set action" | |
56 | ||
57 | mi_gdb_test "-break-insert -a gdb_c_test" \ | |
58 | "\\^done,bkpt=\{number=\"${decimal}\",type=\"tracepoint\".*\"\}" \ | |
59 | "insert tracepoint on gdb_c_test" | |
60 | ||
61 | # Define an action. | |
62 | # Collect a global variable to be sure no registers are collected | |
63 | # except PC. | |
64 | mi_gdb_test "-break-commands 4 \"collect gdb_char_test\" \"end\" " \ | |
65 | {\^done} "set action on tracepoint 4" | |
66 | ||
67 | mi_gdb_test "-trace-start" {.*\^done} "trace start" | |
68 | mi_send_resuming_command "exec-continue" "continuing to end" | |
69 | mi_expect_stop \ | |
70 | "breakpoint-hit" "end" ".*" ".*" ".*" {"" "disp=\"keep\""} \ | |
71 | "stop at end" | |
72 | mi_gdb_test "-trace-stop" {.*\^done,stop-reason=.*} "trace stop" | |
73 | ||
74 | # Save trace frames to tfile. | |
75 | set tracefile [standard_output_file ${testfile}] | |
76 | mi_gdb_test "-trace-save ${tracefile}.tf" ".*\\^done" \ | |
77 | "save tfile trace file" | |
78 | # Save trace frames to ctf. | |
79 | mi_gdb_test "-trace-save -ctf ${tracefile}.ctf" ".*\\^done" \ | |
80 | "save ctf trace file" | |
81 | ||
82 | # Test the MI command '-trace-frame-collected' with DATA_SOURCE as | |
83 | # trace data source. | |
84 | ||
85 | proc test_trace_frame_collected { data_source } { | |
86 | global decimal hex | |
87 | global mi_gdb_prompt | |
88 | ||
89 | with_test_prefix "$data_source" { | |
90 | mi_gdb_test "-trace-find frame-number 0" \ | |
91 | ".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"0\",frame=\{.*" \ | |
92 | "-trace-find frame-number 0" | |
93 | ||
a4105d04 MK |
94 | set reg_pattern "\{number=\"$decimal\",value=\"$hex\"\}" |
95 | ||
aaff8d73 YQ |
96 | # Test MI command '-trace-frame-collected' dumps only |
97 | # collected registers. | |
0646e07d PA |
98 | |
99 | # While the tracepoint has no explicit action that causes | |
100 | # collection of registers other than the PC, some | |
101 | # architectures manage to collect or guess more than that. | |
a4105d04 | 102 | if { [istarget "s390*-*-*"] } { |
0646e07d PA |
103 | # On s390 PC is a pseudo-register - collecting it also |
104 | # collects the underlying PSWA register. | |
a4105d04 MK |
105 | if { "$data_source" != "tfile" } { |
106 | set reg_pattern "$reg_pattern,$reg_pattern" | |
107 | } else { | |
108 | # For tfile, PSWM and CC are also guessed. | |
109 | set reg_pattern "$reg_pattern,$reg_pattern,$reg_pattern,$reg_pattern" | |
110 | } | |
0646e07d PA |
111 | } elseif {[is_amd64_regs_target] && [is_ilp32_target]} { |
112 | # x32. While on the 64-bit ABI gdb only exposes 64-bit | |
113 | # $pc/$rip, on x32, GDB exposes 32-bit $eip as well, as a | |
114 | # pseudo-register. Thus, collecting $pc/$rip | |
115 | # automatically always collects $eip as well. | |
116 | set reg_pattern "$reg_pattern,$reg_pattern" | |
a4105d04 MK |
117 | } |
118 | ||
aaff8d73 | 119 | mi_gdb_test "-trace-frame-collected" \ |
a4105d04 | 120 | "\\^done,explicit-variables=\\\[\{name=\"gdb_char_test\",value=\".*\"\}\\\],computed-expressions=\\\[\\\],registers=\\\[$reg_pattern\\\],tvars=\\\[\\\],memory=\\\[\{address=\"$hex\",length=\"1\"\}\\\]"\ |
aaff8d73 YQ |
121 | "-trace-frame-collected (register)" |
122 | ||
123 | mi_gdb_test "-trace-find frame-number 1" \ | |
124 | ".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"1\",frame=\{.*" \ | |
125 | "-trace-find frame-number 1" | |
126 | ||
127 | # Test MI command '-trace-frame-collected' | |
128 | mi_gdb_test "-trace-frame-collected" \ | |
129 | "\\^done,explicit-variables=\\\[\{name=\"gdb_char_test\",value=\".*\"\},\{name=\"gdb_union1_test\",value=\".*\"\}\\\],computed-expressions=\\\[\{name=\"gdb_struct1_test\.l\",.*\},\{name=\"gdb_arr_test\\\[0\\\]\",.*\}\\\],registers=\\\[.*\\\],tvars=\\\[\{name=\"\\\$tsv\",current=\"2\"\}\\\],memory=\\\[\{address=\"$hex\",length=\"1\"\},.*\\\]"\ | |
130 | "-trace-frame-collected" | |
131 | mi_gdb_test "-trace-frame-collected --var-print-values 2 --comp-print-values --simple-values --registers-format x --memory-contents" \ | |
132 | "\\^done,explicit-variables=\\\[\{name=\"gdb_char_test\",type=\"char\",value=\".*\"\},\{name=\"gdb_union1_test\",type=\"union GDB_UNION_TEST\"\}\\\],computed-expressions=\\\[.*\\\],registers=\\\[.*\\\],tvars=\\\[\{name=\"\\\$tsv\",current=\"2\"\}\\\],memory=\\\[\{address=\"$hex\",length=\"1\",contents=\".*\"\},.*\\\]" \ | |
133 | "-trace-frame-collected --var-print-values 2 --comp-print-values --simple-values --registers-format x --memory-contents" | |
134 | ||
135 | mi_gdb_test "-trace-find none" ".*\\^done,found=\"0\".*" \ | |
136 | "-trace-find none" | |
137 | } | |
138 | } | |
139 | ||
140 | test_trace_frame_collected "live" | |
141 | ||
142 | # Change target to ctf if GDB supports it. | |
143 | set msg "-target-select ctf" | |
144 | send_gdb "-target-select ctf ${tracefile}.ctf\n" | |
145 | gdb_expect { | |
146 | -re ".*\\^connected.*${mi_gdb_prompt}$" { | |
147 | # GDB supports ctf, do the test. | |
148 | test_trace_frame_collected "ctf" | |
149 | } | |
150 | -re ".*\\^error,msg=\"Undefined target command.*${mi_gdb_prompt}$" { | |
151 | # GDB doesn't support ctf, skip the test. | |
152 | unsupported "gdb does not support ctf target" | |
153 | } | |
154 | -re ".*$mi_gdb_prompt$" { | |
155 | fail "$msg" | |
156 | } | |
157 | timeout { | |
158 | fail "$msg (timeout)" | |
159 | } | |
160 | } | |
161 | ||
162 | # Change target to tfile. | |
163 | mi_gdb_test "-target-select tfile ${tracefile}.tf" ".*\\^connected.*" \ | |
164 | "-target-select tfile" | |
165 | test_trace_frame_collected "tfile" | |
166 | ||
167 | mi_gdb_exit |