aboutsummaryrefslogtreecommitdiff
path: root/gdb/value.c
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@embecosm.com>2023-02-10 23:49:19 +0000
committerMaciej W. Rozycki <macro@embecosm.com>2023-02-10 23:49:19 +0000
commitbae19789c0a2d4e88b5b441acebe4d9e1522cd67 (patch)
tree0e87db154b2957b716aa3a3432a95efdbccbaab6 /gdb/value.c
parent4a9efa5d63b2253a595ff9d6944415bf8cbfe408 (diff)
downloadbinutils-bae19789c0a2d4e88b5b441acebe4d9e1522cd67.zip
binutils-bae19789c0a2d4e88b5b441acebe4d9e1522cd67.tar.gz
binutils-bae19789c0a2d4e88b5b441acebe4d9e1522cd67.tar.bz2
GDB: Ignore `max-value-size' setting with value history accesses
We have an inconsistency in value history accesses where array element accesses cause an error for entries exceeding the currently selected `max-value-size' setting even where such accesses successfully complete for elements located in the inferior, e.g.: (gdb) p/d one $1 = 0 (gdb) p/d one_hundred $2 = {0 <repeats 100 times>} (gdb) p/d one_hundred[99] $3 = 0 (gdb) set max-value-size 25 (gdb) p/d one_hundred value requires 100 bytes, which is more than max-value-size (gdb) p/d one_hundred[99] $7 = 0 (gdb) p/d $2 value requires 100 bytes, which is more than max-value-size (gdb) p/d $2[99] value requires 100 bytes, which is more than max-value-size (gdb) According to our documentation the `max-value-size' setting is a safety guard against allocating an overly large amount of memory. Moreover a statement in documentation says, concerning this setting, that: "Setting this variable does not affect values that have already been allocated within GDB, only future allocations." While in the implementer-speak the sentence may be unambiguous I think the outside user may well infer that the setting does not apply to values previously printed. Therefore rather than just fixing this inconsistency it seems reasonable to lift the setting for value history accesses, under an implication that by having been retrieved from the debuggee they have already passed the safety check. Do it then, by suppressing the value size check in `value_copy' -- under an observation that if the original value has been already loaded (i.e. it's not lazy), then it must have previously passed said check -- making the last two commands succeed: (gdb) p/d $2 $8 = {0 <repeats 100 times>} (gdb) p/d $2 [99] $9 = 0 (gdb) Expand the testsuite accordingly, covering both value history handling and the use of `value_copy' by `make_cv_value', used by Python code.
Diffstat (limited to 'gdb/value.c')
-rw-r--r--gdb/value.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/gdb/value.c b/gdb/value.c
index e3f60e7..09e10b9 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1034,31 +1034,42 @@ check_type_length_before_alloc (const struct type *type)
}
}
-/* Allocate the contents of VAL if it has not been allocated yet. */
+/* Allocate the contents of VAL if it has not been allocated yet.
+ If CHECK_SIZE is true, then apply the usual max-value-size checks. */
static void
-allocate_value_contents (struct value *val)
+allocate_value_contents (struct value *val, bool check_size)
{
if (!val->contents)
{
- check_type_length_before_alloc (val->enclosing_type);
+ if (check_size)
+ check_type_length_before_alloc (val->enclosing_type);
val->contents.reset
((gdb_byte *) xzalloc (val->enclosing_type->length ()));
}
}
-/* Allocate a value and its contents for type TYPE. */
+/* Allocate a value and its contents for type TYPE. If CHECK_SIZE is true,
+ then apply the usual max-value-size checks. */
-struct value *
-allocate_value (struct type *type)
+static struct value *
+allocate_value (struct type *type, bool check_size)
{
struct value *val = allocate_value_lazy (type);
- allocate_value_contents (val);
+ allocate_value_contents (val, check_size);
val->lazy = 0;
return val;
}
+/* Allocate a value and its contents for type TYPE. */
+
+struct value *
+allocate_value (struct type *type)
+{
+ return allocate_value (type, true);
+}
+
/* Allocate a value that has the correct length
for COUNT repetitions of type TYPE. */
@@ -1169,7 +1180,7 @@ value_contents_raw (struct value *value)
struct gdbarch *arch = get_value_arch (value);
int unit_size = gdbarch_addressable_memory_unit_size (arch);
- allocate_value_contents (value);
+ allocate_value_contents (value, true);
ULONGEST length = value_type (value)->length ();
return gdb::make_array_view
@@ -1179,7 +1190,7 @@ value_contents_raw (struct value *value)
gdb::array_view<gdb_byte>
value_contents_all_raw (struct value *value)
{
- allocate_value_contents (value);
+ allocate_value_contents (value, true);
ULONGEST length = value_enclosing_type (value)->length ();
return gdb::make_array_view (value->contents.get (), length);
@@ -1752,9 +1763,8 @@ value_release_to_mark (const struct value *mark)
return result;
}
-/* Return a copy of the value ARG.
- It contains the same contents, for same memory address,
- but it's a different block of storage. */
+/* Return a copy of the value ARG. It contains the same contents,
+ for the same memory address, but it's a different block of storage. */
struct value *
value_copy (const value *arg)
@@ -1765,7 +1775,7 @@ value_copy (const value *arg)
if (value_lazy (arg))
val = allocate_value_lazy (encl_type);
else
- val = allocate_value (encl_type);
+ val = allocate_value (encl_type, false);
val->type = arg->type;
VALUE_LVAL (val) = arg->lval;
val->location = arg->location;
@@ -4162,7 +4172,7 @@ void
value_fetch_lazy (struct value *val)
{
gdb_assert (value_lazy (val));
- allocate_value_contents (val);
+ allocate_value_contents (val, true);
/* A value is either lazy, or fully fetched. The
availability/validity is only established as we try to fetch a
value. */