aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-threadevent.c
diff options
context:
space:
mode:
authorSimon Farre <simon.farre.cx@gmail.com>2022-04-20 10:25:47 +0200
committerSimon Farre <simon.farre.cx@gmail.com>2023-06-19 16:17:21 +0200
commit28ab59607ef40b9571c0702ffba8f6aa6fb1b033 (patch)
tree67dca4daefc0eb09ab33f7e93d21cf23124aadfc /gdb/python/py-threadevent.c
parentf1a614dc8f015743e9fe7fe5f3f019303f8db718 (diff)
downloadgdb-28ab59607ef40b9571c0702ffba8f6aa6fb1b033.zip
gdb-28ab59607ef40b9571c0702ffba8f6aa6fb1b033.tar.gz
gdb-28ab59607ef40b9571c0702ffba8f6aa6fb1b033.tar.bz2
gdb/Python: Added ThreadExitedEvent
v6: Fix comments. Fix copyright Remove unnecessary test suite stuff. save_var had to stay, as it mutates some test suite state that otherwise fails. v5: Did what Tom Tromey requested in v4; which can be found here: https://pi.simark.ca/gdb-patches/87pmjm0xar.fsf@tromey.com/ v4: Doc formatting fixed. v3: Eli: Updated docs & NEWS to reflect new changes. Added a reference from the .ptid attribute of the ThreadExitedEvent to the ptid attribute of InferiorThread. To do this, I've added an anchor to that attribute. Tom: Tom requested that I should probably just emit the thread object; I ran into two issues for this, which I could not resolve in this patch; 1 - The Thread Object (the python type) checks it's own validity by doing a comparison of it's `thread_info* thread` to nullptr. This means that any access of it's attributes may (probably, since we are in "async" land) throw Python exceptions because the thread has been removed from the thread object. Therefore I've decided in v3 of this patch to just emit most of the same fields that gdb.InferiorThread has, namely global_num, name, num and ptid (the 3-attribute tuple provided by gdb.InferiorThread.ptid). 2 - A python user can hold a global reference to an exiting thread. Thus in order to have a ThreadExit event that can provide attribute access reliably (both as a global reference, but also inside the thread exit handler, as we can never guarantee that it's executed _before_ the thread_info pointer is removed from the gdbpy thread object), the `thread_info *` thread pointer must not be null. However, this comes at the cost of gdb.InferiorThread believing it is "valid" - which means, that if a user holds takes a global reference to that exiting event thread object, they can some time later do `t.switch()` at which point GDB will 'explode' so to speak. v2: Fixed white space issues and NULL/nullptr stuff, as requested by Tom Tromey. v1: Currently no event is emitted for a thread exit. This adds this functionality by emitting a new gdb.ThreadExitedEvent. It currently provides four attributes: - global_num: The GDB assigned global thread number - num: the per-inferior thread number - name: name of the thread or none if not set - ptid: the PTID of the thread, a 3-attribute tuple, identical to InferiorThread.ptid attribute Added info to docs & the NEWS file as well. Added test to test suite. Fixed formatting. Feedback wanted and appreciated.
Diffstat (limited to 'gdb/python/py-threadevent.c')
-rw-r--r--gdb/python/py-threadevent.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c
index 05a833d..2b2a449 100644
--- a/gdb/python/py-threadevent.c
+++ b/gdb/python/py-threadevent.c
@@ -53,3 +53,24 @@ create_thread_event_object (PyTypeObject *py_type, PyObject *thread)
return thread_event_obj;
}
+
+/* Emits a thread exit event for THREAD */
+
+int
+emit_thread_exit_event (thread_info * thread)
+{
+ if (evregpy_no_listeners_p (gdb_py_events.thread_exited))
+ return 0;
+
+ auto py_thr = thread_to_thread_object (thread);
+
+ if (py_thr == nullptr)
+ return -1;
+
+ auto inf_thr = create_thread_event_object (&thread_exited_event_object_type,
+ py_thr.get ());
+ if (inf_thr == nullptr)
+ return -1;
+
+ return evpy_emit_event (inf_thr.get (), gdb_py_events.thread_exited);
+}