Re: [Cobolforgcc-devel] Debug Error Routines
Status: Pre-Alpha
Brought to you by:
timjosling
From: Tim J. <te...@me...> - 2000-11-26 03:45:48
|
Steven, Look at cobumem.c and cobutil.c in the CVS for examples. I have pasted one below. Note that asserts do not have to be protected by the #if, because they do nothing if NDEBUG is set. Thus the two naked asserts at the end. If the debugging is on, I do lots of checks for integrity of the memory allocation, buffer overrunrs etc. Each allocated area has a magic number for validation, and the length etc. This all disappears when debug is turned off. So, for example, you can put assert(pointer1!=NULL); and such all over the place. You could check that the parameters passed are consistent. The only thing to be careful of is to make sure none of the operational code is in asserts or within the #ifndef scope. This would be bad int next_ix=0; assert(next_ix++<MAX); << increament won't happen if debug turned off item[next_ix]=stuff; By the way if you register with sourceforge I can record your work in the task tracking system. Regards, Tim Josling > #ifndef NDEBUG > for (mem=first_malloc; mem; mem=mem->next) > { > > counter++; > totaller+=mem->size; > > assert(mem->size>0); > assert(mem->magic==MAGIC1); > > if (mem==first_malloc) > assert(!(mem->prev)); > else > { > assert (mem->prev); > assert (mem->prev->next==mem); > } > if (mem==last_malloc) > assert(!(mem->next)); > else > { > assert (mem->next); > assert (mem->next->prev==mem); > } > > memend=(struct malloc_trailer*)(((char*)mem)+(mem->size)+sizeof(struct malloc_header)); > assert(memend->magic==MAGIC2); > > } > > #endif > assert(counter==(malloc_count-free_count)); > assert(totaller==(malloc_total-free_total)); |