From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by sourceware.org (Postfix) with ESMTPS id 38B2E3858C51 for ; Tue, 17 May 2022 10:13:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 38B2E3858C51 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f48.google.com with SMTP id bd25-20020a05600c1f1900b0039485220e16so1061710wmb.0 for ; Tue, 17 May 2022 03:13:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:from:to:references:in-reply-to :content-transfer-encoding; bh=je332sSnrVpW768nRLPKhqVlFCKNH2fW0v2w30XdhbE=; b=X28IYjTqv1cplUswhx99JHxubBqVn8rTc8I1Nblzrx2DouSpHwjIy3Qo32wVl5zzFe oTRmpHfN2S4Rpv1JgXWz/hVT7/2gqp3O4TXjIxDalPKtEekV5DjeZ0MCqk9ZEU5WzYCN fqYaJD9Z0ErOYBdydSZCmq42SSmgJBt3zsc+IHlAp4ShmYR0GwWwW3ozty7Bbsjl7udL NRHki13U57xsN9bTdXh1hUFKNqPgu+d6oU0nrGebikJq1SJhTg/1QNsQJ72+uT1noNLB fIePyTlCV9Qxp9otzpVlWsEmHnbK6Ylet39WRt/qmvItKU7Mu7kAhH/djyLco6ZMAEjp yA+g== X-Gm-Message-State: AOAM531/i9+7KvjqGnWAEMlfLXYY9kdfwMDkB6LSV7igd1Jn56/3mVf3 WDJUBU42AqaP8rl4yRXxPAg= X-Google-Smtp-Source: ABdhPJzCRCNxoHCgEKzfTN6569P4FWLTtAgY+r+0ElMmW85WugFu396cxaAggbP8Oo10M0LbjizkAw== X-Received: by 2002:a05:600c:1f13:b0:396:fee5:ebcf with SMTP id bd19-20020a05600c1f1300b00396fee5ebcfmr10588848wmb.201.1652782412968; Tue, 17 May 2022 03:13:32 -0700 (PDT) Received: from ?IPV6:2001:8a0:f924:2600:209d:85e2:409e:8726? ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id d17-20020adf9b91000000b0020d02ddf4d0sm7776702wrc.69.2022.05.17.03.13.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 May 2022 03:13:32 -0700 (PDT) Message-ID: <7a6a26e1-ec0e-2ea2-03e6-db94f6253f3b@palves.net> Date: Tue, 17 May 2022 11:13:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: [PATCH 5/6] gdb.base/skip.exp: Don't abuse gdb_test's question support (Re: [PATCH 5/5] Make gdb_test's question non-optional if specified) Content-Language: en-US From: Pedro Alves To: Bruno Larsen , gdb-patches@sourceware.org References: <20220330192929.3161015-1-pedro@palves.net> <20220330192929.3161015-6-pedro@palves.net> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Tue, 17 May 2022 10:13:36 -0000 On 2022-04-08 13:18, Pedro Alves wrote: > On 2022-04-07 21:31, Bruno Larsen wrote: >> On 3/30/22 16:29, Pedro Alves wrote: >>> gdb_test supports handling scenarios where GDB asks a question before >>> finishing handling some command.  The full prototype of gdb_test is: >>> >>>    # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE >>> >>> However, QUESTION is a question that GDB _may_ ask, not one that GDB >>> _must_ ask: >>> >>>   # QUESTION is a question GDB may ask in response to COMMAND, like >>>   #   "are you sure?" >>>   # RESPONSE is the response to send if QUESTION appears. >>> >>> If GDB doesn't raise the question, the test still passes. >>> >>> I think that this is a misfeature.  If GDB regresses and stops asking >>> a question, the testsuite won't notice.  So I think that if a QUESTION >>> is specified, gdb_test should ensure it comes out of GDB. >> >> I just ran into a neat use of this, or possibly a mis-use, depending on how much you like it. gdb.base/skip.exp uses: >> >> gdb_test "step" "desired spot" "go to desired spot" "undesirable spot" "step" >> >> as a simple way to handle a gcc 9.2.0 bug (misfeature) where gdb could stop in an undesirable spot without actually causing a failure in the test. This feels like a neat way to deal with compiler problems, as it would introduce a simple way to deal with clang's lack of epilogue, for instance. > > This is: > > # With gcc 9.2.0 we jump once back to main before entering foo here. > # If that happens try to step a second time. > gdb_test "step" "foo \\(\\) at.*" "step 3" \ > "main \\(\\) at .*\r\n$gdb_prompt " "step" > > I think this is a misuse. That case doesn't really handle a GDB confirmation question. > What if you need to issue more steps, or the program may stop elsewhere for > different ports, and thus you need more than one regexp? For the latter you can > use (REGEX1|REGEX1), but it isn't as nice as separate -re entries, IMHO. > > IMHO, writing it with gdb_test_multiple in these cases is OK: > > gdb_test_multiple "step" "step 3" { > -re -wrap "foo \\(\\) at.*" { > pass $gdb_test_multiple > } > -re -wrap "main \\(\\) at .*" { > # With gcc 9.2.0 we jump once back to main before entering foo. > # If that happens try another step. > send_gdb "step\n" > exp_continue > } > } > > It's a standard pattern we use in many places, I don't think it's bad enough that we need > to hide it. > >> >> I'm not suggesting that this patch be scrapped, but maybe this could be implemented on purpose, something like gdb_test_optional. The code itself LGTM, but I am not able to approve patches. >> > I'm adding the patch below to the series, before old patch #5, to prevent gdb.base/skip.exp from starting to fail with older GCCs. I'm going to merge the whole series now. >From d7440bee9ffa6767e704f226ec28b9aa2fb748d6 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 17 May 2022 10:25:12 +0100 Subject: [PATCH] gdb.base/skip.exp: Don't abuse gdb_test's question support gdb.base/skip.exp abuses gdb_test's support for answering a GDB question to do this: # With gcc 9.2.0 we jump once back to main before entering foo here. # If that happens try to step a second time. gdb_test "step" "foo \\(\\) at.*" "step 3" \ "main \\(\\) at .*\r\n$gdb_prompt " "step" After a patch later in this series, gdb_test will FAIL if GDB does NOT issue the question, so this test would start failing on older GCCs. Switch to using gdb_test_multiple instead. There are three spots in the file that have the same pattern, and they're actually in a sequence of commands that is repeated those 3 times. Factor all that out to a procedure. I don't have gcc 9.2 handy, but I do have gcc 6.5, and that one is affected as well, so update the comment. Change-Id: If0a7e3cdf5191b4eec95ce0c8845c3a4d801c39e --- gdb/testsuite/gdb.base/skip.exp | 55 +++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/gdb/testsuite/gdb.base/skip.exp b/gdb/testsuite/gdb.base/skip.exp index 7c71bb07a84..e6b660004d9 100644 --- a/gdb/testsuite/gdb.base/skip.exp +++ b/gdb/testsuite/gdb.base/skip.exp @@ -122,6 +122,32 @@ with_test_prefix "step after deleting 1" { gdb_test "step" "main \\(\\) at.*" "step 3" } +# Test that we step into foo(), then into bar(), but not into baz(). +proc step_bar_foo_skip_baz {} { + gdb_test "step" "bar \\(\\) at.*" "step 1" + gdb_test "step" ".*" "step 2"; # Return from bar() + + # With at least gcc 6.5.0 and 9.2.0, we jump once back to main + # before entering foo here. If that happens try to step a second + # time. + set stepped_again 0 + gdb_test_multiple "step" "step 3" { + -re -wrap "foo \\(\\) at.*" { + pass $gdb_test_name + } + -re -wrap "main \\(\\) at .*" { + if {!$stepped_again} { + set stepped_again 1 + send_gdb "step\n" + } + exp_continue + } + } + + gdb_test "step" ".*" "step 4"; # Return from foo() + gdb_test "step" "main \\(\\) at.*" "step 5" +} + # Now disable the skiplist entry for skip1.c. We should now # step into foo(), then into bar(), but not into baz(). @@ -136,14 +162,7 @@ with_test_prefix "step after disabling 3" { return } - gdb_test "step" "bar \\(\\) at.*" "step 1" - gdb_test "step" ".*" "step 2"; # Return from bar() - # With gcc 9.2.0 we jump once back to main before entering foo here. - # If that happens try to step a second time. - gdb_test "step" "foo \\(\\) at.*" "step 3" \ - "main \\(\\) at .*\r\n$gdb_prompt " "step" - gdb_test "step" ".*" "step 4"; # Return from foo() - gdb_test "step" "main \\(\\) at.*" "step 5" + step_bar_foo_skip_baz } # Enable skiplist entry 3 and make sure we step over it like before. @@ -254,14 +273,8 @@ with_test_prefix "step using -fu for baz" { gdb_test_no_output "skip disable" gdb_test_no_output "skip enable 7" - gdb_test "step" "bar \\(\\) at.*" "step 1" - gdb_test "step" ".*" "step 2"; # Return from bar() - # With gcc 9.2.0 we jump once back to main before entering foo here. - # If that happens try to step a second time. - gdb_test "step" "foo \\(\\) at.*" "step 3" \ - "main \\(\\) at .*\r\n$gdb_prompt " "step" - gdb_test "step" ".*" "step 4"; # Return from foo() - gdb_test "step" "main \\(\\) at.*" "step 5" + + step_bar_foo_skip_baz } with_test_prefix "step using -rfu for baz" { @@ -271,14 +284,8 @@ with_test_prefix "step using -rfu for baz" { gdb_test_no_output "skip disable" gdb_test_no_output "skip enable 8" - gdb_test "step" "bar \\(\\) at.*" "step 1" - gdb_test "step" ".*" "step 2"; # Return from bar() - # With gcc 9.2.0 we jump once back to main before entering foo here. - # If that happens try to step a second time. - gdb_test "step" "foo \\(\\) at.*" "step 3" \ - "main \\(\\) at .*\r\n$gdb_prompt " "step" - gdb_test "step" ".*" "step 4"; # Return from foo() - gdb_test "step" "main \\(\\) at.*" "step 5" + + step_bar_foo_skip_baz } # Test -fi + -fu. -- 2.36.0