From patchwork Thu Mar 31 10:43:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Udma X-Patchwork-Id: 11574 Received: (qmail 77428 invoked by alias); 31 Mar 2016 10:44:27 -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 77418 invoked by uid 89); 31 Mar 2016 10:44:26 -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_00, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*r:8.14.3, H*RU:sk:BN1AFFO, False, 3456 X-HELO: na01-by2-obe.outbound.protection.outlook.com Received: from mail-by2on0101.outbound.protection.outlook.com (HELO na01-by2-obe.outbound.protection.outlook.com) (207.46.100.101) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA256 encrypted) ESMTPS; Thu, 31 Mar 2016 10:44:16 +0000 Received: from BN3PR0301CA0067.namprd03.prod.outlook.com (10.160.152.163) by CY1PR03MB1520.namprd03.prod.outlook.com (10.163.17.26) with Microsoft SMTP Server (TLS) id 15.1.447.15; Thu, 31 Mar 2016 10:44:12 +0000 Received: from BN1AFFO11FD042.protection.gbl (2a01:111:f400:7c10::180) by BN3PR0301CA0067.outlook.office365.com (2a01:111:e400:401e::35) with Microsoft SMTP Server (TLS) id 15.1.447.15 via Frontend Transport; Thu, 31 Mar 2016 10:44:13 +0000 Authentication-Results: spf=neutral (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: Neutral (protection.outlook.com: 192.88.168.50 is neither permitted nor denied by domain of freescale.com) Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD042.mail.protection.outlook.com (10.58.52.253) with Microsoft SMTP Server (TLS) id 15.1.453.6 via Frontend Transport; Thu, 31 Mar 2016 10:44:12 +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 u2VAiAec025299; Thu, 31 Mar 2016 03:44:10 -0700 From: Catalin Udma To: CC: Catalin Udma Subject: [PATCH v2] python: Use console format for output of gdb.execute command Date: Thu, 31 Mar 2016 13:43:04 +0300 Message-ID: <1459420984-6582-1-git-send-email-catalin.udma@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(3190300001)(54534003)(189002)(199003)(377424004)(86362001)(189998001)(110136002)(450100001)(33646002)(107886002)(5008740100001)(15975445007)(6806005)(77096005)(50226001)(104016004)(4001430100002)(50986999)(5003940100001)(106466001)(229853001)(47776003)(92566002)(2351001)(105586002)(87936001)(81166005)(586003)(19580405001)(48376002)(50466002)(4326007)(36756003)(1096002)(2906002)(1220700001)(19580395003)(2004002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR03MB1520; H:tx30smr01.am.freescale.net; FPR:; SPF:Neutral; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD042; 1:bXHlJB8JYtdWIagVRpgwrOjsgjBHUcQf6IisywJYwT5DSbbkcvH8t/1pK7vdPNhSaM+rUHxOkiy2UX9uEPOJli2NMH04c0qcawPdBTnmOkhO3kAu9TCmnIXtZncpaFctqm32RW5d2ZIRkPipRJr/F6gYQiWUwho81nMhJg7hyY8MWmlYjmqmDcpWsuw+ltLdAimzzE7geOnXHD1lu8IJ3m55JZ6CjDuHeNRUMwQMu+BNA/3uXxtTd1RY4fCp1BRJEug8VDzIjF7PUfCNzO7oMoZ23dLG1BkJUaVtQwAUPomWfBGa+vZQA+DuLQx1Pqnb3066eqC5n9wC95R//brC3VXfkfCLCWwqHwk1nMF6+u5MhIdeFPOTPmq5/pykd0D+24wv4dS4CRTmobbRD7QVR+5l6a0jNu+tii7Bj2KQLpyLqwoLxRI820A63zG6GwQuLBqWmmT3nGOZRZnhkRWhLrbrsD8gjBmZ3wQ/86NyVaPETxtOS7c0DF3+IVVJ/yVlQ0pvEhcHPtMR+/QRpDSMmi5Wk8pdHEc3Pw6y9en5wc2JcKhcwZVH2tMDW3UA6S9V MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 88cd6e8d-6402-475c-ee1b-08d3595165fc X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1520; 2:W3uJvNtsoBSyxuUwZaJbhLtDlLtkH8dGxOwutwojncRZO8xk3z/qyaU+qqpGbugBH9Jvrpc9/wvjvX/Ibqywdibw8yvx9bRpteC0qsBZYYEick1R41fe+UV4LVyuOLQNDvUntHu4ZObJbcDiUNmDdSb5iNEOPpuqNTYMwIpCM4AC088CIcEooA9GS4oTEcdA; 3:/9uGZsjJGwZd23iE65UTF6A+9TJDdsgAKEUrZlXGW3qx09/3K3tcttciiMNXlI3K8KsvYhKewXRhwvLm0y+DVBfP1HTZuX+h/z/9jJaYAm9Nlz4hYY065qF29KD0xjjybKH44puYR2mvDqy5AY6SHXC5pWvppfBP9VLru7zyvULtIfzn1AdyLkgB1VyInQaIhevfRGWl+oY7vLsLEkW9Sna9r8Jvr+nqUNp1TEZ33mo= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR03MB1520; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1520; 25:UwF5JFGvikahuYWbuW7RLJFe5xLSLQJThsvkKe5XMSE/9b8gX1qT1uOmBBsA6lHFPRtGxPzuswAB1D+lM00wACDdsaIC4x9TvrI3RLkj2rOS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fWu4GDzVjKXqRd85VRXC5zWyiS7/ECNvTa3MQBzb0J0IKp70r7JenhStGhNW0YeeN107SxPsTQWjO454x3YrO+9lJfxtaHYbL6pkgAzrvJijr6PBNLmIwbPMjl6LcZimQzHq0FrDdpieuym0tfsKiAdoqPd9KK9HIgsh8DWqolFhkWRIH9gOK+dbnKbCwoSYH8L4xU3jH3iP23/P0k8cfQKb6+hraOPUI4noNLVgNezM2eiJu2dHVgijc0HN5yTEjyO+GSTQNoDlI/fgjV7wTYcN4QgBx+OASRs0tXy9XxLgSrS2E2MyvGUSdaI6s/Ng7+21b+nW9v0gKAJ9zECCV4RxnQmetOMmTo5cHRduBkcVUOa2HfNSlN4zyY5k3orTdGIiw/S7AduQuBVlT/ZwQiw7ch0hYbv5ru3FKIPphekWvaKv5vmjYYxxY7fryciqIJ/g== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(13023025)(13017025)(13015025)(13018025)(13024025)(8121501046)(10201501046)(3002001); SRVR:CY1PR03MB1520; BCL:0; PCL:0; RULEID:; SRVR:CY1PR03MB1520; X-Forefront-PRVS: 0898A6E028 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR03MB1520; 23:h9IZUy1XkoDtjMscz+TtRWHPipqtpHZbFsq1/X7vy?= =?us-ascii?Q?O0dTJ9WcKYL9HP5KyTi2VFgia5Z8LEIecqoUOAkpCdAaqgPz4U43fm/Ib42l?= =?us-ascii?Q?dH3k9j6jiZ489UsWoN+Iv8BsKTywWpyQrTc6wUQmJCGE85pXkqT5gyvQ3mh3?= =?us-ascii?Q?Rk0kF+QCGAqwRkJlEIp2lk8kg3MO6q3jXR8eFOpFNb7QW/2H8xypowp8a6nX?= =?us-ascii?Q?IEAf8It1TYwyFjOFjXSofT5gIhGRVcM8dAGXEqp76MKHbAa7iYZ5+jBgKWvN?= =?us-ascii?Q?yGD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cVa9xtGfazJynlowP34tNYuWJTpVZj+PXnBsbzxMyZmNxidS/KMFSof24GMhbZcUwnfMFCVYatPaEsbDjA7mIhWkPFkpzhi+w==; 24:ReVvCSSMn1R9jW/yd6wUA6CnR2DvOh4X6ZOkKtAZUwAcVXurBkHOSLhg4p2jUXE4Tb0+stKnTAqUMw5lw1KLl+ce121PA7W3TcLzsDhyoBE= X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2016 10:44:12.5953 (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: CY1PR03MB1520 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 gdb/ChangeLog: 2016-03-31 Catalin Udma PR python/19743 * python/python.c (execute_gdb_command): Use console uiout when executing gdb command. * utils.c (restore_ui_out_closure): New structure. (do_restore_ui_out): New function. (make_cleanup_restore_ui_out): Likewise. * utils.h (make_cleanup_restore_ui_out): Declare. gdb/testsuite/ChangeLog: 2016-03-31 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 --- Changes for v2: * add a cleanup restore for struct ui_out * restore current_ui_out with a cleanup * test python file: use assert for both stop and continue handlers * don't use test that runs forever gdb/python/python.c | 7 ++ gdb/testsuite/gdb.python/py-mi-events-gdb.py | 48 +++++++++++++++ gdb/testsuite/gdb.python/py-mi-events.c | 26 ++++++++ gdb/testsuite/gdb.python/py-mi-events.exp | 84 ++++++++++++++++++++++++++ gdb/utils.c | 29 +++++++++ gdb/utils.h | 3 + 6 files changed, 197 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 84f0596..e467134 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -658,10 +658,17 @@ 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 interp *interp; make_cleanup_restore_integer (&interpreter_async); interpreter_async = 0; + make_cleanup_restore_ui_out (¤t_uiout); + /* Use the console interpreter uiout to have the same print format + for console or MI. */ + interp = interp_lookup ("console"); + current_uiout = interp_ui_out (interp); + prevent_dont_repeat (); if (to_string) result = execute_command_to_string (copy, from_tty); 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..0aa4fda --- /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""" + assert (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..5e12bd9 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-mi-events.c @@ -0,0 +1,26 @@ +/* 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) +{ + int i = 0; + while (i < 10) + i++; + + 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..6f063e1 --- /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 into the for loop +mi_gdb_test "break ${srcfile}:[gdb_get_line_number "i++;"]" \ + ".*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 diff --git a/gdb/utils.c b/gdb/utils.c index 97e5133..62e169a 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -345,6 +345,35 @@ make_cleanup_htab_delete (htab_t htab) return make_cleanup (do_htab_delete_cleanup, htab); } +struct restore_ui_out_closure +{ + struct ui_out **variable; + struct ui_out *value; +}; + +static void +do_restore_ui_out (void *p) +{ + struct restore_ui_out_closure *closure + = (struct restore_ui_out_closure *) p; + + *(closure->variable) = closure->value; +} + +/* Remember the current value of *VARIABLE and make it restored when + the cleanup is run. */ + +struct cleanup * +make_cleanup_restore_ui_out (struct ui_out **variable) +{ + struct restore_ui_out_closure *c = XNEW (struct restore_ui_out_closure); + + c->variable = variable; + c->value = *variable; + + return make_cleanup_dtor (do_restore_ui_out, (void *) c, xfree); +} + struct restore_ui_file_closure { struct ui_file **variable; diff --git a/gdb/utils.h b/gdb/utils.h index 0687c86..87bb9c0 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -93,6 +93,9 @@ extern struct cleanup *make_cleanup_restore_uinteger (unsigned int *variable); struct target_ops; extern struct cleanup *make_cleanup_unpush_target (struct target_ops *ops); + +extern struct cleanup * + make_cleanup_restore_ui_out (struct ui_out **variable); extern struct cleanup * make_cleanup_restore_ui_file (struct ui_file **variable);