📄 dbg_mlc.c
字号:
(unsigned long)(ohdr -> oh_sz));# endif GC_print_type((ptr_t)(ohdr + 1)); GC_err_puts(")\n"); PRINT_CALL_CHAIN(ohdr);}# if defined(__STDC__) || defined(__cplusplus) void GC_debug_print_heap_obj_proc(ptr_t p)# else void GC_debug_print_heap_obj_proc(p) ptr_t p;# endif{ GC_ASSERT(!I_HOLD_LOCK()); if (GC_HAS_DEBUG_INFO(p)) { GC_print_obj(p); } else { GC_default_print_heap_obj_proc(p); }}#ifndef SHORT_DBG_HDRSvoid GC_print_smashed_obj(p, clobbered_addr)ptr_t p, clobbered_addr;{ register oh * ohdr = (oh *)GC_base(p); GC_ASSERT(!I_HOLD_LOCK()); GC_err_printf2("0x%lx in object at 0x%lx(", (unsigned long)clobbered_addr, (unsigned long)p); if (clobbered_addr <= (ptr_t)(&(ohdr -> oh_sz)) || ohdr -> oh_string == 0) { GC_err_printf1("<smashed>, appr. sz = %ld)\n", (GC_size((ptr_t)ohdr) - DEBUG_BYTES)); } else { if (ohdr -> oh_string[0] == '\0') { GC_err_puts("EMPTY(smashed?)"); } else { GC_err_puts(ohdr -> oh_string); } GC_err_printf2(":%ld, sz=%ld)\n", (unsigned long)(ohdr -> oh_int), (unsigned long)(ohdr -> oh_sz)); PRINT_CALL_CHAIN(ohdr); }}#endifvoid GC_check_heap_proc GC_PROTO((void));void GC_print_all_smashed_proc GC_PROTO((void));void GC_do_nothing() {}void GC_start_debugging(){# ifndef SHORT_DBG_HDRS GC_check_heap = GC_check_heap_proc; GC_print_all_smashed = GC_print_all_smashed_proc;# else GC_check_heap = GC_do_nothing; GC_print_all_smashed = GC_do_nothing;# endif GC_print_heap_obj = GC_debug_print_heap_obj_proc; GC_debugging_started = TRUE; GC_register_displacement((word)sizeof(oh));}size_t GC_debug_header_size = sizeof(oh);# if defined(__STDC__) || defined(__cplusplus) void GC_debug_register_displacement(GC_word offset)# else void GC_debug_register_displacement(offset) GC_word offset;# endif{ GC_register_displacement(offset); GC_register_displacement((word)sizeof(oh) + offset);}# ifdef __STDC__ GC_PTR GC_debug_malloc(size_t lb, GC_EXTRA_PARAMS)# 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); if (result == 0) { GC_err_printf1("GC_debug_malloc(%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));}# ifdef __STDC__ GC_PTR GC_debug_malloc_ignore_off_page(size_t lb, GC_EXTRA_PARAMS)# else GC_PTR GC_debug_malloc_ignore_off_page(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_ignore_off_page(lb + DEBUG_BYTES); if (result == 0) { GC_err_printf1("GC_debug_malloc_ignore_off_page(%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));}# ifdef __STDC__ GC_PTR GC_debug_malloc_atomic_ignore_off_page(size_t lb, GC_EXTRA_PARAMS)# else GC_PTR GC_debug_malloc_atomic_ignore_off_page(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_atomic_ignore_off_page(lb + DEBUG_BYTES); if (result == 0) { GC_err_printf1("GC_debug_malloc_atomic_ignore_off_page(%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));}# ifdef DBG_HDRS_ALL/* * An allocation function for internal use. * Normally internally allocated objects do not have debug information. * But in this case, we need to make sure that all objects have debug * headers. * We assume debugging was started in collector initialization, * and we already hold the GC lock. */ GC_PTR GC_debug_generic_malloc_inner(size_t lb, int k) { GC_PTR result = GC_generic_malloc_inner(lb + DEBUG_BYTES, k); if (result == 0) { GC_err_printf1("GC internal allocation (%ld bytes) returning NIL\n", (unsigned long) lb); return(0); } ADD_CALL_CHAIN(result, GC_RETURN_ADDR); return (GC_store_debug_info_inner(result, (word)lb, "INTERNAL", (word)0)); } GC_PTR GC_debug_generic_malloc_inner_ignore_off_page(size_t lb, int k) { GC_PTR result = GC_generic_malloc_inner_ignore_off_page( lb + DEBUG_BYTES, k); if (result == 0) { GC_err_printf1("GC internal allocation (%ld bytes) returning NIL\n", (unsigned long) lb); return(0); } ADD_CALL_CHAIN(result, GC_RETURN_ADDR); return (GC_store_debug_info_inner(result, (word)lb, "INTERNAL", (word)0)); }# endif#ifdef STUBBORN_ALLOC# ifdef __STDC__ GC_PTR GC_debug_malloc_stubborn(size_t lb, GC_EXTRA_PARAMS)# else GC_PTR GC_debug_malloc_stubborn(lb, s, i) size_t lb; char * s; int i;# endif{ GC_PTR result = GC_malloc_stubborn(lb + DEBUG_BYTES); if (result == 0) { GC_err_printf1("GC_debug_malloc(%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));}void GC_debug_change_stubborn(p)GC_PTR p;{ register GC_PTR q = GC_base(p); register hdr * hhdr; if (q == 0) { GC_err_printf1("Bad argument: 0x%lx to GC_debug_change_stubborn\n", (unsigned long) p); ABORT("GC_debug_change_stubborn: bad arg"); } hhdr = HDR(q); if (hhdr -> hb_obj_kind != STUBBORN) { GC_err_printf1("GC_debug_change_stubborn arg not stubborn: 0x%lx\n", (unsigned long) p); ABORT("GC_debug_change_stubborn: arg not stubborn"); } GC_change_stubborn(q);}void GC_debug_end_stubborn_change(p)GC_PTR p;{ register GC_PTR q = GC_base(p); register hdr * hhdr; if (q == 0) { GC_err_printf1("Bad argument: 0x%lx to GC_debug_end_stubborn_change\n", (unsigned long) p); ABORT("GC_debug_end_stubborn_change: bad arg"); } hhdr = HDR(q); if (hhdr -> hb_obj_kind != STUBBORN) { GC_err_printf1("debug_end_stubborn_change arg not stubborn: 0x%lx\n", (unsigned long) p); ABORT("GC_debug_end_stubborn_change: arg not stubborn"); } GC_end_stubborn_change(q);}#else /* !STUBBORN_ALLOC */# ifdef __STDC__ GC_PTR GC_debug_malloc_stubborn(size_t lb, GC_EXTRA_PARAMS)# else GC_PTR GC_debug_malloc_stubborn(lb, s, i) size_t lb; char * s; int i;# endif{ return GC_debug_malloc(lb, OPT_RA s, i);}void GC_debug_change_stubborn(p)GC_PTR p;{}void GC_debug_end_stubborn_change(p)GC_PTR p;{}#endif /* !STUBBORN_ALLOC */# ifdef __STDC__ GC_PTR GC_debug_malloc_atomic(size_t lb, GC_EXTRA_PARAMS)# else GC_PTR GC_debug_malloc_atomic(lb, s, i) size_t lb; char * s; int i;# endif{ GC_PTR result = GC_malloc_atomic(lb + DEBUG_BYTES); if (result == 0) { GC_err_printf1("GC_debug_malloc_atomic(%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));}# ifdef __STDC__ GC_PTR GC_debug_malloc_uncollectable(size_t lb, GC_EXTRA_PARAMS)# else GC_PTR GC_debug_malloc_uncollectable(lb, s, i) size_t lb; char * s; int i;# endif{ GC_PTR result = GC_malloc_uncollectable(lb + UNCOLLECTABLE_DEBUG_BYTES); if (result == 0) { GC_err_printf1("GC_debug_malloc_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));}#ifdef ATOMIC_UNCOLLECTABLE# ifdef __STDC__ GC_PTR GC_debug_malloc_atomic_uncollectable(size_t lb, GC_EXTRA_PARAMS)# 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 + UNCOLLECTABLE_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)# else void GC_debug_free(p) GC_PTR p;# endif{ register GC_PTR base; register ptr_t clobbered; if (0 == p) return; base = GC_base(p); if (base == 0) { GC_err_printf1("Attempt to free invalid pointer %lx\n", (unsigned long)p); ABORT("free(invalid pointer)"); } if ((ptr_t)p - (ptr_t)base != sizeof(oh)) { GC_err_printf1( "GC_debug_free called on pointer %lx wo debugging info\n", (unsigned long)p); } else {# ifndef SHORT_DBG_HDRS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -