Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Phil Muldoon <pmuldoon@redhat.com>
To: gdb-patches@sourceware.org
Subject: [patch][python] Fix some unguarded GDB calls.
Date: Wed, 20 Mar 2013 14:35:00 -0000	[thread overview]
Message-ID: <5149BAA9.8020902@redhat.com> (raw)


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


             reply	other threads:[~2013-03-20 13:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-20 14:35 Phil Muldoon [this message]
2013-03-20 15:32 ` Tom Tromey
2013-03-20 16:45   ` Phil Muldoon
2013-03-20 17:37     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5149BAA9.8020902@redhat.com \
    --to=pmuldoon@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox