gdb_test "p/d one_hundred" " = \\{0 <repeats 100 times>\\}"
}
gdb_test "p/d one_hundred \[99\]" " = 0"
+ # Verify that accessing value history is undisturbed.
+ gdb_test "p/d \$2" " = \\{0 <repeats 100 times>\\}"
+ gdb_test "p/d \$2 \[99\]" " = 0"
}
}
gdb_test "pt e.method('a')" "type = void"
gdb_test "pt e.method(10)" \
"NotImplementedError.*Error while fetching result type of an xmethod worker defined in Python."
+
+# Verify `max-value-size' obedience with `gdb.Value.const_value'.
+gdb_test "p a1.getarray()" \
+ "From Python <A_getarray>.* = \\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9\\}" \
+ "after: a1.getarray"
+gdb_test "p b1.getarray()" \
+ "From Python <B_getarray>.* = \\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9\\}" \
+ "after: b1.getarray"
+gdb_test_no_output "python gdb.set_parameter('max-value-size', 16)"
+gdb_test "p a1.getarray()" \
+ "From Python <A_getarray>.*value requires $decimal bytes,\
+ which is more than max-value-size" \
+ "after: a1.getarray (max-value-size)"
+gdb_test "p b1.getarray()" \
+ "From Python <B_getarray>.*value requires $decimal bytes,\
+ which is more than max-value-size" \
+ "after: b1.getarray (max-value-size)"
return obj["a"]
+def A_getarray(obj):
+ print("From Python <A_getarray>:")
+ return obj["array"]
+
+
def A_getarrayind(obj, index):
print("From Python <A_getarrayind>:")
return obj["array"][index]
return obj["array"][index].reference_value()
+def B_getarray(obj):
+ print("From Python <B_getarray>:")
+ return obj["array"].const_value()
+
+
def B_indexoper(obj, index):
return obj["array"][index].const_value().reference_value()
type_A = gdb.parse_and_eval("(dop::A *) 0").type.target()
type_B = gdb.parse_and_eval("(dop::B *) 0").type.target()
+type_array = gdb.parse_and_eval("(int[10] *) 0").type.target()
type_int = gdb.parse_and_eval("(int *) 0").type.target()
),
SimpleXMethodMatcher(r"plus_plus_A", r"^dop::A$", r"operator\+\+", plus_plus_A),
SimpleXMethodMatcher(r"A_geta", r"^dop::A$", r"^geta$", A_geta),
+ SimpleXMethodMatcher(
+ r"A_getarray", r"^dop::A$", r"^getarray$", A_getarray, type_array
+ ),
SimpleXMethodMatcher(
r"A_getarrayind", r"^dop::A$", r"^getarrayind$", A_getarrayind, type_int
),
SimpleXMethodMatcher(
r"A_indexoper", r"^dop::A$", r"operator\[\]", A_indexoper, type_int
),
+ SimpleXMethodMatcher(
+ r"B_getarray", r"^dop::B$", r"^getarray$", B_getarray, type_array
+ ),
SimpleXMethodMatcher(
r"B_indexoper", r"^dop::B$", r"operator\[\]", B_indexoper, type_int
),
}
}
-/* 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. */
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
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);
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)
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;
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. */