1 | #!/bin/bash |
---|
2 | |
---|
3 | if [ -z $1 ] ; then |
---|
4 | echo '' |
---|
5 | echo 'Usage: arb_valgrind_1.x [-c <callers>] [-f <filter>] [-l [-r]] <arb_program> <arguments>' |
---|
6 | echo '' |
---|
7 | echo ' runs valgrind (versions 1.x) on <arb_program> piping results through a filter' |
---|
8 | echo ' so that the output can be used as emacs error messages' |
---|
9 | echo '' |
---|
10 | echo ' <callers> show <callers> stackframes (default: none)' |
---|
11 | echo ' [in fact they are always shown, but not marked as errors]' |
---|
12 | echo ' <filter> regexpr to filter the reason (default: all)' |
---|
13 | echo ' -l [-r] turn on leak-checking (-r for reachable blocks)' |
---|
14 | echo '' |
---|
15 | echo '' |
---|
16 | echo 'Usage: arb_valgrind update' |
---|
17 | echo '' |
---|
18 | echo ' Updates the source file list which is needed to create correct file refs.' |
---|
19 | echo ' Called automatically by normal use if list is missing.' |
---|
20 | echo ' Call if files are not highlighted as errors (i.e if you have new files).' |
---|
21 | echo '' |
---|
22 | echo 'Environment:' |
---|
23 | echo '' |
---|
24 | echo ' $ARBHOME a directory which has to contain a subdirectory SOURCE_TOOLS.' |
---|
25 | echo ' SOURCE_TOOLS has to contain valgrind2grep and has to be writeable for the user' |
---|
26 | echo '' |
---|
27 | echo ' $ARB_VALGRIND_SOURCE_ROOT down from here the script scans for sources' |
---|
28 | echo ' (defaults to $ARBHOME if empty)' |
---|
29 | echo '' |
---|
30 | echo 'Note: I use this from inside emacs as follows:' |
---|
31 | echo ' M-x compile' |
---|
32 | echo ' with:' |
---|
33 | echo ' (cd $ARBHOME;make nt) && arb_valgrind -l arb_ntree ~/ARB/demo.arb' |
---|
34 | echo '' |
---|
35 | |
---|
36 | else |
---|
37 | if [ -z $ARB_VALGRIND_SOURCE_ROOT ] ; then |
---|
38 | ARB_VALGRIND_SOURCE_ROOT=$ARBHOME |
---|
39 | fi |
---|
40 | |
---|
41 | DIR=$ARBHOME/SOURCE_TOOLS |
---|
42 | LIST=$DIR/valgrind2grep.lst |
---|
43 | |
---|
44 | UPDATE=0 |
---|
45 | RUN=0 |
---|
46 | CALLERS=0 |
---|
47 | FILTER='.*' |
---|
48 | LEAK_CHECK='' |
---|
49 | |
---|
50 | if [ ! -f $LIST ] ; then |
---|
51 | UPDATE=1 |
---|
52 | fi |
---|
53 | if [ $1 = "update" ] ; then |
---|
54 | UPDATE=1 |
---|
55 | else |
---|
56 | RUN=1 |
---|
57 | SCAN_ARGS=1 |
---|
58 | |
---|
59 | while [ $SCAN_ARGS = 1 ] ; do |
---|
60 | SCAN_ARGS=0 |
---|
61 | if [ $1 = '-c' ] ; then |
---|
62 | CALLERS=$2 |
---|
63 | shift 2 |
---|
64 | SCAN_ARGS=1 |
---|
65 | fi |
---|
66 | if [ $1 = '-f' ] ; then |
---|
67 | FILTER=$2 |
---|
68 | shift 2 |
---|
69 | SCAN_ARGS=1 |
---|
70 | fi |
---|
71 | if [ $1 = '-l' ] ; then |
---|
72 | LEAK_CHECK='--leak-check=yes --leak-resolution=high' |
---|
73 | shift 1 |
---|
74 | SCAN_ARGS=1 |
---|
75 | fi |
---|
76 | if [ $1 = '-r' ] ; then |
---|
77 | LEAK_CHECK="$LEAK_CHECK --show-reachable=yes" |
---|
78 | shift 1 |
---|
79 | SCAN_ARGS=1 |
---|
80 | fi |
---|
81 | done |
---|
82 | fi |
---|
83 | |
---|
84 | if [ $UPDATE = 1 ] ; then |
---|
85 | echo "Creating list of source files starting in $ARB_VALGRIND_SOURCE_ROOT ..." |
---|
86 | find $ARB_VALGRIND_SOURCE_ROOT -name "*.[ch]" -o -name "*.[ch]xx" -o -name "*.[ch]pp" -o -name "*.cc" -o -name "*.hh" > $LIST |
---|
87 | echo 'done.' |
---|
88 | fi |
---|
89 | if [ $RUN = 1 ] ; then |
---|
90 | echo "Running valgrind on '$*' ..." |
---|
91 | echo "CALLERS='$CALLERS'" |
---|
92 | echo "FILTER ='$FILTER'" |
---|
93 | valgrind -v --error-limit=no --num-callers=10 $SHOW_REACHABLE $LEAK_CHECK $* 2>&1 >/tmp/arb_valgrind_$USER.stdout | $DIR/valgrind2grep $CALLERS "$FILTER" |
---|
94 | echo 'valgrind done.' |
---|
95 | fi |
---|
96 | fi |
---|