]> granicus.if.org Git - gc/commitdiff
Replace printf PRIxMAX specifier with '%p' for thread id debug output
authorIvan Maidanski <ivmai@mail.ru>
Thu, 29 Dec 2011 14:46:53 +0000 (18:46 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 29 Dec 2011 14:46:53 +0000 (18:46 +0400)
* pthread_support.c (GC_new_thread, GC_delete_thread,
GC_delete_gc_thread, GC_unregister_my_thread_inner,
GC_unregister_my_thread, GC_thread_exit_proc,
GC_start_rtn_prepare_thread, pthread_create): Output thread id value
(when DEBUG_THREADS) using %p format specifier instead of PRIxMAX, %x
and %lx (casting passed id value to pointer type instead of uintmax_t).
* pthread_start.c (GC_inner_start_routine): Likewise.
GC_stop_world, GC_thread_resume, GC_start_world): Likewise.
* pthread_stop_world.c (GC_suspend_handler_inner, GC_restart_handler,
GC_push_all_stacks, GC_suspend_all, GC_stop_world, GC_start_world):
Likewise.
* darwin_stop_world.c (GC_stack_range_for, GC_suspend_thread_list,
* pthread_start.c: Do not include inttypes.h.
* pthread_support.c: Likewise.
* pthread_support.c (GC_count_threads): Define only if DEBUG_THREADS.
* pthread_support.c (GC_unregister_my_thread): Rename gc_self local
variable to "me".
* pthread_support.c (pthread_create): Report thread started (when
DEBUG_THREADS) only if result is 0.

darwin_stop_world.c
pthread_start.c
pthread_stop_world.c
pthread_support.c

index f05dc685a1fe5b304d34d80a53f5e81df713285c..dfccdc19baac5ae21eb436c79c78e7c676836ef5 100644 (file)
@@ -255,8 +255,8 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p,
     *phi = (p->flags & MAIN_THREAD) != 0 ? GC_stackbottom : p->stack_end;
 # endif
 # ifdef DEBUG_THREADS
-    GC_log_printf("Darwin: Stack for thread 0x%lx = [%p,%p)\n",
-                  (unsigned long)thread, lo, *phi);
+    GC_log_printf("Darwin: Stack for thread %p = [%p,%p)\n",
+                  (void *)thread, lo, *phi);
 # endif
   return lo;
 }
@@ -382,8 +382,7 @@ STATIC GC_bool GC_suspend_thread_list(thread_act_array_t act_list, int count,
 #   endif
 
 #   ifdef DEBUG_THREADS
-      GC_log_printf("Attempting to suspend thread 0x%lx\n",
-                    (unsigned long)thread);
+      GC_log_printf("Attempting to suspend thread %p\n", (void *)thread);
 #   endif
     /* find the current thread in the old list */
     found = FALSE;
@@ -427,8 +426,7 @@ STATIC GC_bool GC_suspend_thread_list(thread_act_array_t act_list, int count,
       continue;
     }
 #   ifdef DEBUG_THREADS
-      GC_log_printf("Thread state for 0x%lx = %d\n", (unsigned long)thread,
-                    info.run_state);
+      GC_log_printf("Thread state for %p = %d\n", (void *)thread, info.run_state);
 #   endif
     if (info.suspend_count != 0) {
       /* thread is already suspended. */
@@ -438,7 +436,7 @@ STATIC GC_bool GC_suspend_thread_list(thread_act_array_t act_list, int count,
     }
 
 #   ifdef DEBUG_THREADS
-      GC_log_printf("Suspending 0x%lx\n", (unsigned long)thread);
+      GC_log_printf("Suspending %p\n", (void *)thread);
 #   endif
     kern_result = thread_suspend(thread);
     if (kern_result != KERN_SUCCESS) {
@@ -465,8 +463,7 @@ GC_INNER void GC_stop_world(void)
   kern_return_t kern_result;
 
 # ifdef DEBUG_THREADS
-    GC_log_printf("Stopping the world from thread 0x%lx\n",
-                  (unsigned long)my_thread);
+    GC_log_printf("Stopping the world from thread %p\n", (void *)my_thread);
 # endif
 # ifdef PARALLEL_MARK
     if (GC_parallel) {
@@ -555,7 +552,7 @@ GC_INNER void GC_stop_world(void)
 # endif
 
 # ifdef DEBUG_THREADS
-    GC_log_printf("World stopped from 0x%lx\n", (unsigned long)my_thread);
+    GC_log_printf("World stopped from %p\n", (void *)my_thread);
 # endif
   mach_port_deallocate(my_task, my_thread);
 }
@@ -572,8 +569,8 @@ GC_INLINE void GC_thread_resume(thread_act_t thread)
       ABORT("thread_info failed");
 # endif
 # ifdef DEBUG_THREADS
-    GC_log_printf("Resuming thread 0x%lx with state %d\n",
-                  (unsigned long)thread, info.run_state);
+    GC_log_printf("Resuming thread %p with state %d\n", (void *)thread,
+                  info.run_state);
 # endif
   /* Resume the thread */
   kern_result = thread_resume(thread);
@@ -630,8 +627,8 @@ GC_INNER void GC_start_world(void)
           /* The thread is found in GC_mach_threads.      */
           if (GC_mach_threads[j].already_suspended) {
 #           ifdef DEBUG_THREADS
-              GC_log_printf("Not resuming already suspended thread 0x%lx\n",
-                            (unsigned long)thread);
+              GC_log_printf("Not resuming already suspended thread %p\n",
+                            (void *)thread);
 #           endif
           } else {
             GC_thread_resume(thread);
index 01bb9674109923e571ef5a99271cf977d2dfee1d..776a368d29dd7b6d36ef9fb1ced3b37314eeb817 100644 (file)
@@ -38,7 +38,6 @@
 
 #if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS)
 
-#include <inttypes.h>
 #include <pthread.h>
 #include <sched.h>
 
@@ -56,7 +55,7 @@ void * GC_CALLBACK GC_inner_start_routine(struct GC_stack_base *sb, void *arg)
 # endif
   result = (*start)(start_arg);
 # ifdef DEBUG_THREADS
-    GC_log_printf("Finishing thread 0x%"PRIxMAX"\n", (uintmax_t)pthread_self());
+    GC_log_printf("Finishing thread %p\n", (void *)pthread_self());
 # endif
   me -> status = result;
 # ifndef NACL
index a354a84db6e6ab922aa9ebd588e5354b61dc795a..274a73cccc19cb1f5e5d52928784c2d0679d24f8 100644 (file)
@@ -210,7 +210,7 @@ STATIC void GC_suspend_handler_inner(ptr_t sig_arg,
       /* cancellation point is inherently a problem, unless there is    */
       /* some way to disable cancellation in the handler.               */
 # ifdef DEBUG_THREADS
-    GC_log_printf("Suspending 0x%x\n", (unsigned)self);
+    GC_log_printf("Suspending %p\n", (void *)self);
 # endif
 
   me = GC_lookup_thread(self);
@@ -264,7 +264,7 @@ STATIC void GC_suspend_handler_inner(ptr_t sig_arg,
   /* unlikely to be efficient.                                          */
 
 # ifdef DEBUG_THREADS
-    GC_log_printf("Continuing 0x%x\n", (unsigned)self);
+    GC_log_printf("Continuing %p\n", (void *)self);
 # endif
   RESTORE_CANCEL(cancel_state);
 }
@@ -286,8 +286,7 @@ STATIC void GC_restart_handler(int sig)
   */
 
 # ifdef DEBUG_THREADS
-    GC_log_printf("In GC_restart_handler for 0x%x\n",
-                  (unsigned)pthread_self());
+    GC_log_printf("In GC_restart_handler for %p\n", (void *)pthread_self());
 # endif
 }
 
@@ -314,7 +313,7 @@ GC_INNER void GC_push_all_stacks(void)
 
     if (!GC_thr_initialized) GC_thr_init();
 #   ifdef DEBUG_THREADS
-      GC_log_printf("Pushing stacks from thread 0x%x\n", (unsigned)self);
+      GC_log_printf("Pushing stacks from thread %p\n", (void *)self);
 #   endif
     for (i = 0; i < THREAD_TABLE_SZ; i++) {
       for (p = GC_threads[i]; p != 0; p = p -> next) {
@@ -342,8 +341,8 @@ GC_INNER void GC_push_all_stacks(void)
             IF_IA64(bs_lo = BACKING_STORE_BASE;)
         }
 #       ifdef DEBUG_THREADS
-          GC_log_printf("Stack for thread 0x%x = [%p,%p)\n",
-                        (unsigned)(p -> id), lo, hi);
+          GC_log_printf("Stack for thread %p = [%p,%p)\n",
+                        (void *)p->id, lo, hi);
 #       endif
         if (0 == lo) ABORT("GC_push_all_stacks: sp not set!");
         GC_push_all_stack_sections(lo, hi, p -> traced_stack_sect);
@@ -360,8 +359,8 @@ GC_INNER void GC_push_all_stacks(void)
 #       endif
 #       ifdef IA64
 #         ifdef DEBUG_THREADS
-            GC_log_printf("Reg stack for thread 0x%x = [%p,%p)\n",
-                          (unsigned)p -> id, bs_lo, bs_hi);
+            GC_log_printf("Reg stack for thread %p = [%p,%p)\n",
+                          (void *)p->id, bs_lo, bs_hi);
 #         endif
           /* FIXME: This (if p->id==self) may add an unbounded number of */
           /* entries, and hence overflow the mark stack, which is bad.   */
@@ -434,8 +433,7 @@ STATIC int GC_suspend_all(void)
               n_live_threads++;
 #           endif
 #           ifdef DEBUG_THREADS
-              GC_log_printf("Sending suspend signal to 0x%x\n",
-                            (unsigned)(p -> id));
+              GC_log_printf("Sending suspend signal to %p\n", (void *)p->id);
 #           endif
 
 #           ifdef GC_OPENBSD_THREADS
@@ -524,7 +522,7 @@ GC_INNER void GC_stop_world(void)
 # endif
   GC_ASSERT(I_HOLD_LOCK());
 # ifdef DEBUG_THREADS
-    GC_log_printf("Stopping the world from 0x%x\n", (unsigned)pthread_self());
+    GC_log_printf("Stopping the world from %p\n", (void *)pthread_self());
 # endif
 
   /* Make sure all free list construction has stopped before we start.  */
@@ -593,7 +591,7 @@ GC_INNER void GC_stop_world(void)
       GC_release_mark_lock();
 # endif
 # ifdef DEBUG_THREADS
-    GC_log_printf("World stopped from 0x%x\n", (unsigned)pthread_self());
+    GC_log_printf("World stopped from %p\n", (void *)pthread_self());
     GC_stopping_thread = 0;
 # endif
 }
@@ -755,8 +753,7 @@ GC_INNER void GC_start_world(void)
               n_live_threads++;
 #           endif
 #           ifdef DEBUG_THREADS
-              GC_log_printf("Sending restart signal to 0x%x\n",
-                            (unsigned)(p -> id));
+              GC_log_printf("Sending restart signal to %p\n", (void *)p->id);
 #           endif
 
 #         ifdef GC_OPENBSD_THREADS
index db1d8bf2ac7a1d6c16b1f9e8109e26a3052b5b17..dabaed1a90399d11b48061b00528bfc9e70d498f 100644 (file)
@@ -47,7 +47,6 @@
 #if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS)
 
 # include <stdlib.h>
-# include <inttypes.h>
 # include <pthread.h>
 # include <sched.h>
 # include <time.h>
@@ -464,8 +463,9 @@ void GC_push_thread_structures(void)
 #   endif
 }
 
-STATIC int GC_count_threads(void)
-{
+#ifdef DEBUG_THREADS
+  STATIC int GC_count_threads(void)
+  {
     int i;
     int count = 0;
     GC_ASSERT(I_HOLD_LOCK());
@@ -478,7 +478,8 @@ STATIC int GC_count_threads(void)
         }
     }
     return count;
-}
+  }
+#endif /* DEBUG_THREADS */
 
 /* It may not be safe to allocate when we register the first thread.    */
 static struct GC_Thread_Rep first_thread;
@@ -491,7 +492,7 @@ STATIC GC_thread GC_new_thread(pthread_t id)
     GC_thread result;
     static GC_bool first_thread_used = FALSE;
 #   ifdef DEBUG_THREADS
-        GC_log_printf("Creating thread %#"PRIxMAX".\n", (uintmax_t)id);
+        GC_log_printf("Creating thread %p\n", (void *)id);
 #   endif
 
     GC_ASSERT(I_HOLD_LOCK());
@@ -527,8 +528,8 @@ STATIC void GC_delete_thread(pthread_t id)
     register GC_thread prev = 0;
 
 #   ifdef DEBUG_THREADS
-      GC_log_printf("Deleting thread 0x%"PRIxMAX". n_threads = %d.\n",
-                    (uintmax_t)id, GC_count_threads());
+      GC_log_printf("Deleting thread %p, n_threads = %d\n",
+                    (void *)id, GC_count_threads());
 #   endif
 
 #   ifdef NACL
@@ -581,8 +582,8 @@ STATIC void GC_delete_gc_thread(GC_thread t)
     GC_INTERNAL_FREE(p);
 
 #   ifdef DEBUG_THREADS
-      GC_log_printf("Deleted gc-thread 0x%"PRIxMAX". n_threads = %d.\n",
-                    (uintmax_t)id, GC_count_threads());
+      GC_log_printf("Deleted thread %p, n_threads = %d\n",
+                    (void *)id, GC_count_threads());
 #   endif
 }
 
@@ -1187,8 +1188,9 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn,
 STATIC void GC_unregister_my_thread_inner(GC_thread me)
 {
 #   ifdef DEBUG_THREADS
-      GC_log_printf("Unregistering thread 0x%"PRIxMAX" -> %p. n_threads = %d.\n",
-                    (uintmax_t)me->id, me, GC_count_threads());
+      GC_log_printf(
+                "Unregistering thread %p, gc_thread = %p, n_threads = %d\n",
+                (void *)me->id, me, GC_count_threads());
 #   endif
     GC_ASSERT(!(me -> flags & FINISHED));
 #   if defined(THREAD_LOCAL_ALLOC)
@@ -1215,7 +1217,7 @@ STATIC void GC_unregister_my_thread_inner(GC_thread me)
 GC_API int GC_CALL GC_unregister_my_thread(void)
 {
     pthread_t self = pthread_self();
-    GC_thread gc_self;
+    GC_thread me;
     IF_CANCEL(int cancel_state;)
     DCL_LOCK_STATE;
 
@@ -1224,13 +1226,14 @@ GC_API int GC_CALL GC_unregister_my_thread(void)
     /* Wait for any GC that may be marking from our stack to    */
     /* complete before we remove this thread.                   */
     GC_wait_for_gc_completion(FALSE);
-    gc_self = GC_lookup_thread(self);
+    me = GC_lookup_thread(self);
 #   ifdef DEBUG_THREADS
-        GC_log_printf("Called GC_unregister_my_thread on %#"PRIxMAX" -> %p.\n",
-                      (uintmax_t)self, GC_lookup_thread(self));
+        GC_log_printf(
+                "Called GC_unregister_my_thread on %p, gc_thread = %p\n",
+                (void *)self, me);
 #   endif
-    GC_ASSERT(gc_self->id == self);
-    GC_unregister_my_thread_inner(gc_self);
+    GC_ASSERT(me->id == self);
+    GC_unregister_my_thread_inner(me);
     RESTORE_CANCEL(cancel_state);
     UNLOCK();
     return GC_SUCCESS;
@@ -1244,8 +1247,8 @@ GC_API int GC_CALL GC_unregister_my_thread(void)
 GC_INNER void GC_thread_exit_proc(void *arg)
 {
 #   ifdef DEBUG_THREADS
-        GC_log_printf("Called GC_thread_exit_proc on %#"PRIxMAX" -> %p.\n",
-                      ((GC_thread)arg)->id, arg);
+        GC_log_printf("Called GC_thread_exit_proc on %p, gc_thread = %p\n",
+                      (void *)((GC_thread)arg)->id, arg);
 #   endif
     IF_CANCEL(int cancel_state;)
     DCL_LOCK_STATE;
@@ -1486,8 +1489,8 @@ GC_INNER GC_thread GC_start_rtn_prepare_thread(void *(**pstart)(void *),
     DCL_LOCK_STATE;
 
 #   ifdef DEBUG_THREADS
-      GC_log_printf("Starting thread 0x%"PRIxMAX", pid = %ld, sp = %p\n",
-                    (uintmax_t)self, (long)getpid(), &arg);
+      GC_log_printf("Starting thread %p, pid = %ld, sp = %p\n",
+                    (void *)self, (long)getpid(), &arg);
 #   endif
     LOCK();
     me = GC_register_my_thread_inner(sb, self);
@@ -1605,22 +1608,24 @@ GC_API int WRAP_FUNC(pthread_create)(pthread_t *new_thread,
     si -> flags = my_flags;
     UNLOCK();
 #   ifdef DEBUG_THREADS
-      GC_log_printf("About to start new thread from thread 0x%x\n",
-                    (unsigned)pthread_self());
+      GC_log_printf("About to start new thread from thread %p\n",
+                    (void *)pthread_self());
 #   endif
     GC_need_to_lock = TRUE;
 
     result = REAL_FUNC(pthread_create)(new_thread, attr, GC_start_routine, si);
 
-#   ifdef DEBUG_THREADS
-      GC_log_printf("Started thread 0x%x\n", (unsigned)(*new_thread));
-#   endif
     /* Wait until child has been added to the thread table.             */
     /* This also ensures that we hold onto si until the child is done   */
     /* with it.  Thus it doesn't matter whether it is otherwise         */
     /* visible to the collector.                                        */
     if (0 == result) {
         IF_CANCEL(int cancel_state;)
+
+#       ifdef DEBUG_THREADS
+          if (new_thread)
+            GC_log_printf("Started thread %p\n", (void *)(*new_thread));
+#       endif
         DISABLE_CANCEL(cancel_state);
                 /* pthread_create is not a cancellation point. */
         while (0 != sem_wait(&(si -> registered))) {