summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-09-05 12:07:00 -0600
committerTom Tromey <tom@tromey.com>2017-09-11 14:15:20 -0600
commit7c96f8c1dae023c7d0b1cabc5e50c4d18fd06960 (patch)
treed842c8f82408e17bde8e8e27a298d7c24a65f91c /gdb/testsuite/gdb.python
parent4ec521f238627f7682306d699c8826390a2cc9e7 (diff)
downloadbinutils-gdb-7c96f8c1dae023c7d0b1cabc5e50c4d18fd06960.tar.gz
Add new_inferior, inferior_deleted, and new_thread events
This adds a few new events to gdb's Python layer: new_inferior, inferior_deleted, and new_thread. I wanted to be able to add a combined inferior/thread display window to my GUI, and I needed a few events to make this work. This is PR python/15622. ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> PR python/15622: * NEWS: Add entry. * python/python.c (do_start_initialization): Initialize new event types. * python/python-internal.h (gdbpy_initialize_new_inferior_event) (gdbpy_initialize_inferior_deleted_event) (gdbpy_initialize_new_thread_event): Declare. * python/py-threadevent.c (create_thread_event_object): Add option "thread" parameter. * python/py-inferior.c (new_thread_event_object_type) (new_inferior_event_object_type) (inferior_deleted_event_object_type): Declare. (python_new_inferior, python_inferior_deleted): New functions. (add_thread_object): Emit new_thread event. (gdbpy_initialize_inferior): Attach new functions to corresponding observers. (new_thread, new_inferior, inferior_deleted): Define new event types. * python/py-evts.c (gdbpy_initialize_py_events): Add new registries. * python/py-events.h (events_object) <new_inferior, inferior_deleted, new_thread>: New fields. * python/py-event.h (create_thread_event_breakpoint): Add optional "thread" parameter. doc/ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> * python.texi (Events In Python): Document new events. testsuite/ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> * gdb.python/py-infthread.exp: Add tests for new_thread event. * gdb.python/py-inferior.exp: Add tests for new inferior events.
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r--gdb/testsuite/gdb.python/py-inferior.exp24
-rw-r--r--gdb/testsuite/gdb.python/py-infthread.exp12
2 files changed, 36 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index c2ea2c2a4bc..715c693c408 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -214,12 +214,33 @@ with_test_prefix "is_valid" {
gdb_test "python print (inf_list\[0\].is_valid())" "True" \
"check inferior validity 1"
+ gdb_py_test_multiple "install new inferior event handler" \
+ "python" "" \
+ "my_inferior_count = 1" "" \
+ "def new_inf_handler(evt):" "" \
+ " global my_inferior_count" "" \
+ " if evt.inferior is not None:" "" \
+ " my_inferior_count = my_inferior_count + 1" "" \
+ "gdb.events.new_inferior.connect(new_inf_handler)" "" \
+ "end" ""
+ gdb_py_test_multiple "install inferior deleted event handler" \
+ "python" "" \
+ "def del_inf_handler(evt):" "" \
+ " global my_inferior_count" "" \
+ " if evt.inferior is not None:" "" \
+ " my_inferior_count = my_inferior_count - 1" "" \
+ "gdb.events.inferior_deleted.connect(del_inf_handler)" "" \
+ "end" ""
+
gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get new list" 1
gdb_test "python print (len(inf_list))" "2" "get inferior list length 2"
gdb_test "python print (inf_list\[0\].is_valid())" "True" \
"check inferior validity 2"
+ gdb_test "python print (my_inferior_count)" "2" \
+ "test new-inferior event handler"
+
gdb_test "python print (inf_list\[1\].is_valid())" "True" \
"check inferior validity 3"
@@ -229,6 +250,9 @@ with_test_prefix "is_valid" {
gdb_test "python print (inf_list\[1\].is_valid())" "False" \
"check inferior validity 5"
+
+ gdb_test "python print (my_inferior_count)" "1" \
+ "test inferior-deleted event handler"
}
# Test gdb.selected_inferior()
diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp
index a5fed8d8934..0711d6994e8 100644
--- a/gdb/testsuite/gdb.python/py-infthread.exp
+++ b/gdb/testsuite/gdb.python/py-infthread.exp
@@ -30,6 +30,16 @@ clean_restart ${testfile}
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
+gdb_py_test_multiple "install new_thread event handler" \
+ "python" "" \
+ "seen_a_thread = False" "" \
+ "def thread_handler(evt):" "" \
+ " if evt.inferior_thread is not None:" "" \
+ " global seen_a_thread" "" \
+ " seen_a_thread = True" "" \
+ "gdb.events.new_thread.connect(thread_handler)" "" \
+ "end" ""
+
# The following tests require execution.
if ![runto_main] then {
@@ -37,6 +47,8 @@ if ![runto_main] then {
return 0
}
+gdb_test "python print(seen_a_thread)" "True"
+
# Test basic gdb.Inferior attributes and methods.
gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test gdb.selected_thread" 1