]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/doc/python.texi
gdb/Python: Added ThreadExitedEvent
authorSimon Farre <simon.farre.cx@gmail.com>
Wed, 20 Apr 2022 08:25:47 +0000 (10:25 +0200)
committerSimon Farre <simon.farre.cx@gmail.com>
Mon, 19 Jun 2023 14:17:21 +0000 (16:17 +0200)
commit28ab59607ef40b9571c0702ffba8f6aa6fb1b033
tree67dca4daefc0eb09ab33f7e93d21cf23124aadfc
parentf1a614dc8f015743e9fe7fe5f3f019303f8db718
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.
gdb/NEWS
gdb/doc/python.texi
gdb/python/py-all-events.def
gdb/python/py-event-types.def
gdb/python/py-event.h
gdb/python/py-inferior.c
gdb/python/py-threadevent.c
gdb/testsuite/gdb.python/py-thread-exited.c [new file with mode: 0644]
gdb/testsuite/gdb.python/py-thread-exited.exp [new file with mode: 0644]
gdb/testsuite/gdb.python/py-thread-exited.py [new file with mode: 0644]