]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: change store_waitstatus to return a target_waitstatus by value
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 1 Dec 2021 18:09:56 +0000 (13:09 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 3 Dec 2021 13:31:05 +0000 (08:31 -0500)
store_waitstatus is basically a translation function between a status
integer and an equivalent target_waitstatus object.  It would make sense
for it to take the integer as a parameter and return the
target_waitstatus by value.  Do that, and rename to
host_status_to_waitstatus.  Users can then do:

  ws = host_status_to_waitstatus (status)

which does the right thing, given the move constructor of
target_waitstatus.

Change-Id: I7a07d59d3dc19d3ed66929642f82f44f3e85d61b

gdb/gnu-nat.c
gdb/inf-child.c
gdb/inf-child.h
gdb/inf-ptrace.c
gdb/linux-nat.c
gdb/netbsd-nat.c
gdb/procfs.c
gdb/rs6000-aix-nat.c

index 13127cd82461068e6b7ea20e4170b81d7f1a5437..6ea836a1a4987630126c49f4ddf3c5bdea4d40b1 100644 (file)
@@ -1821,7 +1821,7 @@ S_proc_wait_reply (mach_port_t reply, kern_return_t err,
     }
   else if (pid == inf->pid)
     {
-      store_waitstatus (&inf->wait.status, status);
+      inf->wait.status = host_status_to_waitstatus (status);
       if (inf->wait.status.kind () == TARGET_WAITKIND_STOPPED)
        /* The process has sent us a signal, and stopped itself in a sane
           state pending our actions.  */
index 5e821f4559825030db9f3376e970181b84ad5ff3..b65bbf30074762565348cc2ad196dc33cfe609b8 100644 (file)
@@ -51,18 +51,19 @@ inf_child_target::info () const
   return inf_child_target_info;
 }
 
-/* Helper function for child_wait and the derivatives of child_wait.
-   HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
-   translation of that in OURSTATUS.  */
-void
-store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
+/* See inf-child.h.  */
+
+target_waitstatus
+host_status_to_waitstatus (int hoststatus)
 {
   if (WIFEXITED (hoststatus))
-    ourstatus->set_exited (WEXITSTATUS (hoststatus));
+    return target_waitstatus ().set_exited (WEXITSTATUS (hoststatus));
   else if (!WIFSTOPPED (hoststatus))
-    ourstatus->set_signalled (gdb_signal_from_host (WTERMSIG (hoststatus)));
+    return target_waitstatus ().set_signalled
+      (gdb_signal_from_host (WTERMSIG (hoststatus)));
   else
-    ourstatus->set_stopped (gdb_signal_from_host (WSTOPSIG (hoststatus)));
+    return target_waitstatus ().set_stopped
+      (gdb_signal_from_host (WSTOPSIG (hoststatus)));
 }
 
 inf_child_target::~inf_child_target ()
index aa33c5381381103e27cc0ea3f4517fe1239d8894..1e009b6b74ae98f32b55f812ac64dfc0b0f9fe8d 100644 (file)
@@ -104,10 +104,9 @@ protected:
   void maybe_unpush_target ();
 };
 
-/* Functions for helping to write a native target.  */
+/* Convert the host wait(2) status to a target_waitstatus.  */
 
-/* This is for native targets which use a unix/POSIX-style waitstatus.  */
-extern void store_waitstatus (struct target_waitstatus *, int);
+extern target_waitstatus host_status_to_waitstatus (int hoststatus);
 
 /* Register TARGET as native target and set it up to respond to the
    "target native" command.  */
index 852636ba646f5249f0f666c5e493f86e4ae85628..2e7a03c63f5e460828cdc61cf73cdb313e8b9360 100644 (file)
@@ -334,7 +334,8 @@ inf_ptrace_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
     }
   while (pid == -1);
 
-  store_waitstatus (ourstatus, status);
+  *ourstatus = host_status_to_waitstatus (status);
+
   return ptid_t (pid);
 }
 
index fbb60a398b0c9e355e0b68646fd4ce8372fe3ba8..656a0975dddfc6fd5f9c4156990338db6b77a8f1 100644 (file)
@@ -2159,7 +2159,7 @@ wait_lwp (struct lwp_info *lp)
                 process is gone.  Store the status to report to the
                 core.  Store it in lp->waitstatus, because lp->status
                 would be ambiguous (W_EXITCODE(0,0) == 0).  */
-             store_waitstatus (&lp->waitstatus, status);
+             lp->waitstatus = host_status_to_waitstatus (status);
              return 0;
            }
 
@@ -2932,7 +2932,7 @@ linux_nat_filter_event (int lwpid, int status)
 
       /* Store the pending event in the waitstatus, because
         W_EXITCODE(0,0) == 0.  */
-      store_waitstatus (&lp->waitstatus, status);
+      lp->waitstatus = host_status_to_waitstatus (status);
       return;
     }
 
@@ -3306,7 +3306,7 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
       lp->waitstatus.set_ignore ();
     }
   else
-    store_waitstatus (ourstatus, status);
+    *ourstatus = host_status_to_waitstatus (status);
 
   linux_nat_debug_printf ("exit");
 
index e06c036fcdd3b8515931726ae416cd05785a7bdd..7dfc586fc7b18acb1655d865a10fd81fd0f4e88a 100644 (file)
@@ -560,7 +560,7 @@ nbsd_wait (ptid_t ptid, struct target_waitstatus *ourstatus,
   if (pid == -1)
     perror_with_name (_("Child process unexpectedly missing"));
 
-  store_waitstatus (ourstatus, status);
+  *ourstatus = host_status_to_waitstatus (status);
   return pid;
 }
 
index 2c96919dcebd47aa9dcfc44f38b145ab8acea485..d77458b6c6ab29bd4e57778e3b5da7cc183ec0b7 100644 (file)
@@ -2353,7 +2353,7 @@ wait_again:
        }
 
       if (status)
-       store_waitstatus (status, wstat);
+       *status = host_status_to_waitstatus (wstat);
     }
 
   return retval;
index 72e59e5e4844783489a4b714a383c0b3be169314..d74211f048e6e77763fb92439e7dced8e175f47c 100644 (file)
@@ -539,7 +539,7 @@ rs6000_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
     ourstatus->set_spurious ();
   /* A normal waitstatus.  Let the usual macros deal with it.  */
   else
-    store_waitstatus (ourstatus, status);
+    *ourstatus = host_status_to_waitstatus (status);
 
   return ptid_t (pid);
 }