From patchwork Mon Feb 29 14:34:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Udma X-Patchwork-Id: 11139 Received: (qmail 70232 invoked by alias); 29 Feb 2016 14:35:02 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 70205 invoked by uid 89); 29 Feb 2016 14:35:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*r:ip*15.1.422.5, H*r:15.1.422, Hx-spam-relays-external:sk:BL2FFO1, H*RU:sk:BL2FFO1 X-HELO: na01-bn1-obe.outbound.protection.outlook.com Received: from mail-bn1bon0112.outbound.protection.outlook.com (HELO na01-bn1-obe.outbound.protection.outlook.com) (157.56.111.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA256 encrypted) ESMTPS; Mon, 29 Feb 2016 14:34:51 +0000 Received: from BY2PR03CA079.namprd03.prod.outlook.com (10.141.249.52) by BLUPR03MB1507.namprd03.prod.outlook.com (10.163.81.25) with Microsoft SMTP Server (TLS) id 15.1.415.20; Mon, 29 Feb 2016 14:34:47 +0000 Received: from BL2FFO11FD007.protection.gbl (2a01:111:f400:7c09::134) by BY2PR03CA079.outlook.office365.com (2a01:111:e400:2c5d::52) with Microsoft SMTP Server (TLS) id 15.1.415.20 via Frontend Transport; Mon, 29 Feb 2016 14:34:47 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD007.mail.protection.outlook.com (10.173.161.3) with Microsoft SMTP Server (TLS) id 15.1.422.5 via Frontend Transport; Mon, 29 Feb 2016 14:34:45 +0000 Received: from udp122517uds.ea.freescale.net (udp122517uds.ea.freescale.net [10.171.74.106]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u1TEYhjh011065; Mon, 29 Feb 2016 07:34:44 -0700 From: Catalin Udma To: CC: Catalin Udma Subject: [PATCH] python: Use console format for output of gdb.execute command Date: Mon, 29 Feb 2016 16:34:12 +0200 Message-ID: <1456756452-15880-1-git-send-email-catalin.udma@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CPI:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1110001)(339900001)(3190300001)(199003)(189002)(377424004)(575784001)(86362001)(2351001)(50986999)(586003)(50226001)(229853001)(33646002)(1220700001)(2906002)(47776003)(48376002)(189998001)(105606002)(450100001)(110136002)(5001960100002)(107886002)(106466001)(50466002)(15975445007)(36756003)(104016004)(11100500001)(6806005)(5008740100001)(92566002)(19580405001)(5003940100001)(19580395003)(85426001)(77096005)(87936001)(4326007)(1096002)(4001430100002)(2004002); DIR:OUT; SFP:1102; SCL:1; SRVR:BLUPR03MB1507; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD007; 1:tX1ZC02Wez3N/PHv4VRNs/wxt+UELIb+B+//rrdHIEkMo4EK3baM2tS7csGhR4xDF8szhjuOEmMahQxN+RarOpO89ztF1v7TpSIWFc9BXDFhR1MmVdBTXJ1ySW1jtU+Q2DEmfLTVXwT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QXVqVkW39trZBTCxn/U5Gn/9XX70jl6uOo2uhmdEaTmwPJH7vBUiiBNLn8ltBf63nMz+qPdNvexyhen5nnGHkaDefA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13023025)(13017025)(5005006)(13024025)(13015025)(13018025)(8121501046)(3002001)(10201501046); SRVR:BLUPR03MB1507; BCL:0; PCL:0; RULEID:; SRVR:BLUPR03MB1507; X-Forefront-PRVS: 0867F4F1AA X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR03MB1507; 23:LPBcAYgV4vGQ+COuEbSTVyGCVnY2sl8MwXH/dx6qC?= =?us-ascii?Q?CRBM+266D4M6l6/5IbCUfAjQxopTBebb9FEalxSN0VIpBYV3Xzpmj5Y9iOSU?= =?us-ascii?Q?BusTRVFdYD0msXQUv/yEAgSWNAdylwY9gVmmBN8mwIf8ICiznvYv+a8vXaFn?= =?us-ascii?Q?Uqfh0ssZvF/x24EJsFZN69SURIiGyz0boXjTw0FIuqfj1+17g2AxOe3wa96/?= =?us-ascii?Q?ypQFZUSfGNxfQNH5rAHCVrtwMztQGHbE7rTsffW3UQuVrxo7tumxC2Fy4HWn?= =?us-ascii?Q?GfEkIwNm2Z5m3RMFu6YDagqz4jme6WgIN0mYmGREAZFP9UOCTF4uIPkx7MZY?= =?us-ascii?Q?4pnTcQeA9js56SIyO3r/+0Q2F788qrL68ScpENh1m3HTz/5GlwzzRPepyVJD?= =?us-ascii?Q?UcMBNppsXA/IMzt1G+wdtTKJlbVOCgYYc11TIoktD63XtMOLNlyukwAwt/rT?= =?us-ascii?Q?HPFMjEsBc/zrII8QK2P26U3abnWRLQ6WxFG2LFoLjupnu990iuXljhSCcxmj?= =?us-ascii?Q?SzCIUTvC+2qAGOXgbA4zjcXskw2buBuRsKcTpPV9SYGT3OxG5RFB6vfcuz0B?= =?us-ascii?Q?HyMffERXN0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S-Exchange-CrossTenant-OriginalArrivalTime: 29 Feb 2016 14:34:45.9914 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB1507 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. PR python/19743 2016-02-29 Catalin Udma PR python/19743 * python/python.c (execute_gdb_command): Use console uiout when executing gdb command. 2016-02-29 Catalin Udma PR python/19743 * gdb.python/py-mi-events-gdb.py: New file. * gdb.python/py-mi-events.c: New file. * gdb.python/py-mi-events.exp: New file. Signed-off-by: Catalin Udma --- gdb/python/python.c | 11 ++++ gdb/testsuite/gdb.python/py-mi-events-gdb.py | 48 +++++++++++++++ gdb/testsuite/gdb.python/py-mi-events.c | 23 +++++++ gdb/testsuite/gdb.python/py-mi-events.exp | 84 ++++++++++++++++++++++++++ 4 files changed, 166 insertions(+), 0 deletions(-) create mode 100644 gdb/testsuite/gdb.python/py-mi-events-gdb.py create mode 100644 gdb/testsuite/gdb.python/py-mi-events.c create mode 100644 gdb/testsuite/gdb.python/py-mi-events.exp 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; + 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 @@ -0,0 +1,48 @@ +# Copyright (C) 2016 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file is part of the GDB testsuite. It tests python printing +# to string from event handlers. + + +import gdb + + +def signal_stop_handler (event): + """Stop event handler""" + if (isinstance (event, gdb.StopEvent)): + print ("stop_handler") + print gdb.execute("info break", False, True) + + +def continue_handler (event): + """Continue event handler""" + assert (isinstance (event, gdb.ContinueEvent)) + print ("continue_handler") + print gdb.execute("info break", False, True) + + +class test_events (gdb.Command): + """Test events.""" + + def __init__ (self): + gdb.Command.__init__ (self, "test-events", gdb.COMMAND_STACK) + + def invoke (self, arg, from_tty): + gdb.events.stop.connect (signal_stop_handler) + gdb.events.cont.connect (continue_handler) + print ("Event testers registered.") + +test_events () diff --git a/gdb/testsuite/gdb.python/py-mi-events.c b/gdb/testsuite/gdb.python/py-mi-events.c new file mode 100644 index 0000000..3299e58 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-mi-events.c @@ -0,0 +1,23 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2016 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main (void) +{ + while (1); + return 0; +} diff --git a/gdb/testsuite/gdb.python/py-mi-events.exp b/gdb/testsuite/gdb.python/py-mi-events.exp new file mode 100644 index 0000000..4c78b9c --- /dev/null +++ b/gdb/testsuite/gdb.python/py-mi-events.exp @@ -0,0 +1,84 @@ +# Copyright (C) 2008-2016 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file is part of the GDB testsuite. It tests PR 19743. + +load_lib mi-support.exp +set MIFLAGS "-i=mi2" + +gdb_exit +if [mi_gdb_start] { + continue +} + +standard_testfile +set pyfile ${testfile}-gdb.py + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested ${testfile}.exp + return -1 +} + +if { [mi_skip_python_tests] } { continue } + +set remote_python_file [gdb_remote_download host ${srcdir}/${subdir}/${pyfile}] + +mi_delete_breakpoints +mi_gdb_reinitialize_dir $srcdir/$subdir +mi_gdb_test "set auto-load safe-path ${remote_python_file}" \ + {.*\^done} \ + "set safe-path" + +if [is_remote host] { + set filename ${testfile} + remote_download host ${binfile} ${filename} +} else { + set filename ${binfile} +} + +mi_gdb_test "-file-exec-and-symbols ${filename}" ".*\\^done" "file-exec-and-symbols operation" +mi_run_to_main + + +# register the python event handlers with test-events command +mi_gdb_test "test-events" \ + ".*~\"Event testers registered.*\\^done" \ + "register events" + + +# set a breakpoint to while (1) loop +mi_gdb_test "break ${srcfile}:[gdb_get_line_number "while (1)"]" \ + ".*Breakpoint $decimal at 0x\[0-9a-fA-F\]+: file .*${srcfile}.*\\\.*\\^done" \ + "set the breakpoint" + + +# resume the program +mi_send_resuming_command "exec-continue" "continue" + + +# test the python event handlers execution. The following checks are performed: +# - python continue handler is executed +# - the continue handler prints "info breakpoints" output in console format +# - breakpoint is hit and python stop handler is executed +# - the stop handler prints "info breakpoints" output in console format +mi_gdb_test "" ".*continue_handler.* +.*Num.*Type.*Disp.*Enb.*Address.*\ +.*$decimal.*breakpoint.*keep.*y.* 0x\[0-9a-fA-F\]+.*${srcfile}.* +.*stop_handler.* +.*Num.*Type.*Disp.*Enb.*Address.*\ +.*$decimal.*breakpoint.*keep.*y.* 0x\[0-9a-fA-F\]+.*${srcfile}.*" \ +"check python continue and stop handlers" + +mi_gdb_exit