* [patch] [python] Use TRY_CATCH in some functions.
@ 2011-10-11 11:57 Phil Muldoon
2011-10-11 17:30 ` Tom Tromey
0 siblings, 1 reply; 7+ messages in thread
From: Phil Muldoon @ 2011-10-11 11:57 UTC (permalink / raw)
To: gdb-patches
After fixing the bugs related to py-value.c not using TRY_CATCH in some
cases, I decided to take a look at the rest of the Python files. I
caught a few others too.
I also changed the behavior of typy_richcompare to not return Py_NE on
error (And to build an exception instead). Not sure what the original
reason for this, but in terms of comparison it seems odd to return a
result on an error.
Cheers,
Phil
--
2011-10-11 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.
--
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 3dc0fca..6e46e88 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 9143367..53f8e69 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 8a8510e..fd365a7 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;
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 c7fd25b..f4746aa 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -608,8 +608,9 @@ typy_lookup_type (struct demangle_component *demangled,
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. */
@@ -624,20 +625,31 @@ typy_lookup_type (struct demangle_component *demangled,
if (! type)
return NULL;
- switch (demangled_type)
+ TRY_CATCH (except, RETURN_MASK_ALL)
{
- 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);
+ 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)
+ {
+ PyErr_Format (except.reason == RETURN_QUIT
+ ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
+ "%s", except.message);
+ return NULL;
}
}
- type_name = cp_comp_to_string (demangled, 10);
type = typy_lookup_typename (type_name, block);
xfree (type_name);
@@ -990,8 +1002,16 @@ typy_richcompare (PyObject *self, PyObject *other, int op)
{
result = check_types_worklist (&worklist, cache);
}
+ /* 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. */
if (except.reason < 0)
- result = Py_NE;
+ {
+ bcache_xfree (cache);
+ VEC_free (type_equality_entry_d, worklist);
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
bcache_xfree (cache);
VEC_free (type_equality_entry_d, worklist);
@@ -1095,7 +1115,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;
@@ -1106,7 +1127,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;
@@ -1161,7 +1187,8 @@ typy_has_key (PyObject *self, PyObject *args)
struct type *type = ((type_object *) self)->type;
char *field;
int i;
-
+ volatile struct gdb_exception except;
+
if (!PyArg_ParseTuple (args, "s", &field))
return NULL;
@@ -1171,7 +1198,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;
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [patch] [python] Use TRY_CATCH in some functions.
2011-10-11 11:57 [patch] [python] Use TRY_CATCH in some functions Phil Muldoon
@ 2011-10-11 17:30 ` Tom Tromey
2011-10-20 13:03 ` Phil Muldoon
0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2011-10-11 17:30 UTC (permalink / raw)
To: pmuldoon; +Cc: gdb-patches
>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
Phil> After fixing the bugs related to py-value.c not using TRY_CATCH in some
Phil> cases, I decided to take a look at the rest of the Python files. I
Phil> caught a few others too.
Thanks for doing this.
Phil> @@ -624,20 +625,31 @@ typy_lookup_type (struct demangle_component *demangled,
[...]
Phil> + if (except.reason < 0)
Phil> + {
Phil> + PyErr_Format (except.reason == RETURN_QUIT
Phil> + ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
Phil> + "%s", except.message);
Phil> + return NULL;
Why not GDB_PY_HANDLE_EXCEPTION here?
(And also fix up typy_lookup_typename to do the same.)
Phil> @@ -990,8 +1002,16 @@ typy_richcompare (PyObject *self, PyObject *other, int op)
[...]
Phil> + {
Phil> + bcache_xfree (cache);
Phil> + VEC_free (type_equality_entry_d, worklist);
Phil> + GDB_PY_HANDLE_EXCEPTION (except);
I think the freeing should be hoisted above the exception check, to
consolidate the code. With the current patch the code is duplicated on
both branches.
Otherwise this look good.
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [patch] [python] Use TRY_CATCH in some functions.
2011-10-11 17:30 ` Tom Tromey
@ 2011-10-20 13:03 ` Phil Muldoon
2011-10-20 14:23 ` Tom Tromey
0 siblings, 1 reply; 7+ messages in thread
From: Phil Muldoon @ 2011-10-20 13:03 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
Tom Tromey <tromey@redhat.com> writes:
> Phil> @@ -624,20 +625,31 @@ typy_lookup_type (struct demangle_component *demangled,
> [...]
>
> Phil> + if (except.reason < 0)
> Phil> + {
> Phil> + PyErr_Format (except.reason == RETURN_QUIT
> Phil> + ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
> Phil> + "%s", except.message);
> Phil> + return NULL;
>
> Why not GDB_PY_HANDLE_EXCEPTION here?
> (And also fix up typy_lookup_typename to do the same.)
Because typy_lookup_typename and typy_lookup_type are helper functions
that return struct type, while GDB_PY_HANDLE_EXCEPTION returns a
PyObject (from gdbpy_convert_exception). Should we have a macro that
builds an exception without returning one? We should, I think. But I was not
going to do that in this patch context.
> Phil> @@ -990,8 +1002,16 @@ typy_richcompare (PyObject *self, PyObject *other, int op)
> [...]
> Phil> + {
> Phil> + bcache_xfree (cache);
> Phil> + VEC_free (type_equality_entry_d, worklist);
> Phil> + GDB_PY_HANDLE_EXCEPTION (except);
>
> I think the freeing should be hoisted above the exception check, to
> consolidate the code. With the current patch the code is duplicated on
> both branches.
I amended the logic to look like this:
@@ -1007,11 +1007,13 @@
{
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)
Cheers,
Phil
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [patch] [python] Use TRY_CATCH in some functions.
2011-10-20 13:03 ` Phil Muldoon
@ 2011-10-20 14:23 ` Tom Tromey
2011-10-24 13:42 ` Phil Muldoon
0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2011-10-20 14:23 UTC (permalink / raw)
To: pmuldoon; +Cc: gdb-patches
>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
Phil> + if (except.reason < 0)
Phil> + {
Phil> + PyErr_Format (except.reason == RETURN_QUIT
Phil> + ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
Phil> + "%s", except.message);
Phil> + return NULL;
Tom> Why not GDB_PY_HANDLE_EXCEPTION here?
Tom> (And also fix up typy_lookup_typename to do the same.)
Phil> Because typy_lookup_typename and typy_lookup_type are helper
Phil> functions that return struct type, while GDB_PY_HANDLE_EXCEPTION
Phil> returns a PyObject (from gdbpy_convert_exception). Should we have
Phil> a macro that builds an exception without returning one? We should,
Phil> I think. But I was not going to do that in this patch context.
Ok, I see. Thanks.
I think both those functions should use gdbpy_convert_exception, though,
instead of replicating the exception-conversion logic themselves.
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [patch] [python] Use TRY_CATCH in some functions.
2011-10-20 14:23 ` Tom Tromey
@ 2011-10-24 13:42 ` Phil Muldoon
2011-10-24 13:59 ` Tom Tromey
0 siblings, 1 reply; 7+ messages in thread
From: Phil Muldoon @ 2011-10-24 13:42 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
Tom Tromey <tromey@redhat.com> writes:
> Tom> Why not GDB_PY_HANDLE_EXCEPTION here?
> Tom> (And also fix up typy_lookup_typename to do the same.)
>
> Phil> Because typy_lookup_typename and typy_lookup_type are helper
> Phil> functions that return struct type, while GDB_PY_HANDLE_EXCEPTION
> Phil> returns a PyObject (from gdbpy_convert_exception). Should we have
> Phil> a macro that builds an exception without returning one? We should,
> Phil> I think. But I was not going to do that in this patch context.
>
> Ok, I see. Thanks.
> I think both those functions should use gdbpy_convert_exception, though,
> instead of replicating the exception-conversion logic themselves.
Updated patch applied. ChangeLog has not changed.
OK?
Cheers,
Phil
--
Index: gdb/python/py-breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-breakpoint.c,v
retrieving revision 1.27
diff -u -r1.27 py-breakpoint.c
--- gdb/python/py-breakpoint.c 20 Oct 2011 13:34:17 -0000 1.27
+++ gdb/python/py-breakpoint.c 24 Oct 2011 13:27:35 -0000
@@ -150,6 +150,7 @@
{
breakpoint_object *self_bp = (breakpoint_object *) self;
int cmp;
+ volatile struct gdb_exception except;
BPPY_SET_REQUIRE_VALID (self_bp);
@@ -170,10 +171,16 @@
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 @@
{
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 @@
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 @@
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;
}
Index: gdb/python/py-frame.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-frame.c,v
retrieving revision 1.20
diff -u -r1.20 py-frame.c
--- gdb/python/py-frame.c 20 Oct 2011 12:31:30 -0000 1.20
+++ gdb/python/py-frame.c 24 Oct 2011 13:27:35 -0000
@@ -101,9 +101,15 @@
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 @@
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 @@
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;
}
Index: gdb/python/py-lazy-string.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-lazy-string.c,v
retrieving revision 1.9
diff -u -r1.9 py-lazy-string.c
--- gdb/python/py-lazy-string.c 26 Jan 2011 20:53:45 -0000 1.9
+++ gdb/python/py-lazy-string.c 24 Oct 2011 13:27:35 -0000
@@ -96,7 +96,8 @@
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 @@
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);
}
Index: gdb/python/py-symbol.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-symbol.c,v
retrieving revision 1.9
diff -u -r1.9 py-symbol.c
--- gdb/python/py-symbol.c 20 Oct 2011 12:31:30 -0000 1.9
+++ gdb/python/py-symbol.c 24 Oct 2011 13:27:35 -0000
@@ -274,9 +274,10 @@
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 @@
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 @@
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)
{
Index: gdb/python/py-type.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-type.c,v
retrieving revision 1.26
diff -u -r1.26 py-type.c
--- gdb/python/py-type.c 20 Oct 2011 12:31:30 -0000 1.26
+++ gdb/python/py-type.c 24 Oct 2011 13:27:35 -0000
@@ -595,9 +595,7 @@
}
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 @@
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 @@
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 @@
{
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 @@
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 @@
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 @@
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 @@
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;
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-10-27 10:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-11 11:57 [patch] [python] Use TRY_CATCH in some functions Phil Muldoon
2011-10-11 17:30 ` Tom Tromey
2011-10-20 13:03 ` Phil Muldoon
2011-10-20 14:23 ` Tom Tromey
2011-10-24 13:42 ` Phil Muldoon
2011-10-24 13:59 ` Tom Tromey
2011-10-27 10:17 ` Phil Muldoon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox