diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2012-12-11 09:28:12 +0400 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2012-12-11 15:28:38 +0400 |
commit | 1c3d8e3f6a963c32c5365ff52a9ebc6d65c088ce (patch) | |
tree | 090b306ecc7cb3126639fe1177964531e72df903 | |
parent | db6df7562ce3dbf5e4eb4269229dee780f489440 (diff) | |
download | bdwgc-1c3d8e3f6a963c32c5365ff52a9ebc6d65c088ce.tar.gz |
Replace GC_log/err_printf() followed by ABORT with ABORT_ARGn()
(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.
-rw-r--r-- | allchblk.c | 5 | ||||
-rw-r--r-- | alloc.c | 5 | ||||
-rw-r--r-- | dbg_mlc.c | 19 | ||||
-rw-r--r-- | dyn_load.c | 33 | ||||
-rw-r--r-- | include/private/gc_priv.h | 19 | ||||
-rw-r--r-- | os_dep.c | 67 | ||||
-rw-r--r-- | pthread_stop_world.c | 18 | ||||
-rw-r--r-- | ptr_chck.c | 10 | ||||
-rw-r--r-- | specific.c | 7 | ||||
-rw-r--r-- | win32_threads.c | 5 |
10 files changed, 82 insertions, 106 deletions
@@ -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)); @@ -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 */ @@ -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( @@ -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 } diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index c3125170..6d7ffacf 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -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) \ @@ -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) { diff --git a/pthread_stop_world.c b/pthread_stop_world.c index a06ffb71..7b0d0168 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -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); } } } @@ -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) = @@ -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); } } } diff --git a/win32_threads.c b/win32_threads.c index 92b34f6f..8ecfcbbf 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -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; |