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 2/3] TUI: Don't print KEY_RESIZE keys


On Thu, Jan 8, 2015 at 8:22 AM, Pedro Alves <palves@redhat.com> wrote:
> On 01/08/2015 12:32 PM, Patrick Palka wrote:
>> On Thu, Jan 8, 2015 at 6:29 AM, Pedro Alves <palves@redhat.com> wrote:
>>> On 01/08/2015 04:04 AM, Patrick Palka wrote:
>>>> wgetch() sometimes returns KEY_RESIZE when ncurses detects that the
>>>> terminal has been resized.
>>>
>>> I think curses SIGWINCH handler ends up _not_ installed, right?
>>> We install our own, and so does readline.
>>> So how did a resize manage to be detected/processed while inside
>>> wgetch?
>>
>> I'm pretty sure that the SIGWINCH handlers does not get installed.
>> However ncurses may detect a resize event when we exit TUI (exiting
>> ncurses), then resize the terminal, then re-enter TUI (restarting
>> ncurses).  From there a KEY_RESIZE key is added to its internal FIFO.
>> And the next call to wgetch will return this KEY_RESIZE key.
>
> Doesn't that mean then that we're delaying the resize until it's
> "too late"?  IOW, there's a moment where we show the contents with
> the wrong sizes.  And trying that out, I do see that happen: if I
> disable the TUI, resize the terminal, and then reenable the TUI,
> like you say, then until you press _another_ key, the windows
> have the wrong size.  We should have resized them already when we
> re-entered the TUI.

I think that is a separate issue.  ncurses simply detects that a
resize happened but doesn't do anything about it, IIRC.  It is up to
the program to intercept these KEY_RESIZEs and to make sure the screen
is resized correctly.  This patch makes tui_getc() ignore such keys
because they are not reliable without a corresponding SIGWINCH
handler.

>
> And if I try that when I'm already debugging an inferior, stopped at
> a breakpoint, I see nasty things.  If I reduce the size of the
> window, TUI gets stuck in an infinite loop in tui_show_source_line:
>
> (top-gdb) bt
> #0  0x0000003b46008446 in waddch_literal (win=0x28dfd30, ch=32) at ../../ncurses/base/lib_addch.c:253
> #1  0x0000003b4600859c in waddch_nosync (win=0x28dfd30, ch=32) at ../../ncurses/base/lib_addch.c:437
> #2  0x0000003b46008878 in waddch (win=0x28dfd30, ch=32) at ../../ncurses/base/lib_addch.c:543
> #3  0x0000000000524d08 in tui_show_source_line (win_info=0x28dfc90, lineno=1) at /home/pedro/gdb/mygit/src/gdb/tui/tui-winsource.c:292
> #4  0x0000000000524d8f in tui_show_source_content (win_info=0x28dfc90) at /home/pedro/gdb/mygit/src/gdb/tui/tui-winsource.c:305
> #5  0x00000000005220cb in tui_refresh_all_win () at /home/pedro/gdb/mygit/src/gdb/tui/tui-win.c:633
> #6  0x000000000052611c in tui_enable () at /home/pedro/gdb/mygit/src/gdb/tui/tui.c:486
> #7  0x0000000000525861 in tui_rl_switch_mode (notused1=1, notused2=1) at /home/pedro/gdb/mygit/src/gdb/tui/tui.c:108
> #8  0x0000000000796d6f in _rl_dispatch_subseq (key=1, map=0xd585c0 <emacs_ctlx_keymap>, got_subseq=0) at /home/pedro/gdb/mygit/src/readline/readline.c:774
> #9  0x0000000000796acb in _rl_dispatch_callback (cxt=0x26e6500) at /home/pedro/gdb/mygit/src/readline/readline.c:686
> #10 0x00000000007af20b in rl_callback_read_char () at /home/pedro/gdb/mygit/src/readline/callback.c:170
> #11 0x000000000063cefd in rl_callback_read_char_wrapper (client_data=0x0) at /home/pedro/gdb/mygit/src/gdb/event-top.c:171
> #12 0x000000000063d366 in stdin_event_handler (error=0, client_data=0x0) at /home/pedro/gdb/mygit/src/gdb/event-top.c:432
> #13 0x000000000063bec6 in handle_file_event (data=...) at /home/pedro/gdb/mygit/src/gdb/event-loop.c:762
> ---Type <return> to continue, or q <return> to quit---
> #14 0x000000000063b3ad in process_event () at /home/pedro/gdb/mygit/src/gdb/event-loop.c:339
> #15 0x000000000063b474 in gdb_do_one_event () at /home/pedro/gdb/mygit/src/gdb/event-loop.c:403
> #16 0x000000000063b4c4 in start_event_loop () at /home/pedro/gdb/mygit/src/gdb/event-loop.c:428
> #17 0x000000000063cf2f in cli_command_loop (data=0x0) at /home/pedro/gdb/mygit/src/gdb/event-top.c:186
> #18 0x0000000000633284 in current_interp_command_loop () at /home/pedro/gdb/mygit/src/gdb/interps.c:317
> #19 0x000000000063444d in captured_command_loop (data=0x0) at /home/pedro/gdb/mygit/src/gdb/main.c:321
> #20 0x0000000000630141 in catch_errors (func=0x634432 <captured_command_loop>, func_args=0x0, errstring=0x9422e1 "", mask=RETURN_MASK_ALL)
>     at /home/pedro/gdb/mygit/src/gdb/exceptions.c:237
> #21 0x000000000063594b in captured_main (data=0x7fffe05ca000) at /home/pedro/gdb/mygit/src/gdb/main.c:1149
> #22 0x0000000000630141 in catch_errors (func=0x63484a <captured_main>, func_args=0x7fffe05ca000, errstring=0x9422e1 "", mask=RETURN_MASK_ALL)
>     at /home/pedro/gdb/mygit/src/gdb/exceptions.c:237
> #23 0x0000000000635974 in gdb_main (args=0x7fffe05ca000) at /home/pedro/gdb/mygit/src/gdb/main.c:1157
> #24 0x0000000000464e57 in main (argc=3, argv=0x7fffe05ca108) at /home/pedro/gdb/mygit/src/gdb/gdb.c:32
>
>
>
> If instead I increase the size of the window, GDB aborts.  E.g.,:
>
> (top-gdb) bt
> #0  internal_error (file=0x986408 "/home/pedro/gdb/mygit/src/gdb/utils.c", line=1076, fmt=0x986834 "virtual memory exhausted.")
>     at /home/pedro/gdb/mygit/src/gdb/common/errors.c:54
> #1  0x000000000074b85d in malloc_failure (size=-8) at /home/pedro/gdb/mygit/src/gdb/utils.c:1076
> #2  0x0000000000783616 in xmalloc (size=18446744073709551608) at /home/pedro/gdb/mygit/src/gdb/common/common-utils.c:43
> #3  0x000000000051a13b in tui_alloc_content (num_elements=-1, type=EXEC_INFO_WIN) at /home/pedro/gdb/mygit/src/gdb/tui/tui-data.c:590
> #4  0x00000000005253ee in tui_set_exec_info_content (win_info=0x1a4a6c0) at /home/pedro/gdb/mygit/src/gdb/tui/tui-winsource.c:510
> #5  0x0000000000525672 in tui_update_exec_info (win_info=0x1a4a6c0) at /home/pedro/gdb/mygit/src/gdb/tui/tui-winsource.c:602
> #6  0x00000000005221c8 in tui_refresh_all_win () at /home/pedro/gdb/mygit/src/gdb/tui/tui-win.c:636
> #7  0x000000000051d3b1 in tui_handle_resize_during_io (original_ch=410) at /home/pedro/gdb/mygit/src/gdb/tui/tui-io.c:770
> #8  0x000000000051d251 in tui_getc (fp=0x3b36db8640 <_IO_2_1_stdin_>) at /home/pedro/gdb/mygit/src/gdb/tui/tui-io.c:693
> #9  0x00000000007aed93 in rl_read_key () at /home/pedro/gdb/mygit/src/readline/input.c:448
> #10 0x0000000000796848 in readline_internal_char () at /home/pedro/gdb/mygit/src/readline/readline.c:517
> #11 0x00000000007af375 in rl_callback_read_char () at /home/pedro/gdb/mygit/src/readline/callback.c:201
> #12 0x000000000063cfb9 in rl_callback_read_char_wrapper (client_data=0x0) at /home/pedro/gdb/mygit/src/gdb/event-top.c:171
> #13 0x000000000063d422 in stdin_event_handler (error=0, client_data=0x0) at /home/pedro/gdb/mygit/src/gdb/event-top.c:432
>
> Another time:
>
> (top-gdb) bt
> #0  internal_error (file=0x986408 "/home/pedro/gdb/mygit/src/gdb/utils.c", line=1076, fmt=0x986834 "virtual memory exhausted.")
>     at /home/pedro/gdb/mygit/src/gdb/common/errors.c:54
> #1  0x000000000074b85d in malloc_failure (size=-79) at /home/pedro/gdb/mygit/src/gdb/utils.c:1076
> #2  0x0000000000783616 in xmalloc (size=18446744073709551537) at /home/pedro/gdb/mygit/src/gdb/common/common-utils.c:43
> #3  0x00000000005256c5 in tui_alloc_source_buffer (win_info=0x28abee0) at /home/pedro/gdb/mygit/src/gdb/tui/tui-winsource.c:621
> #4  0x000000000051ff7b in tui_set_source_content (s=0x2299ae0, line_no=1, noerror=1) at /home/pedro/gdb/mygit/src/gdb/tui/tui-source.c:53
> #5  0x0000000000524871 in tui_update_source_window_as_is (win_info=0x28abee0, gdbarch=0x26a2450, s=0x2299ae0, line_or_addr=..., noerror=1)
>     at /home/pedro/gdb/mygit/src/gdb/tui/tui-winsource.c:96
> #6  0x0000000000524824 in tui_update_source_window (win_info=0x28abee0, gdbarch=0x26a2450, s=0x2299ae0, line_or_addr=..., noerror=1)
>     at /home/pedro/gdb/mygit/src/gdb/tui/tui-winsource.c:78
> #7  0x000000000052360a in make_visible_with_new_height (win_info=0x28abee0) at /home/pedro/gdb/mygit/src/gdb/tui/tui-win.c:1381
> #8  0x000000000052242c in tui_resize_all () at /home/pedro/gdb/mygit/src/gdb/tui/tui-win.c:723
> #9  0x000000000051d3ac in tui_handle_resize_during_io (original_ch=410) at /home/pedro/gdb/mygit/src/gdb/tui/tui-io.c:769
> #10 0x000000000051d251 in tui_getc (fp=0x3b36db8640 <_IO_2_1_stdin_>) at /home/pedro/gdb/mygit/src/gdb/tui/tui-io.c:693
> #11 0x00000000007aed93 in rl_read_key () at /home/pedro/gdb/mygit/src/readline/input.c:448
> #12 0x0000000000796848 in readline_internal_char () at /home/pedro/gdb/mygit/src/readline/readline.c:517
> #13 0x00000000007af375 in rl_callback_read_char () at /home/pedro/gdb/mygit/src/readline/callback.c:201
> #14 0x000000000063cfb9 in rl_callback_read_char_wrapper (client_data=0x0) at /home/pedro/gdb/mygit/src/gdb/event-top.c:171
> #15 0x000000000063d422 in stdin_event_handler (error=0, client_data=0x0) at /home/pedro/gdb/mygit/src/gdb/event-top.c:432
> #16 0x000000000063bf82 in handle_file_event (data=...) at /home/pedro/gdb/mygit/src/gdb/event-loop.c:762
> #17 0x000000000063b469 in process_event () at /home/pedro/gdb/mygit/src/gdb/event-loop.c:339
> #18 0x000000000063b530 in gdb_do_one_event () at /home/pedro/gdb/mygit/src/gdb/event-loop.c:403
> #19 0x000000000063b580 in start_event_loop () at /home/pedro/gdb/mygit/src/gdb/event-loop.c:428
> #20 0x000000000063cfeb in cli_command_loop (data=0x0) at /home/pedro/gdb/mygit/src/gdb/event-top.c:186
> #21 0x0000000000633340 in current_interp_command_loop () at /home/pedro/gdb/mygit/src/gdb/interps.c:317
> #22 0x0000000000634509 in captured_command_loop (data=0x0) at /home/pedro/gdb/mygit/src/gdb/main.c:321
> #23 0x00000000006301fd in catch_errors (func=0x6344ee <captured_command_loop>, func_args=0x0, errstring=0x942261 "", mask=RETURN_MASK_ALL)
>     at /home/pedro/gdb/mygit/src/gdb/exceptions.c:237
> ---Type <return> to continue, or q <return> to quit---
> #24 0x0000000000635a07 in captured_main (data=0x7fffeab9cbb0) at /home/pedro/gdb/mygit/src/gdb/main.c:1149
> #25 0x00000000006301fd in catch_errors (func=0x634906 <captured_main>, func_args=0x7fffeab9cbb0, errstring=0x942261 "", mask=RETURN_MASK_ALL)
>     at /home/pedro/gdb/mygit/src/gdb/exceptions.c:237
> #26 0x0000000000635a30 in gdb_main (args=0x7fffeab9cbb0) at /home/pedro/gdb/mygit/src/gdb/main.c:1157
> #27 0x0000000000464e87 in main (argc=3, argv=0x7fffeab9ccb8) at /home/pedro/gdb/mygit/src/gdb/gdb.c:32
>
> Do you see these?

I don't see these because I have the following patch locally
installed: https://sourceware.org/ml/gdb-patches/2014-09/msg00004.html
I planned on resending that patch today or tomorrow.

>
> As a quick try, I added a call to tui_resize_all in tui_enable, and
> it seems to fix these, and almost fix the "stale" size when we
> reenable the TUI, but a subsequent keypress still changes the
> layout, so apparently something more should be done.

Such a change would be convenient, making sure that the TUI screen is
resized correctly from the get-go.  I have a patch for this somewhere,
too...

>
> diff --git c/gdb/tui/tui.c w/gdb/tui/tui.c
> index 00e505d..f3d0fbf 100644
> --- c/gdb/tui/tui.c
> +++ w/gdb/tui/tui.c
> @@ -467,6 +467,7 @@ tui_enable (void)
>          Curses will restore this state when endwin() is called.  */
>       def_shell_mode ();
>       clearok (stdscr, TRUE);
> +     tui_resize_all ();
>     }
>
>    /* Install the TUI specific hooks.  */
>
> Thanks,
> Pedro Alves


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