This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch][python] Fix some unguarded GDB calls.


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);
	


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]