aboutsummaryrefslogtreecommitdiff
path: root/gdb/doc
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2024-01-04 16:46:40 +0000
committerAndrew Burgess <aburgess@redhat.com>2024-01-12 11:21:30 +0000
commit13cd9bceea3c3a3081c463597146a11ade765e39 (patch)
tree8c2a7b96be594b13b55b320d17d89468303016a2 /gdb/doc
parent2f47f48fe55eb72bfe4d3c5291a74f4a53121c5e (diff)
downloadgdb-13cd9bceea3c3a3081c463597146a11ade765e39.zip
gdb-13cd9bceea3c3a3081c463597146a11ade765e39.tar.gz
gdb-13cd9bceea3c3a3081c463597146a11ade765e39.tar.bz2
gdb/python: Add gdb.Inferior.__dict__ attribute
The gdb.Objfile, gdb.Progspace, and gdb.Type 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.Inferior type. After this commit there is a new gdb.Inferior.__dict__ attribute, which is a dictionary. A user can, for example, do this: (gdb) pi >>> i = gdb.selected_inferior() >>> i._user_attribute = 123 >>> i._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')
-rw-r--r--gdb/doc/python.texi36
1 files changed, 36 insertions, 0 deletions
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index da37348..2fd8a9b 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3667,6 +3667,42 @@ Unset the environment variable @var{name}. @var{name} must be a
string.
@end defun
+One may add arbitrary attributes to @code{gdb.Inferior} objects in the
+usual Python way. This is useful if, for example, one needs to do
+some extra record keeping associated with the inferior.
+
+In this contrived example we record the time when an inferior 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()
+ inferior = thread.inferior
+ inferior._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_inferior()._last_stop_time)
+2024-01-04 14:48:41.347036
+@end group
+@end smallexample
+
@node Events In Python
@subsubsection Events In Python
@cindex inferior events in Python