GNU Binutils with patches for OS216
修訂 | a350efd4fb368a35ada608f6bc26ccd3bed0ae6b (tree) |
---|---|
時間 | 2020-06-17 09:02:20 |
作者 | Tom Tromey <tom@trom...> |
Commiter | Tom Tromey |
Fix crash when exiting TUI with gdb -tui
PR tui/25348 points out that, when "gdb -tui" is used, then exiting
the TUI will cause a crash.
This happens because tui_setup_io stashes some readline variables --
but because this happens before readline is initialized, some of these
are NULL. Then, when exiting the TUI, the NULL values are "restored",
causing a crash in readline.
This patch fixes the problem by ensuring that readline is initialized
first. Back in commit 11061048d ("Give a name to the TUI SingleKey
keymap"), a call to rl_initialize was removed from
tui_initialize_readline; this patch resurrects the call, but moves it
to the end of the function, so as not to remove the ability to modify
the SingleKey map from .inputrc.
gdb/ChangeLog
2020-06-16 Tom Tromey <tom@tromey.com>
PR tui/25348:
* tui/tui.c (tui_ensure_readline_initialized): Rename from
tui_initialize_readline. Only run once. Call rl_initialize.
* tui/tui.h (tui_ensure_readline_initialized): Rename from
tui_initialize_readline.
* tui/tui-io.c (tui_setup_io): Call
tui_ensure_readline_initialized.
* tui/tui-interp.c (tui_interp::init): Update.
@@ -1,5 +1,16 @@ | ||
1 | 1 | 2020-06-16 Tom Tromey <tom@tromey.com> |
2 | 2 | |
3 | + PR tui/25348: | |
4 | + * tui/tui.c (tui_ensure_readline_initialized): Rename from | |
5 | + tui_initialize_readline. Only run once. Call rl_initialize. | |
6 | + * tui/tui.h (tui_ensure_readline_initialized): Rename from | |
7 | + tui_initialize_readline. | |
8 | + * tui/tui-io.c (tui_setup_io): Call | |
9 | + tui_ensure_readline_initialized. | |
10 | + * tui/tui-interp.c (tui_interp::init): Update. | |
11 | + | |
12 | +2020-06-16 Tom Tromey <tom@tromey.com> | |
13 | + | |
3 | 14 | * tui/tui-layout.c (tui_layout_split::remove_windows): Fix logic. |
4 | 15 | Also preserve the status window. |
5 | 16 |
@@ -244,7 +244,7 @@ tui_interp::init (bool top_level) | ||
244 | 244 | tui_initialize_io (); |
245 | 245 | tui_initialize_win (); |
246 | 246 | if (gdb_stdout->isatty ()) |
247 | - tui_initialize_readline (); | |
247 | + tui_ensure_readline_initialized (); | |
248 | 248 | } |
249 | 249 | |
250 | 250 | void |
@@ -746,6 +746,10 @@ tui_setup_io (int mode) | ||
746 | 746 | |
747 | 747 | if (mode) |
748 | 748 | { |
749 | + /* Ensure that readline has been initialized before saving any | |
750 | + of its variables. */ | |
751 | + tui_ensure_readline_initialized (); | |
752 | + | |
749 | 753 | /* Redirect readline to TUI. */ |
750 | 754 | tui_old_rl_redisplay_function = rl_redisplay_function; |
751 | 755 | tui_old_rl_deprep_terminal = rl_deprep_term_function; |
@@ -268,8 +268,14 @@ tui_set_key_mode (enum tui_key_mode mode) | ||
268 | 268 | /* Initialize readline and configure the keymap for the switching |
269 | 269 | key shortcut. */ |
270 | 270 | void |
271 | -tui_initialize_readline (void) | |
271 | +tui_ensure_readline_initialized () | |
272 | 272 | { |
273 | + static bool initialized; | |
274 | + | |
275 | + if (initialized) | |
276 | + return; | |
277 | + initialized = true; | |
278 | + | |
273 | 279 | int i; |
274 | 280 | Keymap tui_ctlx_keymap; |
275 | 281 |
@@ -325,6 +331,9 @@ tui_initialize_readline (void) | ||
325 | 331 | rl_bind_key_in_map ('q', tui_rl_next_keymap, tui_keymap); |
326 | 332 | rl_bind_key_in_map ('s', tui_rl_next_keymap, emacs_ctlx_keymap); |
327 | 333 | rl_bind_key_in_map ('s', tui_rl_next_keymap, tui_ctlx_keymap); |
334 | + | |
335 | + /* Initialize readline after the above. */ | |
336 | + rl_initialize (); | |
328 | 337 | } |
329 | 338 | |
330 | 339 | /* Return the TERM variable from the environment, or "<unset>" |
@@ -49,9 +49,9 @@ extern bool tui_is_window_visible (enum tui_win_type type); | ||
49 | 49 | extern bool tui_get_command_dimension (unsigned int *width, |
50 | 50 | unsigned int *height); |
51 | 51 | |
52 | -/* Initialize readline and configure the keymap for the switching | |
53 | - key shortcut. */ | |
54 | -extern void tui_initialize_readline (void); | |
52 | +/* Initialize readline and configure the keymap for the switching key | |
53 | + shortcut. May be called more than once without issue. */ | |
54 | +extern void tui_ensure_readline_initialized (); | |
55 | 55 | |
56 | 56 | /* Enter in the tui mode (curses). */ |
57 | 57 | extern void tui_enable (void); |