From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id B78383857351 for ; Tue, 22 Aug 2023 15:25:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B78383857351 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-34c9f8c9876so10804255ab.3 for ; Tue, 22 Aug 2023 08:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1692717914; x=1693322714; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=W8+p4XdB2nExj6jIcGaSKEd9LvFSnekePCKsQPJnhr4=; b=b5N5Cq+p5e6yBMSrcD1S+m2hJjQbUixBZ9DdGNdZinDkLYK6ibQ9+oDabqvN5nB+9q mDH+vNmBjjn3BjbFOwMTQtNedjMEf6SC7kY+TxboybXodLbLp3rDsNbaPpI6tC/4UNY0 EYqyeiZNHxahF7XuDBFwhZWZFKt14Z7EioO4ybn2gnAwkrv7Zh1ByR/4E9U8WWqUdvT9 Malrm/CfugxgCfp5RtfXrJGNNSE/FogSHfFdC0Nrz257HHrt00HIxDEs7y0TGc/kKo4c Tfgptv0DILPonvpuaYn7SM21SswYiioazydKjP2+AoshYrzR83eyne+OZAPZpC3c8I5w fWXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692717914; x=1693322714; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W8+p4XdB2nExj6jIcGaSKEd9LvFSnekePCKsQPJnhr4=; b=RsaidtqLAU2+uYqrfAzx9GlppxDJqF/SLHnRxyEysHLNIpHEhFZ+s6aTJVxohK5Gtd P8cyYrUjKanRHAsM5rzgPJ6QeikP7VL7gxRj5Hw2RHY/H1FuIBlXSJSCjHq6YXsisAh8 CithmleysFNAt3fYqIupkWl0q2sYDBiD282Z5Z3Q2DxXTQ1eMQzOAJIHWWyGu3AP5TUd pKPFucXPTnFPEbCw5MT9AlLrgAZ5OHPqKXaiRtq28qOLED0/LjGFP7tYnZz3BJhYE2/B dVr+saIK0e9x6lPHfykucZLFdaRSg86CRCh3qLko3zIahXFXeBxUemaFl2s4t4bnKYil +RaA== X-Gm-Message-State: AOJu0YxOsGPjZYEc0qsZi3Iv/vWtxIFBnSjp9PzVrjtyIh+sLp5U7Pq3 65BrA7ZoRLzqB+81kYtJCPbd4sIGW938Py2M1IWn9Q== X-Google-Smtp-Source: AGHT+IFxcdhnuLKQrJQKgCXBDpKf4U3IZdbjrTjLIXTPOwpskPTPMTTJntWQ9LDokjSCUWsze84TTw== X-Received: by 2002:a05:6e02:1542:b0:348:f4c1:4817 with SMTP id j2-20020a056e02154200b00348f4c14817mr16512ilu.6.1692717913959; Tue, 22 Aug 2023 08:25:13 -0700 (PDT) Received: from localhost.localdomain (75-166-142-177.hlrn.qwest.net. [75.166.142.177]) by smtp.gmail.com with ESMTPSA id e8-20020a92de48000000b003460b8505easm1721608ilr.19.2023.08.22.08.25.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 08:25:13 -0700 (PDT) From: Tom Tromey Date: Tue, 22 Aug 2023 09:25:10 -0600 Subject: [PATCH 4/8] Use ada_value_subscript in valpy_getitem MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230822-array-and-string-like-v1-4-2dcea29b0567@adacore.com> References: <20230822-array-and-string-like-v1-0-2dcea29b0567@adacore.com> In-Reply-To: <20230822-array-and-string-like-v1-0-2dcea29b0567@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 575568cffb5..4d2c94b9044 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2134,6 +2134,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.40.1