xref: /titanic_52/usr/src/lib/libsqlite/tool/memleak2.awk (revision b6c3f7863936abeae522e48a13887dddeb691a45)
1
2#pragma ident	"%Z%%M%	%I%	%E% SMI"
3
4# This AWK script reads the output of testfixture when compiled for memory
5# debugging.  It generates SQL commands that can be fed into an sqlite
6# instance to determine what memory is never freed.  A typical usage would
7# be as follows:
8#
9#     make -f memleak.mk fulltest 2>mem.out
10#     awk -f ../sqlite/tool/memleak2.awk mem.out | ./sqlite :memory:
11#
12# The job performed by this script is the same as that done by memleak.awk.
13# The difference is that this script uses much less memory when the size
14# of the mem.out file is huge.
15#
16BEGIN {
17  print "CREATE TABLE mem(loc INTEGER PRIMARY KEY, src);"
18}
19/[0-9]+ malloc / {
20  print "INSERT INTO mem VALUES(" strtonum($6) ",'" $0 "');"
21}
22/[0-9]+ realloc / {
23  print "INSERT INTO mem VALUES(" strtonum($10) \
24           ",(SELECT src FROM mem WHERE loc=" strtonum($8) "));"
25  print "DELETE FROM mem WHERE loc=" strtonum($8) ";"
26}
27/[0-9]+ free / {
28  print "DELETE FROM mem WHERE loc=" strtonum($6) ";"
29}
30END {
31  print "SELECT src FROM mem;"
32}
33