]>
Commit | Line | Data |
---|---|---|
adc36818 PM |
1 | # Copyright (C) 2010 Free Software Foundation, Inc. |
2 | # | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # This file is part of the GDB testsuite. It tests the mechanism | |
17 | # exposing values to Python. | |
18 | ||
19 | if $tracelevel then { | |
20 | strace $tracelevel | |
21 | } | |
22 | ||
a2c09bd0 DE |
23 | load_lib gdb-python.exp |
24 | ||
adc36818 PM |
25 | set testfile "py-breakpoint" |
26 | set srcfile ${testfile}.c | |
27 | if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { | |
28 | return -1 | |
29 | } | |
30 | ||
adc36818 PM |
31 | # Start with a fresh gdb. |
32 | clean_restart ${testfile} | |
33 | ||
34 | # Skip all tests if Python scripting is not enabled. | |
35 | if { [skip_python_tests] } { continue } | |
36 | ||
37 | if ![runto_main] then { | |
38 | fail "Cannot run to main." | |
39 | return 0 | |
40 | } | |
41 | ||
42 | global hex decimal | |
43 | ||
44 | # Initially there should be one breakpoint: main. | |
45 | ||
46 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 | |
47 | gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists" | |
48 | gdb_test "python print blist\[0\].location" "main." "Check breakpoint location" | |
49 | ||
50 | gdb_breakpoint [gdb_get_line_number "Break at multiply."] | |
51 | gdb_continue_to_breakpoint "Break at multiply." | |
52 | ||
53 | # Check that the Python breakpoint code noted the addition of a | |
54 | # breakpoint "behind the scenes". | |
55 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 | |
56 | gdb_test "python print len(blist)" "2" "Check for two breakpoints" | |
57 | gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists" | |
58 | gdb_test "python print blist\[0\].location" "main." "Check breakpoint location" | |
59 | gdb_test "python print blist\[1\]" "<gdb.Breakpoint object at $hex>" "Check obj exists" | |
60 | gdb_test "python print blist\[1\].location" "py-breakpoint\.c:41*" "Check breakpoint location" | |
61 | ||
62 | # Check hit and ignore counts. | |
63 | gdb_test "python print blist\[1\].hit_count" "1" "Check breakpoint hit count" | |
64 | gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" "Set breakpoint hit count" 0 | |
65 | gdb_continue_to_breakpoint "Break at multiply." | |
66 | gdb_test "python print blist\[1\].hit_count" "6" "Check breakpoint hit count" | |
67 | gdb_test "print result" "545" "Check expected variable result after 6 iterations" | |
68 | ||
69 | # Test breakpoint is enabled and disabled correctly.. | |
70 | gdb_breakpoint [gdb_get_line_number "Break at add."] | |
71 | gdb_continue_to_breakpoint "Break at add." | |
72 | gdb_test "python print blist\[1\].enabled" "True" "Check breakpoint enabled." | |
73 | gdb_py_test_silent_cmd "python blist\[1\].enabled = False" "Set breakpoint disabled." 0 | |
74 | gdb_continue_to_breakpoint "Break at add." | |
75 | gdb_py_test_silent_cmd "python blist\[1\].enabled = True" "Set breakpoint enabled." 0 | |
76 | gdb_continue_to_breakpoint "Break at multiply." | |
77 | ||
78 | # Test other getters and setters. | |
79 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 | |
80 | gdb_test "python print blist\[1\].thread" "None" "Check breakpoint thread" | |
81 | gdb_test "python print blist\[1\].type == gdb.BP_BREAKPOINT" "True" "Check breakpoint type" | |
82 | gdb_test "python print blist\[0\].number" "1" "Check breakpoint number" | |
83 | gdb_test "python print blist\[1\].number" "2" "Check breakpoint number" | |
84 | gdb_test "python print blist\[2\].number" "3" "Check breakpoint number" | |
85 | ||
86 | # Start with a fresh gdb. | |
87 | clean_restart ${testfile} | |
88 | ||
89 | if ![runto_main] then { | |
90 | fail "Cannot run to main." | |
91 | return 0 | |
92 | } | |
93 | ||
94 | # Test conditional setting. | |
95 | set bp_location1 [gdb_get_line_number "Break at multiply."] | |
96 | gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" "Set breakpoint" 0 | |
97 | gdb_continue_to_breakpoint "Break at multiply." | |
98 | gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" "Set breakpoint" 0 | |
99 | gdb_test "python print bp1.condition" "i == 5" "Test conditional has been set" | |
100 | gdb_continue_to_breakpoint "Break at multiply." | |
101 | gdb_test "print i" "5" "Test conditional breakpoint stopped after five iterations" | |
102 | gdb_py_test_silent_cmd "python bp1.condition = None" "Clear condition" 0 | |
103 | gdb_test "python print bp1.condition" "None" "Test conditional read" | |
104 | gdb_continue_to_breakpoint "Break at multiply." | |
105 | gdb_test "print i" "6" "Test breakpoint stopped after six iterations" | |
106 | ||
107 | # Test commands. | |
108 | gdb_breakpoint [gdb_get_line_number "Break at add."] | |
109 | set test {commands $bpnum} | |
110 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
111 | set test {print "Command for breakpoint has been executed."} | |
112 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
113 | set test {print result} | |
114 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
115 | gdb_test "end" | |
116 | ||
117 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 | |
118 | gdb_test "python print blist\[len(blist)-1\].commands" "print \"Command for breakpoint has been executed.\".*print result" | |
119 | ||
84f4c1fe PM |
120 | # Start with a fresh gdb. |
121 | clean_restart ${testfile} | |
122 | ||
123 | if ![runto_main] then { | |
124 | fail "Cannot run to main." | |
125 | return 0 | |
126 | } | |
127 | ||
128 | # Test invisible breakpooints. | |
129 | delete_breakpoints | |
130 | set ibp_location [gdb_get_line_number "Break at multiply."] | |
131 | gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" "Set invisible breakpoint" 0 | |
132 | gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0 | |
133 | gdb_test "python print ilist\[0\]" "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists" | |
134 | gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" | |
135 | gdb_test "python print ilist\[0\].visible" "True" "Check breakpoint visibility" | |
136 | gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check info breakpoints shows visible breakpoints" | |
137 | delete_breakpoints | |
138 | gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" "Set invisible breakpoint" 0 | |
139 | gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0 | |
140 | gdb_test "python print ilist\[0\]" "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists" | |
141 | gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" | |
142 | gdb_test "python print ilist\[0\].visible" "False" "Check breakpoint visibility" | |
143 | gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints" | |
144 | gdb_test "maint info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check maint info breakpoints shows invisible breakpoints" | |
145 | ||
146 | ||
adc36818 PM |
147 | # Watchpoints |
148 | # Start with a fresh gdb. | |
149 | clean_restart ${testfile} | |
150 | ||
e0756905 UW |
151 | # Disable hardware watchpoints if necessary. |
152 | if [target_info exists gdb,no_hardware_watchpoints] { | |
153 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" | |
154 | } | |
155 | ||
adc36818 PM |
156 | if ![runto_main] then { |
157 | fail "Cannot run to main." | |
158 | return 0 | |
159 | } | |
160 | ||
161 | gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" "Set watchpoint" 0 | |
468b1aa7 | 162 | gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" "Test watchpoint write" |
adc36818 | 163 | |
84f4c1fe | 164 | # Internal breakpoints. |
adc36818 | 165 | |
84f4c1fe PM |
166 | # Start with a fresh gdb. |
167 | clean_restart ${testfile} | |
adc36818 | 168 | |
84f4c1fe PM |
169 | if ![runto_main] then { |
170 | fail "Cannot run to main." | |
171 | return 0 | |
172 | } | |
173 | delete_breakpoints | |
174 | gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE, internal=True )" "Set watchpoint" 0 | |
175 | gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints" | |
176 | gdb_test "maint info breakpoints" ".*hw watchpoint.*result.*" "Check maint info breakpoints shows invisible breakpoints" | |
177 | gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" "Test watchpoint write" |