1#!/sw/bin/gawk -f 2# 3# Usage: some_clib_program | verify_alloc.awk 4# 5# Copyright 1998 Stephan Schulz, schulz@informatik.tu-muenchen.de 6# 7# Interpret the debugging output of a program using the CLIB memory 8# management routines (in BASICS/clb_memory.[ch]) and compiled with 9# -DCLB_MEMORY_DEBUG2. 10# 11# verify_alloc.awk reports doubly allocated blocks (hopefully never, 12# as this would indicate a bug in CLIB), blocks freed that are 13# currently not allocated (this catches blocks freed more than once), 14# block allocated with a certain size and freed with a different one, 15# and finally blocks that are allocated but never freed. 16# 17# This works only with memory handled via SizeMalloc()/SizeFree(). 18# 19 20/Block /{ 21 if($3=="A:") 22 { 23 if(mem_array[$2]) 24 { 25 print $0 " doubly allocated"; 26 fail_array[count++] = $0 " DA"; 27 } 28 else 29 { 30 mem_array[$2] = $5+1; 31 } 32 } 33 else if($3=="D:") 34 { 35 if(!mem_array[$2]) 36 { 37 print $0 " freeed but not allocated"; 38 fail_array[count++] = $0 " FN"; 39 } 40 else 41 { 42 if(mem_array[$2] != ($5+1)) 43 { 44 print $0 " freed with wrong size " mem_array[$2]-1; 45 fail_array[count++] = $0 " WS"; 46 } 47 delete mem_array[$2]; 48 } 49 } 50 else if($3=="M:" || $3=="R:") 51 { 52 if(raw_array[$2]) 53 { 54 print $0 " doubly malloc()ed"; 55 fail_array[count++] = $0 " DM"; 56 } 57 else 58 { 59 raw_array[$2] = 1; 60 } 61 } 62 else if($3=="F:") 63 { 64 if(!raw_array[$2]) 65 { 66 print $0 " FREEed but not malloc()ed"; 67 fail_array[count++] = $0 " FM"; 68 } 69 else 70 { 71 delete raw_array[$2]; 72 } 73 } 74 75} 76 77!/Block / && /.+/{ 78 print $0; 79} 80 81END{ 82 print "Malloc errors:" 83 for(i in raw_array) 84 { 85 print "Remaining: " i; 86 } 87 print "SizeMalloc errors:" 88 for(i in mem_array) 89 { 90 print "Remaining: " i " " mem_array[i]-1; 91 } 92 print "Failure list:"; 93 for(i in fail_array) 94 { 95 print fail_array[i]; 96 } 97} 98 99 100 101 102 103 104 105