diff options
author | Phil Muldoon <pmuldoon@redhat.com> | 2010-04-09 09:41:43 +0000 |
---|---|---|
committer | Phil Muldoon <pmuldoon@redhat.com> | 2010-04-09 09:41:43 +0000 |
commit | adc368187c7bc29c3c227cf986dd021973ce6eaf (patch) | |
tree | c01aaab1fc72d2ea058c1be7c717317312a38b81 /gdb/testsuite/gdb.python | |
parent | e760a81b7959d2d3474f12622be217ff218f5e06 (diff) | |
download | gdb-adc368187c7bc29c3c227cf986dd021973ce6eaf.zip gdb-adc368187c7bc29c3c227cf986dd021973ce6eaf.tar.gz gdb-adc368187c7bc29c3c227cf986dd021973ce6eaf.tar.bz2 |
2010-04-09 Phil Muldoon <pmuldoon@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com>
Tom Tromey <tromey@redhat.com>
* breakpoint.c (condition_command): Simplify. Move condition
setting code to ...
(set_breakpoint_condition): ... here. New function.
* breakpoint.h (set_breakpoint_condition): Declare.
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-breakpoint.
(SUBDIR_PYTHON_SRCS): Likewise.
(py-breakpoint.o): New rule.
* python/py-breakpoint.c: New file.
* python/python-internal.h (gdbpy_breakpoints)
(gdbpy_initialize_breakpoints): Declare.
(GDB_PY_SET_HANDLE_EXCEPTION) Define.
2010-04-09 Phil Muldoon <pmuldoon@redhat.com>
* gdb.python/py-breakpoint.exp: New File.
* gdb.python/py-breakpoint.C: Ditto.
2010-04-09 Phil Muldoon <pmuldoon@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com>
Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Breakpoints In Python): New Node.
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r-- | gdb/testsuite/gdb.python/Makefile.in | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-breakpoint.c | 46 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-breakpoint.exp | 142 |
3 files changed, 189 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.python/Makefile.in b/gdb/testsuite/gdb.python/Makefile.in index 578ac54..c6a2678 100644 --- a/gdb/testsuite/gdb.python/Makefile.in +++ b/gdb/testsuite/gdb.python/Makefile.in @@ -2,7 +2,7 @@ VPATH = @srcdir@ srcdir = @srcdir@ EXECUTABLES = py-type py-value py-prettyprint py-template py-block \ - py-symbol py-mi + py-symbol py-mi py-breakpoint all info install-info dvi install uninstall installcheck check: @echo "Nothing to be done for $@..." diff --git a/gdb/testsuite/gdb.python/py-breakpoint.c b/gdb/testsuite/gdb.python/py-breakpoint.c new file mode 100644 index 0000000..b2ad81b --- /dev/null +++ b/gdb/testsuite/gdb.python/py-breakpoint.c @@ -0,0 +1,46 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + + + +int multiply (int i) +{ + return i * i; +} + +int add (int i) +{ + return i + i; +} + + +int main (int argc, char *argv[]) +{ + int foo = 5; + int bar = 42; + int result = 0; + int i; + + for (i = 0; i < 10; i++) + { + result += multiply (foo); /* Break at multiply. */ + result += add (bar); /* Break at add. */ + } + + return 0; /* Break at end. */ +} diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp new file mode 100644 index 0000000..903912c --- /dev/null +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -0,0 +1,142 @@ +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# This file is part of the GDB testsuite. It tests the mechanism +# exposing values to Python. + +if $tracelevel then { + strace $tracelevel +} + +set testfile "py-breakpoint" +set srcfile ${testfile}.c +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { + return -1 +} + +# Run a command in GDB, and report a failure if a Python exception is thrown. +# If report_pass is true, report a pass if no exception is thrown. +proc gdb_py_test_silent_cmd {cmd name report_pass} { + global gdb_prompt + + gdb_test_multiple $cmd $name { + -re "Traceback.*$gdb_prompt $" { fail $name } + -re "$gdb_prompt $" { if $report_pass { pass $name } } + } +} + +# Start with a fresh gdb. +clean_restart ${testfile} + +# Skip all tests if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +if ![runto_main] then { + fail "Cannot run to main." + return 0 +} + +global hex decimal + +# Initially there should be one breakpoint: main. + +gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 +gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists" +gdb_test "python print blist\[0\].location" "main." "Check breakpoint location" + +gdb_breakpoint [gdb_get_line_number "Break at multiply."] +gdb_continue_to_breakpoint "Break at multiply." + +# Check that the Python breakpoint code noted the addition of a +# breakpoint "behind the scenes". +gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 +gdb_test "python print len(blist)" "2" "Check for two breakpoints" +gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists" +gdb_test "python print blist\[0\].location" "main." "Check breakpoint location" +gdb_test "python print blist\[1\]" "<gdb.Breakpoint object at $hex>" "Check obj exists" +gdb_test "python print blist\[1\].location" "py-breakpoint\.c:41*" "Check breakpoint location" + +# Check hit and ignore counts. +gdb_test "python print blist\[1\].hit_count" "1" "Check breakpoint hit count" +gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" "Set breakpoint hit count" 0 +gdb_continue_to_breakpoint "Break at multiply." +gdb_test "python print blist\[1\].hit_count" "6" "Check breakpoint hit count" +gdb_test "print result" "545" "Check expected variable result after 6 iterations" + +# Test breakpoint is enabled and disabled correctly.. +gdb_breakpoint [gdb_get_line_number "Break at add."] +gdb_continue_to_breakpoint "Break at add." +gdb_test "python print blist\[1\].enabled" "True" "Check breakpoint enabled." +gdb_py_test_silent_cmd "python blist\[1\].enabled = False" "Set breakpoint disabled." 0 +gdb_continue_to_breakpoint "Break at add." +gdb_py_test_silent_cmd "python blist\[1\].enabled = True" "Set breakpoint enabled." 0 +gdb_continue_to_breakpoint "Break at multiply." + +# Test other getters and setters. +gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 +gdb_test "python print blist\[1\].thread" "None" "Check breakpoint thread" +gdb_test "python print blist\[1\].type == gdb.BP_BREAKPOINT" "True" "Check breakpoint type" +gdb_test "python print blist\[0\].number" "1" "Check breakpoint number" +gdb_test "python print blist\[1\].number" "2" "Check breakpoint number" +gdb_test "python print blist\[2\].number" "3" "Check breakpoint number" + +# Start with a fresh gdb. +clean_restart ${testfile} + +if ![runto_main] then { + fail "Cannot run to main." + return 0 +} + +# Test conditional setting. +set bp_location1 [gdb_get_line_number "Break at multiply."] +gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" "Set breakpoint" 0 +gdb_continue_to_breakpoint "Break at multiply." +gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" "Set breakpoint" 0 +gdb_test "python print bp1.condition" "i == 5" "Test conditional has been set" +gdb_continue_to_breakpoint "Break at multiply." +gdb_test "print i" "5" "Test conditional breakpoint stopped after five iterations" +gdb_py_test_silent_cmd "python bp1.condition = None" "Clear condition" 0 +gdb_test "python print bp1.condition" "None" "Test conditional read" +gdb_continue_to_breakpoint "Break at multiply." +gdb_test "print i" "6" "Test breakpoint stopped after six iterations" + +# Test commands. +gdb_breakpoint [gdb_get_line_number "Break at add."] +set test {commands $bpnum} +gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } +set test {print "Command for breakpoint has been executed."} +gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } +set test {print result} +gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } +gdb_test "end" + +gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 +gdb_test "python print blist\[len(blist)-1\].commands" "print \"Command for breakpoint has been executed.\".*print result" + +# Watchpoints +# Start with a fresh gdb. +clean_restart ${testfile} + +if ![runto_main] then { + fail "Cannot run to main." + return 0 +} + +gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" "Set watchpoint" 0 +gdb_test "continue" ".*watchpoint.*result.*Old value = 0.*New value = 25.*main.*" "Test watchpoint write" + + + |