diff options
author | Lancelot SIX <lancelot.six@amd.com> | 2021-12-13 07:48:48 -0600 |
---|---|---|
committer | Lancelot SIX <lancelot.six@amd.com> | 2021-12-17 03:56:25 -0500 |
commit | 72994b6028360eccb5d25b39d2e18b386d091426 (patch) | |
tree | 855d88a99f9ca5ddc6110d496f1a2d29e0a5e3bf /gdb/testsuite/lib/notty-wrap | |
parent | 27e3da31c31572fde3d6e244a68ea45fb874b038 (diff) | |
download | gdb-72994b6028360eccb5d25b39d2e18b386d091426.zip gdb-72994b6028360eccb5d25b39d2e18b386d091426.tar.gz gdb-72994b6028360eccb5d25b39d2e18b386d091426.tar.bz2 |
gdb/tui: install SIGWINCH only when connected to a TTY
PR26056 reports that when GDB is connected to non-TTY stdin/stdout, it
crashes when it receives a SIGWINCH signal.
This can be reproduced as follows:
$ gdb/gdb -nx -batch -ex 'run' --args sleep 60 </dev/null 2>&1 | cat
# from another terminal:
$ kill -WINCH %(pidof gdb)
When doing so, the process crashes in a call to rl_resize_terminal:
void
rl_resize_terminal (void)
{
_rl_get_screen_size (fileno (rl_instream), 1);
...
}
The problem is that at this point rl_instream has the value NULL.
The rl_instream variable is supposed to be initialized during a call to
readline_initialize_everything, which in a normal startup sequence is
called under this call chain:
tui_interp::init
tui_ensure_readline_initialized
rl_initialize
readline_initialize_everything
In tui_interp::init, we have the following sequence:
tui_initialize_io ();
tui_initialize_win (); // <- Installs SIGWINCH
if (gdb_stdout->isatty ())
tui_ensure_readline_initialized (); // <- Initializes rl_instream
This function unconditionally installs the SIGWINCH signal handler (this
is done by tui_initialize_win), and then if gdb_stdout is a TTY it
initializes readline. Therefore, if stdout is not a TTY, SIGWINCH is
installed but readline is not initialized. In such situation
rl_instream stays NULL, and when GDB receives a SIGWINCH it calls its
handler and in fine tries to access rl_instream leading to the crash.
This patch proposes to fix this issue by installing the SIGWINCH signal
handler only if GDB is connected to a TTY. Given that this
initialization it the only task of tui_initialize_win, this patch moves
tui_initialize_win just after the call to
tui_ensure_readline_initialized.
Tested on x86_64-linux.
Co-authored-by: Pedro Alves <pedro@palves.net>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26056
Change-Id: I6458acef7b0d9beda2a10715d0345f02361076d9
Diffstat (limited to 'gdb/testsuite/lib/notty-wrap')
-rwxr-xr-x | gdb/testsuite/lib/notty-wrap | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gdb/testsuite/lib/notty-wrap b/gdb/testsuite/lib/notty-wrap new file mode 100755 index 0000000..899c2dd --- /dev/null +++ b/gdb/testsuite/lib/notty-wrap @@ -0,0 +1,24 @@ +#!/bin/sh + +# Copyright (C) 2021 Free Software Foundation, Inc. +# +# This file is part of GDB. +# +# 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/>. + +# Wrap any passed-in program and args in a pipe, so that the program +# is started without a terminal. + +exec "$@" </dev/null 2>&1 | cat |