From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68156 invoked by alias); 29 Mar 2016 16:40:03 -0000 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 Received: (qmail 68137 invoked by uid 89); 29 Mar 2016 16:40:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=handlers, 6716, Stop, assure X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 29 Mar 2016 16:39:52 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 666014628F; Tue, 29 Mar 2016 16:39:51 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2TGdooL016462; Tue, 29 Mar 2016 12:39:50 -0400 Subject: Re: [PATCH] python: Use console format for output of gdb.execute command To: Catalin Udma , gdb-patches@sourceware.org References: <1456756452-15880-1-git-send-email-catalin.udma@freescale.com> From: Pedro Alves Message-ID: <56FAAFD6.8030705@redhat.com> Date: Tue, 29 Mar 2016 16:40:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <1456756452-15880-1-git-send-email-catalin.udma@freescale.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-03/txt/msg00516.txt.bz2 Hi Catalin, On 02/29/2016 02:34 PM, Catalin Udma wrote: > When gdb is started in MI mode, the output of gdb.execute > command is in MI-format in case when it is executed from python stop > handler while for all other cases the output is in console-format. > > To assure consistent output format, this is fixed by using the console > format for all python gdb command executions. This seems like the right thing to do. See comments below. > diff --git a/gdb/python/python.c b/gdb/python/python.c > index 7202105..8a987f9 100644 > --- a/gdb/python/python.c > +++ b/gdb/python/python.c > @@ -658,10 +658,18 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) > /* Copy the argument text in case the command modifies it. */ > char *copy = xstrdup (arg); > struct cleanup *cleanup = make_cleanup (xfree, copy); > + struct ui_out *saved_uiout; > + struct interp *interp; > > make_cleanup_restore_integer (&interpreter_async); > interpreter_async = 0; > > + /* Use the console interpreter uiout to have the same print format > + for console or MI. */ > + interp = interp_lookup ("console"); > + saved_uiout = current_uiout; > + current_uiout = interp_ui_out (interp); > + > prevent_dont_repeat (); > if (to_string) > result = execute_command_to_string (copy, from_tty); > @@ -671,6 +679,9 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) > execute_command (copy, from_tty); > } > > + /* Restore the saved uiout. */ > + current_uiout = saved_uiout; This needs to be restored with a cleanup instead. > + > do_cleanups (cleanup); > } > CATCH (except, RETURN_MASK_ALL) > diff --git a/gdb/testsuite/gdb.python/py-mi-events-gdb.py b/gdb/testsuite/gdb.python/py-mi-events-gdb.py > new file mode 100644 > index 0000000..9d0c070 > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-mi-events-gdb.py > +# This file is part of the GDB testsuite. It tests python printing > +# to string from event handlers. Double-space after period. > + > + > +import gdb > + > + > +def signal_stop_handler (event): > + """Stop event handler""" > + if (isinstance (event, gdb.StopEvent)): > + OOC, why is this one an isinstance check, while below you have an assert? > +def continue_handler (event): > + """Continue event handler""" > + assert (isinstance (event, gdb.ContinueEvent)) > +int > +main (void) > +{ > + while (1); Please avoid tests that run forever: https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Don.27t_write_tests_that_run_forever Thanks, Pedro Alves