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