aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorHannes Domani <ssbssa@yahoo.de>2024-06-03 17:23:26 +0200
committerHannes Domani <ssbssa@yahoo.de>2024-06-03 17:23:26 +0200
commit8a2e940b8d5751805d5fab127cc7dca0ce36ff0d (patch)
tree94b5b029b1435509f9c5974790b1bc669bf2e561 /gdb/python
parentf74da7b8b3d6f14ba9ad21b380f743e4bdc4e952 (diff)
downloadgdb-8a2e940b8d5751805d5fab127cc7dca0ce36ff0d.zip
gdb-8a2e940b8d5751805d5fab127cc7dca0ce36ff0d.tar.gz
gdb-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/python')
-rw-r--r--gdb/python/py-value.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 1ae26d7..dada8bf 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1153,7 +1153,11 @@ valpy_getitem (PyObject *self, PyObject *key)
type. */
struct value *idx = convert_value_from_python (key);
- if (idx != NULL)
+ if (idx != NULL
+ && binop_user_defined_p (BINOP_SUBSCRIPT, tmp, idx))
+ res_val = value_x_binop (tmp, idx, BINOP_SUBSCRIPT,
+ OP_NULL, EVAL_NORMAL);
+ else if (idx != NULL)
{
/* Check the value's type is something that can be accessed via
a subscript. */