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] PR14291: KeyboardInterrupt not caught for Python output


http://sourceware.org/bugzilla/show_bug.cgi?id=14291

python
try:
    for i in range(400):
        print i
except KeyboardInterrupt:
    print "caught interrupt"
end

Entering "q" at "q <return> to quit" results in the Python
program being prematurely terminated.

(BTW, I tried to add this to the test suite, but gdb_test_multiple
catches the "enter q <return>" prompt and fails the test.)


2012-06-25 Michael Eager <eager@eagercon.com>


	* python/python.c (gdbpy_write): Check for interrupted
	output.


Index: python/python.c =================================================================== RCS file: /cvs/src/src/gdb/python/python.c,v retrieving revision 1.90 diff -u -p -r1.90 python.c --- python/python.c 18 May 2012 21:02:52 -0000 1.90 +++ python/python.c 25 Jun 2012 12:25:33 -0000 @@ -862,26 +862,31 @@ gdbpy_write (PyObject *self, PyObject *a const char *arg; static char *keywords[] = {"text", "stream", NULL }; int stream_type = 0; + volatile struct gdb_exception except;

   if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &arg,
 				     &stream_type))
     return NULL;

-  switch (stream_type)
+  TRY_CATCH (except, RETURN_MASK_ALL)
     {
-    case 1:
-      {
-	fprintf_filtered (gdb_stderr, "%s", arg);
-	break;
-      }
-    case 2:
-      {
-	fprintf_filtered (gdb_stdlog, "%s", arg);
-	break;
-      }
-    default:
-      fprintf_filtered (gdb_stdout, "%s", arg);
+      switch (stream_type)
+        {
+        case 1:
+          {
+	    fprintf_filtered (gdb_stderr, "%s", arg);
+	    break;
+          }
+        case 2:
+          {
+	    fprintf_filtered (gdb_stdlog, "%s", arg);
+	    break;
+          }
+        default:
+          fprintf_filtered (gdb_stdout, "%s", arg);
+        }
     }
+  GDB_PY_HANDLE_EXCEPTION (except);

   Py_RETURN_NONE;
 }

--
Michael Eager	 eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077


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