[RFA] Fix PR python/17386 - add __index__ method to gdb.Value

Yao Qi qiyaoltc@gmail.com
Mon May 23 08:34:00 GMT 2016


Tom Tromey <tom@tromey.com> writes:

> While doing this I discovered that value_object_as_number was missing
> an entry.  This patch fixes this.
>

> diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
> index 7dba0ad..d34428d 100644
> --- a/gdb/python/py-value.c
> +++ b/gdb/python/py-value.c
> @@ -1827,6 +1827,7 @@ static PyNumberMethods value_object_as_number = {
>    NULL,                       /* nb_inplace_add */
>    NULL,                       /* nb_inplace_subtract */
>    NULL,                       /* nb_inplace_multiply */
> +  NULL,                       /* nb_inplace_divide */
>    NULL,                       /* nb_inplace_remainder */
>    NULL,                       /* nb_inplace_power */
>    NULL,                       /* nb_inplace_lshift */

This change should be in a separate patch.  Could you split it?  It is
obvious and can be applied.

> diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
> index a9dbe97..019e45b 100644
> --- a/gdb/testsuite/gdb.python/py-value.exp
> +++ b/gdb/testsuite/gdb.python/py-value.exp
> @@ -124,6 +124,9 @@ proc test_value_numeric_ops {} {
>    gdb_test "python print ('result = ' + str(b-2))" " = 0x3( <.*>)?" "subtract python integer from pointer value"
>    gdb_test "python print ('result = ' + str(b-a))" " = 3" "subtract two pointer values"
>  
> +  gdb_test "python print ('result = ' + 'result'\[gdb.Value(0)\])" \
> +    "result = r" "use value as an index"
> +

I tried the test patch on master, and it triggers the exception.
However, the exception is "string indices must be integers, not
gdb.Value", which is different from the exception in the PR.

python print ('result = ' + 'result'[gdb.Value(0)])
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: string indices must be integers, not gdb.Value
Error while executing Python code.
(gdb) FAIL: gdb.python/py-value.exp: use value as an index

These two exceptions look quite similar but can you add a test that
triggers "'gdb.Value' object cannot be interpreted as an integer"?
because that is the symptom this patch is to fix.

-- 
Yao (齐尧)



More information about the Gdb-patches mailing list