Commit | Line | Data |
---|---|---|
714aa61c TW |
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\")" | |
714aa61c TW |
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" | |
714aa61c TW |
84 | gdb_test "python print(i.sal)" "symbol and line for .*" |
85 | gdb_test "python print(i.pc)" "$decimal" | |
cee59b3f TW |
86 | if { $gdb_py_is_py3k == 0 } { |
87 | gdb_test "python print(repr(i.data))" "<read-only buffer for $hex,.*>" | |
88 | } else { | |
89 | gdb_test "python print(repr(i.data))" "<memory at $hex>" | |
90 | } | |
714aa61c TW |
91 | gdb_test "python print(i.decoded)" ".*" |
92 | gdb_test "python print(i.size)" "$decimal" | |
93 | gdb_test "python print(i.is_speculative)" "False" | |
94 | } | |
95 | ||
96 | with_test_prefix "function call" { | |
97 | gdb_test "python print(c.number)" "1" | |
98 | gdb_test "python print(c.symbol)" "main" | |
99 | gdb_test "python print(c.level)" "$decimal" | |
100 | gdb_test "python print(len(c.instructions))" "$decimal" | |
101 | gdb_test "python print(c.up)" "None" | |
102 | gdb_test "python print(c.prev_sibling)" "None" | |
103 | gdb_test "python print(c == c.next_sibling.prev_sibling)" "True" | |
104 | } | |
105 | ||
106 | with_test_prefix "list" { | |
107 | gdb_test "python print(len(insn))" "100" | |
108 | gdb_test "python print(len(insn\[23:65\]))" "42" | |
109 | gdb_test "python print(insn\[17:\]\[2\].number)" "20" | |
110 | gdb_test "python print(i in insn)" "True" | |
111 | gdb_test "python print(i in call)" "False" | |
112 | gdb_test "python print(c in insn)" "False" | |
113 | gdb_test "python print(c in call)" "True" | |
114 | gdb_test "python print(insn.index(i))" "0" | |
115 | gdb_test "python print(insn.count(i))" "1" | |
116 | } | |
117 | ||
118 | with_test_prefix "sublist" { | |
119 | gdb_test_no_output "python s1 = insn\[3:72:5\]" | |
120 | gdb_test_no_output "python s2 = s1\[2:13:3\]" | |
121 | gdb_test_no_output "python s3 = s1\[13:2:-3\]" | |
122 | gdb_test_no_output "python s4 = insn\[::-1\]" | |
123 | ||
124 | gdb_test "python print(\[i.number for i in s1\])" "\\\[4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69\\\]" | |
125 | gdb_test "python print(\[i.number for i in s2\])" "\\\[14, 29, 44, 59\\\]" | |
126 | gdb_test "python print(\[i.number for i in s3\])" "\\\[69, 54, 39, 24\\\]" | |
127 | ||
128 | gdb_test "python print(len(s1))" "14" | |
129 | gdb_test "python print(len(s2))" "4" | |
130 | gdb_test "python print(len(s3))" "4" | |
131 | gdb_test "python print(len(s4))" "100" | |
132 | ||
133 | gdb_test "python print(s4\[5\].number)" "95" | |
134 | gdb_test "python print(s4\[-5\].number)" "5" | |
135 | gdb_test "python print(s4\[100\].number)" ".*IndexError.*" | |
136 | gdb_test "python print(s4\[-101\].number)" ".*IndexError.*" | |
137 | } | |
138 | ||
139 | with_test_prefix "level" { | |
140 | gdb_test_no_output "python gdb.stop_recording()" | |
141 | gdb_test "break inner" "Breakpoint.*" | |
142 | gdb_test "continue" "Continuing\..*" | |
143 | gdb_test_no_output "record btrace" | |
144 | gdb_test "step" "outer ().*" "step one" | |
145 | gdb_test "step" "main ().*" "step two" | |
146 | gdb_test "python print(gdb.current_recording().function_call_history\[0\].level)" "1" | |
147 | gdb_test "python print(gdb.current_recording().function_call_history\[1\].level)" "0" | |
148 | } |