diff options
author | Hannes Domani <ssbssa@yahoo.de> | 2024-06-03 17:23:26 +0200 |
---|---|---|
committer | Hannes Domani <ssbssa@yahoo.de> | 2024-06-03 17:23:26 +0200 |
commit | 8a2e940b8d5751805d5fab127cc7dca0ce36ff0d (patch) | |
tree | 94b5b029b1435509f9c5974790b1bc669bf2e561 /gdb/testsuite/gdb.python/py-value-cc.cc | |
parent | f74da7b8b3d6f14ba9ad21b380f743e4bdc4e952 (diff) | |
download | binutils-8a2e940b8d5751805d5fab127cc7dca0ce36ff0d.zip binutils-8a2e940b8d5751805d5fab127cc7dca0ce36ff0d.tar.gz binutils-8a2e940b8d5751805d5fab127cc7dca0ce36ff0d.tar.bz2 |
Enable call of overloaded subscript operator from python
If you try to use the overloaded subscript operator of a class
in python, it fails like this:
(gdb) py print(gdb.parse_and_eval('b')[5])
Traceback (most recent call last):
File "<string>", line 1, in <module>
gdb.error: Cannot subscript requested type.
Error while executing Python code.
This simply checks if such an operator exists, and calls it
instead, making this possible:
(gdb) py print(gdb.parse_and_eval('b')[5])
102 'f'
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite/gdb.python/py-value-cc.cc')
-rw-r--r-- | gdb/testsuite/gdb.python/py-value-cc.cc | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-value-cc.cc b/gdb/testsuite/gdb.python/py-value-cc.cc index 2d38a26..08b9915 100644 --- a/gdb/testsuite/gdb.python/py-value-cc.cc +++ b/gdb/testsuite/gdb.python/py-value-cc.cc @@ -42,6 +42,7 @@ class B : public A { int arg0_func (); int arg1_func (int arg1); int arg2_func (int arg1, int arg2); + char operator[] (int num); }; int B::static_func () @@ -64,6 +65,11 @@ int B::arg2_func (int arg1, int arg2) return a * arg1 + arg2; } +char B::operator[] (int num) +{ + return a + num; +} + struct X { union { int x; char y; }; |