From: Catalin Udma <catalin.udma@freescale.com>
To: <gdb-patches@sourceware.org>
Cc: Catalin Udma <catalin.udma@freescale.com>
Subject: [PATCH] python: Use console format for output of gdb.execute command
Date: Mon, 29 Feb 2016 14:35:00 -0000 [thread overview]
Message-ID: <1456756452-15880-1-git-send-email-catalin.udma@freescale.com> (raw)
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
next reply other threads:[~2016-02-29 14:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-29 14:35 Catalin Udma [this message]
2016-03-02 22:20 ` Phil Muldoon
2016-03-03 10:25 ` Catalin-Dan Udma
2016-03-29 16:40 ` Pedro Alves
2016-03-31 10:43 ` Catalin-Dan Udma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456756452-15880-1-git-send-email-catalin.udma@freescale.com \
--to=catalin.udma@freescale.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox