Message ID | 54AE848B.1050606@redhat.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 18965 invoked by alias); 8 Jan 2015 13:22:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 18955 invoked by uid 89); 8 Jan 2015 13:22:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 08 Jan 2015 13:22:33 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t08DMTeO000713 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 Jan 2015 08:22:29 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t08DMLFO006916; Thu, 8 Jan 2015 08:22:24 -0500 Message-ID: <54AE848B.1050606@redhat.com> Date: Thu, 08 Jan 2015 13:22:19 +0000 From: Pedro Alves <palves@redhat.com> User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Patrick Palka <patrick@parcs.ath.cx> CC: gdb-patches@sourceware.org Subject: Re: [PATCH 2/3] TUI: Don't print KEY_RESIZE keys References: <1420689885-31156-1-git-send-email-patrick@parcs.ath.cx> <1420689885-31156-2-git-send-email-patrick@parcs.ath.cx> <54AE6A19.9070901@redhat.com> <CA+C-WL-ohtv2BvCT2H5Nfc8furA1uVR7SSa1X9HFO5CaZZN03A@mail.gmail.com> In-Reply-To: <CA+C-WL-ohtv2BvCT2H5Nfc8furA1uVR7SSa1X9HFO5CaZZN03A@mail.gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit |
Commit Message
Pedro Alves
Jan. 8, 2015, 1:22 p.m. UTC
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. 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? 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. Thanks, Pedro Alves
Comments
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
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 have just pushed the patch that fixes this issue. The screen now gets opportunistically resized when switching from the CLI to the TUI. > > 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? > > 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. > > 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. */ The pushed fix was essentially that, but it also sets tui_win_resized to FALSE so that a subsequent keypress does not change the layout. Is this patch now OK? (You have already approved patch #1 and #3 in this series.) > > Thanks, > Pedro Alves
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. */