diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-01-05 11:05:51 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-01-12 11:21:31 +0000 |
commit | 1d586eda5c90bb9e03e997682dce60811f978def (patch) | |
tree | a5f9b50150dce957035c62bd90f5e4ae7750d793 /gdb/doc/python.texi | |
parent | 13cd9bceea3c3a3081c463597146a11ade765e39 (diff) | |
download | binutils-1d586eda5c90bb9e03e997682dce60811f978def.zip binutils-1d586eda5c90bb9e03e997682dce60811f978def.tar.gz binutils-1d586eda5c90bb9e03e997682dce60811f978def.tar.bz2 |
gdb/python: Add gdb.InferiorThread.__dict__ attribute
The gdb.Objfile, gdb.Progspace, gdb.Type, and gdb.Inferior Python
types already have a __dict__ attribute, which allows users to create
user defined attributes within the objects. This is useful if the
user wants to cache information within an object.
This commit adds the same functionality to the gdb.InferiorThread
type.
After this commit there is a new gdb.InferiorThread.__dict__
attribute, which is a dictionary. A user can, for example, do this:
(gdb) pi
>>> t = gdb.selected_thread()
>>> t._user_attribute = 123
>>> t._user_attribute
123
>>>
There's a new test included.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/doc/python.texi')
-rw-r--r-- | gdb/doc/python.texi | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 2fd8a9b..674ec56 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -4184,6 +4184,41 @@ the Python @code{bytes} representation of the handle and @var{type} is a @code{gdb.Type} for the handle type. @end defun +One may add arbitrary attributes to @code{gdb.InferiorThread} objects +in the usual Python way. This is useful if, for example, one needs to +do some extra record keeping associated with the thread. + +In this contrived example we record the time when a thread last +stopped: + +@smallexample +@group +(@value{GDBP}) python +import datetime + +def thread_stopped(event): + if event.inferior_thread is not None: + thread = event.inferior_thread + else: + thread = gdb.selected_thread() + thread._last_stop_time = datetime.datetime.today() + +gdb.events.stop.connect(thread_stopped) +@end group +@group +(@value{GDBP}) file /tmp/hello +Reading symbols from /tmp/hello... +(@value{GDBP}) start +Temporary breakpoint 1 at 0x401198: file /tmp/hello.c, line 18. +Starting program: /tmp/hello + +Temporary breakpoint 1, main () at /tmp/hello.c:18 +18 printf ("Hello World\n"); +(@value{GDBP}) python print(gdb.selected_thread()._last_stop_time) +2024-01-04 14:48:41.347036 +@end group +@end smallexample + @node Recordings In Python @subsubsection Recordings In Python @cindex recordings in python |