diff options
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r-- | gdb/testsuite/gdb.python/py-thread-exited.c | 37 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-thread-exited.exp | 44 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-thread-exited.py | 46 |
3 files changed, 127 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-thread-exited.c b/gdb/testsuite/gdb.python/py-thread-exited.c new file mode 100644 index 0000000..fd0342b --- /dev/null +++ b/gdb/testsuite/gdb.python/py-thread-exited.c @@ -0,0 +1,37 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022-2023 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> +#include <signal.h> +pthread_t thread2_id; +pthread_t thread3_id; + +void* do_thread (void* d) +{ + return NULL; +} + +int main (void) +{ + pthread_create (&thread2_id, NULL, do_thread, NULL); + pthread_join (thread2_id, NULL); + pthread_create (&thread3_id, NULL, do_thread, NULL); + pthread_join (thread3_id, NULL); + return 12; +} diff --git a/gdb/testsuite/gdb.python/py-thread-exited.exp b/gdb/testsuite/gdb.python/py-thread-exited.exp new file mode 100644 index 0000000..a21368b --- /dev/null +++ b/gdb/testsuite/gdb.python/py-thread-exited.exp @@ -0,0 +1,44 @@ +# Copyright (C) 2022-202 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/>. + +load_lib gdb-python.exp + +standard_testfile + +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + return -1 +} + +save_vars { GDBFLAGS } { + clean_restart $testfile +} + +set pyfile [gdb_remote_download host ${srcdir}/${subdir}/py-thread-exited.py] +gdb_test_no_output "source ${pyfile}" "load python file" + +gdb_test "test-events" "Event testers registered." + +if ![runto_main] { + return -1 +} + +gdb_breakpoint 37 "last of main" + +gdb_continue_to_breakpoint "continue to breakpoint" + +gdb_test "python print(threadOneExit)" \ + ".*event type: thread-exited. global num: 2.*" +gdb_test "python print(threadTwoExit)" \ + ".*event type: thread-exited. global num: 3.*" diff --git a/gdb/testsuite/gdb.python/py-thread-exited.py b/gdb/testsuite/gdb.python/py-thread-exited.py new file mode 100644 index 0000000..32a9e5b --- /dev/null +++ b/gdb/testsuite/gdb.python/py-thread-exited.py @@ -0,0 +1,46 @@ +# Copyright 2022-2023 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/>. + +import gdb + +threadOneExit = "" +threadTwoExit = "" +# we don't want to overwrite the 2nd thread's exit event, thus +# store it here. we don't care about it though. +mainThreadExit = "" + +def thread_exited_handler(event): + global threadOneExit, threadTwoExit, mainThreadExit + print("{}".format(event)) + assert isinstance(event, gdb.ThreadExitedEvent) + if threadOneExit == "": + threadOneExit = "event type: thread-exited. global num: {}".format(event.inferior_thread.global_num) + else: + if threadTwoExit == "": + threadTwoExit = "event type: thread-exited. global num: {}".format(event.inferior_thread.global_num) + else: + mainThreadExit = "event type: thread-exited. global num: {}".format(event.inferior_thread.global_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.thread_exited.connect(thread_exited_handler) + print("Event testers registered.") + +test_events() |