From 8a2e940b8d5751805d5fab127cc7dca0ce36ff0d Mon Sep 17 00:00:00 2001 From: Hannes Domani Date: Mon, 3 Jun 2024 17:23:26 +0200 Subject: 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 "", line 1, in 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 --- gdb/testsuite/gdb.python/py-value-cc.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gdb/testsuite/gdb.python/py-value-cc.cc') 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; }; -- cgit v1.1