mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-06 15:43:09 +00:00
Remove 'if' from GDB_PY_HANDLE_EXCEPTION
This removes the embedded 'if' from GDB_PY_HANDLE_EXCEPTION and GDB_PY_SET_HANDLE_EXCEPTION. I believe this 'if' was necessary with the old gdb try/catch macros, but it no longer is: these should only ever be called from a 'catch' block, where it's already known that an exception was thrown. Simon pointed out, though, that in a few spots, these were in facts called outside of 'catch' blocks. This patch cleans up these spots. I also found one spot where a redundant 'return nullptr' could be removed.
This commit is contained in:
@@ -589,7 +589,6 @@ bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
|
|||||||
gdb::unique_xmalloc_ptr<char> exp_holder;
|
gdb::unique_xmalloc_ptr<char> exp_holder;
|
||||||
const char *exp = NULL;
|
const char *exp = NULL;
|
||||||
gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
|
gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
|
||||||
struct gdb_exception except;
|
|
||||||
|
|
||||||
BPPY_SET_REQUIRE_VALID (self_bp);
|
BPPY_SET_REQUIRE_VALID (self_bp);
|
||||||
|
|
||||||
@@ -615,11 +614,9 @@ bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
|
|||||||
}
|
}
|
||||||
catch (gdb_exception &ex)
|
catch (gdb_exception &ex)
|
||||||
{
|
{
|
||||||
except = std::move (ex);
|
GDB_PY_SET_HANDLE_EXCEPTION (ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
GDB_PY_SET_HANDLE_EXCEPTION (except);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -657,7 +654,6 @@ static int
|
|||||||
bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
|
bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
|
||||||
{
|
{
|
||||||
gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
|
gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
|
||||||
struct gdb_exception except;
|
|
||||||
|
|
||||||
BPPY_SET_REQUIRE_VALID (self_bp);
|
BPPY_SET_REQUIRE_VALID (self_bp);
|
||||||
|
|
||||||
@@ -684,11 +680,9 @@ bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
|
|||||||
}
|
}
|
||||||
catch (gdb_exception &ex)
|
catch (gdb_exception &ex)
|
||||||
{
|
{
|
||||||
except = std::move (ex);
|
GDB_PY_SET_HANDLE_EXCEPTION (ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
GDB_PY_SET_HANDLE_EXCEPTION (except);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -586,7 +586,6 @@ static PyObject *
|
|||||||
infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
|
infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
|
||||||
{
|
{
|
||||||
inferior_object *inf = (inferior_object *) self;
|
inferior_object *inf = (inferior_object *) self;
|
||||||
struct gdb_exception except;
|
|
||||||
Py_ssize_t buf_len;
|
Py_ssize_t buf_len;
|
||||||
const gdb_byte *buffer;
|
const gdb_byte *buffer;
|
||||||
CORE_ADDR addr, length;
|
CORE_ADDR addr, length;
|
||||||
@@ -625,11 +624,9 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
}
|
}
|
||||||
catch (gdb_exception &ex)
|
catch (gdb_exception &ex)
|
||||||
{
|
{
|
||||||
except = std::move (ex);
|
GDB_PY_HANDLE_EXCEPTION (ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
GDB_PY_HANDLE_EXCEPTION (except);
|
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,7 +642,6 @@ static PyObject *
|
|||||||
infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
|
infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
|
||||||
{
|
{
|
||||||
inferior_object *inf = (inferior_object *) self;
|
inferior_object *inf = (inferior_object *) self;
|
||||||
struct gdb_exception except;
|
|
||||||
CORE_ADDR start_addr, length;
|
CORE_ADDR start_addr, length;
|
||||||
static const char *keywords[] = { "address", "length", "pattern", NULL };
|
static const char *keywords[] = { "address", "length", "pattern", NULL };
|
||||||
PyObject *start_addr_obj, *length_obj;
|
PyObject *start_addr_obj, *length_obj;
|
||||||
@@ -702,11 +698,9 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
}
|
}
|
||||||
catch (gdb_exception &ex)
|
catch (gdb_exception &ex)
|
||||||
{
|
{
|
||||||
except = std::move (ex);
|
GDB_PY_HANDLE_EXCEPTION (ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
GDB_PY_HANDLE_EXCEPTION (except);
|
|
||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
return gdb_py_object_from_ulongest (found_addr).release ();
|
return gdb_py_object_from_ulongest (found_addr).release ();
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -214,7 +214,6 @@ thpy_get_ptid_string (PyObject *self, void *closure)
|
|||||||
catch (const gdb_exception &except)
|
catch (const gdb_exception &except)
|
||||||
{
|
{
|
||||||
GDB_PY_HANDLE_EXCEPTION (except);
|
GDB_PY_HANDLE_EXCEPTION (except);
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1046,7 +1046,6 @@ get_field_type (PyObject *field)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
valpy_getitem (PyObject *self, PyObject *key)
|
valpy_getitem (PyObject *self, PyObject *key)
|
||||||
{
|
{
|
||||||
struct gdb_exception except;
|
|
||||||
value_object *self_value = (value_object *) self;
|
value_object *self_value = (value_object *) self;
|
||||||
gdb::unique_xmalloc_ptr<char> field;
|
gdb::unique_xmalloc_ptr<char> field;
|
||||||
struct type *base_class_type = NULL, *field_type = NULL;
|
struct type *base_class_type = NULL, *field_type = NULL;
|
||||||
@@ -1178,11 +1177,9 @@ valpy_getitem (PyObject *self, PyObject *key)
|
|||||||
}
|
}
|
||||||
catch (gdb_exception &ex)
|
catch (gdb_exception &ex)
|
||||||
{
|
{
|
||||||
except = std::move (ex);
|
GDB_PY_HANDLE_EXCEPTION (ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
GDB_PY_HANDLE_EXCEPTION (except);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1678,7 +1675,6 @@ valpy_absolute (PyObject *self)
|
|||||||
static int
|
static int
|
||||||
valpy_nonzero (PyObject *self)
|
valpy_nonzero (PyObject *self)
|
||||||
{
|
{
|
||||||
struct gdb_exception except;
|
|
||||||
value_object *self_value = (value_object *) self;
|
value_object *self_value = (value_object *) self;
|
||||||
struct type *type;
|
struct type *type;
|
||||||
int nonzero = 0; /* Appease GCC warning. */
|
int nonzero = 0; /* Appease GCC warning. */
|
||||||
@@ -1698,14 +1694,12 @@ valpy_nonzero (PyObject *self)
|
|||||||
}
|
}
|
||||||
catch (gdb_exception &ex)
|
catch (gdb_exception &ex)
|
||||||
{
|
{
|
||||||
except = std::move (ex);
|
/* This is not documented in the Python documentation, but if
|
||||||
|
this function fails, return -1 as slot_nb_nonzero does (the
|
||||||
|
default Python nonzero function). */
|
||||||
|
GDB_PY_SET_HANDLE_EXCEPTION (ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is not documented in the Python documentation, but if this
|
|
||||||
function fails, return -1 as slot_nb_nonzero does (the default
|
|
||||||
Python nonzero function). */
|
|
||||||
GDB_PY_SET_HANDLE_EXCEPTION (except);
|
|
||||||
|
|
||||||
return nonzero;
|
return nonzero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -847,26 +847,20 @@ private:
|
|||||||
PyGILState_STATE m_state;
|
PyGILState_STATE m_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Use this after a TRY_EXCEPT to throw the appropriate Python
|
/* Use this in a 'catch' block to convert the exception to a Python
|
||||||
exception. */
|
exception and return nullptr. */
|
||||||
#define GDB_PY_HANDLE_EXCEPTION(Exception) \
|
#define GDB_PY_HANDLE_EXCEPTION(Exception) \
|
||||||
do { \
|
do { \
|
||||||
if (Exception.reason < 0) \
|
|
||||||
{ \
|
|
||||||
gdbpy_convert_exception (Exception); \
|
gdbpy_convert_exception (Exception); \
|
||||||
return NULL; \
|
return nullptr; \
|
||||||
} \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Use this after a TRY_EXCEPT to throw the appropriate Python
|
/* Use this in a 'catch' block to convert the exception to a Python
|
||||||
exception. This macro is for use inside setter functions. */
|
exception and return -1. */
|
||||||
#define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
|
#define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
|
||||||
do { \
|
do { \
|
||||||
if (Exception.reason < 0) \
|
|
||||||
{ \
|
|
||||||
gdbpy_convert_exception (Exception); \
|
gdbpy_convert_exception (Exception); \
|
||||||
return -1; \
|
return -1; \
|
||||||
} \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
int gdbpy_print_python_errors_p (void);
|
int gdbpy_print_python_errors_p (void);
|
||||||
|
|||||||
Reference in New Issue
Block a user