This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] python: Use console format for output of gdb.execute command


Hi Catalin,

On 02/29/2016 02:34 PM, Catalin Udma wrote:
> 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.

This seems like the right thing to do.  See comments below.

> 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;

This needs to be restored with a cleanup instead.

> +
>         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


> +# This file is part of the GDB testsuite. It tests python printing
> +# to string from event handlers.

Double-space after period.

> +
> +
> +import gdb
> +
> +
> +def signal_stop_handler (event):
> +    """Stop event handler"""
> +    if (isinstance (event, gdb.StopEvent)):
> +

OOC, why is this one an isinstance check, while below you
have an assert?

> +def continue_handler (event):
> +    """Continue event handler"""
> +    assert (isinstance (event, gdb.ContinueEvent))

> +int
> +main (void)
> +{
> +  while (1);

Please avoid tests that run forever:

 https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Don.27t_write_tests_that_run_forever

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]