]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Enable call of overloaded subscript operator from python
authorHannes Domani <ssbssa@yahoo.de>
Mon, 3 Jun 2024 15:23:26 +0000 (17:23 +0200)
committerHannes Domani <ssbssa@yahoo.de>
Mon, 3 Jun 2024 15:23:26 +0000 (17:23 +0200)
commit8a2e940b8d5751805d5fab127cc7dca0ce36ff0d
tree94b5b029b1435509f9c5974790b1bc669bf2e561
parentf74da7b8b3d6f14ba9ad21b380f743e4bdc4e952
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>
gdb/python/py-value.c
gdb/testsuite/gdb.python/py-value-cc.cc
gdb/testsuite/gdb.python/py-value-cc.exp