gdb: fix python/lib/gdb/__init__.py formatting
[deliverable/binutils-gdb.git] / gdb / darwin-nat.c
index 2d74bc010c35e29a3048b880355b3be5d55d9706..a6790792fb651eb74a1a6e1ef15f5e5aaabddd6f 100644 (file)
@@ -1,5 +1,5 @@
 /* Darwin support for GDB, the GNU debugger.
-   Copyright (C) 2008-2020 Free Software Foundation, Inc.
+   Copyright (C) 2008-2021 Free Software Foundation, Inc.
 
    Contributed by AdaCore.
 
@@ -176,7 +176,7 @@ inferior_debug (int level, const char *fmt, ...)
 
 void
 mach_check_error (kern_return_t ret, const char *file,
-                  unsigned int line, const char *func)
+                 unsigned int line, const char *func)
 {
   if (ret == KERN_SUCCESS)
     return;
@@ -241,8 +241,8 @@ darwin_ptrace (const char *name,
     ret = 0;
 
   inferior_debug (4, _("ptrace (%s, %d, 0x%lx, %d): %d (%s)\n"),
-                  name, pid, (unsigned long) arg3, arg4, ret,
-                  (ret != 0) ? safe_strerror (errno) : _("no error"));
+                 name, pid, (unsigned long) arg3, arg4, ret,
+                 (ret != 0) ? safe_strerror (errno) : _("no error"));
   return ret;
 }
 
@@ -903,8 +903,6 @@ darwin_suspend_inferior_threads (struct inferior *inf)
 void
 darwin_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
 {
-  struct target_waitstatus status;
-
   int nsignal;
 
   inferior_debug
@@ -940,19 +938,19 @@ darwin_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
       darwin_suspend_inferior (inf);
 
       if (tid == 0)
-        darwin_resume_inferior_threads (inf, step, nsignal);
+       darwin_resume_inferior_threads (inf, step, nsignal);
       else
-        {
-          darwin_thread_t *thread;
+       {
+         darwin_thread_t *thread;
 
-          /* Suspend threads of the task.  */
-          darwin_suspend_inferior_threads (inf);
+         /* Suspend threads of the task.  */
+         darwin_suspend_inferior_threads (inf);
 
-          /* Resume the selected thread.  */
-          thread = darwin_find_thread (inf, tid);
-          gdb_assert (thread);
-          darwin_resume_thread (inf, thread, step, nsignal);
-        }
+         /* Resume the selected thread.  */
+         thread = darwin_find_thread (inf, tid);
+         gdb_assert (thread);
+         darwin_resume_thread (inf, thread, step, nsignal);
+       }
 
       /* Resume the task.  */
       darwin_resume_inferior (inf);
@@ -1111,8 +1109,7 @@ darwin_nat_target::decode_message (mach_msg_header_t *hdr,
              /* Looks necessary on Leopard and harmless...  */
              wait4 (inf->pid, &wstatus, 0, NULL);
 
-             inferior_ptid = ptid_t (inf->pid, 0, 0);
-             return inferior_ptid;
+             return ptid_t (inf->pid);
            }
          else
            {
@@ -1286,7 +1283,7 @@ darwin_nat_target::wait_1 (ptid_t ptid, struct target_waitstatus *status)
 
 ptid_t
 darwin_nat_target::wait (ptid_t ptid, struct target_waitstatus *status,
-                        int options)
+                        target_wait_flags options)
 {
   return wait_1 (ptid, status);
 }
@@ -1402,7 +1399,7 @@ darwin_nat_target::stop_inferior (inferior *inf)
   /* Wait until the process is really stopped.  */
   while (1)
     {
-      ptid = wait_1 (inferior_ptid, &wstatus);
+      ptid = wait_1 (ptid_t (inf->pid), &wstatus);
       if (wstatus.kind == TARGET_WAITKIND_STOPPED
          && wstatus.value.sig == GDB_SIGNAL_STOP)
        break;
@@ -1433,10 +1430,10 @@ darwin_restore_exception_ports (darwin_inferior *inf)
   for (i = 0; i < inf->exception_info.count; i++)
     {
       kret = task_set_exception_ports
-        (inf->task, inf->exception_info.masks[i], inf->exception_info.ports[i],
+       (inf->task, inf->exception_info.masks[i], inf->exception_info.ports[i],
         inf->exception_info.behaviors[i], inf->exception_info.flavors[i]);
       if (kret != KERN_SUCCESS)
-        return kret;
+       return kret;
     }
 
   return KERN_SUCCESS;
@@ -1509,31 +1506,31 @@ darwin_nat_target::kill ()
   if (res == 0)
     {
       /* On MacOS version Sierra, the darwin_restore_exception_ports call
-         does not work as expected.
-         When the kill function is called, the SIGKILL signal is received
-         by gdb whereas it should have been received by the kernel since
-         the exception ports have been restored.
-         This behavior is not the expected one thus gdb does not reply to
-         the received SIGKILL message. This situation leads to a "busy"
-         resource from the kernel point of view and the inferior is never
-         released, causing it to remain as a zombie process, even after
+        does not work as expected.
+        When the kill function is called, the SIGKILL signal is received
+        by gdb whereas it should have been received by the kernel since
+        the exception ports have been restored.
+        This behavior is not the expected one thus gdb does not reply to
+        the received SIGKILL message. This situation leads to a "busy"
+        resource from the kernel point of view and the inferior is never
+        released, causing it to remain as a zombie process, even after
         GDB exits.
-         To work around this, we mark all the threads of the inferior as
-         signaled thus darwin_decode_message function knows that the kill
-         signal was sent by gdb and will take the appropriate action
-         (cancel signal and reply to the signal message).  */
+        To work around this, we mark all the threads of the inferior as
+        signaled thus darwin_decode_message function knows that the kill
+        signal was sent by gdb and will take the appropriate action
+        (cancel signal and reply to the signal message).  */
       for (darwin_thread_t *thread : priv->threads)
-        thread->signaled = 1;
+       thread->signaled = 1;
 
       darwin_resume_inferior (inf);
 
-      ptid = wait_1 (inferior_ptid, &wstatus);
+      ptid = wait_1 (ptid_t (inf->pid), &wstatus);
     }
   else if (errno != ESRCH)
     warning (_("Failed to kill inferior: kill (%d, 9) returned [%s]"),
             inf->pid, safe_strerror (errno));
 
-  target_mourn_inferior (inferior_ptid);
+  target_mourn_inferior (ptid_t (inf->pid));
 }
 
 static void
@@ -1653,14 +1650,14 @@ darwin_attach_pid (struct inferior *inf)
   catch (const gdb_exception &ex)
     {
       exit_inferior (inf);
-      inferior_ptid = null_ptid;
+      switch_to_no_thread ();
 
       throw;
     }
 
   target_ops *darwin_ops = get_native_target ();
-  if (!target_is_pushed (darwin_ops))
-    push_target (darwin_ops);
+  if (!inf->target_is_pushed (darwin_ops))
+    inf->push_target (darwin_ops);
 }
 
 /* Get the thread_info object corresponding to this darwin_thread_info.  */
@@ -1692,7 +1689,7 @@ darwin_nat_target::init_thread_list (inferior *inf)
   struct thread_info *first_thread
     = thread_info_from_private_thread_info (first_pti);
 
-  inferior_ptid = first_thread->ptid;
+  switch_to_thread (first_thread);
 }
 
 /* The child must synchronize with gdb: gdb must set the exception port
@@ -1776,7 +1773,7 @@ darwin_execvp (const char *file, char * const argv[], char * const env[])
   if (res != 0)
     {
       fprintf_unfiltered
-        (gdb_stderr, "Cannot initialize attribute for posix_spawn\n");
+       (gdb_stderr, "Cannot initialize attribute for posix_spawn\n");
       return;
     }
 
@@ -1814,7 +1811,7 @@ may_have_sip ()
     {
       unsigned long ver = strtoul (str, NULL, 10);
       if (ver >= 16)
-        return true;
+       return true;
     }
   return false;
 }
@@ -2025,9 +2022,8 @@ darwin_nat_target::attach (const char *args, int from_tty)
 
   if (pid == 0 || ::kill (pid, 0) < 0)
     error (_("Can't attach to process %d: %s (%d)"),
-           pid, safe_strerror (errno), errno);
+          pid, safe_strerror (errno), errno);
 
-  inferior_ptid = ptid_t (pid);
   inf = current_inferior ();
   inferior_appeared (inf, pid);
   inf->attach_flag = 1;
@@ -2329,10 +2325,10 @@ darwin_nat_target::xfer_partial (enum target_object object, const char *annex,
 #ifdef TASK_DYLD_INFO_COUNT
     case TARGET_OBJECT_DARWIN_DYLD_INFO:
       if (writebuf != NULL || readbuf == NULL)
-        {
-          /* Support only read.  */
-          return TARGET_XFER_E_IO;
-        }
+       {
+         /* Support only read.  */
+         return TARGET_XFER_E_IO;
+       }
       return darwin_read_dyld_info (priv->task, offset, readbuf, len,
                                    xfered_len);
 #endif
@@ -2436,10 +2432,10 @@ darwin_nat_target::get_ada_task_ptid (long lwp, long thread)
     }
 
   vm_deallocate (gdb_task, (vm_address_t) names,
-                 names_count * sizeof (mach_port_t));
+                names_count * sizeof (mach_port_t));
 
   if (res)
-    return ptid_t (inferior_ptid.pid (), 0, res);
+    return ptid_t (current_inferior ()->pid, 0, res);
   else
     return null_ptid;
 }
This page took 0.029215 seconds and 4 git commands to generate.