out:;
}
- /* Force a garbage collection and generate a backtrace from a */
- /* random heap address. */
+ /* Force a garbage collection and generate/print a backtrace */
+ /* from a random heap address. */
GC_INNER void GC_generate_random_backtrace_no_gc(void)
{
void * current;
hdr * hhdr = GC_find_header(p);
char buffer[GC_TYPE_DESCR_LEN + 1];
int kind = hhdr -> hb_obj_kind;
+ char *kind_str;
if (0 != GC_describe_type_fns[kind] && GC_is_marked(GC_base(p))) {
/* This should preclude free list objects except with */
buffer[GC_TYPE_DESCR_LEN] = 0;
(GC_describe_type_fns[kind])(p, buffer);
GC_ASSERT(buffer[GC_TYPE_DESCR_LEN] == 0);
- GC_err_puts(buffer);
+ kind_str = buffer;
} else {
switch(kind) {
case PTRFREE:
- GC_err_puts("PTRFREE");
+ kind_str = "PTRFREE";
break;
case NORMAL:
- GC_err_puts("NORMAL");
+ kind_str = "NORMAL";
break;
case UNCOLLECTABLE:
- GC_err_puts("UNCOLLECTABLE");
+ kind_str = "UNCOLLECTABLE";
break;
# ifdef ATOMIC_UNCOLLECTABLE
case AUNCOLLECTABLE:
- GC_err_puts("ATOMIC UNCOLLECTABLE");
+ kind_str = "ATOMIC UNCOLLECTABLE";
break;
# endif
case STUBBORN:
- GC_err_puts("STUBBORN");
+ kind_str = "STUBBORN";
break;
default:
- GC_err_printf("kind=%d descr=0x%lx", kind,
- (unsigned long)(hhdr -> hb_descr));
+ kind_str = NULL;
}
}
+ if (NULL != kind_str) {
+ GC_err_puts(kind_str);
+ } else {
+ GC_err_printf("kind=%d descr=0x%lx",
+ kind, (unsigned long)hhdr->hb_descr);
+ }
}
#define GET_OH_LINENUM(ohdr) ((int)(ohdr)->oh_int)
+#ifndef SHORT_DBG_HDRS
+# define IF_NOT_SHORTDBG_HDRS(x) x
+# define COMMA_IFNOT_SHORTDBG_HDRS(x) /* comma */, x
+#else
+# define IF_NOT_SHORTDBG_HDRS(x) /* empty */
+# define COMMA_IFNOT_SHORTDBG_HDRS(x) /* empty */
+#endif
+
/* Print a human-readable description of the object to stderr. p points */
/* to somewhere inside an object with the debugging info. */
STATIC void GC_print_obj(ptr_t p)
# ifdef LINT2
if (!ohdr) ABORT("Invalid GC_print_obj argument");
# endif
- GC_err_printf("%p (", ((ptr_t)ohdr + sizeof(oh)));
- GC_err_puts(ohdr -> oh_string);
-# ifdef SHORT_DBG_HDRS
- GC_err_printf(":%d, ", GET_OH_LINENUM(ohdr));
-# else
- GC_err_printf(":%d, sz=%lu, ",
- GET_OH_LINENUM(ohdr), (unsigned long)(ohdr -> oh_sz));
-# endif
+ GC_err_printf("%p (%s:%d," IF_NOT_SHORTDBG_HDRS(" sz=%lu,") " ",
+ (ptr_t)ohdr + sizeof(oh), ohdr->oh_string,
+ GET_OH_LINENUM(ohdr) /*, */
+ COMMA_IFNOT_SHORTDBG_HDRS((unsigned long)ohdr->oh_sz));
GC_print_type((ptr_t)(ohdr + 1));
GC_err_puts(")\n");
PRINT_CALL_CHAIN(ohdr);
result = GC_malloc(lb + DEBUG_BYTES);
if (result == 0) {
- GC_err_printf("GC_debug_malloc(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc(%lu) returning NULL (%s:%d)\n",
+ (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
void * result = GC_malloc_ignore_off_page(lb + DEBUG_BYTES);
if (result == 0) {
- GC_err_printf("GC_debug_malloc_ignore_off_page(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc_ignore_off_page(%lu)"
+ " returning NULL (%s:%d)\n", (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
if (result == 0) {
GC_err_printf("GC_debug_malloc_atomic_ignore_off_page(%lu)"
- " returning NULL (", (unsigned long)lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ " returning NULL (%s:%d)\n", (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
void * result = GC_malloc_stubborn(lb + DEBUG_BYTES);
if (result == 0) {
- GC_err_printf("GC_debug_malloc(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc_stubborn(%lu)"
+ " returning NULL (%s:%d)\n", (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
void * result = GC_malloc_atomic(lb + DEBUG_BYTES);
if (result == 0) {
- GC_err_printf("GC_debug_malloc_atomic(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc_atomic(%lu) returning NULL (%s:%d)\n",
+ (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
void * result = GC_malloc_uncollectable(lb + UNCOLLECTABLE_DEBUG_BYTES);
if (result == 0) {
- GC_err_printf("GC_debug_malloc_uncollectable(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc_uncollectable(%lu)"
+ " returning NULL (%s:%d)\n", (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
GC_malloc_atomic_uncollectable(lb + UNCOLLECTABLE_DEBUG_BYTES);
if (result == 0) {
- GC_err_printf(
- "GC_debug_malloc_atomic_uncollectable(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc_atomic_uncollectable(%lu)"
+ " returning NULL (%s:%d)\n", (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
return;
}
if ((ptr_t)obj - base != sizeof(oh)) {
- GC_err_printf(
- "GC_debug_register_finalizer called with non-base-pointer %p\n",
- obj);
+ GC_err_printf("GC_debug_register_finalizer called with"
+ " non-base-pointer %p\n", obj);
}
if (0 == fn) {
GC_register_finalizer(base, 0, 0, &my_old_fn, &my_old_cd);
return;
}
if ((ptr_t)obj - base != sizeof(oh)) {
- GC_err_printf(
- "GC_debug_register_finalizer_no_order called with "
- "non-base-pointer %p\n",
- obj);
+ GC_err_printf("GC_debug_register_finalizer_no_order called with"
+ " non-base-pointer %p\n", obj);
}
if (0 == fn) {
GC_register_finalizer_no_order(base, 0, 0, &my_old_fn, &my_old_cd);
return;
}
if ((ptr_t)obj - base != sizeof(oh)) {
- GC_err_printf(
- "GC_debug_register_finalizer_unreachable called with "
- "non-base-pointer %p\n",
- obj);
+ GC_err_printf("GC_debug_register_finalizer_unreachable called with"
+ " non-base-pointer %p\n", obj);
}
if (0 == fn) {
GC_register_finalizer_unreachable(base, 0, 0, &my_old_fn, &my_old_cd);
return;
}
if ((ptr_t)obj - base != sizeof(oh)) {
- GC_err_printf(
- "GC_debug_register_finalizer_ignore_self called with "
- "non-base-pointer %p\n", obj);
+ GC_err_printf("GC_debug_register_finalizer_ignore_self called with"
+ " non-base-pointer %p\n", obj);
}
if (0 == fn) {
GC_register_finalizer_ignore_self(base, 0, 0, &my_old_fn, &my_old_cd);
myexefile = fopen(path, "rb");
if (myexefile == 0) {
if (GC_print_stats) {
- GC_err_puts("Couldn't open executable ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Could not open executable %s\n", path);
}
ABORT("Failed to open executable");
}
if (fread((char *)(&hdrdos), 1, sizeof(hdrdos), myexefile)
< sizeof(hdrdos)) {
if (GC_print_stats) {
- GC_err_puts("Couldn't read MSDOS header from ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Could not read MSDOS header from %s\n", path);
}
ABORT("Couldn't read MSDOS header");
}
if (E_MAGIC(hdrdos) != EMAGIC) {
if (GC_print_stats) {
- GC_err_puts("Executable has wrong DOS magic number: ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Executable has wrong DOS magic number: %s\n",
+ path);
}
ABORT("Bad DOS magic number");
}
if (fseek(myexefile, E_LFANEW(hdrdos), SEEK_SET) != 0) {
if (GC_print_stats) {
- GC_err_puts("Seek to new header failed in ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Seek to new header failed in %s\n", path);
}
ABORT("Bad DOS magic number");
}
if (fread((char *)(&hdr386), 1, sizeof(hdr386), myexefile)
< sizeof(hdr386)) {
if (GC_print_stats) {
- GC_err_puts("Couldn't read MSDOS header from ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Could not read MSDOS header from %s\n", path);
}
ABORT("Couldn't read OS/2 header");
}
if (E32_MAGIC1(hdr386) != E32MAGIC1 || E32_MAGIC2(hdr386) != E32MAGIC2) {
if (GC_print_stats) {
- GC_err_puts("Executable has wrong OS/2 magic number: ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Executable has wrong OS/2 magic number: %s\n",
+ path);
}
ABORT("Bad OS/2 magic number");
}
if (E32_BORDER(hdr386) != E32LEBO || E32_WORDER(hdr386) != E32LEWO) {
if (GC_print_stats) {
- GC_err_puts("Executable has wrong byte order: ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Executable has wrong byte order: %s\n", path);
}
ABORT("Bad byte order");
}
if (E32_CPU(hdr386) == E32CPU286) {
if (GC_print_stats) {
- GC_err_puts("GC can't handle 80286 executables: ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("GC cannot handle 80286 executables: %s\n", path);
}
ABORT("Intel 80286 executables are unsupported");
}
if (fseek(myexefile, E_LFANEW(hdrdos) + E32_OBJTAB(hdr386),
SEEK_SET) != 0) {
if (GC_print_stats) {
- GC_err_puts("Seek to object table failed: ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Seek to object table failed: %s\n", path);
}
ABORT("Seek to object table failed");
}
int flags;
if (fread((char *)(&seg), 1, sizeof(seg), myexefile) < sizeof(seg)) {
if (GC_print_stats) {
- GC_err_puts("Couldn't read obj table entry from ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Could not read obj table entry from %s\n", path);
}
ABORT("Couldn't read obj table entry");
}