"unset_env". These can be used to modify the inferior's
environment before it is started.
+ ** gdb.Value now has the 'assign' method.
+
*** Changes in GDB 13
* MI version 1 is deprecated, and will be removed in GDB 14.
behaves as though @var{type} was not passed at all.
@end defun
+@defun Value.assign (rhs)
+Assign @var{rhs} to this value, and return @code{None}. If this value
+cannot be assigned to, or if the assignment is invalid for some reason
+(for example a type-checking failure), an exception will be thrown.
+@end defun
+
@defun Value.cast (type)
Return a new instance of @code{gdb.Value} that is the result of
casting this instance to the type described by @var{type}, which must
return valpy_do_cast (self, args, UNOP_REINTERPRET_CAST);
}
+/* Implementation of the "assign" method. */
+
+static PyObject *
+valpy_assign (PyObject *self_obj, PyObject *args)
+{
+ PyObject *val_obj;
+
+ if (! PyArg_ParseTuple (args, "O", &val_obj))
+ return nullptr;
+
+ struct value *val = convert_value_from_python (val_obj);
+ if (val == nullptr)
+ return nullptr;
+
+ try
+ {
+ value_object *self = (value_object *) self_obj;
+ value_assign (self->value, val);
+ }
+ catch (const gdb_exception &except)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
+
+ Py_RETURN_NONE;
+}
+
static Py_ssize_t
valpy_length (PyObject *self)
{
"format_string (...) -> string\n\
Return a string representation of the value using the specified\n\
formatting options" },
+ { "assign", (PyCFunction) valpy_assign, METH_VARARGS,
+ "assign (VAL) -> None\n\
+Assign VAL to this value." },
{NULL} /* Sentinel */
};
}
}
+# Test Value.assign.
+proc test_assign {} {
+ gdb_test_no_output "python i_value = gdb.parse_and_eval('i')" \
+ "evaluate i"
+ gdb_test_no_output "python i_value.assign(27)" \
+ "set i to 27"
+ gdb_test "print i" " = 27"
+ gdb_test_no_output "python i_value = gdb.Value(27)" \
+ "reset i_value"
+ gdb_test "python i_value.assign(89)" "not an lvalue.*" \
+ "cannot assign to integer"
+}
+
# Build C version of executable. C++ is built later.
if { [build_inferior "${binfile}" "c"] < 0 } {
return -1
test_value_from_buffer
test_value_sub_classes
test_inferior_function_call
+test_assign
test_value_after_death
# Test either C or C++ values.