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 3/5] Add is_array_like and to_array to language_defn
Date: Tue, 05 Sep 2023 13:47:03 -0600	[thread overview]
Message-ID: <20230905-dap-30821-pointers-v1-3-0d7323327678@adacore.com> (raw)
In-Reply-To: <20230905-dap-30821-pointers-v1-0-0d7323327678@adacore.com>

This adds new is_array_like and to_array methods to language_defn.
This will be used in a subsequent patch that generalizes the new
Python array- and string-handling code.
---
 gdb/ada-lang.c  | 13 +++++++++++++
 gdb/language.h  | 11 +++++++++++
 gdb/rust-lang.h | 10 ++++++++++
 3 files changed, 34 insertions(+)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index c0cc512bfa3..b03ed53d11c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13810,6 +13810,19 @@ class ada_language : public language_defn
 
   /* See language.h.  */
 
+  bool is_array_like (struct type *type) const override
+  {
+    return (ada_is_constrained_packed_array_type (type)
+	    || ada_is_array_descriptor_type (type));
+  }
+
+  /* See language.h.  */
+
+  struct value *to_array (struct value *val) const override
+  { return ada_coerce_to_simple_array (val); }
+
+  /* See language.h.  */
+
   const char *struct_too_deep_ellipsis () const override
   { return "(...)"; }
 
diff --git a/gdb/language.h b/gdb/language.h
index 9fd2fb6f387..6ee8f6160e1 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -568,6 +568,17 @@ struct language_defn
   /* Return true if TYPE is a string type.  */
   virtual bool is_string_type_p (struct type *type) const;
 
+  /* Return true if TYPE is array-like.  */
+  virtual bool is_array_like (struct type *type) const
+  { return false; }
+
+  /* Underlying implementation of value_to_array.  Return a value of
+     array type that corresponds to VAL.  The caller must ensure that
+     is_array_like is true for VAL's type.  Return nullptr if the type
+     cannot be handled.  */
+  virtual struct value *to_array (struct value *val) const
+  { return nullptr; }
+
   /* Return a string that is used by the 'set print max-depth' setting.
      When GDB replaces a struct or union (during value printing) that is
      "too deep" this string is displayed instead.  The default value here
diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h
index 2c7ccb93bcf..ce1dff211b6 100644
--- a/gdb/rust-lang.h
+++ b/gdb/rust-lang.h
@@ -196,6 +196,16 @@ class rust_language : public language_defn
 
   /* See language.h.  */
 
+  bool is_array_like (struct type *type) const override
+  { return rust_slice_type_p (type); }
+
+  /* See language.h.  */
+
+  struct value *to_array (struct value *val) const override
+  { return rust_slice_to_array (val); }
+
+  /* See language.h.  */
+
   bool range_checking_on_by_default () const override
   { return true; }
 

-- 
2.40.1


  parent reply	other threads:[~2023-09-05 19:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-05 19:47 [PATCH 0/5] Handle pointers and references correctly in DAP Tom Tromey
2023-09-05 19:47 ` [PATCH 1/5] Pass a type allocator to init_fixed_point_type Tom Tromey
2023-09-05 19:47 ` [PATCH 2/5] Regularize some DWARF type initialization Tom Tromey
2023-09-05 19:47 ` Tom Tromey [this message]
2023-09-05 19:47 ` [PATCH 4/5] Give a language to a type Tom Tromey
2023-09-05 19:47 ` [PATCH 5/5] Handle pointers and references correctly in DAP Tom Tromey
2023-09-19 19:30 ` [PATCH 0/5] " 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=20230905-dap-30821-pointers-v1-3-0d7323327678@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).