From cf1eca3cbbfe8b2092d867023df7dac4d00fa4ec Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 17 Aug 2023 10:37:06 -0600 Subject: [PATCH] Use ada_value_subscript in valpy_getitem Ada has a few complexities when it comes to array handling. Currently these are all handled in Ada-specific code -- but unfortunately that means they aren't really accessible to Python. This patch changes the Python code to defer to Ada when given an Ada array. In order to make this work, one spot in ada-lang.c had to be updated to set the "GNAT-specific" flag on an array type. The test case for this will come in a later patch. --- gdb/ada-lang.c | 1 + gdb/python/py-value.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index f6a623d79ed..c0cc512bfa3 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2141,6 +2141,7 @@ ada_type_of_array (struct value *arr, int bounds) longest_to_int (value_as_long (low)), longest_to_int (value_as_long (high))); elt_type = create_array_type (alloc, elt_type, range_type); + INIT_GNAT_SPECIFIC (elt_type); if (ada_is_unconstrained_packed_array_type (arr->type ())) { diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 069560742cf..e1178de89e9 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -28,6 +28,7 @@ #include "expression.h" #include "cp-abi.h" #include "python.h" +#include "ada-lang.h" #include "python-internal.h" @@ -1096,6 +1097,8 @@ valpy_getitem (PyObject *self, PyObject *key) if (type->code () != TYPE_CODE_ARRAY && type->code () != TYPE_CODE_PTR) error (_("Cannot subscript requested type.")); + else if (ADA_TYPE_P (type)) + res_val = ada_value_subscript (tmp, 1, &idx); else res_val = value_subscript (tmp, value_as_long (idx)); } -- 2.30.2