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