]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-record-btrace.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-record-btrace.exp
1 # This testcase is part of GDB, the GNU debugger.
2 #
3 # Copyright 2016-2024 Free Software Foundation, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 # Skip this test if btrace is disabled.
19
20 require allow_btrace_tests allow_python_tests
21
22 load_lib gdb-python.exp
23
24 standard_testfile
25
26 if [prepare_for_testing "failed to prepare" $testfile $srcfile] { return -1 }
27
28 if {![runto_main]} {
29 return -1
30 }
31
32 with_test_prefix "no or double record" {
33 gdb_test "python print(gdb.current_recording())" "None"
34
35 gdb_test_no_output "python gdb.start_recording(\"btrace\")"
36 gdb_test "python gdb.start_recording(\"btrace\")" \
37 ".*gdb\.error: The process is already being recorded\..*" \
38 "already recording"
39
40 gdb_test_no_output "python gdb.stop_recording()" "first"
41 gdb_test "python gdb.stop_recording()" \
42 ".*gdb\.error: No recording is currently active\..*" "second"
43 }
44
45 with_test_prefix "preopened record btrace" {
46 gdb_test_no_output "record btrace"
47 gdb_test "python print(gdb.current_recording().method)" "btrace"
48 gdb_test "python print(gdb.current_recording().format)" "pt|bts"
49 gdb_test_no_output "python gdb.stop_recording()"
50 }
51
52 with_test_prefix "prepare record" {
53 gdb_test_no_output "python r = gdb.start_recording(\"btrace\")"
54 gdb_test "python print(r.method)" "btrace"
55 gdb_test "python print(r.format)" "pt|bts"
56 gdb_test "stepi 100" ".*"
57
58 # There's a HW bug affecting Processor Trace on some Intel processors.
59 # The bug was exposed by linux kernel commit 670638477aed
60 # ("perf/x86/intel/pt: Opportunistically use single range output mode"),
61 # added in version v5.5.0, and was worked around by commit ce0d998be927
62 # ("perf/x86/intel/pt: Fix sampling using single range output") in version
63 # 6.1.0. Detect the kernel version range for which the problem may
64 # manifest.
65 set have_xfail 0
66 set v [linux_kernel_version]
67 if { $v != {} } {
68 set have_xfail \
69 [expr [version_compare [list 5 5 0] <= $v] \
70 && [version_compare $v < [list 6 1 0]]]
71 }
72 set nonl_re \[^\r\n\]
73 set xfail_re \
74 [join \
75 [list \
76 "warning: Decode error \\($nonl_re*\\) at instruction $decimal" \
77 "\\(offset = $hex, pc = $hex\\):" \
78 "$nonl_re*\\."]]
79 set xfail_re_2 \
80 [join \
81 [list \
82 "warning: Non-contiguous trace at instruction $decimal" \
83 "\\(offset = $hex\\)\\."]]
84
85 set got_xfail 0
86 set cmd "python insn = r.instruction_history"
87 gdb_test_multiple $cmd "" {
88 -re "^[string_to_regexp $cmd]\r\n$::gdb_prompt $" {
89 pass $gdb_test_name
90 }
91 -re -wrap "($xfail_re|$xfail_re_2)" {
92 if { $have_xfail } {
93 xfail $gdb_test_name
94 set got_xfail 1
95 } else {
96 fail $gdb_test_name
97 }
98 }
99 }
100 if { $got_xfail } {
101 return
102 }
103
104 # Also handle the case that we're running into the hw bug without
105 # triggering a decode error.
106 gdb_test_multiple "python print(len(insn))" "" {
107 -re -wrap "100" {
108 pass $gdb_test_name
109 }
110 -re -wrap "" {
111 if { $have_xfail } {
112 xfail $gdb_test_name
113 set got_xfail 1
114 } else {
115 fail $gdb_test_name
116 }
117 }
118 }
119 if { $got_xfail } {
120 return
121 }
122
123 gdb_test_no_output "python call = r.function_call_history"
124 gdb_test_no_output "python i = insn\[0\]"
125 gdb_test_no_output "python c = call\[0\]"
126 }
127
128 with_test_prefix "replay begin" {
129 gdb_test "python print(r.replay_position)" "None"
130 gdb_test "python r.goto(r.begin)"
131 gdb_test "python print(r.replay_position.number)" "1"
132 }
133
134 with_test_prefix "replay end" {
135 gdb_test "python r.goto(r.end)"
136 gdb_test "python print(r.replay_position)" "None"
137 }
138
139 with_test_prefix "instruction " {
140 gdb_test "python print(i.number)" "1"
141 gdb_test "python print(i.sal)" "symbol and line for .*"
142 gdb_test "python print(i.pc)" "$decimal"
143 gdb_test "python print(repr(i.data))" "<memory at $hex>"
144 gdb_test "python print(i.decoded)" ".*"
145 gdb_test "python print(i.size)" "$decimal"
146 gdb_test "python print(i.is_speculative)" "False"
147 }
148
149 with_test_prefix "function call" {
150 gdb_test "python print(c.number)" "1"
151 gdb_test "python print(c.symbol)" "main"
152 gdb_test "python print(c.level)" "$decimal"
153 gdb_test "python print(len(c.instructions))" "$decimal"
154 gdb_test "python print(c.up)" "None"
155 gdb_test "python print(c.prev)" "None"
156 gdb_test "python print(c == c.next.prev)" "True"
157 }
158
159 with_test_prefix "list" {
160 gdb_test "python print(len(insn\[23:65\]))" "42"
161 gdb_test "python print(insn\[17:\]\[2\].number)" "20"
162 gdb_test "python print(i in insn)" "True"
163 gdb_test "python print(i in call)" "False"
164 gdb_test "python print(c in insn)" "False"
165 gdb_test "python print(c in call)" "True"
166 gdb_test "python print(insn.index(i))" "0"
167 gdb_test "python print(insn.count(i))" "1"
168 }
169
170 with_test_prefix "sublist" {
171 gdb_test_no_output "python s1 = insn\[3:72:5\]"
172 gdb_test_no_output "python s2 = s1\[2:13:3\]"
173 gdb_test_no_output "python s3 = s1\[13:2:-3\]"
174 gdb_test_no_output "python s4 = insn\[::-1\]"
175
176 gdb_test "python print(\[i.number for i in s1\])" "\\\[4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69\\\]"
177 gdb_test "python print(\[i.number for i in s2\])" "\\\[14, 29, 44, 59\\\]"
178 gdb_test "python print(\[i.number for i in s3\])" "\\\[69, 54, 39, 24\\\]"
179
180 gdb_test "python print(len(s1))" "14"
181 gdb_test "python print(len(s2))" "4"
182 gdb_test "python print(len(s3))" "4"
183 gdb_test "python print(len(s4))" "100"
184
185 gdb_test "python print(s4\[5\].number)" "95"
186 gdb_test "python print(s4\[-5\].number)" "5"
187 gdb_test "python print(s4\[100\].number)" ".*IndexError.*"
188 gdb_test "python print(s4\[-101\].number)" ".*IndexError.*"
189 }
190
191 with_test_prefix "level" {
192 gdb_test_no_output "python gdb.stop_recording()"
193 gdb_test "break inner" "Breakpoint.*"
194 gdb_test "continue" "Continuing\..*"
195 gdb_test_no_output "record btrace"
196 gdb_test "step" "outer ().*" "step one"
197 gdb_test "step" "main ().*" "step two"
198 gdb_test "python print(gdb.current_recording().function_call_history\[0\].level)" "1"
199 gdb_test "python print(gdb.current_recording().function_call_history\[1\].level)" "0"
200 }