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