[PATCH] gdb: Don't change the uiout to console one when doing gdb.execute in TUI

Keith Seitz keiths@redhat.com
Mon May 24 18:25:55 GMT 2021


On 5/20/21 8:37 AM, Marco Barisione via Gdb-patches wrote:
> 
> This fix changes gdb.execute to only change current_uiout while in MI.
> 

This seems reasonable to me, but please wait for a maintainer's approval.
I have just a few minor comments.

> gdb/ChangeLog:
> 
> 	* python/python.c (execute_gdb_command): Change currently_uiout
> 	only when in MI to avoid breaking TUI mode.

s/currently/current/ ?

> 
> gdb/testsuite/ChangeLog:
> 
> 	* gdb.python/py-execute-in-tui.c: New test.
> 	* gdb.python/py-execute-in-tui.exp: New test.
> ---
>  gdb/python/python.c                           | 12 ++-
>  gdb/testsuite/gdb.python/py-execute-in-tui.c  | 22 ++++++
>  .../gdb.python/py-execute-in-tui.exp          | 74 +++++++++++++++++++
>  3 files changed, 104 insertions(+), 4 deletions(-)
>  create mode 100644 gdb/testsuite/gdb.python/py-execute-in-tui.c
>  create mode 100644 gdb/testsuite/gdb.python/py-execute-in-tui.exp
> 
> diff --git a/gdb/python/python.c b/gdb/python/python.c
> index 4cea83c3837..881dd1275f4 100644
> --- a/gdb/python/python.c
> +++ b/gdb/python/python.c
> @@ -630,10 +630,14 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
>  
>  	scoped_restore save_uiout = make_scoped_restore (&current_uiout);
>  
> -	/* Use the console interpreter uiout to have the same print format
> -	   for console or MI.  */
> -	interp = interp_lookup (current_ui, "console");
> -	current_uiout = interp->interp_ui_out ();
> +	/* When in MI, use the console interpreter uiout to have the same
> +	   print format as console.  It's important the uiout is not
> +	   changed in TUI mode, otherwise the output can get garbled.  */

I appreciate the comment!

> +	if (current_uiout->is_mi_like_p ())
> +	  {
> +	    interp = interp_lookup (current_ui, INTERP_CONSOLE);
> +	    current_uiout = interp->interp_ui_out ();
> +	  }
>  
>  	if (to_string)
>  	  to_string_res = execute_control_commands_to_string (lines.get (),
> diff --git a/gdb/testsuite/gdb.python/py-execute-in-tui.exp b/gdb/testsuite/gdb.python/py-execute-in-tui.exp
> new file mode 100644
> index 00000000000..de033aee7d6
> --- /dev/null
> +++ b/gdb/testsuite/gdb.python/py-execute-in-tui.exp
> @@ -0,0 +1,74 @@

I realize this file is copied from another test, however, in the interests
of keeping the code clean(er)...

> +if ![runto_main] then {
> +  fail "can't run to main"
> +  return
> +}

Please maintain a consistent Tcl style here. [Again, I realize this is
copy/paste.] The canonical way to do `if' statements in modern Tcl is

    if {cond} {
    }

[Modern Tcl? Oxymoron? :-)]

> +
> +# A backtrace executed via gdb.execute must produce something like this:
> +#     #0  main () at foo.c:42
> +# Where the function name is styled.  "\x1b" is the start of an ANSI
> +# escape sequence to style the function name.
> +
> +set gdb_execute_backtrace "python gdb.execute ('backtrace')"
> +set expected_backtrace_styled_output ".*#0.*\x1b.*main.*"
> +
> +gdb_test $gdb_execute_backtrace $expected_backtrace_styled_output \
> +  "backtrace from gdb.execute without TUI"
> +
> +# After entering TUI mode, the behaviour must remain the same.
> +
> +if {![Term::enter_tui]} {
> +  unsupported "TUI not supported"
> +  return
> +}
> +
> +# We can't use Term::command and Term::check_contents as that drops the
> +# ANSI escape codes.
> +send_gdb "${gdb_execute_backtrace}\n"
> +set test_name "backtrace from gdb.execute with TUI"
> +gdb_expect {
> +  -re $expected_backtrace_styled_output {
> +    pass $test_name
> +  }
> +  timeout {
> +    fail $test_name
> +  }
> +}
> 

We normally use gdb_test instead of gdb_send/gdb_expect. Is it not possible here?

Keith



More information about the Gdb-patches mailing list