mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-05-24 10:46:24 +08:00
gdb/
* python/py-breakpoint.c (bppy_set_condition): New comment. * python/py-cmd.c (cmdpy_function): Call also gdbpy_print_stack for failed PyUnicode_Decode. (cmdpy_completer): Skip element for failed python_string_to_host_string. (cmdpy_init): Return -1 on failed python_string_to_host_string. * python/py-frame.c (frapy_read_var): Extend the function comment. * python/py-function.c (fnpy_init): Return -1 on failed python_string_to_host_string. * python/py-inferior.c (infpy_read_memory, infpy_write_memory): Extend the function comment. (infpy_search_memory): Extend the function comment. Remove the PyErr_SetString call on already set error state. * python/py-param.c (set_parameter_value): Extend the function comment. Return -1 on failed python_string_to_host_string, twice. (set_attr): Extend the function comment. (compute_enum_values): Extend the function comment. New variable back_to. Protect self->enumeration by BACK_TO cleanups. Return 0 on failed python_string_to_host_string. (get_doc_string): Call gdbpy_print_stack on failed python_string_to_host_string. (parmpy_init): Extend the function comment. * python/py-prettyprint.c (pretty_print_one_value): Likewise. (gdbpy_get_display_hint, print_children): Call gdbpy_print_stack on failed python_string_to_host_string. * python/py-value.c (valpy_new, valpy_getitem, valpy_call) (valpy_binop, valpy_richcompare): Extend the function comment. * python/python.c (struct python_env) <error_type, error_value, error_traceback>: New fields. (restore_python_env): Handle PyErr_Occurred. Call PyErr_Restore. (ensure_python_env): Call PyErr_Fetch. * varobj.c (update_dynamic_varobj_children): Call gdbpy_print_stack on failed convert_value_from_python. (value_get_print_value): Call gdbpy_print_stack on failed python_string_to_target_python_string. gdb/testsuite/ * gdb.python/py-error.exp: New file. * gdb.python/py-error.py: New file.
This commit is contained in:
@ -110,8 +110,8 @@ get_attr (PyObject *obj, PyObject *attr_name)
|
||||
return PyObject_GenericGetAttr (obj, attr_name);
|
||||
}
|
||||
|
||||
/* Set a parameter value from a Python value. Return 0 on success, -1
|
||||
on failure. */
|
||||
/* Set a parameter value from a Python value. Return 0 on success. Returns
|
||||
-1 on error, with a python exception set. */
|
||||
static int
|
||||
set_parameter_value (parmpy_object *self, PyObject *value)
|
||||
{
|
||||
@ -132,17 +132,25 @@ set_parameter_value (parmpy_object *self, PyObject *value)
|
||||
|
||||
return -1;
|
||||
}
|
||||
if (self->value.stringval)
|
||||
xfree (self->value.stringval);
|
||||
if (value == Py_None)
|
||||
{
|
||||
xfree (self->value.stringval);
|
||||
if (self->type == var_optional_filename)
|
||||
self->value.stringval = xstrdup ("");
|
||||
else
|
||||
self->value.stringval = NULL;
|
||||
}
|
||||
else
|
||||
self->value.stringval = python_string_to_host_string (value);
|
||||
{
|
||||
char *string;
|
||||
|
||||
string = python_string_to_host_string (value);
|
||||
if (string == NULL)
|
||||
return -1;
|
||||
|
||||
xfree (self->value.stringval);
|
||||
self->value.stringval = string;
|
||||
}
|
||||
break;
|
||||
|
||||
case var_enum:
|
||||
@ -158,6 +166,8 @@ set_parameter_value (parmpy_object *self, PyObject *value)
|
||||
}
|
||||
|
||||
str = python_string_to_host_string (value);
|
||||
if (str == NULL)
|
||||
return -1;
|
||||
for (i = 0; self->enumeration[i]; ++i)
|
||||
if (! strcmp (self->enumeration[i], str))
|
||||
break;
|
||||
@ -258,7 +268,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set an attribute. */
|
||||
/* Set an attribute. Returns -1 on error, with a python exception set. */
|
||||
static int
|
||||
set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
|
||||
{
|
||||
@ -358,12 +368,13 @@ add_setshow_generic (int parmclass, enum command_class cmdclass,
|
||||
}
|
||||
}
|
||||
|
||||
/* A helper which computes enum values. Returns 1 on success, 0 on
|
||||
error. */
|
||||
/* A helper which computes enum values. Returns 1 on success. Returns 0 on
|
||||
error, with a python exception set. */
|
||||
static int
|
||||
compute_enum_values (parmpy_object *self, PyObject *enum_values)
|
||||
{
|
||||
Py_ssize_t size, i;
|
||||
struct cleanup *back_to;
|
||||
|
||||
if (! enum_values)
|
||||
{
|
||||
@ -390,6 +401,7 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
|
||||
}
|
||||
|
||||
self->enumeration = xmalloc ((size + 1) * sizeof (char *));
|
||||
back_to = make_cleanup (free_current_contents, &self->enumeration);
|
||||
memset (self->enumeration, 0, (size + 1) * sizeof (char *));
|
||||
|
||||
for (i = 0; i < size; ++i)
|
||||
@ -397,16 +409,27 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
|
||||
PyObject *item = PySequence_GetItem (enum_values, i);
|
||||
|
||||
if (! item)
|
||||
return 0;
|
||||
{
|
||||
do_cleanups (back_to);
|
||||
return 0;
|
||||
}
|
||||
if (! gdbpy_is_string (item))
|
||||
{
|
||||
do_cleanups (back_to);
|
||||
PyErr_SetString (PyExc_RuntimeError,
|
||||
_("The enumeration item not a string."));
|
||||
return 0;
|
||||
}
|
||||
self->enumeration[i] = python_string_to_host_string (item);
|
||||
if (self->enumeration[i] == NULL)
|
||||
{
|
||||
do_cleanups (back_to);
|
||||
return 0;
|
||||
}
|
||||
make_cleanup (xfree, (char *) self->enumeration[i]);
|
||||
}
|
||||
|
||||
discard_cleanups (back_to);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -422,7 +445,11 @@ get_doc_string (PyObject *object, PyObject *attr)
|
||||
PyObject *ds_obj = PyObject_GetAttr (object, attr);
|
||||
|
||||
if (ds_obj && gdbpy_is_string (ds_obj))
|
||||
result = python_string_to_host_string (ds_obj);
|
||||
{
|
||||
result = python_string_to_host_string (ds_obj);
|
||||
if (result == NULL)
|
||||
gdbpy_print_stack ();
|
||||
}
|
||||
}
|
||||
if (! result)
|
||||
result = xstrdup (_("This command is not documented."));
|
||||
@ -449,8 +476,9 @@ get_doc_string (PyObject *object, PyObject *attr)
|
||||
|
||||
The documentation for the parameter is taken from the doc string
|
||||
for the python class.
|
||||
|
||||
*/
|
||||
|
||||
Returns -1 on error, with a python exception set. */
|
||||
|
||||
static int
|
||||
parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
|
Reference in New Issue
Block a user