[Gc] Dump blocks with debugging information.

S M Ryan wyrmwif at rawbw.com
Sun Jun 29 02:11:38 PDT 2008


I'm trying to dump all active blocks along with the debugging  
information in GC 6.7. Seems a straightforward task, but I can't find  
any routines to do it except GC_FIND_LEAKS which is not what I want.  
I tried to piece together code, but it insist on crapping out near  
the top of dumpblock.

This has to be possible. Is there some way to do so?

#include "private/gc_priv.h"
#include "private/dbg_mlc.h"

static void dumpblock(struct hblk *p, word dummy) {
	register hdr * hhdr = HDR(p);
	register size_t bytes = WORDS_TO_BYTES(hhdr -> hb_sz);

//	craps out near here because p or hhdr are invalid
//	even though this is a straight copy from GC_print_block_list >>  
GC_print_block_descr
//	and the GC_print_block_list works fine

	GC_err_printf3("(%lu:%lu,%lu)", (unsigned long)(hhdr -> hb_obj_kind),
			(unsigned long)bytes,
			(unsigned long)(GC_n_set_marks(hhdr)));
	if (hhdr -> hb_obj_kind == PTRFREE) {
		GC_err_printf0(" atomic object at ");
	} else {
		GC_err_printf0(" composite object at ");
	}
	register oh * ohdr = (oh *)GC_base(p);
	if (GC_HAS_DEBUG_INFO(p)) {
		GC_err_printf1("0x%lx (", ((unsigned long)ohdr + sizeof(oh)));
		GC_err_puts(ohdr -> oh_string);
		#   ifdef SHORT_DBG_HDRS
			GC_err_printf1(":%ld, ", (unsigned long)(ohdr -> oh_int));
		#   else
			GC_err_printf2(":%ld, sz=%ld, ", (unsigned long)(ohdr -> oh_int),
						(unsigned long)(ohdr -> oh_sz));
		#   endif
		GC_print_type((ptr_t)(ohdr + 1));
		GC_err_puts(")\n");
		PRINT_CALL_CHAIN(ohdr);
	} else {
		ptr_t base = GC_base(p);
		GC_err_printf2("start: 0x%lx, appr. length: %ld", base, GC_size 
(base));
	}
	GC_err_printf0("\n");
}

static void dumpallblocks(void) {
	GC_err_printf0("=======================================\n");
	GC_print_block_list(); // this works fine
	GC_apply_to_all_blocks(dumpblock, (word)0);
	GC_err_printf0("---------------------------------------\n");
}



More information about the Gc mailing list