* [patch][python] Fix some unguarded GDB calls.
@ 2013-03-20 14:35 Phil Muldoon
2013-03-20 15:32 ` Tom Tromey
0 siblings, 1 reply; 4+ messages in thread
From: Phil Muldoon @ 2013-03-20 14:35 UTC (permalink / raw)
To: gdb-patches
This patches adds some GDB exception handling and Python exception
conversions for some existing code.
Cheers,
Phil
2013-03-20 Phil Muldoon <pmuldoon@redhat.com>
* python/py-utils.c (get_addr_from_python): Use exception handler
for value_as_address.
* python/py-cmd.c (gdbpy_parse_command_name): Use exception
handler for lookup_cmd_1..
* python/python.c (execute_gdb_command): Move bpstat_do_actions
into exception handler.
--
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 161b4bc..73897d0 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -323,6 +323,7 @@ gdbpy_parse_command_name (const char *name,
char *prefix_text;
const char *prefix_text2;
char *result;
+ volatile struct gdb_exception except;
/* Skip trailing whitespace. */
for (i = len - 1; i >= 0 && (name[i] == ' ' || name[i] == '\t'); --i)
@@ -358,7 +359,17 @@ gdbpy_parse_command_name (const char *name,
prefix_text[i + 1] = '\0';
prefix_text2 = prefix_text;
- elt = lookup_cmd_1 (&prefix_text2, *start_list, NULL, 1);
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ elt = lookup_cmd_1 (&prefix_text2, *start_list, NULL, 1);
+ }
+ if (except.reason < 0)
+ {
+ gdbpy_convert_exception (except);
+ return NULL;
+ }
+
if (!elt || elt == (struct cmd_list_element *) -1)
{
PyErr_Format (PyExc_RuntimeError, _("Could not find command prefix %s."),
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index b280c8c..65a2921 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -299,7 +299,19 @@ 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));
+ }
+ if (except.reason < 0)
+ {
+ gdbpy_convert_exception (except);
+ return 0;
+ }
+ }
else
{
PyObject *num = PyNumber_Long (obj);
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 4a7cb28..e44cb00 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -555,12 +555,12 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
}
do_cleanups (cleanup);
+
+ /* Do any commands attached to breakpoint we stopped at. */
+ bpstat_do_actions ();
}
GDB_PY_HANDLE_EXCEPTION (except);
- /* Do any commands attached to breakpoint we stopped at. */
- bpstat_do_actions ();
-
if (result)
{
PyObject *r = PyString_FromString (result);
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [patch][python] Fix some unguarded GDB calls.
2013-03-20 14:35 [patch][python] Fix some unguarded GDB calls Phil Muldoon
@ 2013-03-20 15:32 ` Tom Tromey
2013-03-20 16:45 ` Phil Muldoon
0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2013-03-20 15:32 UTC (permalink / raw)
To: Phil Muldoon; +Cc: gdb-patches
>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
Phil> 2013-03-20 Phil Muldoon <pmuldoon@redhat.com>
Phil> * python/py-utils.c (get_addr_from_python): Use exception handler
Phil> for value_as_address.
Phil> * python/py-cmd.c (gdbpy_parse_command_name): Use exception
Phil> handler for lookup_cmd_1..
Phil> * python/python.c (execute_gdb_command): Move bpstat_do_actions
Phil> into exception handler.
Phil> + if (except.reason < 0)
Phil> + {
Phil> + gdbpy_convert_exception (except);
Phil> + return NULL;
Phil> + }
Use GDB_PY_HANDLE_EXCEPTION instead.
Phil> get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
This is documented as being able to throw gdb exceptions.
It is fine by me if you want to fix that (it certainly looks simpler
than fixing the one caller in infpy_search_memory), but then the intro
comment for the function needs an update.
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [patch][python] Fix some unguarded GDB calls.
2013-03-20 15:32 ` Tom Tromey
@ 2013-03-20 16:45 ` Phil Muldoon
2013-03-20 17:37 ` Tom Tromey
0 siblings, 1 reply; 4+ messages in thread
From: Phil Muldoon @ 2013-03-20 16:45 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 20/03/13 15:25, Tom Tromey wrote:
>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
>
> Phil> 2013-03-20 Phil Muldoon <pmuldoon@redhat.com>
> Phil> * python/py-utils.c (get_addr_from_python): Use exception handler
> Phil> for value_as_address.
> Phil> * python/py-cmd.c (gdbpy_parse_command_name): Use exception
> Phil> handler for lookup_cmd_1..
> Phil> * python/python.c (execute_gdb_command): Move bpstat_do_actions
> Phil> into exception handler.
>
> Phil> + if (except.reason < 0)
> Phil> + {
> Phil> + gdbpy_convert_exception (except);
> Phil> + return NULL;
> Phil> + }
>
> Use GDB_PY_HANDLE_EXCEPTION instead.
Can't as this function returns char *. I did check the callers, and
they do a null check though, and deal with python exceptions. I get
this if I use that macro:
../../gdb/gdb/python/py-cmd.c: In function gdbpy_parse_command_name:
../../gdb/gdb/python/py-cmd.c:367:3: error: return from incompatible pointer type [-Werror]
> Phil> get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
>
> This is documented as being able to throw gdb exceptions.
> It is fine by me if you want to fix that (it certainly looks simpler
> than fixing the one caller in infpy_search_memory), but then the intro
> comment for the function needs an update.
Yeah I can fix that.
Cheers
Phil
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-03-20 17:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-20 14:35 [patch][python] Fix some unguarded GDB calls Phil Muldoon
2013-03-20 15:32 ` Tom Tromey
2013-03-20 16:45 ` Phil Muldoon
2013-03-20 17:37 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox