diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-01-04 16:46:40 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-01-12 11:21:30 +0000 |
commit | 13cd9bceea3c3a3081c463597146a11ade765e39 (patch) | |
tree | 8c2a7b96be594b13b55b320d17d89468303016a2 /gdb/testsuite/gdb.python | |
parent | 2f47f48fe55eb72bfe4d3c5291a74f4a53121c5e (diff) | |
download | binutils-13cd9bceea3c3a3081c463597146a11ade765e39.zip binutils-13cd9bceea3c3a3081c463597146a11ade765e39.tar.gz binutils-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/testsuite/gdb.python')
-rw-r--r-- | gdb/testsuite/gdb.python/py-inferior.exp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 5a221f8..0e00636 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -85,6 +85,15 @@ gdb_test "python print (i0.threads ())" \ gdb_test "python print (i0.progspace)" "<gdb.Progspace object at $hex>" gdb_test "python print (i0.progspace == gdb.progspaces()\[0\])" "True" +# Add a user defined attribute to the inferior, and check the +# attribute can be read back. +gdb_test_no_output "python i0._user_attr = 123" \ + "add a user defined attribute to the inferior object" +gdb_test "python print(i0._user_attr)" \ + "123" "read back user defined attribute from i0" +gdb_test "python print(gdb.inferiors()\[0\]._user_attr)" \ + "123" "read back user defined attribute from gdb.inferiors" + # Test the number of inferior threads. gdb_breakpoint check_threads @@ -127,6 +136,16 @@ gdb_test "print str" " = \"hallo, testsuite\"" \ # correct inferior. set num [add_inferior] +# Confirm the new inferior doesn't have the user defined attribute, +# but that the first inferior does still have the attribute. +gdb_test "python print(gdb.inferiors()\[1\]._user_attr)" \ + [multi_line \ + "AttributeError: 'gdb\\.Inferior' object has no attribute '_user_attr'" \ + "Error while executing Python code\\."] \ + "check new inferior doesn't have user defined attribute" +gdb_test "python print(gdb.inferiors()\[0\]._user_attr)" \ + "123" "read back user defined attribute again" + # Test memory search. set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*} |