Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] PR14291:  KeyboardInterrupt not caught for Python output
@ 2012-06-25 12:33 Michael Eager
  2012-06-25 15:26 ` Tom Tromey
  2012-06-27 13:37 ` Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Eager @ 2012-06-25 12:33 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-06-27 14:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-25 12:33 [PATCH] PR14291: KeyboardInterrupt not caught for Python output Michael Eager
2012-06-25 15:26 ` Tom Tromey
2012-06-25 16:54   ` Michael Eager
2012-06-27 13:37 ` Tom Tromey
2012-06-27 14:06   ` Michael Eager

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox