aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-inferior.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2013-05-20 20:24:49 +0000
committerTom Tromey <tromey@redhat.com>2013-05-20 20:24:49 +0000
commitb86af38a5a769f23d1af78761c654d68703c6237 (patch)
treef0b939b8e2ee986c74feff7b493e679a6a226b10 /gdb/python/py-inferior.c
parente19d3afbf8ff364534b0be74980377113082d02f (diff)
downloadgdb-b86af38a5a769f23d1af78761c654d68703c6237.zip
gdb-b86af38a5a769f23d1af78761c654d68703c6237.tar.gz
gdb-b86af38a5a769f23d1af78761c654d68703c6237.tar.bz2
* 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.
Diffstat (limited to 'gdb/python/py-inferior.c')
-rw-r--r--gdb/python/py-inferior.c103
1 files changed, 43 insertions, 60 deletions
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index d35d09a..4e68cdd 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -406,7 +406,6 @@ gdbpy_inferiors (PyObject *unused, PyObject *unused2)
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;
@@ -418,15 +417,12 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
&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);
@@ -437,12 +433,6 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
GDB_PY_HANDLE_EXCEPTION (except);
}
- if (error)
- {
- xfree (buffer);
- return NULL;
- }
-
membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
if (membuf_obj == NULL)
{
@@ -475,7 +465,6 @@ static PyObject *
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;
@@ -498,21 +487,16 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
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
@@ -520,11 +504,13 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
#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. */
@@ -660,34 +646,26 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
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)
{
@@ -695,16 +673,21 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
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.