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 gdb/ChangeLog: 2016-03-31 Catalin Udma <catalin.udma@freescale.com> 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 <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>
This commit is contained in:
parent
f7c382926d
commit
e7ea3ec7c6
8 changed files with 214 additions and 0 deletions
|
@ -1,3 +1,13 @@
|
|||
2016-03-31 Catalin Udma <catalin.udma@freescale.com>
|
||||
|
||||
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.
|
||||
|
||||
2016-03-31 Pedro Alves <palves@redhat.com>
|
||||
|
||||
* NEWS: Mention that support for "target m32rsdi", "target mips",
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
2016-03-31 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.
|
||||
|
||||
2016-03-30 Yao Qi <yao.qi@linaro.org>
|
||||
|
||||
* gdb.reverse/until-precsave.exp: Match function name only.
|
||||
|
|
48
gdb/testsuite/gdb.python/py-mi-events-gdb.py
Normal file
48
gdb/testsuite/gdb.python/py-mi-events-gdb.py
Normal file
|
@ -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"""
|
||||
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 ()
|
26
gdb/testsuite/gdb.python/py-mi-events.c
Normal file
26
gdb/testsuite/gdb.python/py-mi-events.c
Normal file
|
@ -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 <http://www.gnu.org/licenses/>. */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < 10)
|
||||
i++;
|
||||
|
||||
return 0;
|
||||
}
|
84
gdb/testsuite/gdb.python/py-mi-events.exp
Normal file
84
gdb/testsuite/gdb.python/py-mi-events.exp
Normal file
|
@ -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 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
|
29
gdb/utils.c
29
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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue