Remove expecting_notif parameter from getpkt_or_notif_sane_1
[binutils-gdb.git] / gdbserver / fork-child.cc
index c991ce3a9d31ecc434b0249f87622c3381b8ea34..e791a8d22f7614c5be04f7d25360f9cf1a04da0f 100644 (file)
@@ -1,5 +1,5 @@
 /* Fork a Unix child process, and set up to debug it, for GDBserver.
-   Copyright (C) 1989-2022 Free Software Foundation, Inc.
+   Copyright (C) 1989-2023 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -18,6 +18,7 @@
 
 #include "server.h"
 #include "gdbsupport/job-control.h"
+#include "gdbsupport/scoped_restore.h"
 #include "nat/fork-inferior.h"
 #ifdef HAVE_SIGNAL_H
 #include <signal.h>
@@ -45,11 +46,7 @@ void
 prefork_hook (const char *args)
 {
   client_state &cs = get_client_state ();
-  if (debug_threads)
-    {
-      debug_printf ("args: %s\n", args);
-      debug_flush ();
-    }
+  threads_debug_printf ("args: %s", args);
 
 #ifdef SIGTTOU
   signal (SIGTTOU, SIG_DFL);
@@ -107,9 +104,22 @@ post_fork_inferior (int pid, const char *program)
   atexit (restore_old_foreground_pgrp);
 #endif
 
+  process_info *proc = find_process_pid (pid);
+
+  /* If the inferior fails to start, startup_inferior mourns the
+     process (which deletes it), and then throws an error.  This means
+     that on exception return, we don't need or want to clear this
+     flag back, as PROC won't exist anymore.  Thus, we don't use a
+     scoped_restore.  */
+  proc->starting_up = true;
+
   startup_inferior (the_target, pid,
                    START_INFERIOR_TRAPS_EXPECTED,
                    &cs.last_status, &cs.last_ptid);
+
+  /* If we get here, the process was successfully started.  */
+  proc->starting_up = false;
+
   current_thread->last_resume_kind = resume_stop;
   current_thread->last_status = cs.last_status;
   signal_pid = pid;