From patchwork Fri Jan 6 10:25:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62779 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 111CA38493EC for ; Fri, 6 Jan 2023 10:26:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 111CA38493EC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000778; bh=Y4eejOkdUfbmVdpO81F1vKrPyRnS9eT5e5C3xyIzRq8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=QmhKeN2Ctx9ak3NlCvQ0+biRv0Q1KM5CfbPE+nH1w8+NCwTcWrmcceD/KqKvpHuqM gfYXo5tLy5d/zVTogLxJ/2CMEA9OfLU9lssTwB6Zr3GFuwbhPZZ0Rhl6swGDfBnCjE KV553g1u5Pnw7cGhKYWI+J4eG65ncEHzPvpICBBs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id EC71D3858D28 for ; Fri, 6 Jan 2023 10:25:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC71D3858D28 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-247-13Y8DoLyNE2wN6_XnRB9fQ-1; Fri, 06 Jan 2023 05:25:50 -0500 X-MC-Unique: 13Y8DoLyNE2wN6_XnRB9fQ-1 Received: by mail-ej1-f69.google.com with SMTP id ne1-20020a1709077b8100b007c198bb8c0eso875071ejc.8 for ; Fri, 06 Jan 2023 02:25:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y4eejOkdUfbmVdpO81F1vKrPyRnS9eT5e5C3xyIzRq8=; b=gSTT7obgakQQT31DyJrYH37t986XkiHp6P+AMXR+zSSVttCNVjnLpymcJQNuxUM9q7 JxSTt6kT56iqLaRoucVDNh4M80sPzbIWjWGuluMOepz+e38f7431fWUQLQq+KZGDldhp N+LL+M6Vh/54rPu+UTTXIaGPpln6kYhAYvSscFCXXZuMxS7r0xtnCTOHB/DqU/fXNjt2 EFtHwnof3VY8S0exmJvy6FSCIFajXxcPPa+jyXEkhdxfKEfApgiYbs9e4NHV08bZh7T0 kDyE0Z2yfw01ZEVOQXWjV/jMlKy/CvE9Yx7Q8LqsqvylNi76/9Iww23apSfXcud96xhx 3bqQ== X-Gm-Message-State: AFqh2kqas2gyFh+JI+IGWzFFww6vJRnNUSKiMuYmd72XDHTIxOlD/tcd h+xM1ZIhgSkJISqfOKpXr9dJZrAs/J6rOj0XhJLvL96n7+djiWhZfmihxI0ow6/CSXunQMbimz1 cbaC35fSeV6h7lQdvwkhPuRcs6Jdyv0Ljhc/mAri25hU9We1/tuvgryxPc9trwcHPRThbzDee+Q == X-Received: by 2002:a05:6402:1508:b0:489:99c1:d3cc with SMTP id f8-20020a056402150800b0048999c1d3ccmr22214379edw.24.1673000749145; Fri, 06 Jan 2023 02:25:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXsT7Pk4neftuPFOTVJl/3tQt4Ea4vPOXmj9eqas+i3K547ifD8n/8huEOfd06+o+4Q3RRJ4jw== X-Received: by 2002:a05:6402:1508:b0:489:99c1:d3cc with SMTP id f8-20020a056402150800b0048999c1d3ccmr22214367edw.24.1673000748921; Fri, 06 Jan 2023 02:25:48 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id b12-20020a05640202cc00b0046ee136fa3bsm346352edx.69.2023.01.06.02.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:25:48 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 01/15] gdb/testsuite: extend gdb.tui/tui-layout.exp test script Date: Fri, 6 Jan 2023 10:25:28 +0000 Message-Id: <3adda76c2743f4b5c7c811cc68a212ec9fcf3f57.1673000632.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" In passing I noticed that the gdb.tui/tui-layout.exp test script was a little strange, it tests the layout command multiple times, but never sets up our ANSI terminal emulator, so every layout command fails with a message about the terminal lacking the required abilities. It turns out that this was caused by this commit: commit 9162a27c5f5828240b53379d735679e2a69a9f41 Date: Tue Nov 13 11:59:03 2018 -0700 Change gdb test suite's TERM setting This was when we changed the testsuite to set the TERM environment variable to "dumb" by default. After this, any tui test that didn't set the terminal mode back to 'ansi' would fail to activate tui mode. For the tui-layout.exp test it just so happens that the test patterns are generic enough that the test continued to pass, even after this change. In this commit I have updated the test so we now check the layout command both with a 'dumb' terminal and with the 'ansi' terminal. When testing with the 'ansi' terminal, I have some limited validation that GDB correctly entered tui mode. I figured that it is probably worth having at least one test in the test suite that deliberately tries to enter tui mode in a dumb terminal, it would be sad if we one day managed to break GDB such that this caused a crash, and never noticed. --- gdb/testsuite/gdb.tui/tui-layout.exp | 57 ++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/gdb/testsuite/gdb.tui/tui-layout.exp b/gdb/testsuite/gdb.tui/tui-layout.exp index 97734cf7b68..e69760193c5 100644 --- a/gdb/testsuite/gdb.tui/tui-layout.exp +++ b/gdb/testsuite/gdb.tui/tui-layout.exp @@ -16,6 +16,8 @@ # Minimal testcase that just checks that the various "layout $foo" # commands do not cause gdb to crash. +tuiterm_env + standard_testfile if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { @@ -26,13 +28,33 @@ if {[skip_tui_tests]} { return } -# Test one layout command. EXECUTION indicates whether to activate -# the layout with or without execution. +# Run one test of the 'layout' command, selecting LAYOUT_NAME. +# +# TERMINAL should be either 'dumb' or 'ansi'. When TERMINAL is 'dumb' +# then GDB is started in a terminal that does not support tui mode, in +# this case the layout command is expected to fail. +# +# When TERMINAL is 'ansi' then GDB is started using our emulated ANSI +# terminal, and the layout command is expected to succeed. +# +# When EXECUTION is true then a call to runto_main is used, otherwise +# this call is skipped and the inferior is left in whatever state it +# happens to be in after a call to clean_restart. -proc test_layout {layout execution} { +proc test_layout_or_focus {layout_name terminal execution} { global binfile gdb_prompt - clean_restart $binfile + set dumb_terminal [string equal $terminal "dumb"] + + if {$dumb_terminal} { + clean_restart $binfile + } else { + Term::clean_restart 24 80 $binfile + if {![Term::prepare_for_tui]} { + unsupported "TUI not supported" + return + } + } if {$execution} { if {![runto_main]} { @@ -40,16 +62,29 @@ proc test_layout {layout execution} { } } - set test "layout command" - gdb_test_multiple "layout $layout" $test { - -re "$gdb_prompt $" { - pass $test + if {$dumb_terminal} { + gdb_test "layout $layout_name" \ + "Cannot enable the TUI: terminal doesn't support cursor addressing \\\[TERM=dumb\\\]" + } else { + Term::command_no_prompt_prefix "layout $layout_name" + if {$layout_name == "asm"} { + Term::check_box "asm box" 0 0 80 15 + } elseif {$layout_name == "reg"} { + Term::check_box "reg box" 0 0 80 8 + Term::check_box "src box" 0 7 80 8 + } elseif {$layout_name == "src"} { + Term::check_box "src box" 0 0 80 15 + } elseif {$layout_name == "split"} { + Term::check_box "src box" 0 0 80 8 + Term::check_box "asm box" 0 7 80 8 } } } -foreach_with_prefix execution {0 1} { - foreach_with_prefix layout {"asm" "reg" "src" "split"} { - test_layout $layout $execution +foreach_with_prefix terminal {ansi dumb} { + foreach_with_prefix execution {false true} { + foreach_with_prefix layout {"asm" "reg" "src" "split"} { + test_layout_or_focus $layout $terminal $execution + } } } From patchwork Fri Jan 6 10:25:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62780 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B77C9385800A for ; Fri, 6 Jan 2023 10:26:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B77C9385800A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000784; bh=PShYEFtoO9Sa7eigusz3QJbiNJpNfGbXjX26lZZR/gc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ySjtFndwKjQ1m4Epi3rqbyLRHuz5QrdLDRCl1WH4b56utQ5vVKwRII8Kv9P7Tl9wO Fifc97lxWHe3uDXn6sSng5wvo9XyvqOGBOjWrhets49IsIUflK4zqS2/1Omjaf4QVR r4JETIiN/YLwqZgpBs4WCVnQ/Tn1ueDcZQ2T5P0M= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 32FF4385841D for ; Fri, 6 Jan 2023 10:25:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 32FF4385841D Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-446-Ic2Q2ZN_NlekRsaR2kPLpg-1; Fri, 06 Jan 2023 05:25:52 -0500 X-MC-Unique: Ic2Q2ZN_NlekRsaR2kPLpg-1 Received: by mail-ej1-f71.google.com with SMTP id jg25-20020a170907971900b007c0e98ad898so869696ejc.15 for ; Fri, 06 Jan 2023 02:25:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PShYEFtoO9Sa7eigusz3QJbiNJpNfGbXjX26lZZR/gc=; b=CCb/FU6T440uCauZ2TjuvuzfdlLLsH1UpzF7vpvFtPyfvU8ZEOprr3zCXcuwuy3EMJ l9mcn6va6u+86qwF1z+pl4njh+6q+4OcIlGhA3fQGjhUaMDmEza71T0ZcO6YnoOdjUSn 1JOVQ7rhUC4txea1y60aRJPkqSFC7h40VktVI186lziLR1UtOvsBWKoy4qtX8zxEXIc8 NiUK9le2lTRq0k2+l2TdGgmDbPB0GsNWxpRVOYDcj/NmlGgybyBAUh+jCVBPO5qPoBCa KRfVuO76XwyJeeUiHCWFS1dxNFqMF+GfaGIjRp+6u+7pbIORkB42o/bptQgmYGKh1UhU HArw== X-Gm-Message-State: AFqh2ko/iphTBJgNfRihY1szslm0Afz+fEq5X3ob4WDteR9zjlbUtUMB xRF+GGtD/f2A95hJWFtZrIG/S8SJ7n4AeE9Plca/JSrqZSbD5R5x8gXahb1V3wCza4sFHy2alaT xUjxMYKqOswlKVAw++Ef0t79MK2OWz3cdIAP3N5JFKCx9Ts+nXCvMycTMtrWqhaVd/9lKWJAkpw == X-Received: by 2002:a17:906:688f:b0:7ae:31a0:571c with SMTP id n15-20020a170906688f00b007ae31a0571cmr47862483ejr.57.1673000751567; Fri, 06 Jan 2023 02:25:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXskfPOwIotcwZ0OzXf59fIA/YkI/nTMXoZ273w2qMFFFiD06ZjVMuOhBNGFdxt9ItRkcjmONg== X-Received: by 2002:a17:906:688f:b0:7ae:31a0:571c with SMTP id n15-20020a170906688f00b007ae31a0571cmr47862470ejr.57.1673000751279; Fri, 06 Jan 2023 02:25:51 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id e6-20020a170906314600b00781be3e7badsm272826eje.53.2023.01.06.02.25.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:25:50 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 02/15] gdb/testsuite: update gdb.tui/tui-disasm-long-lines.exp Date: Fri, 6 Jan 2023 10:25:29 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Following on from the previous commit, in this commit I am updating the test script gdb.tui/tui-disasm-long-lines.exp to take account of the changes in commit: commit 9162a27c5f5828240b53379d735679e2a69a9f41 Date: Tue Nov 13 11:59:03 2018 -0700 Change gdb test suite's TERM setting In the above commit the TERM environment variable was changed to be 'dumb' by default, which means that tests, that previously activated tui mode, no longer do unless TERM is set to 'ansi'. As the gdb.tui/tui-disasm-long-lines.exp script didn't do this, the test stopped working. As the expect patterns in this script were pretty generic no tests actually started failing, and we never noticed. In this commit I update the script to use Term::clean_restart, which correctly sets TERM to 'ansi'. I've also added a check that the asm box does appear on the screen, which should indicate that tui mode has correctly activated. However, I also notice that GDB doesn't appear to fully work correctly. The test should display the disassembly for the test program, but it doesn't. The test is trying to disassemble some code that (deliberately) uses a very long symbol name, this eventually results in GDB entering tui_source_window_base::show_source_content and trying to allocate an ncurses pad in order to hold the current page of disassembler output. Unfortunately, due to the very long line, the call to newpad fails, meaning that tui_source_window_base::m_pad is nullptr. Luckily non of the following calls appear to crash when passed a nullptr, however, all the output that is written to the pad is lost, which is why we don't see any assembly code written to the screen. As the test history indicates that the script was originally checking for a crash in GDB when the long identifier was encountered, I think there is value in just leaving the test as it is for now, I'll see if I can come up with a solution to the long line problem in a later commit. --- .../gdb.tui/tui-disasm-long-lines.exp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp index 0ad91308ca4..acc4c54063f 100644 --- a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp +++ b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp @@ -16,6 +16,8 @@ # Test that the logic for displaying the TUI disassembly window # handles very long lines. +tuiterm_env + standard_testfile set ccopts {debug quiet} @@ -31,13 +33,16 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "$binfile" \ } } -clean_restart "$binfile" - -if {[skip_tui_tests]} { - # TUI support is disabled. Check for error message. - gdb_test "layout asm" "Undefined command: \"layout\". Try \"help\"." +Term::clean_restart 24 80 $binfile +if {![Term::prepare_for_tui]} { + unsupported "TUI not supported" return } -# Just check the command does not cause gdb to crash. -gdb_test "layout asm" +# Just check the command does not cause gdb to crash. It is worth +# noting that the asm window does infact fail to correctly display the +# disassembler output at this point, but initially we are just +# checking that GDB doesn't crash, fixing the asm display will come +# later. +Term::command_no_prompt_prefix "layout asm" +Term::check_box "asm box" 0 0 80 15 From patchwork Fri Jan 6 10:25:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62782 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 91EF738432E0 for ; Fri, 6 Jan 2023 10:26:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 91EF738432E0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000816; bh=4DL+olIY6p0UVo94aWSNixflUmiSX8kd4yYFU9KQ17M=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Tq7AH2GU+pUrqTgljNC24uCC6oZA4Rsjp5dlLxytxBkN0f7Z9r3iCAOhaIlYFeMcB 9gGBOLQwdPMWTjEEUdhbX+iM6Ca1PLtrpjrAmAjKAhIpk5izL3CpMXIXaDqehPEfNk L8tDLHs6i680xs//9K7LKDL1jkV70cPBDU65Bub8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id AEFF73858CDB for ; Fri, 6 Jan 2023 10:25:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AEFF73858CDB Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-106-5lN1heoNOVe39JidT3sNxg-1; Fri, 06 Jan 2023 05:25:55 -0500 X-MC-Unique: 5lN1heoNOVe39JidT3sNxg-1 Received: by mail-ej1-f69.google.com with SMTP id qk40-20020a1709077fa800b007eeb94ecdb5so871750ejc.12 for ; Fri, 06 Jan 2023 02:25:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4DL+olIY6p0UVo94aWSNixflUmiSX8kd4yYFU9KQ17M=; b=q4wO2sWVW5vEvGcXvvfw9LFa1W44yjCSnPf43DQuSBnx0KQQZU9aJr/FjK6LjrPUQF vnz5ZJa69zQoIf+4lETrHgveMsCR/woWI7Fuqik/jtbx8uLIHiYTEiZy307Hgl0ie3GU 8Xroypjooam39BMyGx6OfOwtfZUuR6XhcvJ0Ym9GgNb1r70b9OTdORjfw4oNOisTggz/ OvVg8DL1ByFpgtnf/pGKRFJrhmWJ//XUF8GbbDvITj6dPf5lTgdb9cQkEDU94ZmVvJnC 1ukOOps7yi6Q1fd1B68J11DIqBoq1UsnlhtpME+uRTNgfIMOUA+157uxcOGCj4tPrR0g /0uQ== X-Gm-Message-State: AFqh2koRR7jh2ZN/5+E+bGKeRVa6k5f540Ujw6skwSS3gx85mJa2K+pq bvQr2W4aNgNoNl2OUA5feIET64jWZ/RpgBLlVbgAuF4Mw/SDf42HXPsF4kA7/ym6tvuGBUYMnQ4 Ay+2Ruu3au73aIKoG/qGbww4YxeVfk/i9jskrgsyuoyE/ABP6YxT79TpMdNvjbR1hlICCg/VKwQ == X-Received: by 2002:a17:907:9d19:b0:7b9:f9d8:9554 with SMTP id kt25-20020a1709079d1900b007b9f9d89554mr43835926ejc.40.1673000753848; Fri, 06 Jan 2023 02:25:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXsWD+OqiEbhK2d2b4s69lP/xEZ61z1NeDXT1sSv4qJnWeTmOeS0ZE7BuIFEw7Pogvr5ugwR/w== X-Received: by 2002:a17:907:9d19:b0:7b9:f9d8:9554 with SMTP id kt25-20020a1709079d1900b007b9f9d89554mr43835915ejc.40.1673000753518; Fri, 06 Jan 2023 02:25:53 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id kv18-20020a17090778d200b0084c643582e0sm276442ejc.14.2023.01.06.02.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:25:53 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 03/15] gdb/testsuite: update gdb.tui/tui-nl-filtered-output.exp Date: Fri, 6 Jan 2023 10:25:30 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Following on from the previous commit, in this commit I am updating the test script gdb.tui/tui-nl-filtered-output.exp to take account of the changes in commit: commit 9162a27c5f5828240b53379d735679e2a69a9f41 Date: Tue Nov 13 11:59:03 2018 -0700 Change gdb test suite's TERM setting In the above commit the TERM environment variable was changed to be 'dumb' by default, which means that tests, that previously activated tui mode, no longer do unless TERM is set to 'ansi'. As the gdb.tui/tui-nl-filtered-output.exp script didn't do this, the test stopped working. As the expect patterns in this script were pretty generic no tests actually started failing, and we never noticed. In this commit I update the test script to correctly activate our terminal emulator, the test continues to pass after this update, but now we are testing in tui mode. --- .../gdb.tui/tui-nl-filtered-output.exp | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/gdb/testsuite/gdb.tui/tui-nl-filtered-output.exp b/gdb/testsuite/gdb.tui/tui-nl-filtered-output.exp index 5a2a4205bb5..b3d80a36a6f 100644 --- a/gdb/testsuite/gdb.tui/tui-nl-filtered-output.exp +++ b/gdb/testsuite/gdb.tui/tui-nl-filtered-output.exp @@ -30,28 +30,19 @@ # # (gdb) -gdb_exit -gdb_start - -if {[skip_tui_tests]} { - return -} - -# Enable the TUI. - -set test "tui enable" -gdb_test_multiple "tui enable" $test { - -re "$gdb_prompt $" { - pass $test - } -} - -# Make sure filtering/pagination is enabled, but make the window high -# enough that we don't paginate in practice. -gdb_test_no_output "set pagination on" -gdb_test_no_output "set height 2000" - -gdb_test \ - {printf "hello\nworld\n"} \ - "hello\r\nworld" \ - "correct line breaks" +tuiterm_env + +# Setup and enter TUI mode. +Term::clean_restart 24 80 +Term::enter_tui + +# Send the command, and check the output is correctly split over +# multiple lines. +Term::command \ + {printf "hello\nworld\n"} +Term::check_region_contents "check printf output" \ + 0 16 80 4 [multi_line \ + "$gdb_prompt printf \"hello\\\\nworld\\\\n\"\\s+" \ + "hello\\s+" \ + "world\\s+" \ + "$gdb_prompt\\s+"] From patchwork Fri Jan 6 10:25:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62781 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5EB16385B51B for ; Fri, 6 Jan 2023 10:26:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5EB16385B51B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000810; bh=3rWgRC5QO2FZeE0yVVJsLJ9yICNaNeoAPISPQEe6a8o=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=V5p6v6yiy24RDfk+5Ig/TfzUerwNgaTC040tAXJIy9lJwZbHaxmXVgQmtAH0nnwWG 3Z7znJfoOWj8fYeunS2xcx2/BEmDyXFhUbUB1j1pb7u5ZhxrGGTl05LEnoohi7dRlB 454MhtKUInse5qBt+XFj4gnOUpcCTopK6p8Tslfw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id F1CC3385840C for ; Fri, 6 Jan 2023 10:25:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F1CC3385840C Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-259-_E8XwacaMnecCnjJZyYUrQ-1; Fri, 06 Jan 2023 05:25:57 -0500 X-MC-Unique: _E8XwacaMnecCnjJZyYUrQ-1 Received: by mail-ej1-f72.google.com with SMTP id hd17-20020a170907969100b007c117851c81so880728ejc.10 for ; Fri, 06 Jan 2023 02:25:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3rWgRC5QO2FZeE0yVVJsLJ9yICNaNeoAPISPQEe6a8o=; b=p46sdhiO6AK+IixXsrvui/ph+ODmesMfo/cGLp6ChbafyjQTk4vUfoRA4GyEvGgs4D nH1bfPicnIolLPktI3kwT/EPNIqO793Wto3VARbR6+cnUEANlE4c/blRzGH2ZQ40bvtU TAE9qcLzFSGX/8f95Wifil4a/qN5o0Y2OFG9dGPV+GAkoBG8A0KqnDXQlvWyrSmWRVb0 0u6URHUQwZ5VZyaKVJlLAVo0i6xMSNdG2Or1O5B041GY7T4fSJuil52UaELaliCj9hjX Kn9rL79FgjS9wrmvG8LNzQdVFq1Ikb1VK3xgi4MIzOF7L5Dq5kCkWaPgq2Xn7cQgbSgr DFcw== X-Gm-Message-State: AFqh2kojez32subC4url5BBAAKk8x/jW87jEy1jN0c2BxlbvhJQCV9m5 mn0418ziuEU37wCllEY6PObjQVjbzoEAjEDeuxhpTiEPTCERA4nnZXKNorNw5E6BJR6XpypQNmk Fk8dZSf5Hq9hQk5cQ/q3416Jr0pOLal1bdXetFamuFWoNacFsr4ZRsqlx4OX0hbqZZvW1ltS5dA == X-Received: by 2002:a17:907:d387:b0:7c1:6fd3:1ef3 with SMTP id vh7-20020a170907d38700b007c16fd31ef3mr46607434ejc.33.1673000756419; Fri, 06 Jan 2023 02:25:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXs6b5IGIap8G3MgFelpgbsxwiZoydGpHAs0UagAyV10KpHARPM8xNF3MkYgqhrcJZpkCgFPMQ== X-Received: by 2002:a17:907:d387:b0:7c1:6fd3:1ef3 with SMTP id vh7-20020a170907d38700b007c16fd31ef3mr46607415ejc.33.1673000756020; Fri, 06 Jan 2023 02:25:56 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id 17-20020a170906329100b007c0bb571da5sm269336ejw.41.2023.01.06.02.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:25:55 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 04/15] gdb/testsuite/tui: more testing of the 'focus' command Date: Fri, 6 Jan 2023 10:25:31 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I noticed that we didn't have much testing of the tui 'focus' command, so I started adding some. This exposed a bug in GDB, we are able to focus windows that should not be focusable, e.g. the 'status' window. This is harmless until we then do 'focus next' or 'focus prev', along this code path we assert that the currently focused window is focusable, which obviously, is no longer true, so GDB fails with an assertion error. The fix is simple; add some code to the tui_set_focus_command function that checks if the selected window is focusable. If it is not then an error is thrown. --- gdb/testsuite/gdb.tui/tui-focus.c | 22 ++++++++++ gdb/testsuite/gdb.tui/tui-focus.exp | 66 +++++++++++++++++++++++++++++ gdb/tui/tui-win.c | 3 ++ 3 files changed, 91 insertions(+) create mode 100644 gdb/testsuite/gdb.tui/tui-focus.c create mode 100644 gdb/testsuite/gdb.tui/tui-focus.exp diff --git a/gdb/testsuite/gdb.tui/tui-focus.c b/gdb/testsuite/gdb.tui/tui-focus.c new file mode 100644 index 00000000000..3a264f239ed --- /dev/null +++ b/gdb/testsuite/gdb.tui/tui-focus.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + 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 . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.tui/tui-focus.exp b/gdb/testsuite/gdb.tui/tui-focus.exp new file mode 100644 index 00000000000..156ced44e05 --- /dev/null +++ b/gdb/testsuite/gdb.tui/tui-focus.exp @@ -0,0 +1,66 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# 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 . + +# Minimal testcase that just checks that the various "layout $foo" +# commands do not cause gdb to crash. + +tuiterm_env + +standard_testfile + +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { + return -1 +} + +if {[skip_tui_tests]} { + return +} + +# Run a series of tests based on various test specifications. +# +# Each test specification is a tuple where the first item is the name of a +# window, and the second item is a boolean indicating if we expect that +# window to be present in the default (src) layout. +##foreach spec {{src true} {cmd true} {status true} {regs false} {asm false}} {} +foreach spec {{status false}} { + lassign $spec window valid_p + with_test_prefix "window=$window" { + + Term::clean_restart 24 80 $binfile + if {![Term::prepare_for_tui]} { + unsupported "TUI not supported" + return + } + + Term::command_no_prompt_prefix "focus $window" + + if {$valid_p} { + Term::check_region_contents "check focus message" 0 16 80 1 \ + "^Focus set to $window window\\.\\s*" + } else { + if {$window == "status"} { + Term::check_region_contents "check focus error" 0 16 80 1 \ + "^Window \"$window\" cannot be focused\\s*" + } else { + Term::check_region_contents "check focus error" 0 16 80 1 \ + "^Unrecognized window name \"$window\"\\s*" + } + } + + Term::check_box "check src box" 0 0 80 15 + + Term::command "focus prev" + } +} diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 58372005ff8..9c088899817 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -723,6 +723,9 @@ tui_set_focus_command (const char *arg, int from_tty) if (!win_info->is_visible ()) error (_("Window \"%s\" is not visible"), arg); + if (!win_info->can_focus ()) + error (_("Window \"%s\" cannot be focused"), arg); + tui_set_win_focus_to (win_info); gdb_printf (_("Focus set to %s window.\n"), tui_win_with_focus ()->name ()); From patchwork Fri Jan 6 10:25:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62785 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB279384F031 for ; Fri, 6 Jan 2023 10:27:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB279384F031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000848; bh=Q7jzm48HHwjSwjGD1mvU2ypNvJbQTjN70k6LFd1pjeU=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ZtLB2+uged5ixW3X/uoAad/zhIhapXM870H5P9u5b/I9gmA8W96ejZQwfWlJG8Edn u++r2epohpnY8vCyGZYFj/RYKvfFoC8Aoienn8dct6CDbXRpV4byBYjvIALNy/x59V gwJQhzCOUyJhZ95Acmo+CH/NSM3fGoI/bVlDL+lA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0F7C93858D33 for ; Fri, 6 Jan 2023 10:26:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F7C93858D33 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-210-EubwYOkzNPirk4sB5A0igw-1; Fri, 06 Jan 2023 05:26:00 -0500 X-MC-Unique: EubwYOkzNPirk4sB5A0igw-1 Received: by mail-ed1-f72.google.com with SMTP id z20-20020a05640240d400b0047028edd264so954438edb.20 for ; Fri, 06 Jan 2023 02:26:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q7jzm48HHwjSwjGD1mvU2ypNvJbQTjN70k6LFd1pjeU=; b=CzxNYVU3DPpBRIkQUtLPsPO73DveptSKFmgl0/Vbl03haFwfvJtLbzWf3kxxdUTbo1 bePgWkQafCgvn51RMxrq7sH2YUA1YAAey8XiVs/dBOlvTxW/bnNhHKkbxJtYnwEaAF2t ygDnlIg7twKb/7SjHE0zJrkyhQ7y5vSZcGD0fsD5l7fGqWTVo+kNKUYrwuPs7+U2+8qj jkmVceqKB7E30fwJ18D1g9/4Mynr6AH1X0AwvJcFjH60EbN7kLpXVUAJCREyeeHnMa7J VVdjRIlmLnTSWV2Fyh/pW01uw8TJ3W1stBV8mgpGlNzNQvaKUnGu8vGv6Iz32yYNk30C 7E8A== X-Gm-Message-State: AFqh2kr0miETuItGmPtllYD8HmDhJeUpUrZrW9fbj9yQkDNMLAiHCpKr KzpxVQ1bRzfP6U57ZPNOckr+clSf5TNfAnd21VsIxB8sVgyioH2mBv3XQ+k5094zidWEBKDfyBQ KSKFH7V+esId9oD4rBDKftJh+Z7YZYMmRBl4hOX93wEgOky6+/4dxwuQAk5/2RAM8hWHHEzYt2A == X-Received: by 2002:a17:907:8748:b0:7c1:ad6:7331 with SMTP id qo8-20020a170907874800b007c10ad67331mr52534234ejc.27.1673000759417; Fri, 06 Jan 2023 02:25:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXtvbnZ6swcwPEMQ3GbjuarSp0/TpeBxQpiPxpgKJNhF7KwCloa+GjDLPIKWXc7vdZ5uuQqBHg== X-Received: by 2002:a17:907:8748:b0:7c1:ad6:7331 with SMTP id qo8-20020a170907874800b007c10ad67331mr52534222ejc.27.1673000759200; Fri, 06 Jan 2023 02:25:59 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id ew3-20020a170907950300b0084cc121f49esm268233ejc.83.2023.01.06.02.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:25:58 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 05/15] gdb/tui: convert if/error to an assert Date: Fri, 6 Jan 2023 10:25:32 +0000 Message-Id: <41ae74a51377abd813ad2bdb29cedfbfbdc54e3c.1673000632.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" While working on the previous commit, I realised that there was an error in tui_set_focus_command that could never be triggered. Since the big tui rewrite (adding dynamic layouts) it is no longer true that there is a tui_win_info object for every window at all times. We now only create a tui_win_info object for a particular window, when the window is part of the current layout. As a result, if we have a tui_win_info pointer, then the window must be visible inside tui_set_focus_command (this function calls tui_enable as its first action, which makes the current layout visible). The gdb.tui/tui-focus.exp test script exercises this area of code, and doesn't trigger the assert, nor do any of our other existing tui tests. --- gdb/tui/tui-win.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 9c088899817..4fc8e7a4503 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -720,8 +720,11 @@ tui_set_focus_command (const char *arg, int from_tty) if (win_info == NULL) error (_("Unrecognized window name \"%s\""), arg); - if (!win_info->is_visible ()) - error (_("Window \"%s\" is not visible"), arg); + + /* If a window is part of the current layout then it will have a + tui_win_info associated with it and be visible, otherwise, there will + be no tui_win_info and the above error will have been raised. */ + gdb_assert (win_info->is_visible ()); if (!win_info->can_focus ()) error (_("Window \"%s\" cannot be focused"), arg); From patchwork Fri Jan 6 10:25:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62783 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA0A2385B508 for ; Fri, 6 Jan 2023 10:27:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DA0A2385B508 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000822; bh=QewMKpnl7bqL9aHbw2HAXfmxbcqIXXFAcaa4h0JOz68=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Y99b32baAJYlLlhbiG6eCHoqqRt1aTlMx/d+wNXRralvFgBswMrLCe9++0Hwnolnn NmxjrROdSOvK2M3IfQx+lNw5WBSmCkgU1yqglddB9YEF69R9PDgv4Ans60YZVASTMU A00L/W0RUpSfD/2U8i51EJnjCo4ovNwoG/h2Nvb0= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D5F493858296 for ; Fri, 6 Jan 2023 10:26:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D5F493858296 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-632-T6QBYnwFPCaPDqdAvnjyaw-1; Fri, 06 Jan 2023 05:26:03 -0500 X-MC-Unique: T6QBYnwFPCaPDqdAvnjyaw-1 Received: by mail-ed1-f72.google.com with SMTP id x13-20020a05640226cd00b0047ac11c9774so949555edd.17 for ; Fri, 06 Jan 2023 02:26:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QewMKpnl7bqL9aHbw2HAXfmxbcqIXXFAcaa4h0JOz68=; b=BK3jZlFfHPWm8g56m9rOWEtdi7Ma6KWhj3qG/RWyG4W93jdVHXK9WLArBUrrpQ//j8 UfpB2/nLMN/Rra8GPPbNU19EmY3CYxv0akfRMqNeGp9amZXwvpixdFjuHZ+H7rCvqvu3 GhT5cd9tNJuhxqkJaEyWCw5aH3biF+i57hKWH2qCdGiqGNsM43/SphopbQOdkqPMzvt8 gcZJ/8kd0ynhaPnc00s1JEUcEsQx8cf05i23PzRLQHw8eEOGlh0x8A7pbPLmQ3rhQ1EL Q7fL7iK+yJqBcVkvD92myimVT9XHH/hUa73a0rbxDafbzG6vc+hos01RNj8OVD+Fg015 o2/g== X-Gm-Message-State: AFqh2kocarKTIX4rG1d+q/QodhgJDwhO6jdaEH9xWTIDwmvX+7KEyJMy toB0cxZFx3RZNoU4ACcls1Zx1cV2FDcZkfi5reUzwPOsebFjzZzUZqfSDnH168fswix/oB6q4wf 2RtwmASgtU4jh+sYqU6g1W+1WIf4RKbIIy5n9CVOLayRc/X9yStA2uSUd1mNtS7NSAK3ESNhqOw == X-Received: by 2002:a17:907:2be8:b0:7e6:bae:fa0f with SMTP id gv40-20020a1709072be800b007e60baefa0fmr50652713ejc.58.1673000762092; Fri, 06 Jan 2023 02:26:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXt89a/urUjiAWywXcrJ1lqV+NOUsPPPHqiLeCYz8mPcSlOCTvUZ1HbPUYaSuDt78CioRQaGIg== X-Received: by 2002:a17:907:2be8:b0:7e6:bae:fa0f with SMTP id gv40-20020a1709072be800b007e60baefa0fmr50652692ejc.58.1673000761751; Fri, 06 Jan 2023 02:26:01 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id e21-20020aa7d7d5000000b0048ca2b6c370sm357624eds.29.2023.01.06.02.26.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:26:01 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 06/15] gdb/tui: better filtering of tab completion results for focus command Date: Fri, 6 Jan 2023 10:25:33 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" While working on the previous couple of commits, I noticed that the 'focus' command would happily suggest 'status' as a possible focus completion, even though the 'status' window is non-focusable, and, after the previous couple of commits, trying to focus the status window will result in an error. This commit improves the tab-completion results for the focus command so that the status window is not included. --- gdb/testsuite/gdb.tui/completion.exp | 18 ++++++++++++++++-- gdb/testsuite/gdb.tui/tui-focus.exp | 4 +--- gdb/tui/tui-win.c | 24 +++++++++++++++++------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/gdb/testsuite/gdb.tui/completion.exp b/gdb/testsuite/gdb.tui/completion.exp index 00956488c9f..1d7de65abb7 100644 --- a/gdb/testsuite/gdb.tui/completion.exp +++ b/gdb/testsuite/gdb.tui/completion.exp @@ -13,8 +13,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -gdb_exit -gdb_start +tuiterm_env + +clean_restart if {[skip_tui_tests] || [target_info exists gdb,nointerrupts]} { return @@ -54,3 +55,16 @@ with_test_prefix "completion of layout names" { with_test_prefix "completion of focus command" { test_tab_completion "focus" "cmd *next *prev *src *" } + +# Now run some completion tests when TUI mode is enabled. +Term::clean_restart 24 80 +if {![Term::prepare_for_tui]} { + unsupported "TUI not supported" + return +} + +Term::command "layout src" +Term::command "complete focus " +Term::dump_screen +Term::check_region_contents "check focus completions" 0 17 80 5 \ + "focus cmd\\s*focus next\\s*focus prev\\s*focus src\\s*$gdb_prompt" diff --git a/gdb/testsuite/gdb.tui/tui-focus.exp b/gdb/testsuite/gdb.tui/tui-focus.exp index 156ced44e05..0563aacd0a2 100644 --- a/gdb/testsuite/gdb.tui/tui-focus.exp +++ b/gdb/testsuite/gdb.tui/tui-focus.exp @@ -33,8 +33,7 @@ if {[skip_tui_tests]} { # Each test specification is a tuple where the first item is the name of a # window, and the second item is a boolean indicating if we expect that # window to be present in the default (src) layout. -##foreach spec {{src true} {cmd true} {status true} {regs false} {asm false}} {} -foreach spec {{status false}} { +foreach spec {{src true} {cmd true} {status false} {regs false} {asm false}} { lassign $spec window valid_p with_test_prefix "window=$window" { @@ -60,7 +59,6 @@ foreach spec {{status false}} { } Term::check_box "check src box" 0 0 80 15 - Term::command "focus prev" } } diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 4fc8e7a4503..492a5191025 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -362,13 +362,19 @@ show_tui_resize_message (struct ui_file *file, int from_tty, /* Generic window name completion function. Complete window name pointed - to by TEXT and WORD. If INCLUDE_NEXT_PREV_P is true then the special - window names 'next' and 'prev' will also be considered as possible - completions of the window name. */ + to by TEXT and WORD. + + If EXCLUDE_CANNOT_FOCUS_P is true, then windows that can't take focus + will be excluded from the completions, otherwise they will be included. + + If INCLUDE_NEXT_PREV_P is true then the special window names 'next' and + 'prev' will also be considered as possible completions of the window + name. This is independent of EXCLUDE_CANNOT_FOCUS_P. */ static void window_name_completer (completion_tracker &tracker, - int include_next_prev_p, + bool include_next_prev_p, + bool exclude_cannot_focus_p, const char *text, const char *word) { std::vector completion_name_vec; @@ -377,10 +383,14 @@ window_name_completer (completion_tracker &tracker, { const char *completion_name = NULL; - /* We can't focus on an invisible window. */ + /* Don't include an invisible window. */ if (!win_info->is_visible ()) continue; + /* If requested, exclude windows that can't be focused. */ + if (exclude_cannot_focus_p && !win_info->can_focus ()) + continue; + completion_name = win_info->name (); gdb_assert (completion_name != NULL); completion_name_vec.push_back (completion_name); @@ -415,7 +425,7 @@ focus_completer (struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word) { - window_name_completer (tracker, 1, text, word); + window_name_completer (tracker, true, true, text, word); } /* Complete possible window names for winheight command. TEXT is the @@ -432,7 +442,7 @@ winheight_completer (struct cmd_list_element *ignore, if (word != text) return; - window_name_completer (tracker, 0, text, word); + window_name_completer (tracker, false, false, text, word); } /* Update gdb's knowledge of the terminal size. */ From patchwork Fri Jan 6 10:25:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62784 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3023E3881D04 for ; Fri, 6 Jan 2023 10:27:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3023E3881D04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000827; bh=kJkCx9qSpyEOJgSbk0rCT0glpH//WHOO7dBUJ+QfHaY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=JCvz9RNasRdS5Y0q8GShPkfK+hmmq1v2KwtXjHwm5U64oldlQvTRMa+NVoKczOaKG /HevxfQNLxWAm1b2YZWPNdEtqrEjeSbu7Q/V+fzFAE+itZ9ewNHmPMMz3ENn2Fnq1U jKheubqNe8lVG/K8wR7vQMDsMeYnBmroL6nFobHU= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 13D52385B509 for ; Fri, 6 Jan 2023 10:26:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13D52385B509 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-16-sqCNwDvZPoaYyP-RKw4uZA-1; Fri, 06 Jan 2023 05:26:06 -0500 X-MC-Unique: sqCNwDvZPoaYyP-RKw4uZA-1 Received: by mail-ed1-f69.google.com with SMTP id c12-20020a05640227cc00b004853521ef55so954909ede.8 for ; Fri, 06 Jan 2023 02:26:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kJkCx9qSpyEOJgSbk0rCT0glpH//WHOO7dBUJ+QfHaY=; b=LEsk/mE7aGfN3nbcI/chrFej0rx3LR+yLWd8mqb2e5z2bi8skObH8fSoFqnKhhTJ9V N5DmcCXZy7+hXuC/QBC/TBX8LAtKkP+IioEGNWCz+Gwqa45mWdy5pmCU5V17khLg12kb y1d2XNUHnFuxeJB6LYqr3JbWzpsT1JshSGlpgwyMIW5SbVRcTM4M4swpNtolwVqMl2AQ 5rNnxmT5hgOfQouF14mUPhBiJJ2945Vu2qzjWLGEx+yrHLQBslLsgdZNf4ytLgutYIqp e+4MOKXHZ9Wrs3G7lSj/VlA4FRfPU/zkB96Ciw3fvmr3M3ls8jjf4oDTewGfFEEDfxIL JNtw== X-Gm-Message-State: AFqh2koAvvexxjgLi2smkvoLUQ4SYYMShkYkPXxg/ZJIxxcf35WujBVg FI+8RYdy8mmmDtY9Y2N2GH1cAT6capHmF7yxB1gjf3hCogUTtQSePKz+Rf58jfE79GNLoW0Frzp UzsPQe7D6DnkASnj5ensVzxaUYWAneLQ193gzdfgzBcSeecnLz3e2CBmwAtH3ANU6byA6PaQslg == X-Received: by 2002:a05:6402:2202:b0:48e:bb08:c96 with SMTP id cq2-20020a056402220200b0048ebb080c96mr11848491edb.28.1673000764678; Fri, 06 Jan 2023 02:26:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXuOABRHuqDPbOMkQKAeX5OQVcAe6qZTpxtxRgXf0isabveMELFEd0sheMUB7Omg6yIfkZeqng== X-Received: by 2002:a05:6402:2202:b0:48e:bb08:c96 with SMTP id cq2-20020a056402220200b0048ebb080c96mr11848480edb.28.1673000764487; Fri, 06 Jan 2023 02:26:04 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id f6-20020a056402150600b0049622a61f8fsm366381edw.30.2023.01.06.02.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:26:04 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 07/15] gdb/testsuite: fix line feed scrolling in tuiterm.exp Date: Fri, 6 Jan 2023 10:25:34 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" In a following commit I managed to trigger the line feed scrolling case in tuiterm.exp. This case is currently unhandled, and this commit fills in this missing functionality. The implementation is pretty simple, just scroll all the content up one line at a time until the cursor is back on the screen (a single line of scroll is all that should be needed). This change is untested in this commit, but is required by the next commit. --- gdb/testsuite/lib/tuiterm.exp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index 591c4ca9c4c..22fc9ab2369 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -99,10 +99,24 @@ namespace eval Term { _log_cur "Line feed" { variable _cur_row variable _rows + variable _cols + variable _chars incr _cur_row 1 - if {$_cur_row >= $_rows} { - error "FIXME scroll" + while {$_cur_row >= $_rows} { + # Scroll the display contents. We scroll one line at + # a time here; as _cur_row was only increased by one, + # a single line scroll should be enough to put the + # cursor back on the screen. But we wrap the + # scrolling inside a while loop just to be on the safe + # side. + for {set y 0} {$y < [expr $_rows - 1]} {incr y} { + set next_y [expr $y + 1] + for {set x 0} {$x < $_cols} {incr x} { + set _chars($x,$y) $_chars($x,$next_y) + } + incr _cur_row -1 + } } } } From patchwork Fri Jan 6 10:25:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62788 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2F2C3385843A for ; Fri, 6 Jan 2023 10:27:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F2C3385843A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000878; bh=DJ7DTbm2xnqDrGzBOP7Nw1t2brxhR6yvk8XNYwIYEfk=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=C9/fg83RxV1GkXKiU+XyKpYKMsQ3khti+sxhop75Xy6Yl8QSanmDkuu3b2/0DFSCR 1e/NoYNswQ+Efc+dx30syKy3xK1jqXiCqfFfLI93oPcHTvnBhkp0V+lpIrqijkceUf BtPzxYngqYf57m6tjO/35KbotZ4vx1jfqdlcDCfs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4D855385700E for ; Fri, 6 Jan 2023 10:26:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D855385700E Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-130-t4aYhPmPNPWcFVccCt7P0A-1; Fri, 06 Jan 2023 05:26:09 -0500 X-MC-Unique: t4aYhPmPNPWcFVccCt7P0A-1 Received: by mail-ej1-f71.google.com with SMTP id qb2-20020a1709077e8200b00842b790008fso872156ejc.21 for ; Fri, 06 Jan 2023 02:26:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DJ7DTbm2xnqDrGzBOP7Nw1t2brxhR6yvk8XNYwIYEfk=; b=pyiCNOJd/6F8h6LcrifjTZ9tNnO/WFl9Q8qotMlAhAh4n0Y2WqV1gCmpWFWLzLbR7m zgZJxzc2ZqQALXv0pslnsGbrhhR7qp3U/d/s/IlHLSwaJ/7MLdaLeUp+vln/q6Tpcb7K iLv4F1ZhCwQ4B0OMjElquHiBb0RJqZXtcjEvI3rx/d2U9OilQ/rXe2TPt9QA/L01GAmz ySuzz9akyWSq3l7fNI1+s0iSeGq6HhA2F3pQ/qFTi+1SAT6v44FxbSaGTz1MQE1+RlrF gXDccFob+mbOWMhaF4EaqQ1XdawrLoTLaBU0z0hzgTQhf1o6/2x/5sVPXC1tnpkhPbFA V+vQ== X-Gm-Message-State: AFqh2krbJ3bIuZURAzZaNAms0uRj3TopZuvl0pBtlR8xP5EieRHDFNUh vJk99n+7qtlXjvt2sgqU/LhlN/apRHVlix05YjI8N/1asX6Ulb/jDUu5iwmjLzXGbWRThr6ZYyJ b3uCt7XKs5sZsSz/hqy0q/8xp98UuC8zQ5UyPmXh63fqcl7FZK268MwTaeAhSYvbwnZ6oEgUb6A == X-Received: by 2002:a17:906:ad93:b0:7c1:100d:331a with SMTP id la19-20020a170906ad9300b007c1100d331amr48045997ejb.70.1673000768195; Fri, 06 Jan 2023 02:26:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXuQ+IFHt6DkDxICS8p7yjrpuVGxtyOMy7hRjoYWtBCpRFbY/Cil/JzDH394MacLWHxH+xhbtw== X-Received: by 2002:a17:906:ad93:b0:7c1:100d:331a with SMTP id la19-20020a170906ad9300b007c1100d331amr48045974ejb.70.1673000767752; Fri, 06 Jan 2023 02:26:07 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id k19-20020a17090646d300b007c10fe64c5dsm265047ejs.86.2023.01.06.02.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:26:07 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 08/15] gdb/tui: improve errors from tui focus command Date: Fri, 6 Jan 2023 10:25:35 +0000 Message-Id: <8dcaa9d935cbfb4136cf5cab804f622b6f6a4c5b.1673000632.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit improves (I think) the errors from the tui focus command. There are a number of errors that can be triggered by the focus command, they include: (1) Window name "NAME" is ambiguous (2) Unrecognized window name "NAME" (3) Window "NAME" cannot be focused Error (1) is triggered when the user gives a partial window name, and the name matches multiple windows in the current layout. It is worth noting that the ambiguity must be within the current layout, if the partial name matches one window in the current layout, and one window not currently displayed, then this is not ambiguous, and focus will shift to the selected window in the current layout. This error was not previous being tested, but in this commit I make use of the Python API to trigger this error. Error (3) is simple enough, and was already being tested. This is triggered by something like 'focus status'. The named window needs to be present in the current layout, and non-focusable in order to trigger the error. Error (2) is what I'd like to improve in this commit. This error triggers if the name the user gives doesn't match any window in the current layout. Even if GDB does know about the window, but the window isn't in the current layout, then GDB will say it doesn't recognize the window name. In this commit I propose to change this. I plan to split this error into three different errors. These will be: (a) Unrecognized window name "NAME" (b) No windows matching "NAME" in the current layout (c) Window "NAME" is not in the current layout Error (a) is the same as before, but will now only trigger if GDB doesn't know about window NAME at all. If the window is known, but not in the current layout then one of the other errors will trigger. Error (b) will trigger if NAME is ambiguous for multiple windows that are not in the current layout. If NAME identifies a single window in the current layout then that window will continue to be selected, just as it currently is. Only in the case where NAME doesn't identify a window in the current layout do we then check all the other known windows, if NAME matches multiple of these, then (b) is triggered. Finally, error (c) is used when NAME uniquely identifies a single window that is not in the current layout. The hope with these new errors is that the user will have a better understanding of what went wrong. Instead of GDB claiming to not know about a window, the mention of the current layout will hint to the user that they should first switch layouts. There are tests included for all the new errors. --- gdb/testsuite/gdb.tui/tui-focus.exp | 81 +++++++++++++++++++++++++++-- gdb/tui/tui-layout.c | 11 +++- gdb/tui/tui-layout.h | 45 ++++++++++++++++ gdb/tui/tui-win.c | 40 +++++++++++++- 4 files changed, 170 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/gdb.tui/tui-focus.exp b/gdb/testsuite/gdb.tui/tui-focus.exp index 0563aacd0a2..4ad2e5327c7 100644 --- a/gdb/testsuite/gdb.tui/tui-focus.exp +++ b/gdb/testsuite/gdb.tui/tui-focus.exp @@ -13,10 +13,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Minimal testcase that just checks that the various "layout $foo" -# commands do not cause gdb to crash. +# Testcase that just checks the tui 'focus' command works as expected. tuiterm_env +load_lib gdb-python.exp standard_testfile @@ -33,7 +33,8 @@ if {[skip_tui_tests]} { # Each test specification is a tuple where the first item is the name of a # window, and the second item is a boolean indicating if we expect that # window to be present in the default (src) layout. -foreach spec {{src true} {cmd true} {status false} {regs false} {asm false}} { +foreach spec {{src true} {cmd true} {status false} {regs false} \ + {asm false} {unknown false}} { lassign $spec window valid_p with_test_prefix "window=$window" { @@ -52,9 +53,12 @@ foreach spec {{src true} {cmd true} {status false} {regs false} {asm false}} { if {$window == "status"} { Term::check_region_contents "check focus error" 0 16 80 1 \ "^Window \"$window\" cannot be focused\\s*" - } else { + } elseif {$window == "unknown"} { Term::check_region_contents "check focus error" 0 16 80 1 \ "^Unrecognized window name \"$window\"\\s*" + } else { + Term::check_region_contents "check focus error" 0 16 80 1 \ + "^Window \"$window\" is not in the current layout\\s*" } } @@ -62,3 +66,72 @@ foreach spec {{src true} {cmd true} {status false} {regs false} {asm false}} { Term::command "focus prev" } } + +# Use the Python TUI API to exercise some of the ambigous window name +# handling parts of the 'focus' command. +Term::clean_restart 24 80 $binfile +if {![skip_python_tests]} { + # Create a very simple tui window. + gdb_py_test_silent_cmd \ + [multi_line_input \ + "python" \ + "class TestWindow:" \ + " def __init__(self, win):" \ + " pass" \ + "" \ + " def render(self):" \ + " pass" \ + "end"] \ + "setup dummy window class" \ + true + + # Register the window with a set of similar names. + gdb_test_no_output "python gdb.register_window_type(\"test1\", TestWindow)" + gdb_test_no_output "python gdb.register_window_type(\"test2\", TestWindow)" + gdb_test_no_output "python gdb.register_window_type(\"test3\", TestWindow)" + + # Create a layout containing just one of the above windows. + gdb_test_no_output "tui new-layout example1 test2 1 status 1 cmd 1" + + # Create a layout containing two of the above windows. + gdb_test_no_output "tui new-layout example2 test1 1 test2 1 status 1 cmd 1" + + if {![Term::prepare_for_tui]} { + unsupported "TUI not supported" + return + } + + # Try to focus using an ambiguous, partial window name. This + # should fail as the default layout (src) doesn't include any + # windows matching this name. + Term::command_no_prompt_prefix "focus test" + Term::check_region_contents "check no matching window focus message" \ + 0 16 80 1 \ + "^No windows matching \"test\" in the current layout\\s*" + + # Now select a layout that includes a single window that matches + # the ambiguous, partial name 'test', and disable tui mode. + Term::command "layout example1" + send_gdb "tui disable\n" + + # Reactivate tui mode and try to set focus using the ambiguous, + # partial window name. This should succeed though, as, within the + # current layout, the partial name is not actually ambiguous. + send_gdb "focus test\n" + gdb_assert [Term::wait_for_region_contents 0 19 80 1 \ + "^Focus set to test2 window\\.\\s*"] \ + "check test2 focus message" + + # Now select a layout that includes two windows that matches the + # ambiguous, partial name 'test', and disable tui mode. + Term::command "layout example2" + send_gdb "tui disable\n" + + # Reactivate tui mode and try to set focus using the ambiguous, + # partial window name. This will fail as now the layout includes + # multiple windows that match 'test'. + send_gdb "focus test\n" + gdb_assert [Term::wait_for_region_contents 0 22 80 1 \ + "^Window name \"test\" is ambiguous\\s*"] \ + "check ambiguous focus message" +} diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 27abee02087..447a20cb614 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -29,7 +29,6 @@ #include "cli/cli-decode.h" #include "cli/cli-utils.h" #include -#include #include #include "tui/tui.h" @@ -353,6 +352,16 @@ make_standard_window (const char *) static std::unordered_map *known_window_types; +/* See tui-layout.h. */ + +all_known_window_names_range +all_known_window_names () +{ + auto begin = all_known_window_names_iterator (known_window_types->begin ()); + auto end = all_known_window_names_iterator (known_window_types->end ()); + return all_known_window_names_range (begin, end); +} + /* Helper function that returns a TUI window, given its name. */ static tui_win_info * diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h index 206f1117445..9ce3ef39507 100644 --- a/gdb/tui/tui-layout.h +++ b/gdb/tui/tui-layout.h @@ -26,6 +26,9 @@ #include "tui/tui.h" #include "tui/tui-data.h" +#include "gdbsupport/iterator-range.h" + +#include /* Values that can be returned when handling a request to adjust a window's size. */ @@ -364,4 +367,46 @@ typedef std::function window_factory; extern void tui_register_window (const char *name, window_factory &&factory); +/* An iterator class for known tui window names. This is just a wrapper + around an iterator of the underlying data structure that holds the + known tui windows. This iterator only reveals the window names. */ + +struct all_known_window_names_iterator +{ + using known_window_types_iterator + = std::unordered_map::iterator; + + all_known_window_names_iterator (known_window_types_iterator &&iter) + : m_iter (std::move (iter)) + { /* Nothing. */ } + + all_known_window_names_iterator &operator++ () + { + ++m_iter; + return *this; + } + + const std::string &operator* () const + { return (*m_iter).first; } + + bool operator!= (const all_known_window_names_iterator &other) const + { return m_iter != other.m_iter; } + +private: + + /* The underlying iterator. */ + known_window_types_iterator m_iter; +}; + +/* A range adapter that makes it possible to iterate over the names of all + known tui windows. */ + +using all_known_window_names_range + = iterator_range; + +/* Return a range that can be used to walk over the name of all known tui + windows in a range-for loop. */ + +extern all_known_window_names_range all_known_window_names (); + #endif /* TUI_TUI_LAYOUT_H */ diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 492a5191025..008189eb99b 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -728,8 +728,44 @@ tui_set_focus_command (const char *arg, int from_tty) else win_info = tui_partial_win_by_name (arg); - if (win_info == NULL) - error (_("Unrecognized window name \"%s\""), arg); + if (win_info == nullptr) + { + /* When WIN_INFO is nullptr this can either mean that the window name + is unknown to GDB, or that the window is not in the current + layout. To try and help the user, give a different error + depending on which of these is the case. */ + std::string matching_window_name; + bool is_ambiguous = false; + + for (const std::string &name : all_known_window_names ()) + { + /* Look through all windows in the current layout, if the window + is in the current layout then we're not interested is it. */ + for (tui_win_info *item : all_tui_windows ()) + if (item->name () == name) + continue; + + if (startswith (name, arg)) + { + if (matching_window_name.empty ()) + matching_window_name = name; + else + is_ambiguous = true; + } + }; + + if (!matching_window_name.empty ()) + { + if (is_ambiguous) + error (_("No windows matching \"%s\" in the current layout"), + arg); + else + error (_("Window \"%s\" is not in the current layout"), + matching_window_name.c_str ()); + } + else + error (_("Unrecognized window name \"%s\""), arg); + } /* If a window is part of the current layout then it will have a tui_win_info associated with it and be visible, otherwise, there will From patchwork Fri Jan 6 10:25:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62786 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 44FDD38493C8 for ; Fri, 6 Jan 2023 10:27:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 44FDD38493C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000852; bh=UPAOAdFHm+AXrmVqmMPZUmUvSH3YbNaw976fSd1EBnA=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=O1h296SSMFFla1DwinhK0oeFwsJWCxUY0vaPF2zK4+TFarT/cgIAJ9JNquMp0DH5o PBXcG2q4k0CvEKcHmV89vUbjWKISzJuAyvcFJSrntVLqlxxyEF/i7ogx2cETVJeeGU 2+9cDL4w+nXSRCBSAA/D3gjkC+T2v5IJVP+jhtpk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BB4E538582B7 for ; Fri, 6 Jan 2023 10:26:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BB4E538582B7 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-621-nYPW5uItO7-CmZdm_d9ixA-1; Fri, 06 Jan 2023 05:26:11 -0500 X-MC-Unique: nYPW5uItO7-CmZdm_d9ixA-1 Received: by mail-ed1-f71.google.com with SMTP id m3-20020a056402430300b0047b94307bbeso961344edc.3 for ; Fri, 06 Jan 2023 02:26:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UPAOAdFHm+AXrmVqmMPZUmUvSH3YbNaw976fSd1EBnA=; b=XdS3EOMW8zrgbJPNTllg+vGSmMfk0mCLkb0vEFQVV+ECd+yZ1SfU7gY2VgkqK8M5nO e1RWlMrJqrI11DMrMfmStPELLpVxeCB0v31JOFSkOCKYo75yvXmjfrkWH1APXWqhIOqH 5gbhfrzO+gc4Cj7elpw2rXGsn8dWdv373oi14rOH/2bNXgOySBw9skNZzi5vfChi/AWX diHCe97fsQVWP+dlPNA79lq4a7Sue8SD1A3WVPZtPQDmkOHOxYLxE+Ft/Oqx02qEmBmb pjT/rZhWF3rzH45n3141z6wp4QMmU2DTB8N4aiC8F7A6BVgWTSGrhF8D+7lf0cRHC8de JX9w== X-Gm-Message-State: AFqh2kpTVChEXbzm61AqNa+HDHfmKVgPJ1btuCRL6G6fF3yXtEpjNo6k HfKjP/pbBaPfJkDu8sN9Qmu6m90U8N62FYR9iRxC5JYkAOnh6Y2cwjuGJinboEESl/QnhgDFCpp CdeJ3EW8jjyfhOGn1HxgihuKvrcgaXGKsa9D+OfV22rtPCfx8Hk/5lTfjcV1lAkS0IQS95H2ZIw == X-Received: by 2002:a17:906:8d03:b0:83f:743e:86d with SMTP id rv3-20020a1709068d0300b0083f743e086dmr6238328ejc.14.1673000770598; Fri, 06 Jan 2023 02:26:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXsKBEc4b+5xv7+oHWn764WlnXtPe2hxhckdvUfLTI2PFXwHLk5Pf5BuWvzPIyG2XC269GnLgw== X-Received: by 2002:a17:906:8d03:b0:83f:743e:86d with SMTP id rv3-20020a1709068d0300b0083f743e086dmr6238312ejc.14.1673000770321; Fri, 06 Jan 2023 02:26:10 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id k17-20020a1709063e1100b0084ca5f2b935sm267372eji.172.2023.01.06.02.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:26:09 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 09/15] gdb/tui: disable tui mode when an assert triggers Date: Fri, 6 Jan 2023 10:25:36 +0000 Message-Id: <212ca24d63f8068c2a3d5f2051435b2b26d4d3ee.1673000632.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" When an assert triggers in tui mode the output is not great, the internal backtrace that is generated is printed directly to the file descriptor for gdb_stderr, and, as a result, does not currently format itself correctly - the output uses only '\n' at the end of each line, and so, when the terminal is in raw mode, the cursor does not return to the start of each line after the '\n'. This is mostly fixable, we could update bt-utils.c to use '\r\n' instead of just '\n', and this would fix most of the problems. The one we can't easily fix is if/when GDB is built to use execinfo instead of libbacktrace, in this case we use backtrace_symbols_fd to print the symbols, and this function only uses '\n' as the line terminator. Fixing this would require switching to backtrace_symbols, but that API uses malloc, which is something we're trying to avoid (this code is called when GDB hits an error, so ideally we don't want to rely on malloc). However, the execinfo code is only used when libbacktrace is not available (or the user specifically disables libbacktrace) so maybe we can ignore that problem... ... but there is another problem. When the backtrace is printed in raw mode, it is possible that the backtrace fills the screen. With the terminal in raw mode we don't have the ability to scroll back, which means we loose some of the backtrace, which isn't ideal. In this commit I propose that we should disable tui mode whenever we handle a fatal signal, or when we hit the internal error code path (e.g. when an assert triggers). With this done then we don't need to update the bt-utils.c code, and the execinfo version of the code (using backtrace_symbols_fd) works just fine. We also get the ability to scroll back to view the error message and all of the backtrace, assuming the users terminal supports scrolling back. The only downside I see with this change is if the tui_disable call itself causes an error for some reason, or, if we handle a single at a time when it is not safe to call tui_disable, in these cases the extra tui_disable call might cause GDB to loose the original error. However, I think (just from personal experience) that the above two issues are pretty rare and the benefits from this change far out weighs the possible drawbacks. --- gdb/event-top.c | 8 ++++++++ gdb/utils.c | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 4a46e1b9346..14984707df1 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -48,6 +48,10 @@ #include "readline/readline.h" #include "readline/history.h" +#ifdef TUI +#include "tui/tui.h" +#endif + /* readline defines this. */ #undef savestring @@ -940,6 +944,10 @@ unblock_signal (int sig) static void ATTRIBUTE_NORETURN handle_fatal_signal (int sig) { +#ifdef TUI + tui_disable (); +#endif + #ifdef GDB_PRINT_INTERNAL_BACKTRACE const auto sig_write = [] (const char *msg) -> void { diff --git a/gdb/utils.c b/gdb/utils.c index 734c5bf7f70..95adbe58e4a 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -29,7 +29,8 @@ #endif /* HAVE_SYS_RESOURCE_H */ #ifdef TUI -#include "tui/tui.h" /* For tui_get_command_dimension. */ +/* For tui_get_command_dimension and tui_disable. */ +#include "tui/tui.h" #endif #ifdef __GO32__ @@ -354,6 +355,10 @@ internal_vproblem (struct internal_problem *problem, } } +#ifdef TUI + tui_disable (); +#endif + /* Create a string containing the full error/warning message. Need to call query with this full string, as otherwize the reason (error/warning) and question become separated. Format using a From patchwork Fri Jan 6 10:25:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62791 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4470C384F032 for ; Fri, 6 Jan 2023 10:28:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4470C384F032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000906; bh=jcdgqCCodrkrGvXu/A1dTmdurdyIuJ6uFOGqjP8e6Zc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=fEvVYfX3LOXdSZveIpZKrGar52Trsk/xG6ABnJEvrrKUXtOHfUHdvr+A43bkc/M1C JH3qiLNj0ECE0B1aSEHWdYsqrfJAxBIETu8OfVWXCe6MdIb3Krusr7LwdKdGq+vRyA t7w/bzfuZsExBDOaburwWUBs1hyJIf4DvMsq8D4M= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C5CC03857B93 for ; Fri, 6 Jan 2023 10:26:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5CC03857B93 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-356-hZV69JQGOFaFbRalfxIRVw-1; Fri, 06 Jan 2023 05:26:14 -0500 X-MC-Unique: hZV69JQGOFaFbRalfxIRVw-1 Received: by mail-ed1-f71.google.com with SMTP id z20-20020a05640240d400b0047028edd264so955010edb.20 for ; Fri, 06 Jan 2023 02:26:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jcdgqCCodrkrGvXu/A1dTmdurdyIuJ6uFOGqjP8e6Zc=; b=F3k/RgMF4dKXEhFCfNWXsECa1cWgNDypr05lbSqsmGqNvK6g3udymknDJyHRXtSX6n P2HAna7+yOKQ/xEVtC0wYOwLEArCVIepoe9JnM71vi9BxY5i1DzaRaRU52C60W3gf0fV qXgXQvaRHwD+d+hZwPreX8OoLzw6I29tx3lpzFgiBUqR37CAfuR5kryH/fcPHQ0ZFYqe JZPv7sN7+xqbYGqmDlV8/Yx9ylCr/XY0yc89TJYCxVAWrcOxsDBgOpIZYEpFLZ6tEhd1 uhEjhu7GRlq1IBUvU5NahIVXmv5UyKaLXWb69CwUcXb/La5iSTBVtqhutVkdW0OW8+DP /0tQ== X-Gm-Message-State: AFqh2kqjtZQZclzl9Ha78TOXGBVXjkAIJzvLotyXrNFv8kzc//UyNNEJ QxuqNtGpngomX4FJx8HwOgFeclxHGlPeyDoj6RBf0DO+JvTYNvoLuWBdRI7Js6n/LPXgZlTMxju XKmJUejYJbS0a6/eLGhgCyi022DDdiqfqybqMSiQihdn0NbX2h4DcieS1ZaBBSo7WYWm6cwt0uw == X-Received: by 2002:aa7:d484:0:b0:468:ccfb:7201 with SMTP id b4-20020aa7d484000000b00468ccfb7201mr44934485edr.17.1673000773174; Fri, 06 Jan 2023 02:26:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXv9EKP86oirHUPOoTyech/wvUIFWoCX1uMzQme74gIesmQrzx2KONrz8/w/aoMcCFK5LdewEA== X-Received: by 2002:aa7:d484:0:b0:468:ccfb:7201 with SMTP id b4-20020aa7d484000000b00468ccfb7201mr44934474edr.17.1673000772913; Fri, 06 Jan 2023 02:26:12 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id m2-20020a509302000000b0046892e493dcsm366196eda.26.2023.01.06.02.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:26:12 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 10/15] gdb/tui: make m_horizontal_offset private Date: Fri, 6 Jan 2023 10:25:37 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I noticed that tui_source_window_base::m_horizontal_offset was protected, but could be made private, so lets do that. This makes more sense in the context of a later commit where I plan to add another member variable that is similar to m_horizontal_offset. The new member variable could also be private. So I had to choose, place the new member variable next to m_horizontal_offset making it protected, but grouping similar variables together, or make m_horizontal_offset private, and then add the new variable as private too. I chose to make m_horizontal_offset private, which is this commit. There should be no user visible changes after this commit. --- gdb/tui/tui-winsource.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index 7d6d64d35c4..bf0ca96c09b 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -124,8 +124,7 @@ struct tui_source_window_base : public tui_win_info /* Redraw the complete line of a source or disassembly window. */ void show_source_line (int lineno); - /* Used for horizontal scroll. */ - int m_horizontal_offset = 0; + /* Where to start generating content from. */ struct tui_line_or_address m_start_line_or_addr; /* Architecture associated with code at this location. */ @@ -179,6 +178,9 @@ struct tui_source_window_base : public tui_win_info private: + /* Used for horizontal scroll. */ + int m_horizontal_offset = 0; + void show_source_content (); /* Called when the user "set style enabled" setting is changed. */ From patchwork Fri Jan 6 10:25:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62789 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75E7038432EB for ; Fri, 6 Jan 2023 10:28:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75E7038432EB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000881; bh=1QNGNGvvgHJKqpFKcpBrXQWUkhPqlYz3Z01pzDcGsrQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=GaG2k+E8JC1+P3qzmWUPvz5s6ppf2baGCRVUSfuZfn1+j2lY5XXs2tVzKB6JdyRj1 sZTl7FSETxHXo5EAof6WP++XYiR8ozSoK/VHwpekxuTvgm+FEjhav8EaEkZBRynxMN VftN3sWmOLCskl7WZ7KkFaT5aQUbvVzYxVxWBZRo= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 33B823858D39 for ; Fri, 6 Jan 2023 10:26:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 33B823858D39 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-343-EYh7UKNpMxOgL4UmSbXmHQ-1; Fri, 06 Jan 2023 05:26:17 -0500 X-MC-Unique: EYh7UKNpMxOgL4UmSbXmHQ-1 Received: by mail-ej1-f71.google.com with SMTP id gb10-20020a170907960a00b007c192c5482eso881201ejc.7 for ; Fri, 06 Jan 2023 02:26:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1QNGNGvvgHJKqpFKcpBrXQWUkhPqlYz3Z01pzDcGsrQ=; b=uAbkERlO7tOA7vMw7DUsM23CSux38iKa5Sx1eabW7qbtgXVDi07yMeeX8p8+TfwFk7 HalMYEXdrMNr/6xSDvZNbeZ8K9zfn2diu68Z5nWiyi6HLKlaMX2ncYvmUP7FcAHPvIW1 JQ47CEnuEfxr79+APCwJP7Qfnui2qtaSJGr324xj4P49FX5Y37HcHuUEp6f3MbWQUROh V3LnRb4zQ2w7FgSSonr0N6ttSYMHg2dxjbQ6ctcdkAt/teG3Tl8Evy2PFMpOSOmzmdXI t6rjrzoY35CPE7egzD4ejm3gBwAvOIKDlhYL5ghXGhtTwGZpGUBwmhWMSO8a3YDcDW29 rqvw== X-Gm-Message-State: AFqh2kqPcOn82gsXp8DhyVfIxtPn0SGrs+lMl+bHv9+S59qaBM0t1F+H p2GJuCITwqugsFLe14JIUVbPOjTfcSAGGST9flmsRoOtRqNM/ifIFzPVOY/OCCXgMCpQfdE38Kl rDZdE21bqKD5TOFlzpzESNOkvKLMeFUjMnRqf/0iVbojTyeC984mcnUdCpfE9GLO2g7zlGHe3CA == X-Received: by 2002:a17:907:1392:b0:84d:1689:74f9 with SMTP id vs18-20020a170907139200b0084d168974f9mr2166065ejb.9.1673000776117; Fri, 06 Jan 2023 02:26:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXuEYJtSv6yYG0T2psEq4uBZTYQxy49yBr30qlDuwg8KboTFR2wI21zQdOR0gFGrYoncb6Uknw== X-Received: by 2002:a17:907:1392:b0:84d:1689:74f9 with SMTP id vs18-20020a170907139200b0084d168974f9mr2166040ejb.9.1673000775520; Fri, 06 Jan 2023 02:26:15 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id k8-20020a1709062a4800b0083ffb81f01esm267076eje.136.2023.01.06.02.26.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:26:15 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 11/15] gdb/tui: rewrite of tui_source_window_base to handle very long lines Date: Fri, 6 Jan 2023 10:25:38 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit addresses an issue that is exposed by the test script gdb.tui/tui-disasm-long-lines.exp, that is, tui_source_window_base does not handle very long lines. The problem can be traced back to the newpad call in tui_source_window_base::show_source_content, this is where we allocate a backing pad to hold the window content. Unfortunately, there appears to be a limit to the size of pad that can be allocated, and the gdb.tui/tui-disasm-long-lines.exp test goes beyond this limit. As a consequence the newpad call fails and returns nullptr. It just so happens that the reset of the tui_source_window_base code can handle the pad being nullptr (this happens anyway when the window is first created, so we already depend on nullptr handling), so all that happens is the source window displays no content. ... well, sort of ... something weird does happen in the command window, we seem to see a whole bunch of blank lines. I've not bothered to track down exactly what's happening there, but it's some consequence of GDB attempting to write content to a WINDOW* that is nullptr. Before explaining my solution, I'll outline how things currently work: Consider we have the following window content to display: aaaaaaaaaa bbbbbbbbbbbbbbbbbbbb ccccccccccccccc the longest line here is 20 characters. If our display window is 10 characters wide, then we will create a pad that is 20 characters wide, and then copy the lines of content into the pad: .--------------------. |aaaaaaaaaa | |bbbbbbbbbbbbbbbbbbbb| |ccccccccccccccc | .--------------------. Now we will copy a 10 character wide view into this pad to the display, our display will then see: .----------. |aaaaaaaaaa| |bbbbbbbbbb| |cccccccccc| .----------. As the user scrolls left and right we adjust m_horizontal_offset and use this to select which part of the pad is copied onto the display. The benefit of this is that we only need to copy the content to the pad once, which includes processing the ansi escape sequences, and then the user can scroll left and right as much as they want relatively cheaply. The problem then, is that if the longest content line is very long, then we try to allocate a very large pad, which can fail. What I propose is that we allow both the pad and the display view to scroll. Once we allow this, then it becomes possible to allocate a pad that is smaller than the longest display line. We then copy part of the content into the pad. As the user scrolls the view left and right GDB will continue to copy content from the pad just as it does right now. But, when the user scrolls to the edge of the pad, GDB will copy a new block of content into the pad, and then update the view as normal. This all works fine so long as the maximum pad size is larger than the current window size - which seems a reasonable restriction, if ncurses can't support a pad of a given size it seems likely it will not support a display window of that size either. If we return to our example above, but this time we assume that the maximum pad size is 15 characters, then initially the pad would be loaded like this: .---------------. |aaaaaaaaaa | |bbbbbbbbbbbbbbb| |ccccccccccccccc| .---------------. Notice that the last 5 characters from the 'b' line are no longer included in the pad. There is still enough content though to fill the 10 character wide display, just as we did before. The pad contents remain unchanged until the user scrolls the display right to this point: .----------. |aaaaa | |bbbbbbbbbb| |cccccccccc| .----------. Now, when the user scrolls right once more GDB spots that the user has reached the end of the pad, and the pad contents are reloaded, like this: .---------------. |aaaaa | |bbbbbbbbbbbbbbb| |cccccccccc | .---------------. The display can now be updated from the pad again just like normal. With this change in place the gdb.tui/tui-disasm-long-lines.exp test now correctly loads the assembler code, and we can scroll around as expected. Most of the changes are pretty mundane, just updating to match the above. One interesting change though is the new member function tui_source_window_base::puts_to_pad_with_skip. This replaces direct calls to tui_puts when copying content to the pad. The content strings contain ansi escape sequences. When these strings are written to the pad these escape sequences are translated into ncurses attribute setting calls. Now however, we sometimes only write a partial string to the pad, skipping some of the leading content. Imagine then that we have a content line like this: "\033[31mABCDEFGHIJKLM\033[0m" Now the escape sequences in this content mean that the actual content (the 'ABCDEFGHIJKLM') will have a red foreground color. If we want to copy this to the pad, but skip the first 3 characters, then what we expect is to have the pad contain 'DEFGHIJKLM', but this text should still have a red foreground color. It is this problem that puts_to_pad_with_skip solves. This function skips some number of printable characters, but processes all the escape sequences. This means that when we do start printing the actual content the content will have the expected attributes. / --- .../gdb.tui/tui-disasm-long-lines.exp | 6 +- gdb/tui/tui-winsource.c | 177 ++++++++++++++++-- gdb/tui/tui-winsource.h | 54 +++++- 3 files changed, 215 insertions(+), 22 deletions(-) diff --git a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp index acc4c54063f..345f7d21109 100644 --- a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp +++ b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp @@ -39,10 +39,6 @@ if {![Term::prepare_for_tui]} { return } -# Just check the command does not cause gdb to crash. It is worth -# noting that the asm window does infact fail to correctly display the -# disassembler output at this point, but initially we are just -# checking that GDB doesn't crash, fixing the asm display will come -# later. Term::command_no_prompt_prefix "layout asm" Term::check_box "asm box" 0 0 80 15 +Term::check_box_contents "check asm box contents" 0 0 80 15 "
" diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 87099ac26f5..6e22638ec74 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -170,6 +170,7 @@ tui_source_window_base::update_source_window_as_is erase_source_content (); else { + validate_scroll_offsets (); update_breakpoint_info (nullptr, false); show_source_content (); update_exec_info (); @@ -231,6 +232,67 @@ tui_source_window_base::do_erase_source_content (const char *str) } } +/* See tui-winsource.h. */ + +void +tui_source_window_base::puts_to_pad_with_skip (const char *string, int skip) +{ + gdb_assert (m_pad.get () != nullptr); + WINDOW *w = m_pad.get (); + + while (skip > 0) + { + const char *next = strpbrk (string, "\033"); + + /* Print the plain text prefix. */ + size_t n_chars = next == nullptr ? strlen (string) : next - string; + if (n_chars > 0) + { + if (skip > 0) + { + if (skip < n_chars) + { + string += skip; + n_chars -= skip; + skip = 0; + } + else + { + skip -= n_chars; + string += n_chars; + n_chars = 0; + } + } + + if (n_chars > 0) + { + std::string copy (string, n_chars); + tui_puts (copy.c_str (), w); + } + } + + /* We finished. */ + if (next == nullptr) + break; + + gdb_assert (*next == '\033'); + + int n_read; + if (skip_ansi_escape (next, &n_read)) + { + std::string copy (next, n_read); + tui_puts (copy.c_str (), w); + next += n_read; + } + else + gdb_assert_not_reached ("unhandled escape"); + + string = next; + } + + if (*string != '\0') + tui_puts (string, w); +} /* Redraw the complete line of a source or disassembly window. */ void @@ -243,7 +305,8 @@ tui_source_window_base::show_source_line (int lineno) tui_set_reverse_mode (m_pad.get (), true); wmove (m_pad.get (), lineno, 0); - tui_puts (line->line.c_str (), m_pad.get ()); + puts_to_pad_with_skip (line->line.c_str (), m_pad_offset); + if (line->is_exec_point) tui_set_reverse_mode (m_pad.get (), false); } @@ -257,13 +320,25 @@ tui_source_window_base::refresh_window () the screen, potentially creating a flicker. */ wnoutrefresh (handle.get ()); - int pad_width = std::max (m_max_length, width); - int left_margin = 1 + TUI_EXECINFO_SIZE + extra_margin (); - int view_width = width - left_margin - 1; - int pad_x = std::min (pad_width - view_width, m_horizontal_offset); - /* Ensure that an equal number of scrolls will work if the user - scrolled beyond where we clip. */ - m_horizontal_offset = pad_x; + int pad_width = getmaxx (m_pad.get ()); + int left_margin = this->left_margin (); + int view_width = this->view_width (); + int content_width = m_max_length; + int pad_x = m_horizontal_offset - m_pad_offset; + + gdb_assert (m_pad_offset >= 0); + gdb_assert (m_horizontal_offset + view_width + <= std::max (content_width, view_width)); + gdb_assert (pad_x >= 0); + gdb_assert (m_horizontal_offset >= 0); + + /* This function can be called before the pad has been allocated, this + should only occur during the initial startup. In this case the first + condition in the following asserts will not be true, but the nullptr + check will. */ + gdb_assert (pad_width > 0 || m_pad.get () == nullptr); + gdb_assert (pad_x + view_width <= pad_width || m_pad.get () == nullptr); + prefresh (m_pad.get (), 0, pad_x, y + 1, x + left_margin, y + m_content.size (), x + left_margin + view_width - 1); } @@ -275,11 +350,51 @@ tui_source_window_base::show_source_content () check_and_display_highlight_if_needed (); - int pad_width = std::max (m_max_length, width); - if (m_pad == nullptr || pad_width > getmaxx (m_pad.get ()) - || m_content.size () > getmaxy (m_pad.get ())) - m_pad.reset (newpad (m_content.size (), pad_width)); + /* The pad should be at least as wide as the window, but ideally, as wide + as the content, however, for some very wide content this might not be + possible. */ + int required_pad_width = std::max (m_max_length, width); + int required_pad_height = m_content.size (); + + /* If the required pad width is wider than the previously requested pad + width, then we might want to grow the pad. */ + if (required_pad_width > m_pad_requested_width + || required_pad_height > getmaxy (m_pad.get ())) + { + /* The current pad width. */ + int pad_width = m_pad == nullptr ? 0 : getmaxx (m_pad.get ()); + + gdb_assert (pad_width <= m_pad_requested_width); + + /* If the current pad width is smaller than the previously requested + pad width, then this means we previously failed to allocate a + bigger pad. There's no point asking again, so we'll just make so + with the pad we currently have. */ + if (pad_width == m_pad_requested_width + || required_pad_height > getmaxy (m_pad.get ())) + { + pad_width = required_pad_width; + + do + { + /* Try to allocate a new pad. */ + m_pad.reset (newpad (required_pad_height, pad_width)); + + if (m_pad == nullptr) + { + int reduced_width = std::max (pad_width / 2, width); + if (reduced_width == pad_width) + error (_("failed to setup source window")); + pad_width = reduced_width; + } + } + while (m_pad == nullptr); + } + + m_pad_requested_width = required_pad_width; + } + gdb_assert (m_pad != nullptr); werase (m_pad.get ()); for (int lineno = 0; lineno < m_content.size (); lineno++) show_source_line (lineno); @@ -370,6 +485,35 @@ tui_source_window_base::refill () update_source_window_as_is (m_gdbarch, sal); } +/* See tui-winsource.h. */ + +bool +tui_source_window_base::validate_scroll_offsets () +{ + int original_pad_offset = m_pad_offset; + + if (m_horizontal_offset < 0) + m_horizontal_offset = 0; + + int content_width = m_max_length; + int pad_width = getmaxx (m_pad.get ()); + int view_width = this->view_width (); + + if (m_horizontal_offset + view_width > content_width) + m_horizontal_offset = std::max (content_width - view_width, 0); + + if ((m_horizontal_offset + view_width) > (m_pad_offset + pad_width)) + { + m_pad_offset = std::min (m_horizontal_offset, content_width - pad_width); + m_pad_offset = std::max (m_pad_offset, 0); + } + else if (m_horizontal_offset < m_pad_offset) + m_pad_offset = std::max (m_horizontal_offset + view_width - pad_width, 0); + + gdb_assert (m_pad_offset >= 0); + return (original_pad_offset != m_pad_offset); +} + /* Scroll the source forward or backward horizontally. */ void @@ -377,10 +521,11 @@ tui_source_window_base::do_scroll_horizontal (int num_to_scroll) { if (!m_content.empty ()) { - int offset = m_horizontal_offset + num_to_scroll; - if (offset < 0) - offset = 0; - m_horizontal_offset = offset; + m_horizontal_offset += num_to_scroll; + + if (validate_scroll_offsets ()) + show_source_content (); + refresh_window (); } } diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index bf0ca96c09b..2762afff010 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -181,16 +181,68 @@ struct tui_source_window_base : public tui_win_info /* Used for horizontal scroll. */ int m_horizontal_offset = 0; + /* Check that the current values of M_HORIZONTAL_OFFSET and M_PAD_OFFSET + make sense given the current M_MAX_LENGTH (content width), WIDTH + (window size), and window margins. After calling this function + M_HORIZONTAL_OFFSET and M_PAD_OFFSET might have been adjusted to + reduce unnecessary whitespace on the right side of the window. + + If M_PAD_OFFSET is adjusted then this function returns true + indicating that the pad contents need to be reloaded by calling + show_source_content. If M_PAD_OFFSET is not adjusted then this + function returns false, the window contents might still need + redrawing if M_HORIZONTAL_OFFSET was adjusted, but right now, this + function is only called in contexts where the window is going to be + redrawn anyway. */ + bool validate_scroll_offsets (); + + /* Return the size of the left margin space, this is the space used to + display things like breakpoint markers. */ + int left_margin () const + { return 1 + TUI_EXECINFO_SIZE + extra_margin (); } + + /* Return the width of the area that is available for window content. + This is the window width minus the borders and the left margin, which + is used for displaying things like breakpoint markers. */ + int view_width () const + { return width - left_margin () - 1; } + void show_source_content (); + /* Write STRING to the window M_PAD, but skip the first SKIP printable + characters. Any escape sequences within the first SKIP characters are + still processed though. This means if we have this string: + + "\033[31mABCDEFGHIJKLM\033[0m" + + and call this function with a skip value of 3, then we effectively + write this string to M_PAD: + + "\033[31mDEFGHIJKLM\033[0m" + + the initial escape that sets the color will still be applied. */ + void puts_to_pad_with_skip (const char *string, int skip); + /* Called when the user "set style enabled" setting is changed. */ void style_changed (); /* A token used to register and unregister an observer. */ gdb::observers::token m_observable; - /* Pad used to display fixme mumble */ + /* Pad to hold some, or all, of the window contents. Content is then + copied from this pad to the screen as the user scrolls horizontally, + this avoids the need to recalculate the screen contents each time the + user does a horizontal scroll. */ std::unique_ptr m_pad; + + /* When M_PAD was allocated, this holds the width that was initially + asked for. If we ask for a very large pad then the allocation may + fail, and we might instead allocate a narrower pad. */ + int m_pad_requested_width = 0; + + /* If M_PAD is not as wide as the content (so less than M_MAX_LENGTH) + then this value indicates the offset at which the pad contents begin. */ + int m_pad_offset = 0; }; From patchwork Fri Jan 6 10:25:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62787 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3CC9038708F5 for ; Fri, 6 Jan 2023 10:27:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CC9038708F5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000857; bh=kN+TGSrhUsQB6Jmk1CbxK2TEbZTQtMX16sxb/eKGfhc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=KczD+bjjr+0MoT6Zl9eXLt5vwoRCUmRdukUgsVkBPFllCb+3CPvhSoasVkcG2qS87 LbVknKQon7+mcyCRtdSsnwYUZPCza8G4oliGmTRDyZrDnecQQva4iEVCP86hl1EMxL jEmhzvmm3WXh5WmjowUEzfekWcefqo+9jPEEhsTM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B9E88385B516 for ; Fri, 6 Jan 2023 10:26:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9E88385B516 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-470-Ie8Z_CLwPhefej1Y4moCTw-1; Fri, 06 Jan 2023 05:26:19 -0500 X-MC-Unique: Ie8Z_CLwPhefej1Y4moCTw-1 Received: by mail-ej1-f71.google.com with SMTP id xh12-20020a170906da8c00b007413144e87fso869620ejb.14 for ; Fri, 06 Jan 2023 02:26:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kN+TGSrhUsQB6Jmk1CbxK2TEbZTQtMX16sxb/eKGfhc=; b=pkUkLZfRycCr67N1O58uhexNzsJ/sygL0wqWx5kcUlyqZXFfnkxDmtmRK6Xn7TC5OE REwDV8i4BTbkZVXOgwQS2Vb1qdsqec59WOm+tLyJh/hAyzd30ZoclQElPtE4IH6w0lYt iUffyeyTZK0PgAIPsb5VD1X237NqPsyXC9g5RC8QIPsI1XI+pSHk53OV2Z/il58xqIgk DUA9/k7sxH39ZIYvl3g87FdbL1U7jMSuFwJNZ+7I8bf/eUWhkmsmgK3L5vQAS2fBWkwj 2LQbXZ+Ey7gZ+X4RgG9G5HMdh70EnB8izBPuQKQlQQdMYR3XWP7eiGbszAO315krTSXe Mu4A== X-Gm-Message-State: AFqh2ko5fLFc9RourWS5Gm0xPLlBiCmtrnLW4RMxMn8C9/Q0ktOMAPHX /QwYnR1+XKPLeEp247Ebnt63r8zXm/gaR0AvaLL0kW5Oxz5o13J+0N8010XFwCfYpeggMokw5A8 yBlxXIwl+O60c7LPRTgo15aISPjcARfMlvEefegRCBKdQ/FS67QVZbPQYRbuy+1QVrpRKbpBVHA == X-Received: by 2002:a05:6402:2b93:b0:47e:5b70:de79 with SMTP id fj19-20020a0564022b9300b0047e5b70de79mr48779122edb.17.1673000778673; Fri, 06 Jan 2023 02:26:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXtucJVjde6eWM7yNjMi1CtdjSaAyhSBNd9FE5BMDxGOtszr9Cn14Z+Fq9AJX+yDv2CVM0/wng== X-Received: by 2002:a05:6402:2b93:b0:47e:5b70:de79 with SMTP id fj19-20020a0564022b9300b0047e5b70de79mr48779105edb.17.1673000778410; Fri, 06 Jan 2023 02:26:18 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id c24-20020aa7c998000000b004589da5e5cesm355555edt.41.2023.01.06.02.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:26:18 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 12/15] gdb/tui: avoid extra refresh_window on horizontal scroll Date: Fri, 6 Jan 2023 10:25:39 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" While working on the previous patches I noticed that in some cases I was seeing two calls to tui_source_window_base::refresh_window when scrolling the window horizontally. The two calls would trigger in for the tui-disasm-long-lines.exp test when the pad needed to be refilled. The two called both come from tui_source_window_base::show_source_content. The first call is nested within check_and_display_highlight_if_needed, while the second call is done directly at the end of show_source_content. The check_and_display_highlight_if_needed is being used to draw the window box to the window, this is needed here because show_source_content is what gets called when the window needs updating, e.g. after a resize. We could potentially do the boxing in refresh_window, but then we'd be doing it each time we scroll, even though the box doesn't need changing in this case. However, we can move the check_and_display_highlight_if_needed to be the last thing done in show_source_content, this means that we can rely on the refresh_window call within it to be our single refresh call. There should be no user visible changes after this commit. --- gdb/tui/tui-winsource.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 6e22638ec74..50efa80576f 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -348,8 +348,6 @@ tui_source_window_base::show_source_content () { gdb_assert (!m_content.empty ()); - check_and_display_highlight_if_needed (); - /* The pad should be at least as wide as the window, but ideally, as wide as the content, however, for some very wide content this might not be possible. */ @@ -399,7 +397,11 @@ tui_source_window_base::show_source_content () for (int lineno = 0; lineno < m_content.size (); lineno++) show_source_line (lineno); - refresh_window (); + /* Calling check_and_display_highlight_if_needed will call refresh_window + (so long as the current window can be boxed), which will ensure that + the newly loaded window content is copied to the screen. */ + gdb_assert (can_box ()); + check_and_display_highlight_if_needed (); } tui_source_window_base::tui_source_window_base () From patchwork Fri Jan 6 10:25:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62792 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C3FA384F037 for ; Fri, 6 Jan 2023 10:29:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C3FA384F037 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000955; bh=LCbS/a6N3S8MjiAV8GUZ53xUs+FT/s2YaIKlZzSnhuw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Nh+7S5gzMVPekUwlB8uv05z6Lq716fX9VvFUeiIuA1DJfbJ5ed66nUArFubL9eSsy azupELmTN0fJQqOF5VkGfSdrsdK/Q0C8R5fRR1luSjofj8PYXkHa9h3u6wjG0xLLtr spgitqNdXhUAtbq+wUL8dmTYpK1OYjuSKcvTTzdE= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C6C95385B539 for ; Fri, 6 Jan 2023 10:26:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C6C95385B539 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-14-ZCLrucEPNXW3fGRyyW4LIw-1; Fri, 06 Jan 2023 05:26:22 -0500 X-MC-Unique: ZCLrucEPNXW3fGRyyW4LIw-1 Received: by mail-ed1-f69.google.com with SMTP id x13-20020a05640226cd00b0047ac11c9774so950270edd.17 for ; Fri, 06 Jan 2023 02:26:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LCbS/a6N3S8MjiAV8GUZ53xUs+FT/s2YaIKlZzSnhuw=; b=WUkUF0YRwQ8Ag+p4gIwWO3qhPURSkbmi7i45wePCmnIIdlCvGywslGl87gQKvD1Gel jUc3PFvSgDhk+RtYdxhOba2KbSx39ppeBjmIBYTPn3wbd5EGK+jrHBaZ86NHCPL/PnjU lVaSSUKfV2jmkxM/HoHxxZDvq1lSDURXOT8LUX+yuquPCok5CQ3BH/cyoDr5KdcO9lsF 0h9O/hckt0JdKz7i6wZgd9FPlcNbhJXIawhN+Qclu41TcV8L5vc0vqJPIbAlxQXlnRx0 nj+T8e72DS0+7ub024n9dKIn2ioQMR9dmvNYvyTxFk+khx3Cwr6AzAspyyIvTqDOYWxJ gQ/A== X-Gm-Message-State: AFqh2krxnXcA6kDE3ZbfHys5OG2EWyoWgj074qESTgiHWuX7r561ZWXV V05Qgb3O3XVQl/hI6E9I/nHuOn0gEvWbF3OntXj5vbidmqYG0HZWBI8EiNS0X97OCz7iBkOA5E0 3WqHFdNzYH+0M0NLVC6OGhCNijyBPxLtLGQssyuyo0i56DM3lOCkQQMoxJglTmPeTqHn02gUtiA == X-Received: by 2002:a17:906:1e17:b0:84c:69f8:2ec2 with SMTP id g23-20020a1709061e1700b0084c69f82ec2mr30094938ejj.22.1673000781153; Fri, 06 Jan 2023 02:26:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXtgZi89JwK6QHVSagZ8Z4b/+Gl0C0/nzYltZRzsbVXrNqG2eLLprO1eMCKoOI7BtGJ1FCjt3Q== X-Received: by 2002:a17:906:1e17:b0:84c:69f8:2ec2 with SMTP id g23-20020a1709061e1700b0084c69f82ec2mr30094926ejj.22.1673000780910; Fri, 06 Jan 2023 02:26:20 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id kv18-20020a17090778d200b007c4f8bc322asm259931ejc.196.2023.01.06.02.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:26:20 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 13/15] gdb/tui: avoid extra refresh_window on vertical scroll Date: Fri, 6 Jan 2023 10:25:40 +0000 Message-Id: <62eb6cb39a74f263852e9f6bcd01ba00b5a8b4a0.1673000632.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" While working on the previous couple of patches I noticed that when I scroll the src and asm windows vertically, I get two refresh_window calls. The two calls can be traced back to tui_source_window_base::update_source_window_as_is, in here we call show_source_content, which calls refresh_window, and then update_exec_info, which also calls refresh_window. In this commit I propose making the refresh_window call in update_exec_info optional. In update_source_window_as_is I'll then call update_exec_info before calling show_source_content, and pass a flag to update_exec_info to defer the refresh. There are places where update_exec_info is used without any subsequent refresh_window call (e.g. when a breakpoint is updated), so update_exec_info does not to call refresh_window in some cases, which is why I'm using a flag to control the refresh. With this changes I'm now only seeing a single refresh_window call for each vertical scroll. There should be no user visible changes after this commit. --- gdb/tui/tui-winsource.c | 12 ++++++------ gdb/tui/tui-winsource.h | 9 ++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 50efa80576f..b5b6079a909 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -172,8 +172,8 @@ tui_source_window_base::update_source_window_as_is { validate_scroll_offsets (); update_breakpoint_info (nullptr, false); + update_exec_info (false); show_source_content (); - update_exec_info (); } } @@ -636,11 +636,10 @@ tui_source_window_base::update_breakpoint_info return need_refresh; } -/* Function to initialize the content of the execution info window, - based upon the input window which is either the source or - disassembly window. */ +/* See tui-winsource.h. */ + void -tui_source_window_base::update_exec_info () +tui_source_window_base::update_exec_info (bool refresh_p) { update_breakpoint_info (nullptr, true); for (int i = 0; i < m_content.size (); i++) @@ -668,5 +667,6 @@ tui_source_window_base::update_exec_info () show_line_number (i); } - refresh_window (); + if (refresh_p) + refresh_window (); } diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index 2762afff010..7370ae95d8b 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -148,7 +148,14 @@ struct tui_source_window_base : public tui_win_info virtual bool location_matches_p (struct bp_location *loc, int line_no) = 0; - void update_exec_info (); + /* Fill in the left margin of the current window with execution indicator + information, e.g. breakpoint indicators, and line numbers. When + REFRESH_P is true this function will call refresh_window to ensure + updates are written to the screen, otherwise the refresh is skipped, + which will leave the on screen contents out of date. When passing + false for REFRESH_P you should be planning to call refresh_window + yourself. */ + void update_exec_info (bool refresh_p = true); /* Update the window to display the given location. Does nothing if the location is already displayed. */ From patchwork Fri Jan 6 10:25:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62793 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 31D8C3857C44 for ; Fri, 6 Jan 2023 10:29:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31D8C3857C44 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000987; bh=pmk6w1/4OYnPSe5NK3XRH/80PsnaQS0/RDZpEiNljHs=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=nORjy5XnhEoaD4tbHrVjpcY8G2xwZrB3P2/0CavsSmKybNB2rn8waYdtNY0itJ6/F YBZWgo/nnr4XpEtdYA072nJMdw1RcBofxOsjyy2yJUCpWUYmcT9fOkLxn86xydQ0d2 GXEavXmuk/rKBkQkINDvQyFw6yZJT4DeTM9SxvI8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 45A913858439 for ; Fri, 6 Jan 2023 10:26:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45A913858439 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-183-WbV4w1v4PU6X1B-XH057ow-1; Fri, 06 Jan 2023 05:26:24 -0500 X-MC-Unique: WbV4w1v4PU6X1B-XH057ow-1 Received: by mail-ej1-f71.google.com with SMTP id nb4-20020a1709071c8400b007c18ba778e9so869553ejc.16 for ; Fri, 06 Jan 2023 02:26:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pmk6w1/4OYnPSe5NK3XRH/80PsnaQS0/RDZpEiNljHs=; b=Xu8Zo7LEfeFM5ipz3tI2Im1qCCve1ZuMC9haK7gihmSupGD5EC45x1J2RQCCO8ihzD sf2mOFWKScD/0MPS05jpo5Az6e1TS76i4VU9+e5plLTolG1q9/iT6WG9N0phPc7gAQ9A ms5xRO5gTcs54I5Ii58W8A8eSiQOZaxjftiO70YGOcD2HEIwgTNt/+LY8haOBnfjA4fs EZU2YL1YhPoaHGzr7xb6VtYSdCEg4xi8gnG9XRlgUpUnBXBCrkKCbGJjh+tOLLP6TX6A CEw4t0np9l71gNapcMZzMmPCxrF3T/Jwr1mrgFtYLOQ5s3vp9IBSHwG24Ll3+Wy+9Pjs kFDQ== X-Gm-Message-State: AFqh2kp/l52A8za0z6xtDVzZ/ahx+51F/uTFz1XN6OPNlaGrnv9bO4dd t8fU0Bm1vXwfU4srkS3osUsgXCnZsx2n/gay1DLX5cjs/Fto/tdNYwKdiGQ29rW0fu87QTOThuN /D4BhoAE5ztNYg/RogBVRCGo2KqxdCL7uR0e6leFCjFkkIk4bHeKV17UeDSCsEFbFNHkGCkPQcg == X-Received: by 2002:a05:6402:5510:b0:495:fa3d:1d72 with SMTP id fi16-20020a056402551000b00495fa3d1d72mr2201754edb.8.1673000783269; Fri, 06 Jan 2023 02:26:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXvv49wXqpyMwoaIkoWT5csrqXNShdfn9+fSr2M02YWEkrBC5l1lGDdfg8HtN6VYwmE2jqCpkw== X-Received: by 2002:a05:6402:5510:b0:495:fa3d:1d72 with SMTP id fi16-20020a056402551000b00495fa3d1d72mr2201738edb.8.1673000782983; Fri, 06 Jan 2023 02:26:22 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id y5-20020aa7ccc5000000b00463bc1ddc76sm361896edt.28.2023.01.06.02.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:26:22 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 14/15] gdb/tui: more debug output Date: Fri, 6 Jan 2023 10:25:41 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Add some additional debug output that I've found really useful while working on the previous set of patches. Unless tui debug is turned on, then there should be no user visible changes with this commit. --- gdb/tui/tui-winsource.c | 21 +++++++++++++++++++++ gdb/tui/tui.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index b5b6079a909..52a0f7af00f 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -316,6 +316,8 @@ tui_source_window_base::show_source_line (int lineno) void tui_source_window_base::refresh_window () { + TUI_SCOPED_DEBUG_START_END ("window `%s`", name ()); + /* tui_win_info::refresh_window would draw the empty background window to the screen, potentially creating a flicker. */ wnoutrefresh (handle.get ()); @@ -326,6 +328,12 @@ tui_source_window_base::refresh_window () int content_width = m_max_length; int pad_x = m_horizontal_offset - m_pad_offset; + tui_debug_printf ("pad_width = %d, left_margin = %d, view_width = %d", + pad_width, left_margin, view_width); + tui_debug_printf ("content_width = %d, pad_x = %d, m_horizontal_offset = %d", + content_width, pad_x, m_horizontal_offset); + tui_debug_printf ("m_pad_offset = %d", m_pad_offset); + gdb_assert (m_pad_offset >= 0); gdb_assert (m_horizontal_offset + view_width <= std::max (content_width, view_width)); @@ -346,6 +354,8 @@ tui_source_window_base::refresh_window () void tui_source_window_base::show_source_content () { + TUI_SCOPED_DEBUG_START_END ("window `%s`", name ()); + gdb_assert (!m_content.empty ()); /* The pad should be at least as wide as the window, but ideally, as wide @@ -390,6 +400,8 @@ tui_source_window_base::show_source_content () } m_pad_requested_width = required_pad_width; + tui_debug_printf ("requested width %d, allocated width %d", + required_pad_width, getmaxx (m_pad.get ())); } gdb_assert (m_pad != nullptr); @@ -431,6 +443,8 @@ tui_source_window_base::update_tab_width () void tui_source_window_base::rerender () { + TUI_SCOPED_DEBUG_START_END ("window `%s`", name ()); + if (!m_content.empty ()) { struct symtab_and_line cursal @@ -492,6 +506,8 @@ tui_source_window_base::refill () bool tui_source_window_base::validate_scroll_offsets () { + TUI_SCOPED_DEBUG_START_END ("window `%s`", name ()); + int original_pad_offset = m_pad_offset; if (m_horizontal_offset < 0) @@ -501,6 +517,11 @@ tui_source_window_base::validate_scroll_offsets () int pad_width = getmaxx (m_pad.get ()); int view_width = this->view_width (); + tui_debug_printf ("pad_width = %d, view_width = %d, content_width = %d", + pad_width, view_width, content_width); + tui_debug_printf ("original_pad_offset = %d, m_horizontal_offset = %d", + original_pad_offset, m_horizontal_offset); + if (m_horizontal_offset + view_width > content_width) m_horizontal_offset = std::max (content_width - view_width, 0); diff --git a/gdb/tui/tui.h b/gdb/tui/tui.h index a9ecd589a70..ca30e7cc65e 100644 --- a/gdb/tui/tui.h +++ b/gdb/tui/tui.h @@ -36,6 +36,9 @@ extern bool debug_tui; #define TUI_SCOPED_DEBUG_ENTER_EXIT \ scoped_debug_enter_exit (debug_tui, "tui") +#define TUI_SCOPED_DEBUG_START_END(fmt, ...) \ + scoped_debug_start_end (debug_tui, "tui", fmt, ##__VA_ARGS__) + struct ui_file; /* Types of error returns. */ From patchwork Fri Jan 6 10:25:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62790 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 412A2382FAE8 for ; Fri, 6 Jan 2023 10:28:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 412A2382FAE8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000885; bh=gYQwumjxxIedgB1zsCT/v3/Tjx7zR2bxysxd5OwjhlM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=PzflhWg+i37xb5965fYvvYDLjmeQ9FHRmXnLGQUs1+YZPjbTGmkpYd0P/bCIDslB6 7itfCJ5zeJUPyYOPJsny5HKbeOJysRtgkTgOKT15+rCTXsb0bGzNp5s3fW68oBbFAR ugzeKh7d2d2uYhZLgtfJ9NlCCzyFjHsfIV3qnVtI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 45F56385842B for ; Fri, 6 Jan 2023 10:26:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45F56385842B Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-271-tgOpcYnmMgiIbeWiZr-BCQ-1; Fri, 06 Jan 2023 05:26:26 -0500 X-MC-Unique: tgOpcYnmMgiIbeWiZr-BCQ-1 Received: by mail-ed1-f71.google.com with SMTP id b16-20020a056402279000b0046fb99731e6so964354ede.1 for ; Fri, 06 Jan 2023 02:26:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gYQwumjxxIedgB1zsCT/v3/Tjx7zR2bxysxd5OwjhlM=; b=Kzxdge0jN8B6aocp/PsRIRfA9jcrlY2gNobJbLolaqVgtTSbq/1XwjP0chthJKQiHk ZIhYs6LG3mpTPXwCvhMv6JjJqw75U/klzjglrFTEn9Cz2QjfWg9RARRTIqNw10AGR9Y8 e9hcQWtIs0WVQnp/0jwAGoGD/gIjTeiq2fw3ZjhdEkJn+NpnfxBdtzZFnz1y/T4aGPno b5YwJ1SeHfpqLDUCpgrlOZkEINZ3K6tV3n4fMXWgCkuzrdQT05lMjZCG2iaa6N+zZFgu h0w0JPp1JbDLxfaKXRhhNtWCkIEeO5t6nIMkbAgFTz5Gk8qX+wxakDTFNfQSzVKVJqA0 p5tA== X-Gm-Message-State: AFqh2kqz5s4MXu7twrDDNc/INOx1K7YoeL5PG1jscfcQmuCO4+fhcH+u djs1mAjL2bfehh9pIFmK3d4qr4H+BxIjlbS3sYx1DGJDDlQBmDTeaJsVT0p9+RU4iziN8NMR99V TMYPK10O/QbImzPV80AzpEJS9E5MKgBCzXTMOJ9Sc5BNhdZsMk6y19Jg//CHpddlcPzZS6w4Vgg == X-Received: by 2002:a05:6402:f17:b0:489:5852:fbb5 with SMTP id i23-20020a0564020f1700b004895852fbb5mr27705483eda.16.1673000785374; Fri, 06 Jan 2023 02:26:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXtrqnEIj3ws9w3UvAHwJXUDzCK8xgagiAeCV5naSO5mdGmH5V4zxosI+EMTE4r5HyLWTtroXA== X-Received: by 2002:a05:6402:f17:b0:489:5852:fbb5 with SMTP id i23-20020a0564020f1700b004895852fbb5mr27705470eda.16.1673000785147; Fri, 06 Jan 2023 02:26:25 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id u10-20020a1709061daa00b0084cc87c03ebsm271240ejh.110.2023.01.06.02.26.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:26:24 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 15/15] gdb/tui: make use of a scoped_restore Date: Fri, 6 Jan 2023 10:25:42 +0000 Message-Id: <086366914f866559bc26512dfc67cf1f9fae2964.1673000632.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Make use of a scoped_restore object in tui_mld_read_key instead of doing a manual save/restore. I don't think the existing code can throw an exception, so this is just a cleanup rather than a bug fix. There should be no user visible changes after this commit. --- gdb/tui/tui-io.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 2f39e34df2f..a17cf38a1f2 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -773,14 +773,10 @@ tui_mld_getc (FILE *fp) static int tui_mld_read_key (const struct match_list_displayer *displayer) { - rl_getc_func_t *prev = rl_getc_function; - int c; - /* We can't use tui_getc as we need NEWLINE to not get emitted. */ - rl_getc_function = tui_mld_getc; - c = rl_read_key (); - rl_getc_function = prev; - return c; + scoped_restore restore_getc_function + = make_scoped_restore (&rl_getc_function, tui_mld_getc); + return rl_read_key (); } /* TUI version of rl_completion_display_matches_hook.