static PyObject *
infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
{
- int error = 0;
CORE_ADDR addr, length;
void *buffer = NULL;
membuf_object *membuf_obj;
&addr_obj, &length_obj))
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)
{
- if (!get_addr_from_python (addr_obj, &addr)
- || !get_addr_from_python (length_obj, &length))
- {
- error = 1;
- break;
- }
-
buffer = xmalloc (length);
read_memory (addr, buffer, length);
GDB_PY_HANDLE_EXCEPTION (except);
}
- if (error)
- {
- xfree (buffer);
- return NULL;
- }
-
membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
if (membuf_obj == NULL)
{
infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
{
Py_ssize_t buf_len;
- int error = 0;
const char *buffer;
CORE_ADDR addr, length;
PyObject *addr_obj, *length_obj = NULL;
return NULL;
#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)
{
- 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);
}
#ifdef IS_PY3K
#endif
GDB_PY_HANDLE_EXCEPTION (except);
-
- if (error)
- return NULL;
-
Py_RETURN_NONE;
+
+ fail:
+#ifdef IS_PY3K
+ PyBuffer_Release (&pybuf);
+#endif
+ return NULL;
}
/* Destructor of Membuf objects. */
return NULL;
#endif
- if (get_addr_from_python (start_addr_obj, &start_addr)
- && get_addr_from_python (length_obj, &length))
- {
- if (!length)
- {
- PyErr_SetString (PyExc_ValueError,
- _("Search range is empty."));
+ if (get_addr_from_python (start_addr_obj, &start_addr) < 0)
+ goto fail;
+
+ if (get_addr_from_python (length_obj, &length) < 0)
+ goto fail;
-#ifdef IS_PY3K
- PyBuffer_Release (&pybuf);
-#endif
- return NULL;
- }
- /* Watch for overflows. */
- 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;
- }
+ if (!length)
+ {
+ PyErr_SetString (PyExc_ValueError,
+ _("Search range is empty."));
+ goto fail;
+ }
+ /* Watch for overflows. */
+ else if (length > CORE_ADDR_MAX
+ || (start_addr + length - 1) < start_addr)
+ {
+ PyErr_SetString (PyExc_ValueError,
+ _("The search range is too large."));
+ goto fail;
}
- else
- return NULL;
TRY_CATCH (except, RETURN_MASK_ALL)
{
buffer, pattern_size,
&found_addr);
}
- GDB_PY_HANDLE_EXCEPTION (except);
-
#ifdef IS_PY3K
PyBuffer_Release (&pybuf);
#endif
+ GDB_PY_HANDLE_EXCEPTION (except);
if (found)
return PyLong_FromLong (found_addr);
else
Py_RETURN_NONE;
+
+ fail:
+#ifdef IS_PY3K
+ PyBuffer_Release (&pybuf);
+#endif
+ return NULL;
}
/* Implementation of gdb.Inferior.is_valid (self) -> Boolean.
/* Converts OBJ to a CORE_ADDR value.
- Returns 1 on success or 0 on failure, with a Python exception set. This
- function can also throw GDB exceptions.
+ Returns 0 on success or -1 on failure, with a Python exception set.
*/
int
get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
{
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
{
PyObject *num = PyNumber_Long (obj);
gdb_py_ulongest val;
if (num == NULL)
- return 0;
+ return -1;
val = gdb_py_long_as_ulongest (num);
Py_XDECREF (num);
if (PyErr_Occurred ())
- return 0;
+ return -1;
if (sizeof (val) > sizeof (CORE_ADDR) && ((CORE_ADDR) val) != val)
{
PyErr_SetString (PyExc_ValueError,
_("Overflow converting to address."));
- return 0;
+ return -1;
}
*addr = val;
}
- return 1;
+ return 0;
}
/* Convert a LONGEST to the appropriate Python object -- either an