public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 4/8] Use ada_value_subscript in valpy_getitem
Date: Tue, 22 Aug 2023 09:25:10 -0600	[thread overview]
Message-ID: <20230822-array-and-string-like-v1-4-2dcea29b0567@adacore.com> (raw)
In-Reply-To: <20230822-array-and-string-like-v1-0-2dcea29b0567@adacore.com>

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


  parent reply	other threads:[~2023-08-22 15:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 15:25 [PATCH 0/8] Handle array- and string-like types in DAP Tom Tromey
2023-08-22 15:25 ` [PATCH 1/8] Move rust_language::lookup_symbol_nonlocal Tom Tromey
2023-08-22 15:25 ` [PATCH 2/8] Refactor Rust code for slice-to-array operation Tom Tromey
2023-08-22 15:25 ` [PATCH 3/8] Introduce TYPE_SPECIFIC_RUST_STUFF Tom Tromey
2023-08-22 15:25 ` Tom Tromey [this message]
2023-08-22 15:25 ` [PATCH 5/8] Introduce type::is_array_like and value_to_array Tom Tromey
2023-08-22 15:25 ` [PATCH 6/8] Select frame when fetching a frame variable in DAP Tom Tromey
2023-08-22 15:25 ` [PATCH 7/8] Add new Python APIs to support DAP value display Tom Tromey
2023-08-22 15:46   ` Eli Zaretskii
2023-08-22 15:25 ` [PATCH 8/8] Handle array- and string-like values in no-op pretty printers Tom Tromey
2023-09-05 17:22 ` [PATCH 0/8] Handle array- and string-like types in DAP Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230822-array-and-string-like-v1-4-2dcea29b0567@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).