]>
git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/lib/fuzzer/scripts/unbalanced_allocs.py
2 #===- lib/fuzzer/scripts/unbalanced_allocs.py ------------------------------===#
4 # The LLVM Compiler Infrastructure
6 # This file is distributed under the University of Illinois Open Source
7 # License. See LICENSE.TXT for details.
9 #===------------------------------------------------------------------------===#
11 # Post-process -trace_malloc=2 output and printout only allocations and frees
12 # unbalanced inside of fuzzer runs.
14 # my_fuzzer -trace_malloc=2 -runs=10 2>&1 | unbalanced_allocs.py -skip=5
16 #===------------------------------------------------------------------------===#
23 def PrintStack(line
, stack
):
27 print 'Unbalanced ' + line
.rstrip();
31 def ProcessStack(line
, f
):
33 while line
and line
.startswith(' #'):
38 def ProcessFree(line
, f
, allocs
):
39 if not line
.startswith('FREE['):
42 addr
= int(line
.split()[1], 16)
43 next_line
, stack
= ProcessStack(f
.readline(), f
)
47 PrintStack(line
, stack
)
50 def ProcessMalloc(line
, f
, allocs
):
51 if not line
.startswith('MALLOC['):
52 return ProcessFree(line
, f
, allocs
)
54 addr
= int(line
.split()[1], 16)
55 assert not addr
in allocs
57 next_line
, stack
= ProcessStack(f
.readline(), f
)
58 allocs
[addr
] = (line
, stack
)
61 def ProcessRun(line
, f
):
62 if not line
.startswith('MallocFreeTracer: START'):
63 return ProcessMalloc(line
, f
, {})
69 if line
.startswith('MallocFreeTracer: STOP'):
72 for _
, (l
, s
) in allocs
.iteritems():
76 line
= ProcessMalloc(line
, f
, allocs
)
82 line
= ProcessRun(line
, f
);
85 parser
= argparse
.ArgumentParser()
86 parser
.add_argument('--skip', default
=0, help='number of runs to ignore')
87 args
= parser
.parse_args()
89 _skip
= int(args
.skip
) + 1
90 ProcessFile(sys
.stdin
)
92 if __name__
== '__main__':