]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-record-btrace.exp
gdb/python: remove Python 2 support
[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-2022 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 if { [skip_btrace_tests] } {
21 untested "skipping btrace tests"
22 return -1
23 }
24
25 load_lib gdb-python.exp
26
27 standard_testfile
28
29 if [prepare_for_testing "failed to prepare" $testfile $srcfile] { return -1 }
30
31 # Skip this test if python is disabled.
32
33 if { [skip_python_tests] } {
34 untested "skipping python tests"
35 return -1
36 }
37
38 if ![runto_main ] then {
39 return -1
40 }
41
42 with_test_prefix "no or double record" {
43 gdb_test "python print(gdb.current_recording())" "None"
44
45 gdb_test_no_output "python gdb.start_recording(\"btrace\")"
46 gdb_test "python gdb.start_recording(\"btrace\")" \
47 ".*gdb\.error: The process is already being recorded\..*" \
48 "already recording"
49
50 gdb_test_no_output "python gdb.stop_recording()" "first"
51 gdb_test "python gdb.stop_recording()" \
52 ".*gdb\.error: No recording is currently active\..*" "second"
53 }
54
55 with_test_prefix "preopened record btrace" {
56 gdb_test_no_output "record btrace"
57 gdb_test "python print(gdb.current_recording().method)" "btrace"
58 gdb_test "python print(gdb.current_recording().format)" "pt|bts"
59 gdb_test_no_output "python gdb.stop_recording()"
60 }
61
62 with_test_prefix "prepare record" {
63 gdb_test_no_output "python r = gdb.start_recording(\"btrace\")"
64 gdb_test "python print(r.method)" "btrace"
65 gdb_test "python print(r.format)" "pt|bts"
66 gdb_test "stepi 100" ".*"
67 gdb_test_no_output "python insn = r.instruction_history"
68 gdb_test_no_output "python call = r.function_call_history"
69 gdb_test_no_output "python i = insn\[0\]"
70 gdb_test_no_output "python c = call\[0\]"
71 }
72
73 with_test_prefix "replay begin" {
74 gdb_test "python print(r.replay_position)" "None"
75 gdb_test "python r.goto(r.begin)"
76 gdb_test "python print(r.replay_position.number)" "1"
77 }
78
79 with_test_prefix "replay end" {
80 gdb_test "python r.goto(r.end)"
81 gdb_test "python print(r.replay_position)" "None"
82 }
83
84 with_test_prefix "instruction " {
85 gdb_test "python print(i.number)" "1"
86 gdb_test "python print(i.sal)" "symbol and line for .*"
87 gdb_test "python print(i.pc)" "$decimal"
88 gdb_test "python print(repr(i.data))" "<memory at $hex>"
89 gdb_test "python print(i.decoded)" ".*"
90 gdb_test "python print(i.size)" "$decimal"
91 gdb_test "python print(i.is_speculative)" "False"
92 }
93
94 with_test_prefix "function call" {
95 gdb_test "python print(c.number)" "1"
96 gdb_test "python print(c.symbol)" "main"
97 gdb_test "python print(c.level)" "$decimal"
98 gdb_test "python print(len(c.instructions))" "$decimal"
99 gdb_test "python print(c.up)" "None"
100 gdb_test "python print(c.prev)" "None"
101 gdb_test "python print(c == c.next.prev)" "True"
102 }
103
104 with_test_prefix "list" {
105 gdb_test "python print(len(insn))" "100"
106 gdb_test "python print(len(insn\[23:65\]))" "42"
107 gdb_test "python print(insn\[17:\]\[2\].number)" "20"
108 gdb_test "python print(i in insn)" "True"
109 gdb_test "python print(i in call)" "False"
110 gdb_test "python print(c in insn)" "False"
111 gdb_test "python print(c in call)" "True"
112 gdb_test "python print(insn.index(i))" "0"
113 gdb_test "python print(insn.count(i))" "1"
114 }
115
116 with_test_prefix "sublist" {
117 gdb_test_no_output "python s1 = insn\[3:72:5\]"
118 gdb_test_no_output "python s2 = s1\[2:13:3\]"
119 gdb_test_no_output "python s3 = s1\[13:2:-3\]"
120 gdb_test_no_output "python s4 = insn\[::-1\]"
121
122 gdb_test "python print(\[i.number for i in s1\])" "\\\[4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69\\\]"
123 gdb_test "python print(\[i.number for i in s2\])" "\\\[14, 29, 44, 59\\\]"
124 gdb_test "python print(\[i.number for i in s3\])" "\\\[69, 54, 39, 24\\\]"
125
126 gdb_test "python print(len(s1))" "14"
127 gdb_test "python print(len(s2))" "4"
128 gdb_test "python print(len(s3))" "4"
129 gdb_test "python print(len(s4))" "100"
130
131 gdb_test "python print(s4\[5\].number)" "95"
132 gdb_test "python print(s4\[-5\].number)" "5"
133 gdb_test "python print(s4\[100\].number)" ".*IndexError.*"
134 gdb_test "python print(s4\[-101\].number)" ".*IndexError.*"
135 }
136
137 with_test_prefix "level" {
138 gdb_test_no_output "python gdb.stop_recording()"
139 gdb_test "break inner" "Breakpoint.*"
140 gdb_test "continue" "Continuing\..*"
141 gdb_test_no_output "record btrace"
142 gdb_test "step" "outer ().*" "step one"
143 gdb_test "step" "main ().*" "step two"
144 gdb_test "python print(gdb.current_recording().function_call_history\[0\].level)" "1"
145 gdb_test "python print(gdb.current_recording().function_call_history\[1\].level)" "0"
146 }