From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 678D33858401 for ; Fri, 10 Sep 2021 20:54:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 678D33858401 X-ASG-Debug-ID: 1631307244-0c856e0387270b50001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id uIRDZpJOesSWYFgb (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 10 Sep 2021 16:54:04 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (173-246-27-5.qc.cable.ebox.net [173.246.27.5]) by smtp.ebox.ca (Postfix) with ESMTP id B9ECE441D65; Fri, 10 Sep 2021 16:54:04 -0400 (EDT) From: Simon Marchi X-Barracuda-RBL-IP: 173.246.27.5 X-Barracuda-Effective-Source-IP: 173-246-27-5.qc.cable.ebox.net[173.246.27.5] X-Barracuda-Apparent-Source-IP: 173.246.27.5 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 3/6] gdb.base/foll-fork.exp: refactor to restart GDB between each portion of the test Date: Fri, 10 Sep 2021 16:53:59 -0400 X-ASG-Orig-Subj: [PATCH 3/6] gdb.base/foll-fork.exp: refactor to restart GDB between each portion of the test Message-Id: <20210910205402.3853607-3-simon.marchi@efficios.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910205402.3853607-1-simon.marchi@efficios.com> References: <20210910205402.3853607-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1631307244 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 8110 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.92507 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-21.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Fri, 10 Sep 2021 20:54:11 -0000 This test is difficult to follow and modify because the state of GDB is preserved some tests. Add a setup proc, which starts a new GDB and runs to main, and use it in all test procs. Use proc_with_prefix to avoid duplicates. The check_fork_catchpoints proc also seems used to check for follow-fork support by checking if catchpoints are supported. If they are not, it uses "return -code return", which makes its caller return. I find this unnecessary complex, versus just returning a boolean. Modify it to do so. Change-Id: I23e62b204286c5e9c5c86d2727f7d33fb126ed08 --- gdb/testsuite/gdb.base/foll-fork.exp | 144 +++++++++++++++------------ 1 file changed, 81 insertions(+), 63 deletions(-) diff --git a/gdb/testsuite/gdb.base/foll-fork.exp b/gdb/testsuite/gdb.base/foll-fork.exp index e6e84bd3bc0..4661bf56a52 100644 --- a/gdb/testsuite/gdb.base/foll-fork.exp +++ b/gdb/testsuite/gdb.base/foll-fork.exp @@ -22,13 +22,33 @@ if [gdb_debug_enabled] { standard_testfile -if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { +if {[build_executable "failed to prepare" $testfile $srcfile debug]} { return -1 } -proc check_fork_catchpoints {} { +# Restart GDB and run the inferior to main. Return 1 on success, 0 on failure. + +proc setup {} { + clean_restart $::testfile + + if { ![runto_main] } { + fail "could not run to main" + return 0 + } + + return 1 +} + +# Check that fork catchpoints are supported, as an indicator for whether +# fork-following is supported. Return 1 if they are, else 0. + +proc_with_prefix check_fork_catchpoints {} { global gdb_prompt + if { ![setup] } { + return + } + # Verify that the system supports "catch fork". gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "insert first fork catchpoint" set has_fork_catchpoints 0 @@ -42,10 +62,7 @@ proc check_fork_catchpoints {} { } } - if {$has_fork_catchpoints == 0} { - unsupported "fork catchpoints" - return -code return - } + return $has_fork_catchpoints } # Test follow-fork to ensure that the correct process is followed, that @@ -57,7 +74,7 @@ proc check_fork_catchpoints {} { # execute the program past the fork. If the value of WHO or DETACH is # 'default', the corresponding GDB command is skipped for that test. # The value of CMD must be either 'next 2' or 'continue'. -proc test_follow_fork { who detach cmd } { +proc_with_prefix test_follow_fork { who detach cmd } { global gdb_prompt global srcfile global testfile @@ -65,11 +82,8 @@ proc test_follow_fork { who detach cmd } { with_test_prefix "follow $who, detach $detach, command \"$cmd\"" { # Start a new debugger session each time so defaults are legitimate. - clean_restart $testfile - - if ![runto_main] { - untested "could not run to main" - return -1 + if { ![setup] } { + return } # The "Detaching..." and "Attaching..." messages may be hidden by @@ -174,11 +188,18 @@ proc test_follow_fork { who detach cmd } { set reading_in_symbols_re {(?:\r\nReading in symbols for [^\r\n]*)?} -proc catch_fork_child_follow {} { +# Test the ability to catch a fork, specify that the child be +# followed, and continue. Make the catchpoint permanent. + +proc_with_prefix catch_fork_child_follow {} { global gdb_prompt global srcfile global reading_in_symbols_re + if { ![setup] } { + return + } + set bp_after_fork [gdb_get_line_number "set breakpoint here"] gdb_test "catch fork" \ @@ -224,10 +245,18 @@ proc catch_fork_child_follow {} { "y" } -proc catch_fork_unpatch_child {} { +# Test that parent breakpoints are successfully detached from the +# child at fork time, even if the user removes them from the +# breakpoints list after stopping at a fork catchpoint. + +proc_with_prefix catch_fork_unpatch_child {} { global gdb_prompt global srcfile + if { ![setup] } { + return + } + set bp_exit [gdb_get_line_number "at exit"] gdb_test "break callee" "file .*$srcfile, line .*" \ @@ -271,11 +300,18 @@ proc catch_fork_unpatch_child {} { } } -proc tcatch_fork_parent_follow {} { +# Test the ability to catch a fork, specify via a -do clause that +# the parent be followed, and continue. Make the catchpoint temporary. + +proc_with_prefix tcatch_fork_parent_follow {} { global gdb_prompt global srcfile global reading_in_symbols_re + if { ![setup] } { + return + } + set bp_after_fork [gdb_get_line_number "set breakpoint here"] gdb_test "catch fork" \ @@ -313,9 +349,10 @@ proc tcatch_fork_parent_follow {} { "y" } -proc do_fork_tests {} { - global gdb_prompt - global testfile +# Test simple things about the "set follow-fork-mode" command. + +proc_with_prefix test_set_follow_fork_command {} { + clean_restart # Verify that help is available for "set follow-fork-mode". # @@ -342,56 +379,37 @@ By default, the debugger will follow the parent process..*" "set follow-fork to nonsense is prohibited" gdb_test_no_output "set follow-fork parent" "reset parent" +} - # Check that fork catchpoints are supported, as an indicator for whether - # fork-following is supported. - if [runto_main] then { check_fork_catchpoints } +test_set_follow_fork_command - # Test the basic follow-fork functionality using all combinations of - # values for follow-fork-mode and detach-on-fork, using either a - # breakpoint or single-step to execute past the fork. - # - # The first loop should be sufficient to test the defaults. There - # is no need to test using the defaults in other permutations (e.g. - # "default" "on", "parent" "default", etc.). - foreach cmd {"next 2" "continue"} { - test_follow_fork "default" "default" $cmd - } +if { ![check_fork_catchpoints] } { + untested "follow-fork not supported" + return +} - # Now test all explicit permutations. - foreach who {"parent" "child"} { - foreach detach {"on" "off"} { - foreach cmd {"next 2" "continue"} { - test_follow_fork $who $detach $cmd - } +# Test the basic follow-fork functionality using all combinations of +# values for follow-fork-mode and detach-on-fork, using either a +# breakpoint or single-step to execute past the fork. +# +# The first loop should be sufficient to test the defaults. There +# is no need to test using the defaults in other permutations (e.g. +# "default" "on", "parent" "default", etc.). +foreach cmd {"next 2" "continue"} { + test_follow_fork "default" "default" $cmd +} + +# Now test all explicit permutations. +foreach who {"parent" "child"} { + foreach detach {"on" "off"} { + foreach cmd {"next 2" "continue"} { + test_follow_fork $who $detach $cmd } } - - # Catchpoint tests. - - # Restart to eliminate any effects of the follow-fork tests. - clean_restart $testfile - gdb_test_no_output "set verbose" - - # Test the ability to catch a fork, specify that the child be - # followed, and continue. Make the catchpoint permanent. - # - if [runto_main] then { catch_fork_child_follow } - - # Test that parent breakpoints are successfully detached from the - # child at fork time, even if the user removes them from the - # breakpoints list after stopping at a fork catchpoint. - if [runto_main] then { catch_fork_unpatch_child } - - # Test the ability to catch a fork, specify via a -do clause that - # the parent be followed, and continue. Make the catchpoint temporary. - # - if [runto_main] then { tcatch_fork_parent_follow } } -# This is a test of gdb's ability to follow the parent, child or both -# parent and child of a Unix fork() system call. -# -do_fork_tests +# Catchpoint tests. -return 0 +catch_fork_child_follow +catch_fork_unpatch_child +tcatch_fork_parent_follow -- 2.33.0