Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* gdb on macOS 10.12 "Sierra"
@ 2016-10-01 12:08 Jonas Maebe
  2016-10-04 11:42 ` Tristan Gingold
  0 siblings, 1 reply; 10+ messages in thread
From: Jonas Maebe @ 2016-10-01 12:08 UTC (permalink / raw)
  To: gdb

Hi,

Has anyone succeeded yet in getting gdb to work on macOS 10.12?  
Reportedly, it works when you disable SIP (which is understandable,  
given  
https://developer.apple.com/library/content/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html ), but plain code signing no longer seems to cut  
it.

With gdb 7.11.1, I occasionally get this when I try to start an inferior:
	During startup program terminated with signal SIG113, Real-time event 113.

and usually (with darwin_debug_flag set to 100 -- didn't manage to get  
the SIG113 anymore after I recompiled gdb with that variable set to  
100):

***
Starting program: textthr
[632 inferior]: inferior task: 0x300b, pid: 701
[632 inferior]:  new_ix:0/1, old_ix:0/0, new_id:0x3203 old_id:0x0
[632 inferior]: darwin_wait: waiting for a message pid=701 thread=0
[701 inferior]: ptrace (PT_TRACE_ME, 0, 0x0, 0): 0 (no error)
[701 inferior]: ptrace (PT_SIGEXC, 0, 0x0, 0): 0 (no error)
message header:
  bits: 0x1200
  size: 0x24
  remote-port: 0x0
  local-port: 0xf87
  reserved: 0x0
  id: 0x48
   data: 00000000 00000001 0000300b
[632 inferior]: darwin_wait: pid=701 exit, status=0x5
[632 inferior]: task=0x300b, prev=0x0, notify_port=0xf87
During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.
***

gdb is code signed, the code signing certificate is the System  
keychain and set to "Trust always".

Thanks,


Jonas


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: gdb on macOS 10.12 "Sierra"
@ 2016-10-31 23:14 C Western
  0 siblings, 0 replies; 10+ messages in thread
From: C Western @ 2016-10-31 23:14 UTC (permalink / raw)
  To: gdb

An additional note on this - I have been having similar problems with 
running gdb under Sierra, and it seems the problem is more subtle than a 
simple permissions problem. I am able to attach to a running process, 
but not start a new process with gdb. This is even after using:

	set startup-with-shell off

which I have seen suggested elsewhere.

Colin


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: gdb on macOS 10.12 "Sierra"
@ 2016-11-03 22:05 David Jenkins
  0 siblings, 0 replies; 10+ messages in thread
From: David Jenkins @ 2016-11-03 22:05 UTC (permalink / raw)
  To: gdb

I can confirm that refreshing the task port after exec does allow gdb to 
work.  Here is a patch that I made against 7.12 that allows gdb to run 
on Sierra.  I cannot speak to the complete quality of the patch as this 
is my first dive into gdb code.  We just starting using the patched gdb 
and it does allows us to break, step, and view variables in the Lazarus IDE.

Patch is inlined below

David Jenkins

Scooter Software


--- gdb-7.12/gdb/darwin-nat.c    2016-10-07 12:09:21.000000000 -0500
+++ gdb-7.12-dfj/gdb/darwin-nat.c    2016-11-03 15:56:49.000000000 -0500
@@ -171,6 +171,9 @@
    "</dict>\n"
    "</plist>\n";

+static kern_return_t darwin_save_exception_ports (darwin_inferior *inf);
+static kern_return_t darwin_restore_exception_ports (darwin_inferior *inf);
+
  static void inferior_debug (int level, const char *fmt, ...)
    ATTRIBUTE_PRINTF (2, 3);

@@ -401,6 +404,12 @@
  }

  static int
+find_inferior_pid_it (struct inferior *inf, void *pid_ptr)
+{
+  return inf->pid == *(int *)pid_ptr;
+}
+
+static int
  find_inferior_task_it (struct inferior *inf, void *port_ptr)
  {
    return inf->priv->task == *(task_t*)port_ptr;
@@ -412,6 +421,13 @@
    return inf->priv->notify_port == *(task_t*)port_ptr;
  }

+/* Return an inferior by pid.  */
+static struct inferior *
+darwin_find_inferior_by_pid (int pid)
+{
+  return iterate_over_inferiors (&find_inferior_pid_it, &pid);
+}
+
  /* Return an inferior by task port.  */
  static struct inferior *
  darwin_find_inferior_by_task (task_t port)
@@ -572,6 +588,7 @@
    thread_t thread_port;
    kern_return_t kret;
    int i;
+  int task_pid;

    /* Check message destination.  */
    if (hdr->msgh_local_port != darwin_ex_port)
@@ -606,6 +623,7 @@

    task_port = desc[1].name;
    thread_port = desc[0].name;
+  pid_for_task(task_port, &task_pid);

    /* 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.  */
@@ -617,25 +635,61 @@
    *pinf = inf;
    if (inf == NULL)
      {
-      /* Not a known inferior.  This could happen if the child fork, as
-     the created process will inherit its exception port.
-     FIXME: should the exception port be restored ?  */
-      kern_return_t kret;
-      mig_reply_error_t reply;
+      if MACH_PORT_VALID(task_port)
+    {
+      //int task_pid;
+      mach_port_name_t new_task;
+      mach_port_t prev_not;
+      exception_mask_t mask;
+
+      inf = darwin_find_inferior_by_pid(task_pid);
+      if (inf == NULL)
+        return 0;

-      /* Free thread port (we don't know it).  */
-      kret = mach_port_deallocate (mach_task_self (), thread_port);
-      MACH_CHECK_ERROR (kret);
+      kret = mach_port_deallocate (mach_task_self (), inf->priv->task);
+      MACH_CHECK_ERROR (kret);

-      darwin_encode_reply (&reply, hdr, KERN_SUCCESS);
+      task_for_pid(gdb_task, task_pid, &new_task);

-      kret = mach_msg (&reply.Head, MACH_SEND_MSG | MACH_SEND_INTERRUPT,
-               reply.Head.msgh_size, 0,
-               MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE,
-               MACH_PORT_NULL);
-      MACH_CHECK_ERROR (kret);
+      inf->priv->task = new_task;
+      *pinf = inf;
+
+      mach_port_request_notification (gdb_task, inf->priv->task,
+                      MACH_NOTIFY_DEAD_NAME, 0,
+                      inf->priv->notify_port,
+                      MACH_MSG_TYPE_MAKE_SEND_ONCE,
+                      &prev_not);
+
+      darwin_restore_exception_ports(inf->priv);
+      if (enable_mach_exceptions)
+        mask = EXC_MASK_ALL;
+      else
+        mask = EXC_MASK_SOFTWARE | EXC_MASK_BREAKPOINT;
+      task_set_exception_ports (inf->priv->task, mask, darwin_ex_port,
+                    EXCEPTION_DEFAULT, THREAD_STATE_NONE);
+    }
+      else
+    {
+      /* Not a known inferior.  This could happen if the child fork, as
+         the created process will inherit its exception port.
+         FIXME: should the exception port be restored ?  */
+      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);

-      return 0;
+      darwin_encode_reply (&reply, hdr, KERN_SUCCESS);
+
+      kret = mach_msg (&reply.Head, MACH_SEND_MSG | MACH_SEND_INTERRUPT,
+               reply.Head.msgh_size, 0,
+               MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE,
+               MACH_PORT_NULL);
+      MACH_CHECK_ERROR (kret);
+
+      return 0;
+    }
      }

    /* Find thread by port.  */
@@ -900,6 +954,7 @@
  {
    darwin_thread_t *thread;
    struct inferior *inf;
+

    /* Exception message.  2401 == 0x961 is exc.  */
    if (hdr->msgh_id == 2401)
@@ -992,6 +1047,14 @@
        inf = darwin_find_inferior_by_notify (hdr->msgh_local_port);
        if (inf != NULL)
      {
+     mach_dead_name_notification_t *notif;
+     mach_port_t dead_port;
+
+    notif = (mach_dead_name_notification_t *)(hdr);
+    dead_port = notif->not_port;
+      if (dead_port != inf->priv->task)
+        return ptid_build (inf->pid, 0, 0);
+
        if (!inf->priv->no_ptrace)
          {
            pid_t res;



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-11-03 22:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-01 12:08 gdb on macOS 10.12 "Sierra" Jonas Maebe
2016-10-04 11:42 ` Tristan Gingold
2016-10-04 13:47   ` Tedeschi, Walfred
2016-10-31 11:54   ` Jonas Maebe
2016-10-31 12:00     ` Jack Howarth
2016-10-31 12:11       ` Jonas Maebe
2016-10-31 23:24     ` Jason Molenda
2016-11-03 16:00       ` Tristan Gingold
2016-10-31 23:14 C Western
2016-11-03 22:05 David Jenkins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox