From: Pedro Alves <palves@redhat.com>
To: Pedro Alves <palves@redhat.com>,
Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: Doug Evans <dje@google.com>, Mark Wielaard <mjw@redhat.com>,
gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] testsuite: refactor spawn and wait for attach
Date: Thu, 11 Sep 2014 12:34:00 -0000 [thread overview]
Message-ID: <541196E5.3090708@redhat.com> (raw)
In-Reply-To: <5410C1DD.1090200@redhat.com>
On 09/10/2014 10:25 PM, Pedro Alves wrote:
> On 09/09/2014 06:35 PM, Pedro Alves wrote:
>> On 09/09/2014 06:29 PM, Jan Kratochvil wrote:
>>> On Mon, 08 Sep 2014 18:19:17 +0200, Pedro Alves wrote:
>>>> Indeed it could. I've done that now. See below. There were actually more
>>>> places around the testsuite that have that same code. Let me know how it looks
>>>> to you.
>>>
>>> As long as it has been tested on *-*-cygwin* I do not see anything wrong
>>> there.
>>
>> It hasn't. I wonder if someone can help with this?
>
> FYI, Keith was kind enough to run testing and sent me the logs,
> though I haven't analyzed them yet.
There was a silly bug, causing new Cygwin fails.
lreplace was being misused. This fixed it:
+++ w/gdb/testsuite/lib/gdb.exp
@@ -3381,7 +3381,7 @@ proc spawn_wait_for_attach { executable_list } {
# which might be different due to the way fork/exec works.
set testpid [lindex $pid_list $i]
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
- lreplace $i $i $testpid
+ set pid_list [lreplace $pid_list $i $i $testpid]
}
}
I borrowed the wife's laptop and managed to test the fix
on Cygwin myself (boy is that slow...).
Here's what I pushed to both master and 7.8.
----
From 7ec5670becb3f978f4d2f4df252ad0cbf805e37a Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Thu, 11 Sep 2014 13:14:47 +0100
Subject: [PATCH] testsuite: refactor spawn and wait for attach
Several places in the testsuite have a copy of a snippet of code that
spawns a test program, waits a bit, and then does some PID munging for
Cygwin. This is in order to have GDB attach to the spawned program.
This refactors all that to a common procedure.
(multi-attach.exp wants to spawn multiple processes, so this makes the
new procedure's interface work with lists.)
Tested on x86_64 Fedora 20.
gdb/testsuite/ChangeLog:
2014-09-11 Pedro Alves <palves@redhat.com>
* lib/gdb.exp (spawn_wait_for_attach): New procedure.
* gdb.base/attach.exp (do_attach_tests, do_call_attach_tests)
(do_command_attach_tests): Use spawn_wait_for_attach.
* gdb.base/solib-overlap.exp: Likewise.
* gdb.multi/multi-attach.exp: Likewise.
* gdb.python/py-prompt.exp: Likewise.
* gdb.python/py-sync-interp.exp: Likewise.
* gdb.server/ext-attach.exp: Likewise.
---
gdb/testsuite/ChangeLog | 11 ++++++++
gdb/testsuite/gdb.base/attach.exp | 41 +++--------------------------
gdb/testsuite/gdb.base/solib-overlap.exp | 11 +-------
gdb/testsuite/gdb.multi/multi-attach.exp | 13 +++------
gdb/testsuite/gdb.python/py-prompt.exp | 10 +------
gdb/testsuite/gdb.python/py-sync-interp.exp | 10 +------
gdb/testsuite/gdb.server/ext-attach.exp | 10 +------
gdb/testsuite/lib/gdb.exp | 25 ++++++++++++++++++
8 files changed, 48 insertions(+), 83 deletions(-)
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index f85f9b5..a388194 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,14 @@
+2014-09-11 Pedro Alves <palves@redhat.com>
+
+ * lib/gdb.exp (spawn_wait_for_attach): New procedure.
+ * gdb.base/attach.exp (do_attach_tests, do_call_attach_tests)
+ (do_command_attach_tests): Use spawn_wait_for_attach.
+ * gdb.base/solib-overlap.exp: Likewise.
+ * gdb.multi/multi-attach.exp: Likewise.
+ * gdb.python/py-prompt.exp: Likewise.
+ * gdb.python/py-sync-interp.exp: Likewise.
+ * gdb.server/ext-attach.exp: Likewise.
+
2014-09-07 Jan Kratochvil <jan.kratochvil@redhat.com>
PR python/17355
diff --git a/gdb/testsuite/gdb.base/attach.exp b/gdb/testsuite/gdb.base/attach.exp
index 9714c29..a20c51a 100644
--- a/gdb/testsuite/gdb.base/attach.exp
+++ b/gdb/testsuite/gdb.base/attach.exp
@@ -70,13 +70,7 @@ proc do_attach_tests {} {
# Start the program running and then wait for a bit, to be sure
# that it can be attached to.
- set testpid [eval exec $binfile &]
- exec sleep 2
- if { [istarget "*-*-cygwin*"] } {
- # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
- # different due to the way fork/exec works.
- set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
- }
+ set testpid [spawn_wait_for_attach $binfile]
# Verify that we cannot attach to nonsense.
@@ -279,16 +273,7 @@ proc do_attach_tests {} {
remote_exec build "kill -9 ${testpid}"
- # Start the program running and then wait for a bit, to be sure
- # that it can be attached to.
-
- set testpid [eval exec $binfile &]
- exec sleep 2
- if { [istarget "*-*-cygwin*"] } {
- # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
- # different due to the way fork/exec works.
- set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
- }
+ set testpid [spawn_wait_for_attach $binfile]
# Verify that we can attach to the process, and find its a.out
# when we're cd'd to some directory that doesn't contain the
@@ -335,16 +320,7 @@ proc do_call_attach_tests {} {
global gdb_prompt
global binfile2
- # Start the program running and then wait for a bit, to be sure
- # that it can be attached to.
-
- set testpid [eval exec $binfile2 &]
- exec sleep 2
- if { [istarget "*-*-cygwin*"] } {
- # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
- # different due to the way fork/exec works.
- set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
- }
+ set testpid [spawn_wait_for_attach $binfile2]
# Attach
@@ -397,16 +373,7 @@ proc do_command_attach_tests {} {
return 0
}
- # Start the program running and then wait for a bit, to be sure
- # that it can be attached to.
-
- set testpid [eval exec $binfile &]
- exec sleep 2
- if { [istarget "*-*-cygwin*"] } {
- # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
- # different due to the way fork/exec works.
- set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
- }
+ set testpid [spawn_wait_for_attach $binfile]
gdb_exit
if $verbose>1 then {
diff --git a/gdb/testsuite/gdb.base/solib-overlap.exp b/gdb/testsuite/gdb.base/solib-overlap.exp
index 68731be..7486b07 100644
--- a/gdb/testsuite/gdb.base/solib-overlap.exp
+++ b/gdb/testsuite/gdb.base/solib-overlap.exp
@@ -82,16 +82,7 @@ foreach prelink_lib1 {0x40000000 0x50000000} { with_test_prefix "$prelink_lib1"
return -1
}
- # Start the program running and then wait for a bit, to be sure
- # that it can be attached to.
-
- set testpid [eval exec $binfile &]
- sleep 2
- if { [istarget "*-*-cygwin*"] } {
- # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
- # different due to the way fork/exec works.
- set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
- }
+ set testpid [spawn_wait_for_attach $binfile]
remote_exec build "mv -f ${binfile_lib1} ${binfile_lib1}-running"
remote_exec build "mv -f ${binfile_lib2} ${binfile_lib2}-running"
diff --git a/gdb/testsuite/gdb.multi/multi-attach.exp b/gdb/testsuite/gdb.multi/multi-attach.exp
index e933520..eaff2c9 100644
--- a/gdb/testsuite/gdb.multi/multi-attach.exp
+++ b/gdb/testsuite/gdb.multi/multi-attach.exp
@@ -30,15 +30,10 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug additiona
# Start the programs running and then wait for a bit, to be sure that
# they can be attached to.
-set testpid1 [eval exec $binfile &]
-set testpid2 [eval exec $binfile &]
-exec sleep 2
-if { [istarget "*-*-cygwin*"] } {
- # testpid{1,2} are the Cygwin PID, GDB uses the Windows PID, which might be
- # different due to the way fork/exec works.
- set testpid1 [ exec ps -e | gawk "{ if (\$1 == $testpid1) print \$4; }" ]
- set testpid2 [ exec ps -e | gawk "{ if (\$1 == $testpid2) print \$4; }" ]
-}
+
+set pid_list [spawn_wait_for_attach [list $binfile $binfile]]
+set testpid1 [lindex $pid_list 0]
+set testpid2 [lindex $pid_list 1]
gdb_test "attach $testpid1" \
"Attaching to program: .*, process $testpid1.*(in|at).*" \
diff --git a/gdb/testsuite/gdb.python/py-prompt.exp b/gdb/testsuite/gdb.python/py-prompt.exp
index ebe4cb6..1c53c03 100644
--- a/gdb/testsuite/gdb.python/py-prompt.exp
+++ b/gdb/testsuite/gdb.python/py-prompt.exp
@@ -80,15 +80,7 @@ gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
"prompt_hook argument is default prompt. 2"
gdb_exit
-# Start the program running and then wait for a bit, to be sure
-# that it can be attached to.
-set testpid [eval exec $binfile &]
-exec sleep 2
-if { [istarget "*-*-cygwin*"] } {
- # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
- # different due to the way fork/exec works.
- set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
-}
+set testpid [spawn_wait_for_attach $binfile]
set GDBFLAGS [concat $tmp_gdbflags " -ex \"set pagination off\""]
set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
diff --git a/gdb/testsuite/gdb.python/py-sync-interp.exp b/gdb/testsuite/gdb.python/py-sync-interp.exp
index b9b86bc..d62f966 100644
--- a/gdb/testsuite/gdb.python/py-sync-interp.exp
+++ b/gdb/testsuite/gdb.python/py-sync-interp.exp
@@ -41,15 +41,7 @@ if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
return -1
}
-# Start the program running and then wait for a bit, to be sure
-# that it can be attached to.
-set testpid [eval exec $binfile &]
-exec sleep 2
-if { [istarget "*-*-cygwin*"] } {
- # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
- # different due to the way fork/exec works.
- set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
-}
+set testpid [spawn_wait_for_attach $binfile]
# Test command 'where' is executed when command 'attach' is done, otherwise
# function 'sleep' may not show up in backtrace.
diff --git a/gdb/testsuite/gdb.server/ext-attach.exp b/gdb/testsuite/gdb.server/ext-attach.exp
index 5f7bac4..9baeeb7 100644
--- a/gdb/testsuite/gdb.server/ext-attach.exp
+++ b/gdb/testsuite/gdb.server/ext-attach.exp
@@ -44,15 +44,7 @@ gdbserver_start_extended
gdb_test_no_output "set remote exec-file $target_exec" "set remote exec-file"
-# Start the program running and then wait for a bit, to be sure
-# that it can be attached to.
-set testpid [eval exec $binfile &]
-exec sleep 2
-if { [istarget "*-*-cygwin*"] } {
- # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
- # different due to the way fork/exec works.
- set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
-}
+set testpid [spawn_wait_for_attach $binfile]
gdb_test "attach $testpid" \
"Attaching to program: .*, process $testpid.*(in|at).*" \
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 7650d2a..e2ee110 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3323,6 +3323,31 @@ proc gdb_exit { } {
catch default_gdb_exit
}
+# Start a set of programs running and then wait for a bit, to be sure
+# that they can be attached to. Return a list of the processes' PIDs.
+
+proc spawn_wait_for_attach { executable_list } {
+ set pid_list {}
+
+ foreach {executable} $executable_list {
+ lappend pid_list [eval exec $executable &]
+ }
+
+ sleep 2
+
+ if { [istarget "*-*-cygwin*"] } {
+ for {set i 0} {$i < [llength $pid_list]} {incr i} {
+ # testpid is the Cygwin PID, GDB uses the Windows PID,
+ # which might be different due to the way fork/exec works.
+ set testpid [lindex $pid_list $i]
+ set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
+ set pid_list [lreplace $pid_list $i $i $testpid]
+ }
+ }
+
+ return $pid_list
+}
+
#
# gdb_load_cmd -- load a file into the debugger.
# ARGS - additional args to load command.
--
1.9.3
next prev parent reply other threads:[~2014-09-11 12:34 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-23 20:59 [PATCH v6 0/2] enable target-async by default Pedro Alves
2014-05-23 20:59 ` [PATCH v6 1/2] Make display_gdb_prompt CLI-only Pedro Alves
2014-05-23 20:59 ` [PATCH v6 2/2] enable target async by default; separate MI and target notions of async Pedro Alves
2014-05-24 7:03 ` Eli Zaretskii
2014-05-29 13:49 ` Pedro Alves
2014-07-30 18:40 ` Doug Evans
2014-05-29 13:44 ` [pushed] Re: [PATCH v6 0/2] enable target-async by default Pedro Alves
2014-07-01 16:28 ` Regression for attach from stdin [Re: [pushed] Re: [PATCH v6 0/2] enable target-async by default] Jan Kratochvil
2014-07-02 8:59 ` Mark Wielaard
2014-07-02 9:16 ` Pedro Alves
2014-07-03 15:39 ` Pedro Alves
2014-07-04 13:48 ` [PATCH] Fix "attach" command vs user input race [Re: Regression for attach from stdin [Re: [pushed] Re: [PATCH v6 0/2] enable target-async by default]] Pedro Alves
2014-07-04 21:13 ` Mark Wielaard
2014-07-07 16:39 ` Doug Evans
2014-07-08 15:24 ` Pedro Alves
2014-07-09 16:37 ` Doug Evans
2014-07-09 17:09 ` [pushed+7.8] " Pedro Alves
2014-07-29 22:03 ` Doug Evans
2014-07-29 23:10 ` Doug Evans
2014-07-30 12:46 ` Pedro Alves
2014-07-30 12:38 ` Pedro Alves
2014-07-30 16:59 ` Doug Evans
2014-08-21 16:34 ` [PUSHED] infcmd.c: Remove stale TODO Pedro Alves
2014-09-03 7:59 ` Regression: GDB stopped on run with attached process (PR 17347) [Re: [pushed+7.8] Re: [PATCH] Fix "attach" command vs user input race [Re: Regression for attach from stdin [Re: [pushed] Re: [PATCH v6 0/2] enable target-async by default]]] Jan Kratochvil
2014-09-03 20:11 ` Regression: GDB stopped on run with attached process (PR 17347) [Re: [pushed+7.8] Re: [PATCH] Fix "attach" command vs user input race Pedro Alves
2014-09-07 19:28 ` Jan Kratochvil
2014-09-08 16:19 ` [PATCH 1/2] testsuite: refactor spawn and wait for attach (was: Re: Regression: GDB stopped on run with attached process) Pedro Alves
2014-09-09 17:29 ` Jan Kratochvil
2014-09-09 17:35 ` [PATCH 1/2] testsuite: refactor spawn and wait for attach Pedro Alves
2014-09-10 21:25 ` Pedro Alves
2014-09-11 12:34 ` Pedro Alves [this message]
2014-09-08 16:27 ` Regression: GDB stopped on run with attached process (PR 17347) [Re: [pushed+7.8] Re: [PATCH] Fix "attach" command vs user input race Pedro Alves
2014-09-09 18:25 ` Jan Kratochvil
2014-09-11 12:36 ` Pedro Alves
2014-09-12 7:34 ` [testsuite patch] runaway attach processes [Re: Regression: GDB stopped on run with attached process (PR 17347)] Jan Kratochvil
2014-09-12 10:14 ` Pedro Alves
2014-09-12 11:40 ` [commit] " Jan Kratochvil
2014-07-07 17:02 ` [PATCH] Fix "attach" command vs user input race [Re: Regression for attach from stdin [Re: [pushed] Re: [PATCH v6 0/2] enable target-async by default]] Jan Kratochvil
2014-10-05 14:00 ` Crash regression for annota1.exp w/vDSO debuginfo [Re: [pushed] Re: [PATCH v6 0/2] enable target-async by default] Jan Kratochvil
2014-10-05 14:14 ` Jan Kratochvil
2014-10-05 16:43 ` Jan Kratochvil
2014-10-09 15:48 ` 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=541196E5.3090708@redhat.com \
--to=palves@redhat.com \
--cc=dje@google.com \
--cc=gdb-patches@sourceware.org \
--cc=jan.kratochvil@redhat.com \
--cc=mjw@redhat.com \
/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