File: verify_alloc.awk

package info (click to toggle)
eprover 3.2.5%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,504 kB
  • sloc: ansic: 104,396; csh: 13,135; python: 11,207; awk: 5,825; makefile: 554; sh: 400
file content (104 lines) | stat: -rwxr-xr-x 1,976 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/opt/local/bin/gawk -f
#
# Usage: some_clib_program | verify_alloc.awk
#
# Copyright 1998 Stephan Schulz, schulz@informatik.tu-muenchen.de
#
# Interpret the debugging output of a program using the CLIB memory
# management routines (in BASICS/clb_memory.[ch]) and compiled with
# -DCLB_MEMORY_DEBUG2. 
# 
# verify_alloc.awk reports doubly allocated blocks (hopefully never,
# as this would indicate a bug in CLIB), blocks freed that are
# currently not allocated (this catches blocks freed more than once),
# block allocated with a certain size and freed with a different one, 
# and finally blocks that are allocated but never freed.
#
# This works only with memory handled via SizeMalloc()/SizeFree().
#

/Block /{
   if($3=="A:")
   {
      if(mem_array[$2])
      {
	 print $0 " doubly allocated";
	 fail_array[count++] = $0 " DA";
      }
      else
      {
	 mem_array[$2] = $5+1;
      }
   }
   else if($3=="D:")
   {
      if(!mem_array[$2])
      {
	 print $0 " freeed but not allocated";
	 fail_array[count++] = $0 " FN";
      }
      else
      {
	 if(mem_array[$2] != ($5+1))
	 {
	    print $0 " freed with wrong size " mem_array[$2]-1;
	    fail_array[count++] = $0 " WS";
	   }
	 delete mem_array[$2];
      }
   }
   else if($3=="M:" || $3=="R:")
   {
      if(raw_array[$2])
      {
	 print $0 " doubly malloc()ed";
	 fail_array[count++] = $0 " DM";
      }
      else
      {
	 raw_array[$2] = 1;
      }
   }
   else if($3=="F:")
   {
      if(!raw_array[$2])
      {
	 print $0 " FREEed but not malloc()ed";
	 fail_array[count++] = $0 " FM";
      }
      else
      {
	 delete raw_array[$2];
      }
   }
   
}

!/Block / && /.+/{
   print $0;
}

END{
   print "Malloc errors:"
   for(i in raw_array)
   {
      print "Remaining: " i;
   }
   print "SizeMalloc errors:"
   for(i in mem_array)
   {
      print "Remaining: " i " " mem_array[i]-1;      
   }
   print "Failure list:";
   for(i in fail_array)
   {
      print fail_array[i];
   }
}