Use canonicalize_file_name unconditionally
[deliverable/binutils-gdb.git] / gdb / darwin-nat.c
index 7d2508e3aeaec9d7fb906603533dcc57067a823b..511f37046d9e89f1e46399c23d9dcc814dc541ac 100644 (file)
@@ -33,7 +33,6 @@
 #include "event-top.h"
 #include "inf-loop.h"
 #include <sys/stat.h>
-#include "exceptions.h"
 #include "inf-child.h"
 #include "value.h"
 #include "arch-utils.h"
@@ -46,7 +45,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <signal.h>
-#include <string.h>
 #include <ctype.h>
 #include <sys/sysctl.h>
 #include <sys/proc.h>
@@ -303,9 +301,18 @@ darwin_check_new_threads (struct inferior *inf)
          break;
       if (i == new_nbr)
        {
+         /* Deallocate ports.  */
+         for (i = 0; i < new_nbr; i++)
+           {
+             kret = mach_port_deallocate (mach_task_self (), thread_list[i]);
+             MACH_CHECK_ERROR (kret);
+           }
+
+         /* Deallocate the buffer.  */
          kret = vm_deallocate (gdb_task, (vm_address_t) thread_list,
                                new_nbr * sizeof (int));
          MACH_CHECK_ERROR (kret);
+
          return;
        }
     }
@@ -331,8 +338,10 @@ darwin_check_new_threads (struct inferior *inf)
          new_ix++;
          old_ix++;
 
-         kret = mach_port_deallocate (gdb_task, old_id);
+         /* Deallocate the port.  */
+         kret = mach_port_deallocate (gdb_task, new_id);
          MACH_CHECK_ERROR (kret);
+
          continue;
        }
       if (new_ix < new_nbr && new_id == MACH_PORT_DEAD)
@@ -382,6 +391,7 @@ darwin_check_new_threads (struct inferior *inf)
     VEC_free (darwin_thread_t, darwin_inf->threads);
   darwin_inf->threads = thread_vec;
 
+  /* Deallocate the buffer.  */
   kret = vm_deallocate (gdb_task, (vm_address_t) thread_list,
                        new_nbr * sizeof (int));
   MACH_CHECK_ERROR (kret);
@@ -594,11 +604,10 @@ darwin_decode_exception_message (mach_msg_header_t *hdr,
   task_port = desc[1].name;
   thread_port = desc[0].name;
 
-  /* We got new rights to the task and the thread.  Get rid of them.  */
+  /* We got new rights to the task, get rid of it.  Do not get rid of thread
+     right, as we will need it to find the thread.  */
   kret = mach_port_deallocate (mach_task_self (), task_port);
   MACH_CHECK_ERROR (kret);
-  kret = mach_port_deallocate (mach_task_self (), thread_port);
-  MACH_CHECK_ERROR (kret);
 
   /* Find process by port.  */
   inf = darwin_find_inferior_by_task (task_port);
@@ -611,6 +620,10 @@ darwin_decode_exception_message (mach_msg_header_t *hdr,
       kern_return_t kret;
       mig_reply_error_t reply;
 
+      /* Free thread port (we don't know it).  */
+      kret = mach_port_deallocate (mach_task_self (), thread_port);
+      MACH_CHECK_ERROR (kret);
+
       darwin_encode_reply (&reply, hdr, KERN_SUCCESS);
 
       kret = mach_msg (&reply.Head, MACH_SEND_MSG | MACH_SEND_INTERRUPT,
@@ -627,6 +640,11 @@ darwin_decode_exception_message (mach_msg_header_t *hdr,
      message can be deallocated.  */
   darwin_check_new_threads (inf);
 
+  /* Free the thread port (as gdb knows the thread, it has already has a right
+     for it, so this just decrement a reference counter).  */
+  kret = mach_port_deallocate (mach_task_self (), thread_port);
+  MACH_CHECK_ERROR (kret);
+
   thread = darwin_find_thread (inf, thread_port);
   if (thread == NULL)
     return -1;
@@ -1017,7 +1035,7 @@ darwin_decode_message (mach_msg_header_t *hdr,
     }
 
   /* Unknown message.  */
-  warning (_("darwin: got unknown message, id: 0x%x\n"), hdr->msgh_id);
+  warning (_("darwin: got unknown message, id: 0x%x"), hdr->msgh_id);
   status->kind = TARGET_WAITKIND_IGNORE;
   return minus_one_ptid;
 }
@@ -1194,8 +1212,6 @@ darwin_mourn_inferior (struct target_ops *ops)
   mach_port_t prev;
   int i;
 
-  unpush_target (darwin_ops);
-
   /* Deallocate threads.  */
   if (inf->private->threads)
     {
@@ -1250,7 +1266,7 @@ darwin_mourn_inferior (struct target_ops *ops)
   xfree (inf->private);
   inf->private = NULL;
 
-  generic_mourn_inferior ();
+  inf_child_mourn_inferior (ops);
 }
 
 static void
@@ -1486,7 +1502,8 @@ impact on the debugging session."));
             "returned: %d"),
           kret);
 
-  push_target (darwin_ops);
+  if (!target_is_pushed (darwin_ops))
+    push_target (darwin_ops);
 }
 
 static void
@@ -1653,7 +1670,7 @@ darwin_setup_fake_stop_event (struct inferior *inf)
 /* Attach to process PID, then initialize for debugging it
    and wait for the trace-trap that results from attaching.  */
 static void
-darwin_attach (struct target_ops *ops, char *args, int from_tty)
+darwin_attach (struct target_ops *ops, const char *args, int from_tty)
 {
   pid_t pid;
   pid_t pid2;
@@ -2128,10 +2145,6 @@ _initialize_darwin_inferior (void)
 
   darwin_ops = inf_child_target ();
 
-  darwin_ops->to_shortname = "darwin-child";
-  darwin_ops->to_longname = _("Darwin child process");
-  darwin_ops->to_doc =
-    _("Darwin child process (started by the \"run\" command).");
   darwin_ops->to_create_inferior = darwin_create_inferior;
   darwin_ops->to_attach = darwin_attach;
   darwin_ops->to_attach_no_wait = 0;
This page took 0.025047 seconds and 4 git commands to generate.