From ffeea2cc1ab89e52b7f76516dc156f71f01b5cfb Mon Sep 17 00:00:00 2001 From: Felix Willgerodt Date: Thu, 22 Aug 2019 10:12:36 +0200 Subject: [PATCH] WIP: Fixes for macos 10.15. Signed-off-by: Felix Willgerodt --- gdb/darwin-nat.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 8f71def069d..ef5244b2eb9 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -1151,7 +1151,7 @@ darwin_decode_message (mach_msg_header_t *hdr, res_pid, wstatus); /* Looks necessary on Leopard and harmless... */ - wait4 (inf->pid, &wstatus, 0, NULL); + // wait4 (inf->pid, &wstatus, 0, NULL); inferior_ptid = ptid_t (inf->pid, 0, 0); return inferior_ptid; @@ -1610,11 +1610,16 @@ darwin_attach_pid (struct inferior *inf) darwin_inferior *priv = new darwin_inferior; inf->priv.reset (priv); + const uint32_t num_retries = 10; + const uint32_t usec_interval = 10000; + try { - kret = task_for_pid (gdb_task, inf->pid, &priv->task); - if (kret != KERN_SUCCESS) - { + for (uint32_t i = 1; i <= num_retries; i++) + { + kret = task_for_pid (gdb_task, inf->pid, &priv->task); + if (kret != KERN_SUCCESS && i == 10) + { int status; if (!inf->attach_flag) @@ -1627,7 +1632,14 @@ darwin_attach_pid (struct inferior *inf) (_("Unable to find Mach task port for process-id %d: %s (0x%lx).\n" " (please check gdb is codesigned - see taskgated(8))"), inf->pid, mach_error_string (kret), (unsigned long) kret); - } + } + else + { + break; + } + + usleep (usec_interval); + } inferior_debug (2, _("inferior task: 0x%x, pid: %d\n"), priv->task, inf->pid); @@ -1756,8 +1768,8 @@ darwin_ptrace_me (void) trace_start_error_with_name ("close"); /* Get rid of privileges. */ - if (setegid (getgid ()) < 0) - trace_start_error_with_name ("setegid"); + //if (setegid (getgid ()) < 0) + //trace_start_error_with_name ("setegid"); /* Set TRACEME. */ if (PTRACE (PT_TRACE_ME, 0, 0, 0) < 0) @@ -1766,6 +1778,15 @@ darwin_ptrace_me (void) /* Redirect signals to exception port. */ if (PTRACE (PT_SIGEXC, 0, 0, 0) < 0) trace_start_error_with_name ("PTRACE"); + + if (setgid (getgid ()) == 0) { + + // Set the child process group to match its pid. + setpgid (0, 0); + + // Sleep a bit to before the exec call. + sleep(1); + } } /* Dummy function to be sure fork_inferior uses fork(2) and not vfork(2). */ @@ -1788,6 +1809,10 @@ darwin_ptrace_him (int pid) { struct inferior *inf = current_inferior (); + // Set the child process group to match its pid + if (pid > 0) + setpgid (pid, pid); + darwin_attach_pid (inf); /* Let's the child run. */ -- 2.20.1