diff options
author | Phil Muldoon <pmuldoon@redhat.com> | 2011-10-27 09:14:27 +0000 |
---|---|---|
committer | Phil Muldoon <pmuldoon@redhat.com> | 2011-10-27 09:14:27 +0000 |
commit | 76dce0be7b6b831559f41f69e85fc1e8f9d28343 (patch) | |
tree | 06396641895472efb609d0ddeb6b815a472fd3fe | |
parent | d848dec6d9d34420121d9de18315c111d88017fd (diff) | |
download | gdb-76dce0be7b6b831559f41f69e85fc1e8f9d28343.zip gdb-76dce0be7b6b831559f41f69e85fc1e8f9d28343.tar.gz gdb-76dce0be7b6b831559f41f69e85fc1e8f9d28343.tar.bz2 |
2011-10-27 Phil Muldoon <pmuldoon@redhat.com>
* python/py-breakpoint.c (bppy_set_enabled): Use TRY_CATCH.
(bppy_set_task): Ditto.
(bppy_delete_breakpoint): Ditto.
* python/py-symbol.c (gdbpy_lookup_symbol): Ditto.
(gdbpy_lookup_global_symbol): Ditto.
* python/py-lazy-string.c (stpy_convert_to_value): Ditto.
* python/py-frame.c (frapy_is_valid): Ditto.
(frame_info_to_frame_object): Ditto.
* python/py-type.c (typy_lookup_type): Ditto.
(typy_getitem): Ditto.
(typy_has_key): Ditto.
(typy_richcompare): Use TRY_CATCH. Do not return Py_NE on error.
-rw-r--r-- | gdb/ChangeLog | 15 | ||||
-rw-r--r-- | gdb/python/py-breakpoint.c | 32 | ||||
-rw-r--r-- | gdb/python/py-frame.c | 45 | ||||
-rw-r--r-- | gdb/python/py-lazy-string.c | 10 | ||||
-rw-r--r-- | gdb/python/py-symbol.c | 18 | ||||
-rw-r--r-- | gdb/python/py-type.c | 63 |
6 files changed, 133 insertions, 50 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3b25e23..4acd4e5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,18 @@ +2011-10-27 Phil Muldoon <pmuldoon@redhat.com> + + * python/py-breakpoint.c (bppy_set_enabled): Use TRY_CATCH. + (bppy_set_task): Ditto. + (bppy_delete_breakpoint): Ditto. + * python/py-symbol.c (gdbpy_lookup_symbol): Ditto. + (gdbpy_lookup_global_symbol): Ditto. + * python/py-lazy-string.c (stpy_convert_to_value): Ditto. + * python/py-frame.c (frapy_is_valid): Ditto. + (frame_info_to_frame_object): Ditto. + * python/py-type.c (typy_lookup_type): Ditto. + (typy_getitem): Ditto. + (typy_has_key): Ditto. + (typy_richcompare): Use TRY_CATCH. Do not return Py_NE on error. + 2011-10-26 Joel Brobecker <brobecker@adacore.com> * gdbarch.h: Regenerate. diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index daceb99..f235bbc 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -150,6 +150,7 @@ bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure) { breakpoint_object *self_bp = (breakpoint_object *) self; int cmp; + volatile struct gdb_exception except; BPPY_SET_REQUIRE_VALID (self_bp); @@ -170,10 +171,16 @@ bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure) cmp = PyObject_IsTrue (newvalue); if (cmp < 0) return -1; - else if (cmp == 1) - enable_breakpoint (self_bp->bp); - else - disable_breakpoint (self_bp->bp); + + TRY_CATCH (except, RETURN_MASK_ALL) + { + if (cmp == 1) + enable_breakpoint (self_bp->bp); + else + disable_breakpoint (self_bp->bp); + } + GDB_PY_SET_HANDLE_EXCEPTION (except); + return 0; } @@ -255,6 +262,8 @@ bppy_set_task (PyObject *self, PyObject *newvalue, void *closure) { breakpoint_object *self_bp = (breakpoint_object *) self; long id; + int valid_id = 0; + volatile struct gdb_exception except; BPPY_SET_REQUIRE_VALID (self_bp); @@ -269,7 +278,13 @@ bppy_set_task (PyObject *self, PyObject *newvalue, void *closure) if (! gdb_py_int_as_long (newvalue, &id)) return -1; - if (! valid_task_id (id)) + TRY_CATCH (except, RETURN_MASK_ALL) + { + valid_id = valid_task_id (id); + } + GDB_PY_SET_HANDLE_EXCEPTION (except); + + if (! valid_id) { PyErr_SetString (PyExc_RuntimeError, _("Invalid task ID.")); @@ -299,10 +314,15 @@ static PyObject * bppy_delete_breakpoint (PyObject *self, PyObject *args) { breakpoint_object *self_bp = (breakpoint_object *) self; + volatile struct gdb_exception except; BPPY_REQUIRE_VALID (self_bp); - delete_breakpoint (self_bp->bp); + TRY_CATCH (except, RETURN_MASK_ALL) + { + delete_breakpoint (self_bp->bp); + } + GDB_PY_HANDLE_EXCEPTION (except); Py_RETURN_NONE; } diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index 398ce84..e192ffa 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -101,9 +101,15 @@ frapy_str (PyObject *self) static PyObject * frapy_is_valid (PyObject *self, PyObject *args) { - struct frame_info *frame; + struct frame_info *frame = NULL; + volatile struct gdb_exception except; + + TRY_CATCH (except, RETURN_MASK_ALL) + { + frame = frame_object_to_frame_info ((frame_object *) self); + } + GDB_PY_HANDLE_EXCEPTION (except); - frame = frame_object_to_frame_info ((frame_object *) self); if (frame == NULL) Py_RETURN_FALSE; @@ -276,6 +282,7 @@ PyObject * frame_info_to_frame_object (struct frame_info *frame) { frame_object *frame_obj; + volatile struct gdb_exception except; frame_obj = PyObject_New (frame_object, &frame_object_type); if (frame_obj == NULL) @@ -285,23 +292,27 @@ frame_info_to_frame_object (struct frame_info *frame) return NULL; } - /* Try to get the previous frame, to determine if this is the last frame - in a corrupt stack. If so, we need to store the frame_id of the next - frame and not of this one (which is possibly invalid). */ - if (get_prev_frame (frame) == NULL - && get_frame_unwind_stop_reason (frame) != UNWIND_NO_REASON - && get_next_frame (frame) != NULL) - { - frame_obj->frame_id = get_frame_id (get_next_frame (frame)); - frame_obj->frame_id_is_next = 1; - } - else + TRY_CATCH (except, RETURN_MASK_ALL) { - frame_obj->frame_id = get_frame_id (frame); - frame_obj->frame_id_is_next = 0; - } - frame_obj->gdbarch = get_frame_arch (frame); + /* Try to get the previous frame, to determine if this is the last frame + in a corrupt stack. If so, we need to store the frame_id of the next + frame and not of this one (which is possibly invalid). */ + if (get_prev_frame (frame) == NULL + && get_frame_unwind_stop_reason (frame) != UNWIND_NO_REASON + && get_next_frame (frame) != NULL) + { + frame_obj->frame_id = get_frame_id (get_next_frame (frame)); + frame_obj->frame_id_is_next = 1; + } + else + { + frame_obj->frame_id = get_frame_id (frame); + frame_obj->frame_id_is_next = 0; + } + frame_obj->gdbarch = get_frame_arch (frame); + } + GDB_PY_HANDLE_EXCEPTION (except); return (PyObject *) frame_obj; } diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c index 940ce88..45ba41e 100644 --- a/gdb/python/py-lazy-string.c +++ b/gdb/python/py-lazy-string.c @@ -96,7 +96,8 @@ static PyObject * stpy_convert_to_value (PyObject *self, PyObject *args) { lazy_string_object *self_string = (lazy_string_object *) self; - struct value *val; + struct value *val = NULL; + volatile struct gdb_exception except; if (self_string->address == 0) { @@ -105,7 +106,12 @@ stpy_convert_to_value (PyObject *self, PyObject *args) return NULL; } - val = value_at_lazy (self_string->type, self_string->address); + TRY_CATCH (except, RETURN_MASK_ALL) + { + val = value_at_lazy (self_string->type, self_string->address); + } + GDB_PY_HANDLE_EXCEPTION (except); + return value_to_value_object (val); } diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 3fdbe48..3f8defa 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -274,9 +274,10 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) int domain = VAR_DOMAIN, is_a_field_of_this = 0; const char *name; static char *keywords[] = { "name", "block", "domain", NULL }; - struct symbol *symbol; + struct symbol *symbol = NULL; PyObject *block_obj = NULL, *ret_tuple, *sym_obj, *bool_obj; const struct block *block = NULL; + volatile struct gdb_exception except; if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name, &block_object_type, &block_obj, &domain)) @@ -297,7 +298,11 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) GDB_PY_HANDLE_EXCEPTION (except); } - symbol = lookup_symbol (name, block, domain, &is_a_field_of_this); + TRY_CATCH (except, RETURN_MASK_ALL) + { + symbol = lookup_symbol (name, block, domain, &is_a_field_of_this); + } + GDB_PY_HANDLE_EXCEPTION (except); ret_tuple = PyTuple_New (2); if (!ret_tuple) @@ -335,14 +340,19 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw) int domain = VAR_DOMAIN; const char *name; static char *keywords[] = { "name", "domain", NULL }; - struct symbol *symbol; + struct symbol *symbol = NULL; PyObject *sym_obj; + volatile struct gdb_exception except; if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name, &domain)) return NULL; - symbol = lookup_symbol_global (name, NULL, domain); + TRY_CATCH (except, RETURN_MASK_ALL) + { + symbol = lookup_symbol_global (name, NULL, domain); + } + GDB_PY_HANDLE_EXCEPTION (except); if (symbol) { diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index f155d63..585100d 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -595,9 +595,7 @@ typy_lookup_typename (const char *type_name, const struct block *block) } if (except.reason < 0) { - PyErr_Format (except.reason == RETURN_QUIT - ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, - "%s", except.message); + gdbpy_convert_exception (except); return NULL; } @@ -609,8 +607,9 @@ typy_lookup_type (struct demangle_component *demangled, const struct block *block) { struct type *type; - char *type_name; + char *type_name = NULL; enum demangle_component_type demangled_type; + volatile struct gdb_exception except; /* Save the type: typy_lookup_type() may (indirectly) overwrite memory pointed by demangled. */ @@ -625,20 +624,29 @@ typy_lookup_type (struct demangle_component *demangled, if (! type) return NULL; - switch (demangled_type) + TRY_CATCH (except, RETURN_MASK_ALL) + { + switch (demangled_type) + { + case DEMANGLE_COMPONENT_REFERENCE: + return lookup_reference_type (type); + case DEMANGLE_COMPONENT_POINTER: + return lookup_pointer_type (type); + case DEMANGLE_COMPONENT_CONST: + return make_cv_type (1, 0, type, NULL); + case DEMANGLE_COMPONENT_VOLATILE: + return make_cv_type (0, 1, type, NULL); + } + + type_name = cp_comp_to_string (demangled, 10); + } + if (except.reason < 0) { - case DEMANGLE_COMPONENT_REFERENCE: - return lookup_reference_type (type); - case DEMANGLE_COMPONENT_POINTER: - return lookup_pointer_type (type); - case DEMANGLE_COMPONENT_CONST: - return make_cv_type (1, 0, type, NULL); - case DEMANGLE_COMPONENT_VOLATILE: - return make_cv_type (0, 1, type, NULL); + gdbpy_convert_exception (except); + return NULL; } } - type_name = cp_comp_to_string (demangled, 10); type = typy_lookup_typename (type_name, block); xfree (type_name); @@ -1007,11 +1015,13 @@ typy_richcompare (PyObject *self, PyObject *other, int op) { result = check_types_worklist (&worklist, cache); } - if (except.reason < 0) - result = Py_NE; - + /* check_types_worklist calls several nested Python helper + functions, some of which can raise a GDB Exception, so we + just check and convert here. If there is a GDB exception, a + comparison is not capable (or trusted), so exit. */ bcache_xfree (cache); VEC_free (type_equality_entry_d, worklist); + GDB_PY_HANDLE_EXCEPTION (except); } if (op == result) @@ -1112,7 +1122,8 @@ typy_getitem (PyObject *self, PyObject *key) struct type *type = ((type_object *) self)->type; char *field; int i; - + volatile struct gdb_exception except; + field = python_string_to_host_string (key); if (field == NULL) return NULL; @@ -1123,7 +1134,12 @@ typy_getitem (PyObject *self, PyObject *key) for (;;) { - CHECK_TYPEDEF (type); + TRY_CATCH (except, RETURN_MASK_ALL) + { + CHECK_TYPEDEF (type); + } + GDB_PY_HANDLE_EXCEPTION (except); + if (TYPE_CODE (type) != TYPE_CODE_PTR && TYPE_CODE (type) != TYPE_CODE_REF) break; @@ -1178,7 +1194,8 @@ typy_has_key (PyObject *self, PyObject *args) struct type *type = ((type_object *) self)->type; const char *field; int i; - + volatile struct gdb_exception except; + if (!PyArg_ParseTuple (args, "s", &field)) return NULL; @@ -1188,7 +1205,11 @@ typy_has_key (PyObject *self, PyObject *args) for (;;) { - CHECK_TYPEDEF (type); + TRY_CATCH (except, RETURN_MASK_ALL) + { + CHECK_TYPEDEF (type); + } + GDB_PY_HANDLE_EXCEPTION (except); if (TYPE_CODE (type) != TYPE_CODE_PTR && TYPE_CODE (type) != TYPE_CODE_REF) break; |