From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
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 [thread overview]
Message-ID: <20210910205402.3853607-3-simon.marchi@efficios.com> (raw)
In-Reply-To: <20210910205402.3853607-1-simon.marchi@efficios.com>
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
next prev parent reply other threads:[~2021-09-10 20:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-10 20:53 [PATCH 1/6] gdb.base/foll-fork.exp: remove DUPLICATEs Simon Marchi
2021-09-10 20:53 ` [PATCH 2/6] gdb.base/foll-fork.exp: remove gating based on target triplet Simon Marchi
2021-09-10 20:53 ` Simon Marchi [this message]
2021-09-10 20:54 ` [PATCH 4/6] gdb.base/foll-fork.exp: rename variables Simon Marchi
2021-09-10 20:54 ` [PATCH 5/6] gdb.base/foll-fork.exp: use foreach_with_prefix to handle prefixes Simon Marchi
2021-09-10 20:54 ` [PATCH 6/6] gdb: don't share aspace/pspace on fork with "detach-on-fork on" and "follow-fork-mode child" Simon Marchi
2021-09-10 23:33 ` John Baldwin
2021-09-11 3:16 ` Simon Marchi
2021-09-11 13:02 ` Simon Marchi
2021-09-11 13:03 ` Simon Marchi
2021-09-27 19:32 ` Simon Marchi
2021-09-28 15:10 ` Tom de Vries
2021-09-28 19:12 ` Simon Marchi
2021-09-28 19:31 ` Pedro Alves
2021-09-28 19:35 ` Pedro Alves
2021-09-28 23:32 ` Simon Marchi
2021-09-28 22:38 ` Tom de Vries
2021-09-23 19:23 ` [PATCH 1/6] gdb.base/foll-fork.exp: remove DUPLICATEs Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210910205402.3853607-3-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).