* python/py-inferior.c (gdbpy_inferiors): Update. Hoist
get_addr_from_python calls out of TRY_CATCH. (infpy_write_memory, infpy_search_memory): Likewise. * python/py-utils.c (get_addr_from_python): Return negative value on error. Use TRY_CATCH. * python/python-internal.h (get_addr_from_python): Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
This commit is contained in:
parent
e19d3afbf8
commit
b86af38a5a
@ -1,3 +1,13 @@
|
|||||||
|
2013-05-20 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
|
* python/py-inferior.c (gdbpy_inferiors): Update. Hoist
|
||||||
|
get_addr_from_python calls out of TRY_CATCH.
|
||||||
|
(infpy_write_memory, infpy_search_memory): Likewise.
|
||||||
|
* python/py-utils.c (get_addr_from_python): Return negative
|
||||||
|
value on error. Use TRY_CATCH.
|
||||||
|
* python/python-internal.h (get_addr_from_python): Use
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
|
||||||
|
|
||||||
2013-05-20 Tom Tromey <tromey@redhat.com>
|
2013-05-20 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
* python/py-event.c (evpy_emit_event): Decref the
|
* python/py-event.c (evpy_emit_event): Decref the
|
||||||
|
@ -406,7 +406,6 @@ gdbpy_inferiors (PyObject *unused, PyObject *unused2)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
|
infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
|
||||||
{
|
{
|
||||||
int error = 0;
|
|
||||||
CORE_ADDR addr, length;
|
CORE_ADDR addr, length;
|
||||||
void *buffer = NULL;
|
void *buffer = NULL;
|
||||||
membuf_object *membuf_obj;
|
membuf_object *membuf_obj;
|
||||||
@ -418,15 +417,12 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
&addr_obj, &length_obj))
|
&addr_obj, &length_obj))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (get_addr_from_python (addr_obj, &addr) < 0
|
||||||
|
|| get_addr_from_python (length_obj, &length) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
TRY_CATCH (except, RETURN_MASK_ALL)
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
||||||
{
|
{
|
||||||
if (!get_addr_from_python (addr_obj, &addr)
|
|
||||||
|| !get_addr_from_python (length_obj, &length))
|
|
||||||
{
|
|
||||||
error = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer = xmalloc (length);
|
buffer = xmalloc (length);
|
||||||
|
|
||||||
read_memory (addr, buffer, length);
|
read_memory (addr, buffer, length);
|
||||||
@ -437,12 +433,6 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
GDB_PY_HANDLE_EXCEPTION (except);
|
GDB_PY_HANDLE_EXCEPTION (except);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error)
|
|
||||||
{
|
|
||||||
xfree (buffer);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
|
membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
|
||||||
if (membuf_obj == NULL)
|
if (membuf_obj == NULL)
|
||||||
{
|
{
|
||||||
@ -475,7 +465,6 @@ static PyObject *
|
|||||||
infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
|
infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
|
||||||
{
|
{
|
||||||
Py_ssize_t buf_len;
|
Py_ssize_t buf_len;
|
||||||
int error = 0;
|
|
||||||
const char *buffer;
|
const char *buffer;
|
||||||
CORE_ADDR addr, length;
|
CORE_ADDR addr, length;
|
||||||
PyObject *addr_obj, *length_obj = NULL;
|
PyObject *addr_obj, *length_obj = NULL;
|
||||||
@ -498,21 +487,16 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (get_addr_from_python (addr_obj, &addr) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (!length_obj)
|
||||||
|
length = buf_len;
|
||||||
|
else if (get_addr_from_python (length_obj, &length) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
TRY_CATCH (except, RETURN_MASK_ALL)
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
||||||
{
|
{
|
||||||
if (!get_addr_from_python (addr_obj, &addr))
|
|
||||||
{
|
|
||||||
error = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!length_obj)
|
|
||||||
length = buf_len;
|
|
||||||
else if (!get_addr_from_python (length_obj, &length))
|
|
||||||
{
|
|
||||||
error = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
write_memory_with_notification (addr, (gdb_byte *) buffer, length);
|
write_memory_with_notification (addr, (gdb_byte *) buffer, length);
|
||||||
}
|
}
|
||||||
#ifdef IS_PY3K
|
#ifdef IS_PY3K
|
||||||
@ -520,11 +504,13 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
#endif
|
#endif
|
||||||
GDB_PY_HANDLE_EXCEPTION (except);
|
GDB_PY_HANDLE_EXCEPTION (except);
|
||||||
|
|
||||||
|
|
||||||
if (error)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
#ifdef IS_PY3K
|
||||||
|
PyBuffer_Release (&pybuf);
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destructor of Membuf objects. */
|
/* Destructor of Membuf objects. */
|
||||||
@ -660,34 +646,26 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (get_addr_from_python (start_addr_obj, &start_addr)
|
if (get_addr_from_python (start_addr_obj, &start_addr) < 0)
|
||||||
&& get_addr_from_python (length_obj, &length))
|
goto fail;
|
||||||
|
|
||||||
|
if (get_addr_from_python (length_obj, &length) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (!length)
|
||||||
{
|
{
|
||||||
if (!length)
|
PyErr_SetString (PyExc_ValueError,
|
||||||
{
|
_("Search range is empty."));
|
||||||
PyErr_SetString (PyExc_ValueError,
|
goto fail;
|
||||||
_("Search range is empty."));
|
}
|
||||||
|
/* Watch for overflows. */
|
||||||
#ifdef IS_PY3K
|
else if (length > CORE_ADDR_MAX
|
||||||
PyBuffer_Release (&pybuf);
|
|| (start_addr + length - 1) < start_addr)
|
||||||
#endif
|
{
|
||||||
return NULL;
|
PyErr_SetString (PyExc_ValueError,
|
||||||
}
|
_("The search range is too large."));
|
||||||
/* Watch for overflows. */
|
goto fail;
|
||||||
else if (length > CORE_ADDR_MAX
|
|
||||||
|| (start_addr + length - 1) < start_addr)
|
|
||||||
{
|
|
||||||
PyErr_SetString (PyExc_ValueError,
|
|
||||||
_("The search range is too large."));
|
|
||||||
|
|
||||||
#ifdef IS_PY3K
|
|
||||||
PyBuffer_Release (&pybuf);
|
|
||||||
#endif
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
TRY_CATCH (except, RETURN_MASK_ALL)
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
||||||
{
|
{
|
||||||
@ -695,16 +673,21 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
buffer, pattern_size,
|
buffer, pattern_size,
|
||||||
&found_addr);
|
&found_addr);
|
||||||
}
|
}
|
||||||
GDB_PY_HANDLE_EXCEPTION (except);
|
|
||||||
|
|
||||||
#ifdef IS_PY3K
|
#ifdef IS_PY3K
|
||||||
PyBuffer_Release (&pybuf);
|
PyBuffer_Release (&pybuf);
|
||||||
#endif
|
#endif
|
||||||
|
GDB_PY_HANDLE_EXCEPTION (except);
|
||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
return PyLong_FromLong (found_addr);
|
return PyLong_FromLong (found_addr);
|
||||||
else
|
else
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
#ifdef IS_PY3K
|
||||||
|
PyBuffer_Release (&pybuf);
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Implementation of gdb.Inferior.is_valid (self) -> Boolean.
|
/* Implementation of gdb.Inferior.is_valid (self) -> Boolean.
|
||||||
|
@ -313,39 +313,46 @@ gdbpy_convert_exception (struct gdb_exception exception)
|
|||||||
|
|
||||||
/* Converts OBJ to a CORE_ADDR value.
|
/* Converts OBJ to a CORE_ADDR value.
|
||||||
|
|
||||||
Returns 1 on success or 0 on failure, with a Python exception set. This
|
Returns 0 on success or -1 on failure, with a Python exception set.
|
||||||
function can also throw GDB exceptions.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
|
get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
|
||||||
{
|
{
|
||||||
if (gdbpy_is_value_object (obj))
|
if (gdbpy_is_value_object (obj))
|
||||||
*addr = value_as_address (value_object_to_value (obj));
|
{
|
||||||
|
volatile struct gdb_exception except;
|
||||||
|
|
||||||
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
||||||
|
{
|
||||||
|
*addr = value_as_address (value_object_to_value (obj));
|
||||||
|
}
|
||||||
|
GDB_PY_SET_HANDLE_EXCEPTION (except);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PyObject *num = PyNumber_Long (obj);
|
PyObject *num = PyNumber_Long (obj);
|
||||||
gdb_py_ulongest val;
|
gdb_py_ulongest val;
|
||||||
|
|
||||||
if (num == NULL)
|
if (num == NULL)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
val = gdb_py_long_as_ulongest (num);
|
val = gdb_py_long_as_ulongest (num);
|
||||||
Py_XDECREF (num);
|
Py_XDECREF (num);
|
||||||
if (PyErr_Occurred ())
|
if (PyErr_Occurred ())
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
if (sizeof (val) > sizeof (CORE_ADDR) && ((CORE_ADDR) val) != val)
|
if (sizeof (val) > sizeof (CORE_ADDR) && ((CORE_ADDR) val) != val)
|
||||||
{
|
{
|
||||||
PyErr_SetString (PyExc_ValueError,
|
PyErr_SetString (PyExc_ValueError,
|
||||||
_("Overflow converting to address."));
|
_("Overflow converting to address."));
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*addr = val;
|
*addr = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert a LONGEST to the appropriate Python object -- either an
|
/* Convert a LONGEST to the appropriate Python object -- either an
|
||||||
|
@ -433,7 +433,8 @@ extern PyObject *gdbpy_gdberror_exc;
|
|||||||
extern void gdbpy_convert_exception (struct gdb_exception)
|
extern void gdbpy_convert_exception (struct gdb_exception)
|
||||||
CPYCHECKER_SETS_EXCEPTION;
|
CPYCHECKER_SETS_EXCEPTION;
|
||||||
|
|
||||||
int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
|
int get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
|
||||||
|
|
||||||
PyObject *gdb_py_object_from_longest (LONGEST l);
|
PyObject *gdb_py_object_from_longest (LONGEST l);
|
||||||
PyObject *gdb_py_object_from_ulongest (ULONGEST l);
|
PyObject *gdb_py_object_from_ulongest (ULONGEST l);
|
||||||
|
Loading…
Reference in New Issue
Block a user