aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-08-29 09:14:01 -0600
committerTom Tromey <tromey@adacore.com>2023-08-29 13:36:55 -0600
commitb47331bf901065e051d6490105a61e677cafc451 (patch)
treec6fd7f523e1f1aecb574085d6e7965358aa6fb60 /gdb
parent8b2ac9b21649a9c7f9edecfd817e9d10f20158c0 (diff)
downloadgdb-b47331bf901065e051d6490105a61e677cafc451.zip
gdb-b47331bf901065e051d6490105a61e677cafc451.tar.gz
gdb-b47331bf901065e051d6490105a61e677cafc451.tar.bz2
Remove "highbound" parameter from value_array
value_array requires the passed-in bounds to match the length of the array_view it is given. This patch removes the redundant "highbound" parameter. Reviewed-by: John Baldwin <jhb@FreeBSD.org> Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/eval.c2
-rw-r--r--gdb/rust-lang.c2
-rw-r--r--gdb/valops.c25
-rw-r--r--gdb/value.h2
4 files changed, 12 insertions, 19 deletions
diff --git a/gdb/eval.c b/gdb/eval.c
index 8dd1b53..7c955a4 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2515,7 +2515,7 @@ array_operation::evaluate (struct type *expect_type,
objects. */
argvec[tem] = in_args[tem]->evaluate_with_coercion (exp, noside);
}
- return value_array (tem2, tem3, argvec);
+ return value_array (tem2, argvec);
}
value *
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f6e7d25..0e2ca09 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1344,7 +1344,7 @@ eval_op_rust_array (struct type *expect_type, struct expression *exp,
for (i = 0; i < copies; ++i)
eltvec[i] = elt;
- return value_array (0, copies - 1, eltvec);
+ return value_array (0, eltvec);
}
else
{
diff --git a/gdb/valops.c b/gdb/valops.c
index 1133049..6404091 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1684,18 +1684,16 @@ value_ind (struct value *arg1)
/* Create a value for an array by allocating space in GDB, copying the
data into that space, and then setting up an array value.
- The array bounds are set from LOWBOUND and HIGHBOUND, and the array
- is populated from the values passed in ELEMVEC.
+ The array bounds are set from LOWBOUND and the size of ELEMVEC, and
+ the array is populated from the values passed in ELEMVEC.
The element type of the array is inherited from the type of the
first element, and all elements must have the same size (though we
don't currently enforce any restriction on their types). */
struct value *
-value_array (int lowbound, int highbound,
- gdb::array_view<struct value *> elemvec)
+value_array (int lowbound, gdb::array_view<struct value *> elemvec)
{
- int nelem;
int idx;
ULONGEST typelength;
struct value *val;
@@ -1704,28 +1702,23 @@ value_array (int lowbound, int highbound,
/* Validate that the bounds are reasonable and that each of the
elements have the same size. */
- nelem = highbound - lowbound + 1;
- if (nelem <= 0)
- {
- error (_("bad array bounds (%d, %d)"), lowbound, highbound);
- }
typelength = type_length_units (elemvec[0]->enclosing_type ());
- for (idx = 1; idx < nelem; idx++)
+ for (struct value *other : elemvec.slice (1))
{
- if (type_length_units (elemvec[idx]->enclosing_type ())
- != typelength)
+ if (type_length_units (other->enclosing_type ()) != typelength)
{
error (_("array elements must all be the same size"));
}
}
arraytype = lookup_array_range_type (elemvec[0]->enclosing_type (),
- lowbound, highbound);
+ lowbound,
+ lowbound + elemvec.size () - 1);
if (!current_language->c_style_arrays_p ())
{
val = value::allocate (arraytype);
- for (idx = 0; idx < nelem; idx++)
+ for (idx = 0; idx < elemvec.size (); idx++)
elemvec[idx]->contents_copy (val, idx * typelength, 0, typelength);
return val;
}
@@ -1734,7 +1727,7 @@ value_array (int lowbound, int highbound,
copying in each element. */
val = value::allocate (arraytype);
- for (idx = 0; idx < nelem; idx++)
+ for (idx = 0; idx < elemvec.size (); idx++)
elemvec[idx]->contents_copy (val, idx * typelength, 0, typelength);
return val;
}
diff --git a/gdb/value.h b/gdb/value.h
index ccf5219..c28b731 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1225,7 +1225,7 @@ inline struct value *value_string (const char *ptr, ssize_t count,
return value_string ((const gdb_byte *) ptr, count, char_type);
}
-extern struct value *value_array (int lowbound, int highbound,
+extern struct value *value_array (int lowbound,
gdb::array_view<struct value *> elemvec);
extern struct value *value_concat (struct value *arg1, struct value *arg2);