]> granicus.if.org Git - gc/commitdiff
Replace GC_log/err_printf() followed by ABORT with ABORT_ARGn()
authorIvan Maidanski <ivmai@mail.ru>
Tue, 11 Dec 2012 05:28:12 +0000 (09:28 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 11 Dec 2012 11:28:38 +0000 (15:28 +0400)
(code refactoring)

* allchblk.c (GC_freehblk): Replace GC_COND_LOG_PRINTF (or
GC_log_printf, or GC_err_printf) followed by ABORT with ABORT_ARG<n>
(where 'n' is the number of arguments matching format string).
* alloc.c (GC_check_fl_marks): Likewise.
* dbg_mlc.c (GC_debug_change_stubborn, GC_debug_end_stubborn_change,
GC_debug_free, GC_debug_realloc): Likewise.
* dyn_load.c (GC_register_dynamic_libraries): Likewise.
* os_dep.c (GC_get_maps, GC_register_data_segments, GC_remap, PROTECT,
GC_write_fault_handler, GC_mprotect_thread): Likewise.
* pthread_stop_world.c (GC_suspend_all, GC_start_world): Likewise.
* ptr_chck.c (GC_default_same_obj_print_proc,
GC_default_is_valid_displacement_print_proc,
GC_default_is_visible_print_proc): Likewise.
* specific.c (GC_check_tsd_marks): Likewise.
* win32_threads.c (GC_register_my_thread_inner): Likewise.
* include/private/gc_priv.h (ABORT_ARG1, ABORT_ARG2, ABORT_ARG3): New
macro.

allchblk.c
alloc.c
dbg_mlc.c
dyn_load.c
include/private/gc_priv.h
os_dep.c
pthread_stop_world.c
ptr_chck.c
specific.c
win32_threads.c

index 5ddafdb3f7ffc113885cad2313140c1b36f2f42b..9afa878e1def8c064b27125bc1db635027da83a7 100644 (file)
@@ -845,9 +845,8 @@ GC_INNER void GC_freehblk(struct hblk *hbp)
 
     /* Check for duplicate deallocation in the easy case */
       if (HBLK_IS_FREE(hhdr)) {
-        GC_COND_LOG_PRINTF("Duplicate large block deallocation of %p\n",
-                           (void *)hbp);
-        ABORT("Duplicate large block deallocation");
+        ABORT_ARG1("Duplicate large block deallocation",
+                   " of %p", (void *)hbp);
       }
 
     GC_ASSERT(IS_MAPPED(hhdr));
diff --git a/alloc.c b/alloc.c
index 97f88916d93e918c80791a90eef4fd0029722510..8a64de136c59d129bb64cd7c304ab536fb0df07b 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -736,9 +736,8 @@ GC_INNER void GC_set_fl_marks(ptr_t q)
         AO_t *next;
 
         if (!GC_is_marked(p)) {
-          GC_err_printf("Unmarked object %p on list %p\n",
-                        (void *)p, (void *)list);
-          ABORT("Unmarked local free list entry");
+          ABORT_ARG2("Unmarked local free list entry",
+                     ": object %p on list %p", (void *)p, (void *)list);
         }
 
         /* While traversing the free-list, it re-reads the pointer to   */
index 5287149fe1409a3dbd7af42b4d58b4f96329a7dd..54126e03d8f771c10ffb08ac80ed9e2ce1d3ee73 100644 (file)
--- a/dbg_mlc.c
+++ b/dbg_mlc.c
@@ -603,13 +603,11 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb,
     hdr * hhdr;
 
     if (q == 0) {
-        GC_err_printf("Bad argument: %p to GC_debug_change_stubborn\n", p);
-        ABORT("GC_debug_change_stubborn: bad arg");
+        ABORT_ARG1("GC_debug_change_stubborn: bad arg", ": %p", p);
     }
     hhdr = HDR(q);
     if (hhdr -> hb_obj_kind != STUBBORN) {
-        GC_err_printf("GC_debug_change_stubborn arg not stubborn: %p\n", p);
-        ABORT("GC_debug_change_stubborn: arg not stubborn");
+        ABORT_ARG1("GC_debug_change_stubborn: arg not stubborn", ": %p", p);
     }
     GC_change_stubborn(q);
   }
@@ -620,13 +618,12 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb,
     hdr * hhdr;
 
     if (q == 0) {
-        GC_err_printf("Bad argument: %p to GC_debug_end_stubborn_change\n", p);
-        ABORT("GC_debug_end_stubborn_change: bad arg");
+        ABORT_ARG1("GC_debug_end_stubborn_change: bad arg", ": %p", p);
     }
     hhdr = HDR(q);
     if (hhdr -> hb_obj_kind != STUBBORN) {
-        GC_err_printf("debug_end_stubborn_change arg not stubborn: %p\n", p);
-        ABORT("GC_debug_end_stubborn_change: arg not stubborn");
+        ABORT_ARG1("GC_debug_end_stubborn_change: arg not stubborn",
+                   ": %p", p);
     }
     GC_end_stubborn_change(q);
   }
@@ -772,8 +769,7 @@ GC_API void GC_CALL GC_debug_free(void * p)
 
     base = GC_base(p);
     if (base == 0) {
-      GC_err_printf("Attempt to free invalid pointer %p\n", p);
-      ABORT("Invalid pointer passed to free()");
+      ABORT_ARG1("Invalid pointer passed to free()", ": %p", p);
     }
     if ((ptr_t)p - (ptr_t)base != sizeof(oh)) {
       GC_err_printf(
@@ -850,8 +846,7 @@ GC_API void * GC_CALL GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS)
 
     base = GC_base(p);
     if (base == 0) {
-        GC_err_printf("Attempt to reallocate invalid pointer %p\n", p);
-        ABORT("Invalid pointer passed to realloc()");
+        ABORT_ARG1("Invalid pointer passed to realloc()", ": %p", p);
     }
     if ((ptr_t)p - (ptr_t)base != sizeof(oh)) {
         GC_err_printf(
index 8e07de3218113ba157f6db487ea05ee6a5af4592..b1ec60145fe2e00aebd07107824ce95768f7446a 100644 (file)
@@ -753,8 +753,8 @@ GC_INNER void GC_register_dynamic_libraries(void)
       }
     }
     if (ioctl(fd, PIOCNMAP, &needed_sz) < 0) {
-        GC_err_printf("fd = %d, errno = %d\n", fd, errno);
-        ABORT("/proc PIOCNMAP ioctl failed");
+        ABORT_ARG2("/proc PIOCNMAP ioctl failed",
+                   ": fd = %d, errno = %d", fd, errno);
     }
     if (needed_sz >= current_sz) {
         current_sz = needed_sz * 2 + 1;
@@ -765,9 +765,9 @@ GC_INNER void GC_register_dynamic_libraries(void)
           ABORT("Insufficient memory for address map");
     }
     if (ioctl(fd, PIOCMAP, addr_map) < 0) {
-        GC_err_printf("fd = %d, errno = %d, needed_sz = %d, addr_map = %p\n",
-                        fd, errno, needed_sz, addr_map);
-        ABORT("/proc PIOCMAP ioctl failed");
+        ABORT_ARG3("/proc PIOCMAP ioctl failed",
+                   ": errcode= %d, needed_sz= %d, addr_map= %p",
+                   errno, needed_sz, addr_map);
     };
     if (GC_n_heap_sects > 0) {
         heap_end = GC_heap_sects[GC_n_heap_sects-1].hs_start
@@ -1015,16 +1015,12 @@ GC_INNER void GC_register_dynamic_libraries(void)
         if (moduleid == LDR_NULL_MODULE)
             break;    /* No more modules */
 
-      /* Check status AFTER checking moduleid because */
-      /* of a bug in the non-shared ldr_next_module stub */
+      /* Check status AFTER checking moduleid because       */
+      /* of a bug in the non-shared ldr_next_module stub.   */
         if (status != 0) {
-          GC_COND_LOG_PRINTF("dynamic_load: status = %d\n", status);
-          if (errno < sys_nerr) {
-            GC_COND_LOG_PRINTF("dynamic_load: %s\n", sys_errlist[errno]);
-          } else {
-            GC_COND_LOG_PRINTF("dynamic_load: err_code = %d\n", errno);
-          }
-          ABORT("ldr_next_module failed");
+          ABORT_ARG3("ldr_next_module failed",
+                     ": status= %d, errcode= %d (%s)", status, errno,
+                     errno < sys_nerr ? sys_errlist[errno] : "");
         }
 
       /* Get the module information */
@@ -1109,12 +1105,9 @@ GC_INNER void GC_register_dynamic_libraries(void)
           if (errno == EINVAL) {
             break; /* Moved past end of shared library list --> finished */
           } else {
-            if (errno < sys_nerr) {
-              GC_COND_LOG_PRINTF("dynamic_load: %s\n", sys_errlist[errno]);
-            } else {
-              GC_COND_LOG_PRINTF("dynamic_load: err_code = %d\n", errno);
-            }
-            ABORT("shl_get failed");
+            ABORT_ARG3("shl_get failed",
+                       ": status= %d, errcode= %d (%s)", status, errno,
+                       errno < sys_nerr ? sys_errlist[errno] : "");
           }
 #        endif
         }
index c3125170f7b7c8be0717a056b1684fe9673f0307..6d7ffacf2c6a69d2dd2ffdbf48ed04b290f30c77 100644 (file)
@@ -485,6 +485,25 @@ typedef char * ptr_t;   /* A generic pointer to which we can add        */
 #   endif /* !MSWIN32 */
 # endif /* !PCR */
 
+/* For abort message with 1-3 arguments.  C_msg and C_fmt should be     */
+/* literals.  C_msg should not contain format specifiers.  Arguments    */
+/* should match their format specifiers.                                */
+#define ABORT_ARG1(C_msg, C_fmt, arg1) \
+                do { \
+                  GC_COND_LOG_PRINTF(C_msg /* + */ C_fmt, arg1); \
+                  ABORT(C_msg); \
+                } while (0)
+#define ABORT_ARG2(C_msg, C_fmt, arg1, arg2) \
+                do { \
+                  GC_COND_LOG_PRINTF(C_msg /* + */ C_fmt, arg1, arg2); \
+                  ABORT(C_msg); \
+                } while (0)
+#define ABORT_ARG3(C_msg, C_fmt, arg1, arg2, arg3) \
+                do { \
+                  GC_COND_LOG_PRINTF(C_msg /* + */ C_fmt, arg1, arg2, arg3); \
+                  ABORT(C_msg); \
+                } while (0)
+
 /* Same as ABORT but does not have 'no-return' attribute.       */
 /* ABORT on dummy condition (which is always true).             */
 #define ABORT_RET(msg) { if ((signed_word)GC_current_warn_proc != -1) \
index fdde091a925b5660e524c30dede9b1a0b02b478a..0ab17828830d021157fe711fa2305b6b521949e4 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -265,12 +265,10 @@ GC_INNER char * GC_get_maps(void)
               return 0;
 #           ifdef THREADS
               if (maps_size > old_maps_size) {
-                GC_COND_LOG_PRINTF(
-                        "Unexpected maps size growth from %lu to %lu\n",
-                        (unsigned long)old_maps_size,
-                        (unsigned long)maps_size);
-                ABORT("Unexpected asynchronous /proc/self/maps growth: "
-                      "unregistered thread?");
+                ABORT_ARG2("Unexpected asynchronous /proc/self/maps growth "
+                           "(unregistered thread?)", " from %lu to %lu",
+                           (unsigned long)old_maps_size,
+                           (unsigned long)maps_size);
               }
 #           endif
         } while (maps_size >= maps_buf_sz || maps_size < old_maps_size);
@@ -1476,51 +1474,39 @@ void GC_register_data_segments(void)
     }
     myexefile = fopen(path, "rb");
     if (myexefile == 0) {
-        GC_COND_LOG_PRINTF("Could not open executable %s\n", path);
-        ABORT("Failed to open executable");
+        ABORT_ARG1("Failed to open executable", ": %s", path);
     }
     if (fread((char *)(&hdrdos), 1, sizeof(hdrdos), myexefile)
           < sizeof(hdrdos)) {
-        GC_COND_LOG_PRINTF("Could not read MSDOS header from %s\n", path);
-        ABORT("Couldn't read MSDOS header");
+        ABORT_ARG1("Could not read MSDOS header", " from: %s", path);
     }
     if (E_MAGIC(hdrdos) != EMAGIC) {
-        GC_COND_LOG_PRINTF("Executable has wrong DOS magic number: %s\n",
-                           path);
-        ABORT("Bad DOS magic number");
+        ABORT_ARG1("Bad DOS magic number", " in file: %s", path);
     }
     if (fseek(myexefile, E_LFANEW(hdrdos), SEEK_SET) != 0) {
-        GC_COND_LOG_PRINTF("Seek to new header failed in %s\n", path);
-        ABORT("Bad DOS magic number");
+        ABORT_ARG1("Bad DOS magic number", " in file: %s", path);
     }
     if (fread((char *)(&hdr386), 1, sizeof(hdr386), myexefile)
           < sizeof(hdr386)) {
-        GC_COND_LOG_PRINTF("Could not read MSDOS header from %s\n", path);
-        ABORT("Couldn't read OS/2 header");
+        ABORT_ARG1("Could not read OS/2 header", " from: %s", path);
     }
     if (E32_MAGIC1(hdr386) != E32MAGIC1 || E32_MAGIC2(hdr386) != E32MAGIC2) {
-        GC_COND_LOG_PRINTF("Executable has wrong OS/2 magic number: %s\n",
-                           path);
-        ABORT("Bad OS/2 magic number");
+        ABORT_ARG1("Bad OS/2 magic number", " in file: %s", path);
     }
     if (E32_BORDER(hdr386) != E32LEBO || E32_WORDER(hdr386) != E32LEWO) {
-        GC_COND_LOG_PRINTF("Executable has wrong byte order: %s\n", path);
-        ABORT("Bad byte order");
+        ABORT_ARG1("Bad byte order in executable", " file: %s", path);
     }
     if (E32_CPU(hdr386) == E32CPU286) {
-        GC_COND_LOG_PRINTF("GC cannot handle 80286 executables: %s\n", path);
-        ABORT("Intel 80286 executables are unsupported");
+        ABORT_ARG1("GC cannot handle 80286 executables", ": %s", path);
     }
     if (fseek(myexefile, E_LFANEW(hdrdos) + E32_OBJTAB(hdr386),
               SEEK_SET) != 0) {
-        GC_COND_LOG_PRINTF("Seek to object table failed: %s\n", path);
-        ABORT("Seek to object table failed");
+        ABORT_ARG1("Seek to object table failed", " in file: %s", path);
     }
     for (nsegs = E32_OBJCNT(hdr386); nsegs > 0; nsegs--) {
       int flags;
       if (fread((char *)(&seg), 1, sizeof(seg), myexefile) < sizeof(seg)) {
-        GC_COND_LOG_PRINTF("Could not read obj table entry from %s\n", path);
-        ABORT("Couldn't read obj table entry");
+        ABORT_ARG1("Could not read obj table entry", " from file: %s", path);
       }
       flags = O32_FLAGS(seg);
       if (!(flags & OBJWRITE)) continue;
@@ -2460,10 +2446,9 @@ GC_INNER void GC_remap(ptr_t start, size_t bytes)
 #       else
           if (mprotect(start_addr, len, (PROT_READ | PROT_WRITE)
                             | (GC_pages_executable ? PROT_EXEC : 0)) != 0) {
-            GC_COND_LOG_PRINTF("mprotect failed at %p (length %lu)"
-                               " with errno %d\n",
-                               start_addr, (unsigned long)len, errno);
-            ABORT("mprotect remapping failed");
+            ABORT_ARG3("mprotect remapping failed",
+                       " at %p (length %lu), errcode= %d",
+                       start_addr, (unsigned long)len, errno);
           }
 #       endif /* !NACL */
       }
@@ -2963,9 +2948,8 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
                             GC_pages_executable ? PAGE_EXECUTE_READ : \
                                                   PAGE_READONLY, \
                             &protect_junk)) { \
-          GC_COND_LOG_PRINTF("Last error code: 0x%lx\n", \
-                             (long)GetLastError()); \
-          ABORT("VirtualProtect failed"); \
+          ABORT_ARG1("VirtualProtect failed", \
+                     ": errcode= 0x%X", (unsigned)GetLastError()); \
         }
 #   define UNPROTECT(addr, len) \
         if (!VirtualProtect((addr), (len), \
@@ -3173,8 +3157,8 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
 
             if (old_handler == (SIG_HNDLR_PTR)SIG_DFL) {
 #               if !defined(MSWIN32) && !defined(MSWINCE)
-                    GC_COND_LOG_PRINTF("Unexpected segfault at %p\n", addr);
-                    ABORT("Unexpected bus error or segmentation fault");
+                    ABORT_ARG1("Unexpected bus error or segmentation fault",
+                               " at %p", addr);
 #               else
                     return(EXCEPTION_CONTINUE_SEARCH);
 #               endif
@@ -3224,8 +3208,8 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
 #   if defined(MSWIN32) || defined(MSWINCE)
       return EXCEPTION_CONTINUE_SEARCH;
 #   else
-      GC_COND_LOG_PRINTF("Unexpected segfault at %p\n", addr);
-      ABORT("Unexpected bus error or segmentation fault");
+      ABORT_ARG1("Unexpected bus error or segmentation fault",
+                 " at %p", addr);
 #   endif
   }
 
@@ -4038,9 +4022,8 @@ STATIC void *GC_mprotect_thread(void *arg)
 #   endif /* THREADS */
 
     if (r != MACH_MSG_SUCCESS) {
-      GC_COND_LOG_PRINTF("mach_msg failed with code %d: %s\n", (int)r,
-                         mach_error_string(r));
-      ABORT("mach_msg failed");
+      ABORT_ARG2("mach_msg failed",
+                 ": errcode= %d (%s)", (int)r, mach_error_string(r));
     }
 
     switch(id) {
index a06ffb71cc815cc63e47066fa526d410fdbd5af7..7b0d016817676295a53fa81ccb381424c0201acb 100644 (file)
@@ -493,11 +493,8 @@ STATIC int GC_suspend_all(void)
                 case 0:
                     break;
                 default:
-#                   ifdef DEBUG_THREADS
-                      GC_log_printf("pthread_kill failed at suspend,"
-                                    " errcode=%d\n", result);
-#                   endif
-                    ABORT("pthread_kill failed");
+                    ABORT_ARG1("pthread_kill failed at suspend",
+                               ": errcode= %d", result);
               }
 #           endif
         }
@@ -820,11 +817,8 @@ GC_INNER void GC_start_world(void)
                 case 0:
                     break;
                 default:
-#                   ifdef DEBUG_THREADS
-                      GC_log_printf("pthread_kill failed at resume,"
-                                    " errcode=%d\n", result);
-#                   endif
-                    ABORT("pthread_kill failed");
+                    ABORT_ARG1("pthread_kill failed at resume",
+                               ": errcode= %d", result);
             }
 #         endif
         }
@@ -834,8 +828,8 @@ GC_INNER void GC_start_world(void)
       for (i = 0; i < n_live_threads; i++) {
         while (0 != (code = sem_wait(&GC_restart_ack_sem))) {
           if (errno != EINTR) {
-            GC_COND_LOG_PRINTF("sem_wait() returned %d\n", code);
-            ABORT("sem_wait() for restart handler failed");
+            ABORT_ARG1("sem_wait() for restart handler failed",
+                       ": errcode= %d", code);
           }
         }
       }
index eb1c45697f73f048143f5445ada98f79970887ba..16662495e4a5f39f6ae13dde29337169c26a0f61 100644 (file)
@@ -20,8 +20,8 @@
 
 STATIC void GC_CALLBACK GC_default_same_obj_print_proc(void * p, void * q)
 {
-    GC_err_printf("%p and %p are not in the same object\n", p, q);
-    ABORT("GC_same_obj test failed");
+    ABORT_ARG2("GC_same_obj test failed",
+               ": %p and %p are not in the same object", p, q);
 }
 
 void (GC_CALLBACK *GC_same_obj_print_proc) (void *, void *)
@@ -102,8 +102,7 @@ fail:
 
 STATIC void GC_CALLBACK GC_default_is_valid_displacement_print_proc (void *p)
 {
-    GC_err_printf("%p does not point to valid object displacement\n", p);
-    ABORT("GC_is_valid_displacement test failed");
+    ABORT_ARG1("GC_is_valid_displacement test failed", ": %p not valid", p);
 }
 
 void (GC_CALLBACK *GC_is_valid_displacement_print_proc)(void *) =
@@ -152,8 +151,7 @@ fail:
 
 STATIC void GC_CALLBACK GC_default_is_visible_print_proc(void * p)
 {
-    GC_err_printf("%p is not a GC visible pointer location\n", p);
-    ABORT("GC_is_visible test failed");
+    ABORT_ARG1("GC_is_visible test failed", ": %p not GC-visible", p);
 }
 
 void (GC_CALLBACK *GC_is_visible_print_proc)(void * p) =
index 20c78ade78f2198967d83314f8c28b2b1d82841d..3657fbadff5a1b9bcc6a273e9b3b23924c815734 100644 (file)
@@ -149,17 +149,14 @@ GC_INNER void * GC_slow_getspecific(tsd * key, word qtid,
     for (i = 0; i < TS_HASH_SIZE; ++i) {
       for (p = key->hash[i].p; p != 0; p = p -> next) {
         if (!GC_is_marked(GC_base(p))) {
-          GC_err_printf("Thread-specific-data entry at %p not marked\n", p);
-          ABORT("Unmarked tse");
+          ABORT_ARG1("Unmarked thread-specific-data entry", " at %p", p);
         }
       }
     }
     for (i = 0; i < TS_CACHE_SIZE; ++i) {
       p = key -> cache[i];
       if (p != &invalid_tse && !GC_is_marked(GC_base(p))) {
-        GC_err_printf("Cached thread-specific-data entry at %p not marked\n",
-                      p);
-        ABORT("Unmarked cached tse");
+        ABORT_ARG1("Unmarked cached thread-specific-data entry", " at %p", p);
       }
     }
   }
index 92b34f6f5f1f1f560da0557bcdd5a24421c0ae02..8ecfcbbf3b98e92e7d6d9b0bdfcb3e670f72e651 100644 (file)
@@ -458,9 +458,8 @@ STATIC GC_thread GC_register_my_thread_inner(const struct GC_stack_base *sb,
                         (HANDLE*)&(me -> handle),
                         0 /* dwDesiredAccess */, FALSE /* bInheritHandle */,
                         DUPLICATE_SAME_ACCESS)) {
-        GC_COND_LOG_PRINTF("DuplicateHandle failed with error code: %d\n",
-                           (int)GetLastError());
-        ABORT("DuplicateHandle failed");
+        ABORT_ARG1("DuplicateHandle failed",
+                   ": errcode= 0x%X", (unsigned)GetLastError());
     }
 # endif
   me -> last_stack_min = ADDR_LIMIT;