From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5004 invoked by alias); 25 Jun 2012 12:33:34 -0000 Received: (qmail 4984 invoked by uid 22791); 25 Jun 2012 12:33:33 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,TW_DB X-Spam-Check-By: sourceware.org Received: from shell4.bayarea.net (HELO shell4.bayarea.net) (209.128.82.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 25 Jun 2012 12:32:56 +0000 Received: (qmail 9631 invoked from network); 25 Jun 2012 05:32:55 -0700 Received: from c-76-102-3-160.hsd1.ca.comcast.net (HELO redwood.eagercon.com) (76.102.3.160) by shell4.bayarea.net with SMTP; 25 Jun 2012 05:32:55 -0700 Message-ID: <4FE85A77.70809@eagerm.com> Date: Mon, 25 Jun 2012 12:33:00 -0000 From: Michael Eager User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 MIME-Version: 1.0 To: "gdb-patches@sourceware.org" Subject: [PATCH] PR14291: KeyboardInterrupt not caught for Python output Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-06/txt/msg00768.txt.bz2 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 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 " prompt and fails the test.) 2012-06-25 Michael Eager * 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