Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] Fix `shell' command for async (PR 12850)
@ 2011-06-07 15:24 Jan Kratochvil
  2011-06-07 17:13 ` Pedro Alves
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2011-06-07 15:24 UTC (permalink / raw)
  To: gdb-patches

Hi,

this was completely debugged by Pedro so just wrote it and posted.
I mentioned+filed this problem at:
	Re: Sending signal to inferior program.
	http://sourceware.org/ml/gdb/2011-06/msg00036.html

procfs.c contains such fix but #if0-ed, left it as is:
    /* FIXME: should we use waitpid to make sure we get the right event?
       Should we check the returned event?  */
    {
#if 0
      int status, ret;

      ret = waitpid (pi->pid, &status, 0);
#else
      wait (NULL);
#endif

proc-api.c also contains dangerous wait() call but both are for procfs
platforms.

No regressions on {x86_64,x86_64-m32,i686}-fedora15-linux-gnu.  I have not
regression tested the modified PPC* file.  The testcase can have false PASS
(with buggy GDB) but I do not see how to avoid it.

I will check it in with no comments.


Thanks,
Jan


gdb/
2011-06-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* cli/cli-cmds.c (shell_escape): Use waitpid.
	* rs6000-nat.c (exec_one_dummy_insn): Likewise.

gdb/testsuite/
2011-06-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.base/async-shell.c: New file.
	* gdb.base/async-shell.exp: New file.

--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -750,7 +750,7 @@ shell_escape (char *arg, int from_tty)
     }
 
   if (pid != -1)
-    while ((rc = wait (&status)) != pid && rc != -1)
+    while ((rc = waitpid (pid, &status, 0)) != pid && rc != -1)
       ;
   else
     error (_("Fork failed"));
--- a/gdb/rs6000-nat.c
+++ b/gdb/rs6000-nat.c
@@ -614,7 +614,7 @@ exec_one_dummy_insn (struct regcache *regcache)
 
   do
     {
-      pid = wait (&status);
+      pid = waitpid (PIDGET (inferior_ptid), &status, 0);
     }
   while (pid != PIDGET (inferior_ptid));
 
--- /dev/null
+++ b/gdb/testsuite/gdb.base/async-shell.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2011 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 <http://www.gnu.org/licenses/>.  */
+
+int
+main (void)
+{
+  return sleep (600);
+}
--- /dev/null
+++ b/gdb/testsuite/gdb.base/async-shell.exp
@@ -0,0 +1,42 @@
+# Copyright (C) 2011 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 <http://www.gnu.org/licenses/>.
+
+set testfile async-shell
+if { [prepare_for_testing ${testfile}.exp ${testfile}] } {
+    return -1
+}
+
+gdb_test_no_output "set target-async on "
+gdb_test_no_output "set non-stop on"
+gdb_test "run &" "Starting program: \[^\r\n\]*"
+
+# `sleep 5' here would workaround the bug, do not sleep here.
+# "shell" could eat waitpid event from the asynchronous inferior process.
+
+gdb_test "shell echo foo" "foo"
+
+set test "interrupt"
+gdb_test_multiple $test $test {
+    -re "interrupt\r\n$gdb_prompt " {
+	pass $test
+    }
+}
+
+set test "process stopped"
+gdb_test_multiple "" $test {
+    -re "\r\n\\\[process \[0-9\]+\\\] #1 stopped\\\.\r\n" {
+	pass $test
+    }
+}


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] Fix `shell' command for async (PR 12850)
  2011-06-07 15:24 [patch] Fix `shell' command for async (PR 12850) Jan Kratochvil
@ 2011-06-07 17:13 ` Pedro Alves
  2011-06-07 17:28   ` Jan Kratochvil
  2011-06-07 19:06   ` Joel Brobecker
  0 siblings, 2 replies; 7+ messages in thread
From: Pedro Alves @ 2011-06-07 17:13 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Kratochvil

On Tuesday 07 June 2011 16:24:09, Jan Kratochvil wrote:
> Hi,
> 
> this was completely debugged by Pedro so just wrote it and posted.

Thanks!  And thanks for writing a test as well.

> --- a/gdb/cli/cli-cmds.c
> +++ b/gdb/cli/cli-cmds.c
> @@ -750,7 +750,7 @@ shell_escape (char *arg, int from_tty)
>      }
>  
>    if (pid != -1)
> -    while ((rc = wait (&status)) != pid && rc != -1)
> +    while ((rc = waitpid (pid, &status, 0)) != pid && rc != -1)
>        ;

Pedantically, I think this could be simplified.  PID is
a specific pid, not -1, and when WNOHANG is not used,
waitpid(pid, ..., 0) can only return pid or -1.
Thus, the loop only ever executes once.

> +++ b/gdb/rs6000-nat.c
> @@ -614,7 +614,7 @@ exec_one_dummy_insn (struct regcache *regcache)

(Urgh, had never seen this bizarre code before.  I wonder if 
this is still needed on any sane platform, or if it was only
necessary on some ancient aix.)

-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] Fix `shell' command for async (PR 12850)
  2011-06-07 17:13 ` Pedro Alves
@ 2011-06-07 17:28   ` Jan Kratochvil
  2011-06-07 19:06   ` Joel Brobecker
  1 sibling, 0 replies; 7+ messages in thread
From: Jan Kratochvil @ 2011-06-07 17:28 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Tue, 07 Jun 2011 19:13:24 +0200, Pedro Alves wrote:
> > -    while ((rc = wait (&status)) != pid && rc != -1)
> > +    while ((rc = waitpid (pid, &status, 0)) != pid && rc != -1)
> >        ;
> 
> Pedantically, I think this could be simplified.  PID is
> a specific pid, not -1, and when WNOHANG is not used,
> waitpid(pid, ..., 0) can only return pid or -1.
> Thus, the loop only ever executes once.

Oops, yes, changed.

Checked in.


Thanks,
Jan


http://sourceware.org/ml/gdb-cvs/2011-06/msg00039.html

--- src/gdb/ChangeLog	2011/06/07 12:31:03	1.13083
+++ src/gdb/ChangeLog	2011/06/07 17:26:41	1.13084
@@ -1,3 +1,9 @@
+2011-06-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
+	    Pedro Alves  <pedro@codesourcery.com>
+
+	* cli/cli-cmds.c (shell_escape): Use waitpid.
+	* rs6000-nat.c (exec_one_dummy_insn): Likewise.
+
 2011-06-07  Tristan Gingold  <gingold@adacore.com>
 
 	* xcoffread.c (dwarf2_xcoff_names): New variable.
--- src/gdb/testsuite/ChangeLog	2011/06/06 13:33:07	1.2739
+++ src/gdb/testsuite/ChangeLog	2011/06/07 17:26:46	1.2740
@@ -1,3 +1,8 @@
+2011-06-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* gdb.base/async-shell.c: New file.
+	* gdb.base/async-shell.exp: New file.
+
 2011-06-06  Pedro Alves  <pedro@codesourcery.com>
 
 	* gdb.threads/pending-step.exp: Add more context to SIGTRAP match.
--- src/gdb/rs6000-nat.c	2011/01/11 15:10:01	1.104
+++ src/gdb/rs6000-nat.c	2011/06/07 17:26:45	1.105
@@ -614,7 +614,7 @@
 
   do
     {
-      pid = wait (&status);
+      pid = waitpid (PIDGET (inferior_ptid), &status, 0);
     }
   while (pid != PIDGET (inferior_ptid));
 
--- src/gdb/cli/cli-cmds.c	2011/04/04 17:41:07	1.113
+++ src/gdb/cli/cli-cmds.c	2011/06/07 17:26:46	1.114
@@ -726,7 +726,7 @@
   chdir (current_directory);
 #endif
 #else /* Can fork.  */
-  int rc, status, pid;
+  int status, pid;
 
   if ((pid = vfork ()) == 0)
     {
@@ -750,8 +750,7 @@
     }
 
   if (pid != -1)
-    while ((rc = wait (&status)) != pid && rc != -1)
-      ;
+    waitpid (pid, &status, 0);
   else
     error (_("Fork failed"));
 #endif /* Can fork.  */
--- src/gdb/testsuite/gdb.base/async-shell.c
+++ src/gdb/testsuite/gdb.base/async-shell.c	2011-06-07 17:27:07.593604000 +0000
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2011 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 <http://www.gnu.org/licenses/>.  */
+
+int
+main (void)
+{
+  return sleep (600);
+}
--- src/gdb/testsuite/gdb.base/async-shell.exp
+++ src/gdb/testsuite/gdb.base/async-shell.exp	2011-06-07 17:27:07.926556000 +0000
@@ -0,0 +1,42 @@
+# Copyright (C) 2011 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 <http://www.gnu.org/licenses/>.
+
+set testfile async-shell
+if { [prepare_for_testing ${testfile}.exp ${testfile}] } {
+    return -1
+}
+
+gdb_test_no_output "set target-async on "
+gdb_test_no_output "set non-stop on"
+gdb_test "run &" "Starting program: \[^\r\n\]*"
+
+# `sleep 5' here would workaround the bug, do not sleep here.
+# "shell" could eat waitpid event from the asynchronous inferior process.
+
+gdb_test "shell echo foo" "foo"
+
+set test "interrupt"
+gdb_test_multiple $test $test {
+    -re "interrupt\r\n$gdb_prompt " {
+	pass $test
+    }
+}
+
+set test "process stopped"
+gdb_test_multiple "" $test {
+    -re "\r\n\\\[process \[0-9\]+\\\] #1 stopped\\\.\r\n" {
+	pass $test
+    }
+}


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] Fix `shell' command for async (PR 12850)
  2011-06-07 17:13 ` Pedro Alves
  2011-06-07 17:28   ` Jan Kratochvil
@ 2011-06-07 19:06   ` Joel Brobecker
  2011-06-07 22:57     ` Pedro Alves
  1 sibling, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2011-06-07 19:06 UTC (permalink / raw)
  To: Pedro Alves, Ulrich.Weigand; +Cc: gdb-patches

> > +++ b/gdb/rs6000-nat.c
> > @@ -614,7 +614,7 @@ exec_one_dummy_insn (struct regcache *regcache)
> 
> (Urgh, had never seen this bizarre code before.  I wonder if 
> this is still needed on any sane platform, or if it was only
> necessary on some ancient aix.)

I think it's worth testing. From the logs that I could gather,
this function was already there in 1992 (!) but it's not entirely
clear that it was for AIX.  But, right now, I'd have a hard time
believing that it would be for any other kernel but AIX (the other
ones I can see are (Linux, *BSDs).

The oldest AIX we have now at AdaCore is 5.2. I'm wondering if Ulrich
might have access to something a little older?

-- 
Joel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] Fix `shell' command for async (PR 12850)
  2011-06-07 19:06   ` Joel Brobecker
@ 2011-06-07 22:57     ` Pedro Alves
  2011-06-15 17:03       ` Ulrich Weigand
  0 siblings, 1 reply; 7+ messages in thread
From: Pedro Alves @ 2011-06-07 22:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker, Ulrich.Weigand

On Tuesday 07 June 2011 20:05:59, Joel Brobecker wrote:
> > > +++ b/gdb/rs6000-nat.c
> > > @@ -614,7 +614,7 @@ exec_one_dummy_insn (struct regcache *regcache)
> > 
> > (Urgh, had never seen this bizarre code before.  I wonder if 
> > this is still needed on any sane platform, or if it was only
> > necessary on some ancient aix.)
> 
> I think it's worth testing. 

That'd be great.  It'd get rid of another instance of
deprecated_insert_raw_breakpoint along with the bizarreness. :-)

> From the logs that I could gather,
> this function was already there in 1992 (!) but it's not entirely
> clear that it was for AIX.  But, right now, I'd have a hard time
> believing that it would be for any other kernel but AIX (the other
> ones I can see are (Linux, *BSDs).

It can only be for AIX, AFAICS.  grepping for rs6000-nat.o
only hits on gdb/config/powerpc/aix.mh --- the whole rs6000-nat.c
file is AIX only.

> The oldest AIX we have now at AdaCore is 5.2. I'm wondering if Ulrich
> might have access to something a little older?

-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] Fix `shell' command for async (PR 12850)
  2011-06-07 22:57     ` Pedro Alves
@ 2011-06-15 17:03       ` Ulrich Weigand
  2011-06-15 17:23         ` Joel Brobecker
  0 siblings, 1 reply; 7+ messages in thread
From: Ulrich Weigand @ 2011-06-15 17:03 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Joel Brobecker, Ulrich.Weigand

Pedro Alves wrote:
> On Tuesday 07 June 2011 20:05:59, Joel Brobecker wrote:
> > > > +++ b/gdb/rs6000-nat.c
> > > > @@ -614,7 +614,7 @@ exec_one_dummy_insn (struct regcache *regcache)
> > > 
> > > (Urgh, had never seen this bizarre code before.  I wonder if 
> > > this is still needed on any sane platform, or if it was only
> > > necessary on some ancient aix.)
> > 
> > I think it's worth testing. 
> 
> That'd be great.  It'd get rid of another instance of
> deprecated_insert_raw_breakpoint along with the bizarreness. :-)

Unfortunately, I have no idea either whether this is still necessary
on any (reasonably) current AIX version ...

> > From the logs that I could gather,
> > this function was already there in 1992 (!) but it's not entirely
> > clear that it was for AIX.  But, right now, I'd have a hard time
> > believing that it would be for any other kernel but AIX (the other
> > ones I can see are (Linux, *BSDs).
> 
> It can only be for AIX, AFAICS.  grepping for rs6000-nat.o
> only hits on gdb/config/powerpc/aix.mh --- the whole rs6000-nat.c
> file is AIX only.

Yes, that file is AIX only.

> > The oldest AIX we have now at AdaCore is 5.2. I'm wondering if Ulrich
> > might have access to something a little older?

The only AIX I have access to is 5.3, sorry ...

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] Fix `shell' command for async (PR 12850)
  2011-06-15 17:03       ` Ulrich Weigand
@ 2011-06-15 17:23         ` Joel Brobecker
  0 siblings, 0 replies; 7+ messages in thread
From: Joel Brobecker @ 2011-06-15 17:23 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: Pedro Alves, gdb-patches, Ulrich.Weigand

> > > The oldest AIX we have now at AdaCore is 5.2. I'm wondering if Ulrich
> > > might have access to something a little older?
> 
> The only AIX I have access to is 5.3, sorry ...

OK, I guess that it means I'm on duty for AIX testing ;-).

If neither of us has access to an older version of AIX (5.2),
I think it is reasonable to drop support for anything that's older.

-- 
Joel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-06-15 17:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-07 15:24 [patch] Fix `shell' command for async (PR 12850) Jan Kratochvil
2011-06-07 17:13 ` Pedro Alves
2011-06-07 17:28   ` Jan Kratochvil
2011-06-07 19:06   ` Joel Brobecker
2011-06-07 22:57     ` Pedro Alves
2011-06-15 17:03       ` Ulrich Weigand
2011-06-15 17:23         ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox