Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2013-2020 Free Software Foundation, Inc. |
8cb5cc78 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 trace-unavailable.c | |
19 | ||
ba22ff86 | 20 | if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug nopie}] } { |
8cb5cc78 YQ |
21 | return -1 |
22 | } | |
23 | ||
24 | if ![runto_main] { | |
bc6c7af4 | 25 | fail "can't run to main to check for trace support" |
8cb5cc78 YQ |
26 | return -1 |
27 | } | |
28 | ||
29 | if ![gdb_target_supports_trace] { | |
bc6c7af4 | 30 | unsupported "current target does not support trace" |
8cb5cc78 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 marker" \ | |
45 | "\\^done,bkpt=\{number=\"${decimal}\",type=\"breakpoint\".*\"\}" \ | |
46 | "insert tracepoint on marker" | |
47 | mi_gdb_test "-break-insert -a bar" \ | |
48 | "\\^done,bkpt=\{number=\"${decimal}\",type=\"tracepoint\".*\"\}" \ | |
49 | "insert tracepoint on bar" | |
50 | ||
51 | # Define an action. | |
52 | mi_gdb_test "-break-commands 3 \"collect array\" \"collect j\" \"end\" " \ | |
53 | {\^done} "set action" | |
54 | ||
c898adb7 YQ |
55 | mi_gdb_test "-break-insert -a foo" \ |
56 | "\\^done,bkpt=\{number=\"${decimal}\",type=\"tracepoint\".*\"\}" \ | |
57 | "insert tracepoint on foo" | |
58 | ||
59 | # Collect 'main' to make sure no registers are collected except PC. | |
60 | mi_gdb_test "-break-commands 4 \"collect main\" \"end\" " \ | |
61 | {\^done} "set action on tracepoint 4" | |
62 | ||
8cb5cc78 YQ |
63 | mi_gdb_test "-trace-start" {.*\^done} "trace start" |
64 | mi_send_resuming_command "exec-continue" "continuing to marker" | |
65 | mi_expect_stop \ | |
66 | "breakpoint-hit" "marker" ".*" ".*" ".*" {"" "disp=\"keep\""} \ | |
67 | "stop at marker" | |
68 | mi_gdb_test "-trace-stop" {.*} "trace stop" | |
69 | ||
70 | # Save trace frames to tfile. | |
71 | set tracefile [standard_output_file ${testfile}] | |
72 | mi_gdb_test "-trace-save ${tracefile}.tf" ".*\\^done" \ | |
73 | "save tfile trace file" | |
74 | # Save trace frames to ctf. | |
75 | mi_gdb_test "-trace-save -ctf ${tracefile}.ctf" ".*\\^done" \ | |
76 | "save ctf trace file" | |
77 | ||
8cb5cc78 YQ |
78 | proc test_trace_unavailable { data_source } { |
79 | global decimal | |
80 | ||
81 | with_test_prefix "$data_source" { | |
82 | ||
83 | # Test MI commands '-stack-list-locals', '-stack-list-arguments', | |
84 | # and '-stack-list-variables'. | |
85 | mi_gdb_test "-trace-find frame-number 0" \ | |
86 | ".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"0\",frame=\{.*" \ | |
87 | "-trace-find frame-number 0" | |
88 | ||
82a0a75f YQ |
89 | # The "print entry-values" option shouldn't affect the output of |
90 | # '-stack-list-locals'. | |
91 | foreach entry_values { no only preferred if-needed both compact default } { | |
92 | mi_gdb_test "-gdb-set print entry-values $entry_values" {\^done} "" | |
93 | ||
94 | with_test_prefix "$entry_values" { | |
95 | # Test MI command '-stack-list-locals'. | |
96 | mi_gdb_test "-stack-list-locals --simple-values" \ | |
97 | ".*\\^done,locals=\\\[\{name=\"array\",type=\"unsigned char \\\[2\\\]\"\},\{name=\"i\",type=\"int\",value=\"<unavailable>\"\}\\\]" \ | |
98 | "-stack-list-locals --simple-values" | |
99 | } | |
100 | } | |
101 | ||
102 | mi_gdb_test "-gdb-set print entry-values no" {\^done} \ | |
103 | "-gdb-set print entry-values no" | |
104 | ||
8cb5cc78 YQ |
105 | # Test MI command '-stack-list-locals'. |
106 | mi_gdb_test "-stack-list-locals --simple-values" \ | |
107 | ".*\\^done,locals=\\\[\{name=\"array\",type=\"unsigned char \\\[2\\\]\"\},\{name=\"i\",type=\"int\",value=\"<unavailable>\"\}\\\]" \ | |
108 | "-stack-list-locals --simple-values" | |
6211c335 YQ |
109 | mi_gdb_test "-stack-list-locals --skip-unavailable --simple-values" \ |
110 | ".*\\^done,locals=\\\[\{name=\"array\",type=\"unsigned char \\\[2\\\]\"\}\\\]" \ | |
111 | "-stack-list-locals --skip-unavailable --simple-values" | |
8cb5cc78 YQ |
112 | |
113 | # Test MI command '-stack-list-arguments'. | |
114 | mi_gdb_test "-stack-list-arguments --simple-values" \ | |
115 | ".*\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"j\",type=\"int\",value=\"4\"\},\{name=\"s\",type=\"char \\\*\",value=\"<unavailable>\"\}\\\]\},.*\}.*" \ | |
116 | "-stack-list-arguments --simple-values" | |
6211c335 YQ |
117 | mi_gdb_test "-stack-list-arguments --skip-unavailable --simple-values" \ |
118 | ".*\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"j\",type=\"int\",value=\"4\"\}\\\]\},.*\}.*" \ | |
119 | "-stack-list-arguments --skip-unavailable --simple-values" | |
8cb5cc78 YQ |
120 | |
121 | # Test MI command '-stack-list-variables'. | |
122 | mi_gdb_test "-stack-list-variables --simple-values" \ | |
123 | ".*\\^done,variables=\\\[\{name=\"j\",arg=\"1\",type=\"int\",value=\"4\"\},\{name=\"s\",arg=\"1\",type=\"char \\\*\",value=\"<unavailable>\"\},\{name=\"array\",type=\"unsigned char \\\[2\\\]\"\},\{name=\"i\",type=\"int\",value=\"<unavailable>\"\}\\\]" \ | |
124 | "-stack-list-variables --simple-values" | |
6211c335 YQ |
125 | mi_gdb_test "-stack-list-variables --skip-unavailable --simple-values" \ |
126 | ".*\\^done,variables=\\\[\{name=\"j\",arg=\"1\",type=\"int\",value=\"4\"\},\{name=\"array\",type=\"unsigned char \\\[2\\\]\"\}\\\]" \ | |
127 | "-stack-list-variables --skip-unavailable --simple-values" | |
8cb5cc78 | 128 | |
c898adb7 YQ |
129 | mi_gdb_test "-trace-find frame-number 1" \ |
130 | ".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"1\",frame=\{.*" \ | |
131 | "-trace-find frame-number 1" | |
132 | ||
a4105d04 MK |
133 | set pcnum -1 |
134 | set gpr0num -1 | |
c898adb7 YQ |
135 | if [is_amd64_regs_target] { |
136 | set pcnum 16 | |
a4105d04 | 137 | set gpr0num 0 |
c898adb7 YQ |
138 | } elseif [is_x86_like_target] { |
139 | set pcnum 8 | |
a4105d04 | 140 | set gpr0num 0 |
7890fb45 PL |
141 | } elseif [is_aarch64_target] { |
142 | set pcnum 32 | |
a4105d04 | 143 | set gpr0num 0 |
b04fd3be MK |
144 | } elseif [istarget "powerpc*-*-*"] { |
145 | set pcnum 64 | |
a4105d04 MK |
146 | set gpr0num 0 |
147 | } elseif { [istarget "s390*-*-*"] } { | |
148 | # Strictly speaking, this is PSWA, not PC. | |
149 | set pcnum 1 | |
150 | set gpr0num 2 | |
c898adb7 YQ |
151 | } else { |
152 | # Other ports support tracepoint should define the number | |
153 | # of its own pc register. | |
154 | } | |
155 | ||
a4105d04 | 156 | if { $pcnum != -1 } { |
c898adb7 YQ |
157 | global hex |
158 | # Test that register 0 and PC are displayed, and register | |
159 | # 0 is unavailable. | |
a4105d04 MK |
160 | mi_gdb_test "-data-list-register-values x ${gpr0num} ${pcnum}" \ |
161 | ".*\\^done,register-values=\\\[\{number=\"${gpr0num}\",value=\"<unavailable>\"\},\{number=\"${pcnum}\",value=\"${hex}\"\}\\\]" \ | |
c898adb7 YQ |
162 | "-data-list-register-values x" |
163 | ||
164 | # Test that only available register PC is displayed. | |
a4105d04 | 165 | mi_gdb_test "-data-list-register-values --skip-unavailable x ${gpr0num} ${pcnum}" \ |
c898adb7 YQ |
166 | ".*\\^done,register-values=\\\[\{number=\"${pcnum}\",value=\"${hex}\"\}\\\]" \ |
167 | "-data-list-register-values --skip-unavailable x" | |
168 | } | |
169 | ||
8cb5cc78 YQ |
170 | # Don't issue command '-trace-find none' to return from |
171 | # tfind mode (examining trace frames) on purpose, in order | |
172 | # to test that GDB is able to clear its tracing-related local state | |
173 | # in the next -target-select. | |
174 | # mi_gdb_test "-trace-find none" ".*\\^done,found=\"0\".*" "-trace-find none" | |
175 | } | |
176 | } | |
177 | ||
178 | test_trace_unavailable "live" | |
179 | ||
180 | # Change target to ctf if GDB supports it. | |
181 | set msg "-target-select ctf" | |
182 | send_gdb "-target-select ctf ${tracefile}.ctf\n" | |
183 | gdb_expect { | |
184 | -re ".*\\^connected.*${mi_gdb_prompt}$" { | |
185 | # GDB supports ctf, do the test. | |
186 | test_trace_unavailable "ctf" | |
187 | } | |
188 | -re ".*\\^error,msg=\"Undefined target command.*${mi_gdb_prompt}$" { | |
189 | # GDB doesn't support ctf, skip the test. | |
190 | unsupported "gdb does not support ctf target" | |
191 | } | |
192 | -re ".*$mi_gdb_prompt$" { | |
193 | fail "$msg" | |
194 | } | |
195 | timeout { | |
196 | fail "$msg (timeout)" | |
197 | } | |
198 | } | |
199 | ||
200 | # Change target to tfile. | |
201 | mi_gdb_test "-target-select tfile ${tracefile}.tf" ".*\\^connected.*" \ | |
202 | "-target-select tfile" | |
203 | test_trace_unavailable "tfile" | |
204 | ||
205 | mi_gdb_exit |