diff options
author | Hui Zhu <teawater@gmail.com> | 2011-02-05 05:27:23 +0000 |
---|---|---|
committer | Hui Zhu <teawater@gmail.com> | 2011-02-05 05:27:23 +0000 |
commit | c17a9e46882cb057d7e1d150ac9974425dc55e03 (patch) | |
tree | fbd60a7c8eae30e33e904fe1877671b2ba378551 /gdb/testsuite | |
parent | 55382fb77a791c87165d4a3f65a53dc00c80959c (diff) | |
download | gdb-c17a9e46882cb057d7e1d150ac9974425dc55e03.zip gdb-c17a9e46882cb057d7e1d150ac9974425dc55e03.tar.gz gdb-c17a9e46882cb057d7e1d150ac9974425dc55e03.tar.bz2 |
Add the file that prev commit forget.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/gdb.python/py-events.c | 29 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-events.exp | 59 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-events.py | 64 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-evthreads.c | 55 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-evthreads.exp | 119 |
5 files changed, 326 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-events.c b/gdb/testsuite/gdb.python/py-events.c new file mode 100644 index 0000000..ceb697e --- /dev/null +++ b/gdb/testsuite/gdb.python/py-events.c @@ -0,0 +1,29 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010, 2011 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 second(){ + return 12; +} + +int first(){ + return second(); +} + +int main (){ + return first(); +} diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp new file mode 100644 index 0000000..e5d6daf --- /dev/null +++ b/gdb/testsuite/gdb.python/py-events.exp @@ -0,0 +1,59 @@ +# Copyright (C) 2010, 2011 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 Python-based +# pretty-printing for the CLI. + +# Skip all tests if Python scripting is not enabled. + +if $tracelevel then { + strace $tracelevel +} + +load_lib gdb-python.exp + +set testfile "py-events" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +set pyfile ${srcdir}/${subdir}/${testfile}.py + +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { + return -1 +} + +if { [skip_python_tests] } { continue } + +gdb_test_no_output "python execfile ('${pyfile}')" "" + +if ![runto_main ] then { + fail "Can't run to main" + return -1 +} + +gdb_test "Test_Events" "Event testers registered." + +gdb_breakpoint "first" + +# Test continue event and breakpoint stop event +gdb_test "continue" ".*event type: continue.* +.*event type: stop.* +.*stop reason: breakpoint.* +.*breakpoint number: 2.* +all threads stopped" + +#test exited event. +gdb_test "continue" ".*event type: continue.* +.*event type: exit.* +.*exit code: 12.*" diff --git a/gdb/testsuite/gdb.python/py-events.py b/gdb/testsuite/gdb.python/py-events.py new file mode 100644 index 0000000..9f05b9f --- /dev/null +++ b/gdb/testsuite/gdb.python/py-events.py @@ -0,0 +1,64 @@ +# Copyright (C) 2010, 2011 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 python pretty +# printers. +import gdb + +def signal_stop_handler (event): + if (isinstance (event, gdb.StopEvent)): + print "event type: stop" + if (isinstance (event, gdb.SignalEvent)): + print "stop reason: signal" + print "stop signal: %s" % (event.stop_signal) + if ( event.inferior_thread is not None) : + print "thread num: %s" % (event.inferior_thread.num); + +def breakpoint_stop_handler (event): + if (isinstance (event, gdb.StopEvent)): + print "event type: stop" + if (isinstance (event, gdb.BreakpointEvent)): + print "stop reason: breakpoint" + print "breakpoint number: %s" % (event.breakpoint.number) + if ( event.inferior_thread is not None) : + print "thread num: %s" % (event.inferior_thread.num); + else: + print "all threads stopped" + +def exit_handler (event): + if (isinstance (event, gdb.ExitedEvent)): + print "event type: exit" + print "exit code: %d" % (event.exit_code) + +def continue_handler (event): + if (isinstance (event, gdb.ContinueEvent)): + print "event type: continue" + if ( event.inferior_thread is not None) : + print "thread num: %s" % (event.inferior_thread.num); + +class test_events (gdb.Command): + """Test events.""" + + def __init__ (self): + gdb.Command.__init__ (self, "test_events", gdb.COMMAND_STACK) + + def invoke (self, arg, from_tty): + gdb.events.stop.connect (signal_stop_handler) + gdb.events.stop.connect (breakpoint_stop_handler) + gdb.events.exited.connect (exit_handler) + gdb.events.cont.connect (continue_handler) + print "Event testers registered." + +test_events () diff --git a/gdb/testsuite/gdb.python/py-evthreads.c b/gdb/testsuite/gdb.python/py-evthreads.c new file mode 100644 index 0000000..1464ce6 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-evthreads.c @@ -0,0 +1,55 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010, 2011 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/>. +*/ + +#include <stdio.h> +#include <pthread.h> +#include <unistd.h> + +pthread_t thread2_id; +pthread_t thread3_id; + +void* thread3 (void* d) +{ + int count3 = 0; + count3++; + + int *bad; + *bad = 1; + + return NULL; +} + +void* thread2 (void* d) +{ + int count2 = 0; + count2++; + return NULL; +} + +int main (){ + + pthread_create (&thread2_id, NULL, thread2, NULL); + pthread_create (&thread3_id, NULL, thread3, NULL); + + int count1 = 0; // stop1 + count1++; + + pthread_join (thread2_id, NULL); + pthread_join (thread3_id, NULL); + return 12; +} diff --git a/gdb/testsuite/gdb.python/py-evthreads.exp b/gdb/testsuite/gdb.python/py-evthreads.exp new file mode 100644 index 0000000..6ea7eb4 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-evthreads.exp @@ -0,0 +1,119 @@ +# Copyright (C) 2010, 2011 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 Python-based +# pretty-printing for the CLI. + +# Skip all tests if Python scripting is not enabled. + +if $tracelevel then { + strace $tracelevel +} + +load_lib gdb-python.exp + +set testfile "py-evthreads" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +set pyfile ${srcdir}/${subdir}/py-events.py + +gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings} +clean_restart $testfile + +if { [skip_python_tests] } { continue } + +gdb_test_no_output "python execfile ('${pyfile}')" "" + +gdb_test "Test_Events" "Event testers registered." +gdb_test_no_output "set non-stop on" +gdb_test_no_output "set target-async on" + +gdb_breakpoint "main" +gdb_breakpoint "thread2" +gdb_breakpoint "thread3" + +send_gdb "run\n" +gdb_expect { + -re "event type: stop.* +.*stop reason: breakpoint.* +.*breakpoint number: 1.* +.*thread num: 1.*" { + pass "reached breakpoint 1" + } + timeout { + fail "did not reach breakpoint 1" + } +} + +send_gdb "next\n" +gdb_expect { + -re "event type: stop.* +.*stop reason: breakpoint.* +.*breakpoint number: 2.* +.*thread num: 2.*" { + pass "reached breakpoint 2" + } + timeout { + fail "did not reach breakpoint 2" + } +} + +send_gdb "next\n" +gdb_expect { + -re "event type: stop.* +.*stop reason: breakpoint.* +.*breakpoint number: 3.* +.*thread num: 3.*" { + pass "reached breakpoint 3" + } + timeout { + fail "did not reach breakpoint 3" + } +} + +send_gdb "continue&\n" +gdb_expect { + -re ".*event type: continue.* +.*thread num: 1.*" { + pass "continue thread 1" + } + timeout { + fail "continue thread 1 failed" + } +} + +gdb_test "thread 2" ".*Switching to thread 2.*" +send_gdb "continue&\n" +gdb_expect { + -re ".*event type: continue.* +.*thread num: 2.*" { + pass "continue thread 2" + } + timeout { + fail "continue thread 2 failed" + } +} + +send_gdb "continue -a\n" +gdb_expect { + -re ".*stop reason: signal.* +.*stop signal: SIGSEGV.* +.*thread num: 3.*" { + pass "thread 3 was signalled" + } + timeout { + fail "thread 3 was not signalled" + } +} |