include/elf/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-breakpoint.exp
CommitLineData
7b6bb8da 1# Copyright (C) 2010, 2011 Free Software Foundation, Inc.
adc36818
PM
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
19if $tracelevel then {
20 strace $tracelevel
21}
22
a2c09bd0
DE
23load_lib gdb-python.exp
24
adc36818
PM
25set testfile "py-breakpoint"
26set srcfile ${testfile}.c
27if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
28 return -1
29}
30
adc36818
PM
31# Skip all tests if Python scripting is not enabled.
32if { [skip_python_tests] } { continue }
33
34if ![runto_main] then {
35 fail "Cannot run to main."
36 return 0
37}
38
39global hex decimal
40
41# Initially there should be one breakpoint: main.
42
43gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
44gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists"
45gdb_test "python print blist\[0\].location" "main." "Check breakpoint location"
46
47gdb_breakpoint [gdb_get_line_number "Break at multiply."]
48gdb_continue_to_breakpoint "Break at multiply."
49
50# Check that the Python breakpoint code noted the addition of a
51# breakpoint "behind the scenes".
52gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
53gdb_test "python print len(blist)" "2" "Check for two breakpoints"
54gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists"
55gdb_test "python print blist\[0\].location" "main." "Check breakpoint location"
56gdb_test "python print blist\[1\]" "<gdb.Breakpoint object at $hex>" "Check obj exists"
57gdb_test "python print blist\[1\].location" "py-breakpoint\.c:41*" "Check breakpoint location"
58
59# Check hit and ignore counts.
60gdb_test "python print blist\[1\].hit_count" "1" "Check breakpoint hit count"
61gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" "Set breakpoint hit count" 0
62gdb_continue_to_breakpoint "Break at multiply."
63gdb_test "python print blist\[1\].hit_count" "6" "Check breakpoint hit count"
8bfb830f 64gdb_test "print result" " = 545" "Check expected variable result after 6 iterations"
adc36818
PM
65
66# Test breakpoint is enabled and disabled correctly..
67gdb_breakpoint [gdb_get_line_number "Break at add."]
68gdb_continue_to_breakpoint "Break at add."
69gdb_test "python print blist\[1\].enabled" "True" "Check breakpoint enabled."
70gdb_py_test_silent_cmd "python blist\[1\].enabled = False" "Set breakpoint disabled." 0
71gdb_continue_to_breakpoint "Break at add."
72gdb_py_test_silent_cmd "python blist\[1\].enabled = True" "Set breakpoint enabled." 0
73gdb_continue_to_breakpoint "Break at multiply."
74
75# Test other getters and setters.
76gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
77gdb_test "python print blist\[1\].thread" "None" "Check breakpoint thread"
78gdb_test "python print blist\[1\].type == gdb.BP_BREAKPOINT" "True" "Check breakpoint type"
79gdb_test "python print blist\[0\].number" "1" "Check breakpoint number"
80gdb_test "python print blist\[1\].number" "2" "Check breakpoint number"
81gdb_test "python print blist\[2\].number" "3" "Check breakpoint number"
82
94b6973e
PM
83# Start with a fresh gdb.
84clean_restart ${testfile}
85
86if ![runto_main] then {
87 fail "Cannot run to main."
88 return 0
89}
90
91# Test breakpoints are deleted correctly.
92set deltst_location [gdb_get_line_number "Break at multiply."]
93set end_location [gdb_get_line_number "Break at end."]
94gdb_py_test_silent_cmd "python dp1 = gdb.Breakpoint (\"$deltst_location\")" "Set breakpoint" 0
95gdb_breakpoint [gdb_get_line_number "Break at end."]
96gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" "Get Breakpoint List" 0
97gdb_test "python print len(del_list)" "3" "Number of breakpoints before delete"
98gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$deltst_location.*"
99gdb_py_test_silent_cmd "python dp1.delete()" "Delete Breakpoint" 0
100gdb_test "python print dp1.number" "RuntimeError: Breakpoint 2 is invalid.*" "Check breakpoint invalidated"
101gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" "Get Breakpoint List" 0
102gdb_test "python print len(del_list)" "2" "Number of breakpoints after delete"
103gdb_continue_to_breakpoint "Break at end." ".*/$srcfile:$end_location.*"
104
105
adc36818
PM
106# Start with a fresh gdb.
107clean_restart ${testfile}
108
109if ![runto_main] then {
110 fail "Cannot run to main."
111 return 0
112}
113
114# Test conditional setting.
115set bp_location1 [gdb_get_line_number "Break at multiply."]
116gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" "Set breakpoint" 0
117gdb_continue_to_breakpoint "Break at multiply."
118gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" "Set breakpoint" 0
119gdb_test "python print bp1.condition" "i == 5" "Test conditional has been set"
120gdb_continue_to_breakpoint "Break at multiply."
121gdb_test "print i" "5" "Test conditional breakpoint stopped after five iterations"
122gdb_py_test_silent_cmd "python bp1.condition = None" "Clear condition" 0
123gdb_test "python print bp1.condition" "None" "Test conditional read"
124gdb_continue_to_breakpoint "Break at multiply."
125gdb_test "print i" "6" "Test breakpoint stopped after six iterations"
126
127# Test commands.
128gdb_breakpoint [gdb_get_line_number "Break at add."]
129set test {commands $bpnum}
130gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
131set test {print "Command for breakpoint has been executed."}
132gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
133set test {print result}
134gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
135gdb_test "end"
136
137gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
138gdb_test "python print blist\[len(blist)-1\].commands" "print \"Command for breakpoint has been executed.\".*print result"
139
84f4c1fe
PM
140# Start with a fresh gdb.
141clean_restart ${testfile}
142
143if ![runto_main] then {
144 fail "Cannot run to main."
145 return 0
146}
147
8bfb830f 148# Test invisible breakpoints.
84f4c1fe
PM
149delete_breakpoints
150set ibp_location [gdb_get_line_number "Break at multiply."]
151gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" "Set invisible breakpoint" 0
152gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0
153gdb_test "python print ilist\[0\]" "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists"
154gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location"
155gdb_test "python print ilist\[0\].visible" "True" "Check breakpoint visibility"
156gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check info breakpoints shows visible breakpoints"
157delete_breakpoints
158gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" "Set invisible breakpoint" 0
159gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0
160gdb_test "python print ilist\[0\]" "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists"
161gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location"
162gdb_test "python print ilist\[0\].visible" "False" "Check breakpoint visibility"
163gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints"
164gdb_test "maint info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check maint info breakpoints shows invisible breakpoints"
165
166
adc36818
PM
167# Watchpoints
168# Start with a fresh gdb.
169clean_restart ${testfile}
170
e0756905
UW
171# Disable hardware watchpoints if necessary.
172if [target_info exists gdb,no_hardware_watchpoints] {
173 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
174}
175
adc36818
PM
176if ![runto_main] then {
177 fail "Cannot run to main."
178 return 0
179}
180
181gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" "Set watchpoint" 0
468b1aa7 182gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" "Test watchpoint write"
adc36818 183
84f4c1fe 184# Internal breakpoints.
adc36818 185
84f4c1fe
PM
186# Start with a fresh gdb.
187clean_restart ${testfile}
adc36818 188
84f4c1fe
PM
189if ![runto_main] then {
190 fail "Cannot run to main."
191 return 0
192}
193delete_breakpoints
194gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE, internal=True )" "Set watchpoint" 0
195gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints"
b9b35694 196gdb_test "maint info breakpoints" ".*watchpoint.*result.*" "Check maint info breakpoints shows invisible breakpoints"
84f4c1fe 197gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" "Test watchpoint write"
This page took 0.137923 seconds and 4 git commands to generate.