]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-breakpoint.exp
This commit was manufactured by cvs2svn to create branch 'gdb_7_2-branch'.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-breakpoint.exp
CommitLineData
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
19if $tracelevel then {
20 strace $tracelevel
21}
22
23set testfile "py-breakpoint"
24set srcfile ${testfile}.c
25if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
26 return -1
27}
28
29# Run a command in GDB, and report a failure if a Python exception is thrown.
30# If report_pass is true, report a pass if no exception is thrown.
31proc gdb_py_test_silent_cmd {cmd name report_pass} {
32 global gdb_prompt
33
34 gdb_test_multiple $cmd $name {
35 -re "Traceback.*$gdb_prompt $" { fail $name }
36 -re "$gdb_prompt $" { if $report_pass { pass $name } }
37 }
38}
39
40# Start with a fresh gdb.
41clean_restart ${testfile}
42
43# Skip all tests if Python scripting is not enabled.
44if { [skip_python_tests] } { continue }
45
46if ![runto_main] then {
47 fail "Cannot run to main."
48 return 0
49}
50
51global hex decimal
52
53# Initially there should be one breakpoint: main.
54
55gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
56gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists"
57gdb_test "python print blist\[0\].location" "main." "Check breakpoint location"
58
59gdb_breakpoint [gdb_get_line_number "Break at multiply."]
60gdb_continue_to_breakpoint "Break at multiply."
61
62# Check that the Python breakpoint code noted the addition of a
63# breakpoint "behind the scenes".
64gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
65gdb_test "python print len(blist)" "2" "Check for two breakpoints"
66gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists"
67gdb_test "python print blist\[0\].location" "main." "Check breakpoint location"
68gdb_test "python print blist\[1\]" "<gdb.Breakpoint object at $hex>" "Check obj exists"
69gdb_test "python print blist\[1\].location" "py-breakpoint\.c:41*" "Check breakpoint location"
70
71# Check hit and ignore counts.
72gdb_test "python print blist\[1\].hit_count" "1" "Check breakpoint hit count"
73gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" "Set breakpoint hit count" 0
74gdb_continue_to_breakpoint "Break at multiply."
75gdb_test "python print blist\[1\].hit_count" "6" "Check breakpoint hit count"
76gdb_test "print result" "545" "Check expected variable result after 6 iterations"
77
78# Test breakpoint is enabled and disabled correctly..
79gdb_breakpoint [gdb_get_line_number "Break at add."]
80gdb_continue_to_breakpoint "Break at add."
81gdb_test "python print blist\[1\].enabled" "True" "Check breakpoint enabled."
82gdb_py_test_silent_cmd "python blist\[1\].enabled = False" "Set breakpoint disabled." 0
83gdb_continue_to_breakpoint "Break at add."
84gdb_py_test_silent_cmd "python blist\[1\].enabled = True" "Set breakpoint enabled." 0
85gdb_continue_to_breakpoint "Break at multiply."
86
87# Test other getters and setters.
88gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
89gdb_test "python print blist\[1\].thread" "None" "Check breakpoint thread"
90gdb_test "python print blist\[1\].type == gdb.BP_BREAKPOINT" "True" "Check breakpoint type"
91gdb_test "python print blist\[0\].number" "1" "Check breakpoint number"
92gdb_test "python print blist\[1\].number" "2" "Check breakpoint number"
93gdb_test "python print blist\[2\].number" "3" "Check breakpoint number"
94
95# Start with a fresh gdb.
96clean_restart ${testfile}
97
98if ![runto_main] then {
99 fail "Cannot run to main."
100 return 0
101}
102
103# Test conditional setting.
104set bp_location1 [gdb_get_line_number "Break at multiply."]
105gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" "Set breakpoint" 0
106gdb_continue_to_breakpoint "Break at multiply."
107gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" "Set breakpoint" 0
108gdb_test "python print bp1.condition" "i == 5" "Test conditional has been set"
109gdb_continue_to_breakpoint "Break at multiply."
110gdb_test "print i" "5" "Test conditional breakpoint stopped after five iterations"
111gdb_py_test_silent_cmd "python bp1.condition = None" "Clear condition" 0
112gdb_test "python print bp1.condition" "None" "Test conditional read"
113gdb_continue_to_breakpoint "Break at multiply."
114gdb_test "print i" "6" "Test breakpoint stopped after six iterations"
115
116# Test commands.
117gdb_breakpoint [gdb_get_line_number "Break at add."]
118set test {commands $bpnum}
119gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
120set test {print "Command for breakpoint has been executed."}
121gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
122set test {print result}
123gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
124gdb_test "end"
125
126gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
127gdb_test "python print blist\[len(blist)-1\].commands" "print \"Command for breakpoint has been executed.\".*print result"
128
129# Watchpoints
130# Start with a fresh gdb.
131clean_restart ${testfile}
132
e0756905
UW
133# Disable hardware watchpoints if necessary.
134if [target_info exists gdb,no_hardware_watchpoints] {
135 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
136}
137
adc36818
PM
138if ![runto_main] then {
139 fail "Cannot run to main."
140 return 0
141}
142
143gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" "Set watchpoint" 0
468b1aa7 144gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" "Test watchpoint write"
adc36818
PM
145
146
147