This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: [PING][PATCH] python: Use console format for output of gdb.execute command
- From: Catalin-Dan Udma <catalin-dan dot udma at nxp dot com>
- To: Catalin Udma <catalin dot udma at freescale dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Thu, 17 Mar 2016 07:54:47 +0000
- Subject: RE: [PING][PATCH] python: Use console format for output of gdb.execute command
- Authentication-results: sourceware.org; auth=none
- Authentication-results: freescale.com; dkim=none (message not signed) header.d=none;freescale.com; dmarc=none action=none header.from=nxp.com;
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:23
Ping.
The patch:
https://sourceware.org/ml/gdb-patches/2016-02/msg00886.html
And two replies:
https://sourceware.org/ml/gdb-patches/2016-03/msg00039.html
https://sourceware.org/ml/gdb-patches/2016-03/msg00044.html
Thank you,
Catalin
> -----Original Message-----
> From: Catalin Udma [mailto:catalin.udma@freescale.com]
> Sent: Monday, February 29, 2016 4:34 PM
> To: gdb-patches@sourceware.org
> Cc: Catalin Udma <catalin.udma@freescale.com>
> Subject: [PATCH] python: Use console format for output of gdb.execute
> command
>
> 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 <catalin.udma@freescale.com>
>
> PR python/19743
> * python/python.c (execute_gdb_command): Use console uiout
> when executing gdb command.
>
> 2016-02-29 Catalin Udma <catalin.udma@freescale.com>
>
> 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 <catalin.udma@freescale.com>
> ---
> 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 <http://www.gnu.org/licenses/>.
> +
> +# 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 <http://www.gnu.org/licenses/>. */
> +
> +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 <http://www.gnu.org/licenses/>.
> +
> +# 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
> --
> 1.7.8