From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 5/8] Introduce type::is_array_like and value_to_array
Date: Tue, 22 Aug 2023 09:25:11 -0600 [thread overview]
Message-ID: <20230822-array-and-string-like-v1-5-2dcea29b0567@adacore.com> (raw)
In-Reply-To: <20230822-array-and-string-like-v1-0-2dcea29b0567@adacore.com>
This adds the type::is_array_like method and the value_to_array
function.
The former can be used to see whether a given type is known to be
"array-like". This is the currently the case for certain
compiler-generated structure types; in particular both the Ada and
Rust compilers do this.
---
gdb/gdbtypes.c | 17 +++++++++++++++++
gdb/gdbtypes.h | 5 +++++
gdb/valarith.c | 21 +++++++++++++++++++++
gdb/value.h | 4 ++++
4 files changed, 47 insertions(+)
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 082d85bb4fc..8b69a06748a 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -43,6 +43,8 @@
#include "f-lang.h"
#include <algorithm>
#include "gmp-utils.h"
+#include "rust-lang.h"
+#include "ada-lang.h"
/* The value of an invalid conversion badness. */
#define INVALID_CONVERSION 100
@@ -5919,6 +5921,21 @@ type::fixed_point_scaling_factor ()
return type->fixed_point_info ().scaling_factor;
}
+/* See gdbtypes.h. */
+
+bool
+type::is_array_like ()
+{
+ if (code () == TYPE_CODE_ARRAY)
+ return true;
+ if (HAVE_GNAT_AUX_INFO (this))
+ return (ada_is_constrained_packed_array_type (this)
+ || ada_is_array_descriptor_type (this));
+ if (HAVE_RUST_SPECIFIC (this))
+ return rust_slice_type_p (this);
+ return false;
+}
+
\f
static const registry<gdbarch>::key<struct builtin_type> gdbtypes_data;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 389cd6c5757..153ecb4ed5c 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1397,6 +1397,11 @@ struct type
return this->code () == TYPE_CODE_PTR || TYPE_IS_REFERENCE (this);
}
+ /* Return true if this type is "array-like". This includes arrays,
+ but also some forms of structure type that are recognized as
+ representations of arrays by the type's language. */
+ bool is_array_like ();
+
/* * Type that is a pointer to this type.
NULL if no such pointer-to type is known yet.
The debugger may add the address of such a type
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 637047fd853..ef376f05936 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -28,6 +28,8 @@
#include "infcall.h"
#include "gdbsupport/byte-vector.h"
#include "gdbarch.h"
+#include "rust-lang.h"
+#include "ada-lang.h"
/* Forward declarations. */
static struct value *value_subscripted_rvalue (struct value *array,
@@ -249,6 +251,25 @@ value_subscripted_rvalue (struct value *array, LONGEST index,
return value_from_component (array, elt_type, elt_offs);
}
+/* See value.h. */
+
+struct value *
+value_to_array (struct value *val)
+{
+ struct type *type = check_typedef (val->type ());
+ if (type->code () == TYPE_CODE_ARRAY)
+ return val;
+
+ if (type->is_array_like ())
+ {
+ if (HAVE_GNAT_AUX_INFO (type))
+ return ada_coerce_to_simple_array (val);
+ if (HAVE_RUST_SPECIFIC (type))
+ return rust_slice_to_array (val);
+ }
+ return nullptr;
+}
+
\f
/* Check to see if either argument is a structure, or a reference to
one. This is called so we know whether to go ahead with the normal
diff --git a/gdb/value.h b/gdb/value.h
index e5c63dccbe2..bf0bd7dde7b 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1319,6 +1319,10 @@ extern struct value *value_repeat (struct value *arg1, int count);
extern struct value *value_subscript (struct value *array, LONGEST index);
+/* Assuming VAL is array-like (see type::is_array_like), return an
+ array form of VAL. */
+extern struct value *value_to_array (struct value *val);
+
extern struct value *value_bitstring_subscript (struct type *type,
struct value *bitstring,
LONGEST index);
--
2.40.1
next prev 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 ` [PATCH 4/8] Use ada_value_subscript in valpy_getitem Tom Tromey
2023-08-22 15:25 ` Tom Tromey [this message]
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-5-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).