From 1e1e619b6b382f9b354d78018ddb73f0070375d2 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 29 Oct 2014 14:49:05 +0000 Subject: PR tui/16138 is about failure to initialize curses resulting in GDB exiting instead of throwing an error. E.g.: $ TERM=foo gdb (gdb) layout asm Error opening terminal: foo. $ The problem is that we're calling initscr to initialize the screen. As mentioned in http://pubs.opengroup.org/onlinepubs/7908799/xcurses/initscr.html: If errors occur, initscr() writes an appropriate error message to standard error and exits. ^^^^^ Instead, we should use newterm: "A program that needs an indication of error conditions, so it can continue to run in a line-oriented mode if the terminal cannot support a screen-oriented program, would also use this function." After the patch: $ TERM=foo gdb -q -nx (gdb) layout asm Cannot enable the TUI: error opening terminal [TERM=foo] (gdb) And then PR tui/17519 is about GDB not validating whether the terminal has the necessary capabilities when enabling the TUI. If one tries to enable the TUI with TERM=dumb (and e.g., from a shell within emacs), GDB ends up with a clear screen, the cursor is placed at the bottom/right corner of the screen, there's no prompt, typing shows no echo, and there's no indication of what's going on. c-x,a gets you out of the TUI, but it's completely non-obvious. After the patch, we get: $ TERM=dumb gdb -q -nx (gdb) layout asm Cannot enable the TUI: terminal doesn't support cursor addressing [TERM=dumb] (gdb) While at it, I've moved all the tui_allowed_p validation to tui_enable, and expanded the error messages. Previously we'd get: $ gdb -q -nx -i=mi (gdb) layout asm &"layout asm\n" &"TUI mode not allowed\n" ^error,msg="TUI mode not allowed" and: $ gdb -q -nx -ex "layout asm" > foo TUI mode not allowed While now we get: $ gdb -q -nx -i=mi (gdb) layout asm &"layout asm\n" &"Cannot enable the TUI when the interpreter is 'mi'\n" ^error,msg="Cannot enable the TUI when the interpreter is 'mi'" (gdb) and: $ gdb -q -nx -ex "layout asm" > foo Cannot enable the TUI when output is not a terminal Tested on x86_64 Fedora 20. gdb/ 2014-10-29 Pedro Alves PR tui/16138 PR tui/17519 * tui/tui-interp.c (tui_is_toplevel): Delete global. (tui_allowed_p): Delete function. * tui/tui.c: Include "interps.h". (tui_enable): Don't use tui_allowed_p. Error out here with detailed error messages if the TUI is the top level interpreter, or if output is not a terminal. Use newterm instead of initscr, and error out if initializing the terminal fails. Also error out if the terminal doesn't support cursor addressing. * tui/tui.h (tui_allowed_p): Delete declaration. --- gdb/ChangeLog | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 88c18e0..1125b1e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -3,6 +3,20 @@ * tui/tui.c (tui_rl_switch_mode): Wrap tui_enable/tui_disable in TRY_CATCH. +2014-10-29 Pedro Alves + + PR tui/16138 + PR tui/17519 + * tui/tui-interp.c (tui_is_toplevel): Delete global. + (tui_allowed_p): Delete function. + * tui/tui.c: Include "interps.h". + (tui_enable): Don't use tui_allowed_p. Error out here with + detailed error messages if the TUI is the top level interpreter, + or if output is not a terminal. Use newterm instead of initscr, + and error out if initializing the terminal fails. Also error out if + the terminal doesn't support cursor addressing. + * tui/tui.h (tui_allowed_p): Delete declaration. + 2014-10-29 Joel Brobecker * arm-tdep.c (arm_skip_stack_protector): Return early if -- cgit v1.1