summaryrefslogtreecommitdiff
path: root/dbg_mlc.c
diff options
context:
space:
mode:
Diffstat (limited to 'dbg_mlc.c')
-rw-r--r--dbg_mlc.c134
1 files changed, 113 insertions, 21 deletions
diff --git a/dbg_mlc.c b/dbg_mlc.c
index 094614a5..f9ed6f3f 100644
--- a/dbg_mlc.c
+++ b/dbg_mlc.c
@@ -1,6 +1,7 @@
/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
+ * Copyright (c) 1997 by Silicon Graphics. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
@@ -14,6 +15,11 @@
/* Boehm, October 9, 1995 1:16 pm PDT */
# include "gc_priv.h"
+void GC_default_print_heap_obj_proc();
+GC_API void GC_register_finalizer_no_order
+ GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
+ GC_finalization_proc *ofn, GC_PTR *ocd));
+
/* Do we want to and know how to save the call stack at the time of */
/* an allocation? How much space do we want to use in each object? */
@@ -27,7 +33,7 @@
typedef struct {
char * oh_string; /* object descriptor string */
word oh_int; /* object descriptor integers */
-# ifdef SAVE_CALL_CHAIN
+# ifdef NEED_CALLINFO
struct callinfo oh_ci[NFRAMES];
# endif
word oh_sz; /* Original malloc arg. */
@@ -42,17 +48,22 @@ typedef struct {
#ifdef SAVE_CALL_CHAIN
-# define ADD_CALL_CHAIN(base) GC_save_callers(((oh *)(base)) -> oh_ci)
+# define ADD_CALL_CHAIN(base, ra) GC_save_callers(((oh *)(base)) -> oh_ci)
# define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
#else
-# define ADD_CALL_CHAIN(base)
+# ifdef GC_ADD_CALLER
+# define ADD_CALL_CHAIN(base, ra) ((oh *)(base)) -> oh_ci[0].ci_pc = (ra)
+# define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
+# else
+# define ADD_CALL_CHAIN(base, ra)
# define PRINT_CALL_CHAIN(base)
+# endif
#endif
/* Check whether object with base pointer p has debugging info */
/* p is assumed to point to a legitimate object in our part */
/* of the heap. */
-bool GC_has_debug_info(p)
+GC_bool GC_has_debug_info(p)
ptr_t p;
{
register oh * ohdr = (oh *)p;
@@ -134,6 +145,17 @@ ptr_t p;
(unsigned long)(ohdr -> oh_sz));
PRINT_CALL_CHAIN(ohdr);
}
+
+void GC_debug_print_heap_obj_proc(p)
+ptr_t p;
+{
+ if (GC_has_debug_info(p)) {
+ GC_print_obj(p);
+ } else {
+ GC_default_print_heap_obj_proc(p);
+ }
+}
+
void GC_print_smashed_obj(p, clobbered_addr)
ptr_t p, clobbered_addr;
{
@@ -162,6 +184,7 @@ void GC_check_heap_proc();
void GC_start_debugging()
{
GC_check_heap = GC_check_heap_proc;
+ GC_print_heap_obj = GC_debug_print_heap_obj_proc;
GC_debugging_started = TRUE;
GC_register_displacement((word)sizeof(oh));
}
@@ -177,13 +200,24 @@ void GC_start_debugging()
GC_register_displacement((word)sizeof(oh) + offset);
}
+# ifdef GC_ADD_CALLER
+# define EXTRA_ARGS word ra, char * s, int i
+# define OPT_RA ra,
+# else
+# define EXTRA_ARGS char * s, int i
+# define OPT_RA
+# endif
+
# ifdef __STDC__
- GC_PTR GC_debug_malloc(size_t lb, char * s, int i)
+ GC_PTR GC_debug_malloc(size_t lb, EXTRA_ARGS)
# else
GC_PTR GC_debug_malloc(lb, s, i)
size_t lb;
char * s;
int i;
+# ifdef GC_ADD_CALLER
+ --> GC_ADD_CALLER not implemented for K&R C
+# endif
# endif
{
GC_PTR result = GC_malloc(lb + DEBUG_BYTES);
@@ -198,13 +232,13 @@ void GC_start_debugging()
if (!GC_debugging_started) {
GC_start_debugging();
}
- ADD_CALL_CHAIN(result);
+ ADD_CALL_CHAIN(result, ra);
return (GC_store_debug_info(result, (word)lb, s, (word)i));
}
#ifdef STUBBORN_ALLOC
# ifdef __STDC__
- GC_PTR GC_debug_malloc_stubborn(size_t lb, char * s, int i)
+ GC_PTR GC_debug_malloc_stubborn(size_t lb, EXTRA_ARGS)
# else
GC_PTR GC_debug_malloc_stubborn(lb, s, i)
size_t lb;
@@ -224,7 +258,7 @@ void GC_start_debugging()
if (!GC_debugging_started) {
GC_start_debugging();
}
- ADD_CALL_CHAIN(result);
+ ADD_CALL_CHAIN(result, ra);
return (GC_store_debug_info(result, (word)lb, s, (word)i));
}
@@ -271,7 +305,7 @@ GC_PTR p;
#endif /* STUBBORN_ALLOC */
# ifdef __STDC__
- GC_PTR GC_debug_malloc_atomic(size_t lb, char * s, int i)
+ GC_PTR GC_debug_malloc_atomic(size_t lb, EXTRA_ARGS)
# else
GC_PTR GC_debug_malloc_atomic(lb, s, i)
size_t lb;
@@ -291,12 +325,12 @@ GC_PTR p;
if (!GC_debugging_started) {
GC_start_debugging();
}
- ADD_CALL_CHAIN(result);
+ ADD_CALL_CHAIN(result, ra);
return (GC_store_debug_info(result, (word)lb, s, (word)i));
}
# ifdef __STDC__
- GC_PTR GC_debug_malloc_uncollectable(size_t lb, char * s, int i)
+ GC_PTR GC_debug_malloc_uncollectable(size_t lb, EXTRA_ARGS)
# else
GC_PTR GC_debug_malloc_uncollectable(lb, s, i)
size_t lb;
@@ -316,10 +350,37 @@ GC_PTR p;
if (!GC_debugging_started) {
GC_start_debugging();
}
- ADD_CALL_CHAIN(result);
+ ADD_CALL_CHAIN(result, ra);
return (GC_store_debug_info(result, (word)lb, s, (word)i));
}
+#ifdef ATOMIC_UNCOLLECTABLE
+# ifdef __STDC__
+ GC_PTR GC_debug_malloc_atomic_uncollectable(size_t lb, EXTRA_ARGS)
+# else
+ GC_PTR GC_debug_malloc_atomic_uncollectable(lb, s, i)
+ size_t lb;
+ char * s;
+ int i;
+# endif
+{
+ GC_PTR result = GC_malloc_atomic_uncollectable(lb + DEBUG_BYTES);
+
+ if (result == 0) {
+ GC_err_printf1(
+ "GC_debug_malloc_atomic_uncollectable(%ld) returning NIL (",
+ (unsigned long) lb);
+ GC_err_puts(s);
+ GC_err_printf1(":%ld)\n", (unsigned long)i);
+ return(0);
+ }
+ if (!GC_debugging_started) {
+ GC_start_debugging();
+ }
+ ADD_CALL_CHAIN(result, ra);
+ return (GC_store_debug_info(result, (word)lb, s, (word)i));
+}
+#endif /* ATOMIC_UNCOLLECTABLE */
# ifdef __STDC__
void GC_debug_free(GC_PTR p)
@@ -359,7 +420,7 @@ GC_PTR p;
# else
{
register hdr * hhdr = HDR(p);
- bool uncollectable = FALSE;
+ GC_bool uncollectable = FALSE;
if (hhdr -> hb_obj_kind == UNCOLLECTABLE) {
uncollectable = TRUE;
@@ -375,7 +436,7 @@ GC_PTR p;
}
# ifdef __STDC__
- GC_PTR GC_debug_realloc(GC_PTR p, size_t lb, char *s, int i)
+ GC_PTR GC_debug_realloc(GC_PTR p, size_t lb, EXTRA_ARGS)
# else
GC_PTR GC_debug_realloc(p, lb, s, i)
GC_PTR p;
@@ -386,15 +447,15 @@ GC_PTR p;
{
register GC_PTR base = GC_base(p);
register ptr_t clobbered;
- register GC_PTR result = GC_debug_malloc(lb, s, i);
+ register GC_PTR result;
register size_t copy_sz = lb;
register size_t old_sz;
register hdr * hhdr;
- if (p == 0) return(GC_debug_malloc(lb, s, i));
+ if (p == 0) return(GC_debug_malloc(lb, OPT_RA s, i));
if (base == 0) {
GC_err_printf1(
- "Attempt to free invalid pointer %lx\n", (unsigned long)p);
+ "Attempt to reallocate invalid pointer %lx\n", (unsigned long)p);
ABORT("realloc(invalid pointer)");
}
if ((ptr_t)p - (ptr_t)base != sizeof(oh)) {
@@ -407,18 +468,23 @@ GC_PTR p;
switch (hhdr -> hb_obj_kind) {
# ifdef STUBBORN_ALLOC
case STUBBORN:
- result = GC_debug_malloc_stubborn(lb, s, i);
+ result = GC_debug_malloc_stubborn(lb, OPT_RA s, i);
break;
# endif
case NORMAL:
- result = GC_debug_malloc(lb, s, i);
+ result = GC_debug_malloc(lb, OPT_RA s, i);
break;
case PTRFREE:
- result = GC_debug_malloc_atomic(lb, s, i);
+ result = GC_debug_malloc_atomic(lb, OPT_RA s, i);
break;
case UNCOLLECTABLE:
- result = GC_debug_malloc_uncollectable(lb, s, i);
+ result = GC_debug_malloc_uncollectable(lb, OPT_RA s, i);
break;
+# ifdef ATOMIC_UNCOLLECTABLE
+ case AUNCOLLECTABLE:
+ result = GC_debug_malloc_atomic_uncollectable(lb, OPT_RA s, i);
+ break;
+# endif
default:
GC_err_printf0("GC_debug_realloc: encountered bad kind\n");
ABORT("bad kind");
@@ -432,6 +498,7 @@ GC_PTR p;
if (old_sz < copy_sz) copy_sz = old_sz;
if (result == 0) return(0);
BCOPY(p, result, copy_sz);
+ GC_debug_free(p);
return(result);
}
@@ -542,6 +609,31 @@ struct closure {
}
# ifdef __STDC__
+ void GC_debug_register_finalizer_no_order
+ (GC_PTR obj, GC_finalization_proc fn,
+ GC_PTR cd, GC_finalization_proc *ofn,
+ GC_PTR *ocd)
+# else
+ void GC_debug_register_finalizer_no_order
+ (obj, fn, cd, ofn, ocd)
+ GC_PTR obj;
+ GC_finalization_proc fn;
+ GC_PTR cd;
+ GC_finalization_proc *ofn;
+ GC_PTR *ocd;
+# endif
+{
+ ptr_t base = GC_base(obj);
+ if (0 == base || (ptr_t)obj - base != sizeof(oh)) {
+ GC_err_printf1(
+ "GC_register_finalizer_no_order called with non-base-pointer 0x%lx\n",
+ obj);
+ }
+ GC_register_finalizer_no_order(base, GC_debug_invoke_finalizer,
+ GC_make_closure(fn,cd), ofn, ocd);
+ }
+
+# ifdef __STDC__
void GC_debug_register_finalizer_ignore_self
(GC_PTR obj, GC_finalization_proc fn,
GC_PTR cd, GC_finalization_proc *ofn,