This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug gdb/21954] New: "run" stops too early with detach-on-fork=off


https://sourceware.org/bugzilla/show_bug.cgi?id=21954

            Bug ID: 21954
           Summary: "run" stops too early with detach-on-fork=off
           Product: gdb
           Version: unknown
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: tromey at sourceware dot org
  Target Milestone: ---

Consider this program:

#include <unistd.h>
int main () {
  if (fork () == 0) {
    sleep(10);
  }
  return 0;
}


Start gdb.  "set detach-on-fork off".  Then "run".

What I expect to happen is that I will get a gdb prompt back when
both inferiors have stopped.  My reason for this is that it seems
more "shell-like", but also because I think a process exit shouldn't
be a stop-worth event, at least not (1) when other processes are running,
or (2) there isn't a "catch exit" in place (which is a hypothetical
command but seems like a decent idea).

What actually happens is that I get a prompt after the parent exits.
Then, in all-stop, the other inferior is attached, but stopped.
In non-stop, the child process continues to run in the background.

This patch works ok for non-stop but I don't really know if it makes sense.
And, it doesn't work for all-stop, presumably because the child has
already been stopped at this point, and nothing restarts it.

diff --git a/gdb/infrun.c b/gdb/infrun.c
index d6723fd..c51bec6 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -5128,7 +5128,12 @@ Cannot fill $_exitsignal with the correct signal
number.\n"));
       gdb_flush (gdb_stdout);
       target_mourn_inferior (inferior_ptid);
       stop_print_frame = 0;
-      stop_waiting (ecs);
+      /* In multi-inferior, there might still be other processes
+        running.  Only stop waiting if everything has exited.  */
+      if (have_live_inferiors ())
+       prepare_to_wait (ecs);
+      else
+       stop_waiting (ecs);
       return;

       /* The following are the only cases in which we keep going;

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]