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 Python error when "Quit"ting a paged info pretty-printers


Right now the "Quit" command used in the output paging is handled as an exception.
If we issue a "Quit" while outputting the registered pretty-printers list, the
Python handling layer will catch it and think it's a Python error.

The fix is to check if the error coming from Python is a Quit signal. If it is,
do not handle it as an error and resume the execution normally.

gdb/ChangeLog:
2016-03-08  Leonardo Boquillon  <leonardo.boquillon@tallertechnologies.com>

	* python/py-cmd.c (cmdpy_function): Handle the "Quit" exception.

---
 gdb/python/py-cmd.c | 85 +++++++++++++++++++++++++++++------------------------
 1 file changed, 47 insertions(+), 38 deletions(-)

diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index af6c5cf..edcaf79 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -165,46 +165,55 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
 	 we no longer own ptype, pvalue after the call to PyErr_Restore.  */
 
       msg = gdbpy_exception_to_string (ptype, pvalue);
-      make_cleanup (xfree, msg);
-
-      if (msg == NULL)
-	{
-	  /* An error occurred computing the string representation of the
-	     error message.  This is rare, but we should inform the user.  */
-	  printf_filtered (_("An error occurred in a Python command\n"
-			     "and then another occurred computing the "
-			     "error message.\n"));
-	  gdbpy_print_stack ();
-	}
-
-      /* Don't print the stack for gdb.GdbError exceptions.
-	 It is generally used to flag user errors.
-
-	 We also don't want to print "Error occurred in Python command"
-	 for user errors.  However, a missing message for gdb.GdbError
-	 exceptions is arguably a bug, so we flag it as such.  */
-
-      if (! PyErr_GivenExceptionMatches (ptype, gdbpy_gdberror_exc)
-	  || msg == NULL || *msg == '\0')
-	{
-	  PyErr_Restore (ptype, pvalue, ptraceback);
-	  gdbpy_print_stack ();
-	  if (msg != NULL && *msg != '\0')
-	    error (_("Error occurred in Python command: %s"), msg);
+      /* We need to check this because the "Quit" command used in the output 
+         paging is handled as an exception. If we issue a "Quit" while 
+         outputting the registered pretty-printers list, the Python handling 
+         layer will catch it and think it's a Python error                 */
+      if (strncmp(msg, "Quit", 5))
+	  {
+	    if (msg == NULL)
+	      {
+		/* An error occurred computing the string representation of the
+		   error message.  This is rare, but we should inform the user.*/
+		printf_filtered (_("An error occurred in a Python command\n"
+				   "and then another occurred computing the "
+				   "error message.\n"));
+		gdbpy_print_stack ();
+	      }
+
+	/* Don't print the stack for gdb.GdbError exceptions.
+	   It is generally used to flag user errors.
+
+	   We also don't want to print "Error occurred in Python command"
+	   for user errors.  However, a missing message for gdb.GdbError
+	   exceptions is arguably a bug, so we flag it as such.  */
+
+	  if (! PyErr_GivenExceptionMatches (ptype, gdbpy_gdberror_exc)
+	      || msg == NULL || *msg == '\0')
+	    {
+	      PyErr_Restore (ptype, pvalue, ptraceback);
+	      gdbpy_print_stack ();
+	      if (msg != NULL && *msg != '\0')
+	        error (_("Error occurred in Python command: %s"), msg);
+	      else
+	        error (_("Error occurred in Python command."));
+	    }
 	  else
-	    error (_("Error occurred in Python command."));
-	}
-      else
-	{
-	  Py_XDECREF (ptype);
-	  Py_XDECREF (pvalue);
-	  Py_XDECREF (ptraceback);
-	  error ("%s", msg);
-	}
-    }
+	    {
+	      Py_XDECREF (ptype);
+	      Py_XDECREF (pvalue);
+	      Py_XDECREF (ptraceback);
+	      error ("%s", msg);
+	    }
+	} // ELSE: This was not an error just quit signal. Do nothing.
 
-  Py_DECREF (result);
-  do_cleanups (cleanup);
+      make_cleanup (xfree, msg);
+    }
+  else
+    {
+      Py_DECREF (result);
+      do_cleanups (cleanup);
+    }
 }
 
 /* Helper function for the Python command completers (both "pure"
-- 
1.9.1


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