]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-record-btrace.exp
[gdb/testsuite] Add xfail in gdb.python/py-record-btrace.exp
[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-2023 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
80 set got_xfail 0
81 set cmd "python insn = r.instruction_history"
82 gdb_test_multiple $cmd "" {
83 -re "^[string_to_regexp $cmd]\r\n$::gdb_prompt $" {
84 pass $gdb_test_name
85 }
86 -re -wrap "$xfail_re" {
87 if { $have_xfail } {
88 xfail $gdb_test_name
89 set got_xfail 1
90 } else {
91 fail $gdb_test_name
92 }
93 }
94 }
95 if { $got_xfail } {
96 return
97 }
98
99 gdb_test_no_output "python call = r.function_call_history"
100 gdb_test_no_output "python i = insn\[0\]"
101 gdb_test_no_output "python c = call\[0\]"
102 }
103
104 with_test_prefix "replay begin" {
105 gdb_test "python print(r.replay_position)" "None"
106 gdb_test "python r.goto(r.begin)"
107 gdb_test "python print(r.replay_position.number)" "1"
108 }
109
110 with_test_prefix "replay end" {
111 gdb_test "python r.goto(r.end)"
112 gdb_test "python print(r.replay_position)" "None"
113 }
114
115 with_test_prefix "instruction " {
116 gdb_test "python print(i.number)" "1"
117 gdb_test "python print(i.sal)" "symbol and line for .*"
118 gdb_test "python print(i.pc)" "$decimal"
119 gdb_test "python print(repr(i.data))" "<memory at $hex>"
120 gdb_test "python print(i.decoded)" ".*"
121 gdb_test "python print(i.size)" "$decimal"
122 gdb_test "python print(i.is_speculative)" "False"
123 }
124
125 with_test_prefix "function call" {
126 gdb_test "python print(c.number)" "1"
127 gdb_test "python print(c.symbol)" "main"
128 gdb_test "python print(c.level)" "$decimal"
129 gdb_test "python print(len(c.instructions))" "$decimal"
130 gdb_test "python print(c.up)" "None"
131 gdb_test "python print(c.prev)" "None"
132 gdb_test "python print(c == c.next.prev)" "True"
133 }
134
135 with_test_prefix "list" {
136 gdb_test "python print(len(insn))" "100"
137 gdb_test "python print(len(insn\[23:65\]))" "42"
138 gdb_test "python print(insn\[17:\]\[2\].number)" "20"
139 gdb_test "python print(i in insn)" "True"
140 gdb_test "python print(i in call)" "False"
141 gdb_test "python print(c in insn)" "False"
142 gdb_test "python print(c in call)" "True"
143 gdb_test "python print(insn.index(i))" "0"
144 gdb_test "python print(insn.count(i))" "1"
145 }
146
147 with_test_prefix "sublist" {
148 gdb_test_no_output "python s1 = insn\[3:72:5\]"
149 gdb_test_no_output "python s2 = s1\[2:13:3\]"
150 gdb_test_no_output "python s3 = s1\[13:2:-3\]"
151 gdb_test_no_output "python s4 = insn\[::-1\]"
152
153 gdb_test "python print(\[i.number for i in s1\])" "\\\[4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69\\\]"
154 gdb_test "python print(\[i.number for i in s2\])" "\\\[14, 29, 44, 59\\\]"
155 gdb_test "python print(\[i.number for i in s3\])" "\\\[69, 54, 39, 24\\\]"
156
157 gdb_test "python print(len(s1))" "14"
158 gdb_test "python print(len(s2))" "4"
159 gdb_test "python print(len(s3))" "4"
160 gdb_test "python print(len(s4))" "100"
161
162 gdb_test "python print(s4\[5\].number)" "95"
163 gdb_test "python print(s4\[-5\].number)" "5"
164 gdb_test "python print(s4\[100\].number)" ".*IndexError.*"
165 gdb_test "python print(s4\[-101\].number)" ".*IndexError.*"
166 }
167
168 with_test_prefix "level" {
169 gdb_test_no_output "python gdb.stop_recording()"
170 gdb_test "break inner" "Breakpoint.*"
171 gdb_test "continue" "Continuing\..*"
172 gdb_test_no_output "record btrace"
173 gdb_test "step" "outer ().*" "step one"
174 gdb_test "step" "main ().*" "step two"
175 gdb_test "python print(gdb.current_recording().function_call_history\[0\].level)" "1"
176 gdb_test "python print(gdb.current_recording().function_call_history\[1\].level)" "0"
177 }