mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-08-06 14:49:38 +08:00
Add gdb.Value.assign method
This adds an 'assign' method to gdb.Value. This allows for assignment without requiring the use of parse_and_eval. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
This commit is contained in:
2
gdb/NEWS
2
gdb/NEWS
@ -220,6 +220,8 @@ info main
|
|||||||
"unset_env". These can be used to modify the inferior's
|
"unset_env". These can be used to modify the inferior's
|
||||||
environment before it is started.
|
environment before it is started.
|
||||||
|
|
||||||
|
** gdb.Value now has the 'assign' method.
|
||||||
|
|
||||||
*** Changes in GDB 13
|
*** Changes in GDB 13
|
||||||
|
|
||||||
* MI version 1 is deprecated, and will be removed in GDB 14.
|
* MI version 1 is deprecated, and will be removed in GDB 14.
|
||||||
|
@ -947,6 +947,12 @@ If @var{type} is @code{None} then this version of @code{__init__}
|
|||||||
behaves as though @var{type} was not passed at all.
|
behaves as though @var{type} was not passed at all.
|
||||||
@end defun
|
@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)
|
@defun Value.cast (type)
|
||||||
Return a new instance of @code{gdb.Value} that is the result of
|
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
|
casting this instance to the type described by @var{type}, which must
|
||||||
|
@ -853,6 +853,33 @@ valpy_reinterpret_cast (PyObject *self, PyObject *args)
|
|||||||
return valpy_do_cast (self, args, UNOP_REINTERPRET_CAST);
|
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
|
static Py_ssize_t
|
||||||
valpy_length (PyObject *self)
|
valpy_length (PyObject *self)
|
||||||
{
|
{
|
||||||
@ -2119,6 +2146,9 @@ Return Unicode string representation of the value." },
|
|||||||
"format_string (...) -> string\n\
|
"format_string (...) -> string\n\
|
||||||
Return a string representation of the value using the specified\n\
|
Return a string representation of the value using the specified\n\
|
||||||
formatting options" },
|
formatting options" },
|
||||||
|
{ "assign", (PyCFunction) valpy_assign, METH_VARARGS,
|
||||||
|
"assign (VAL) -> None\n\
|
||||||
|
Assign VAL to this value." },
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -633,6 +633,19 @@ proc test_history_count {} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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.
|
# Build C version of executable. C++ is built later.
|
||||||
if { [build_inferior "${binfile}" "c"] < 0 } {
|
if { [build_inferior "${binfile}" "c"] < 0 } {
|
||||||
return -1
|
return -1
|
||||||
@ -663,6 +676,7 @@ test_value_in_inferior
|
|||||||
test_value_from_buffer
|
test_value_from_buffer
|
||||||
test_value_sub_classes
|
test_value_sub_classes
|
||||||
test_inferior_function_call
|
test_inferior_function_call
|
||||||
|
test_assign
|
||||||
test_value_after_death
|
test_value_after_death
|
||||||
|
|
||||||
# Test either C or C++ values.
|
# Test either C or C++ values.
|
||||||
|
Reference in New Issue
Block a user