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