[gimp] Fix empty lldb backtrace on OSX



commit 559d9b89e348a6713dc0650577330f93fc8ed0bb
Author: Alex Samorukov <samm os2 kiev ua>
Date:   Fri Jun 22 17:00:59 2018 +0000

    Fix empty lldb backtrace on OSX
    
    When lldb attaching to the process it triggers few "-1" errors on read with
    EINTR error. After 1-2 errors read() call works again.
    Also this patch fixing TID detection, syscall SYS_gettid is oficially deprecated
    now and does not work. Also adding safecheck to avoid enldless loop.

 libgimpbase/gimputils.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/libgimpbase/gimputils.c b/libgimpbase/gimputils.c
index c40314a9c6..8c7fa78a95 100644
--- a/libgimpbase/gimputils.c
+++ b/libgimpbase/gimputils.c
@@ -1180,8 +1180,13 @@ gimp_stack_trace_print (const gchar   *prog_name,
   int      out_fd[2];
   pid_t    fork_pid;
   pid_t    pid = getpid();
+  gint     eintr_count = 0;
 #if defined(G_OS_WIN32)
   DWORD    tid = GetCurrentThreadId ();
+#elif defined(PLATFORM_OSX)
+  uint64   tid64;
+  pthread_threadid_np (NULL, &tid64);
+  long     tid = (long)tid64;
 #elif defined(SYS_gettid)
   long     tid = syscall (SYS_gettid);
 #elif defined(HAVE_THR_SELF)
@@ -1275,8 +1280,17 @@ gimp_stack_trace_print (const gchar   *prog_name,
        */
       close (out_fd[1]);
 
-      while ((read_n = read (out_fd[0], buffer, 256)) > 0)
+      while ((read_n = read (out_fd[0], buffer, 256)) != 0)
         {
+          if (read_n < 0)
+            {
+              if (errno == EINTR && eintr_count <= 5)
+                {
+                  eintr_count++;
+                  continue;
+                }
+              break;
+            }
           if (! stack_printed)
             {
 #if defined(G_OS_WIN32) || defined(SYS_gettid) || defined(HAVE_THR_SELF)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]