source: tags/ms_r16q3/SOURCE_TOOLS/arb_valgrind

Last change on this file was 14626, checked in by westram, 8 years ago
  • sync gtk and motif versions
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1#!/bin/bash
2
3if [ -z $1 ] ; then
4    echo ''
5    echo 'Usage: arb_valgrind [options] <arb_program> <arguments>'
6    echo ''
7    echo '    runs valgrind (versions 3.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 '    options:'
11    echo ''
12    echo '    -m             use massif (default uses memcheck)'
13    echo '    -c <callers>   show <callers> stackframes (default: none)'
14    echo '                   [in fact they are always shown, but not marked as errors]'
15    echo '    -f <filter>    regexpr to filter the reason (default: all)'
16    echo '    -l [-r]        turn on leak-checking (-r for reachable blocks)'
17    echo '    -A             show known boring errors (most Xt/Motif-related)'
18    echo '    -q             quiet'
19    echo '    -L <file>      log stdout to <file> (does not work with -D)'
20    echo '    -E <file>      log stderr to <file> (does not work with -D)'
21    echo '                   Default is to collect output and print in after valgrind terminates'
22    echo '    -D             run gdb on error'
23    echo '    -e             return exitcode 1 on valgrind-errors'
24    echo ''
25    echo ''
26    echo 'Usage: arb_valgrind update'
27    echo ''
28    echo '    Updates the source file list which is needed to create correct file refs.'
29    echo '    Called automatically by normal use if list is missing.'
30    echo '    Call if files are not highlighted as errors (i.e if you have new files).'
31    echo ''
32    echo 'Environment:'
33    echo ''
34    echo '      $ARBHOME     a directory which has to contain a subdirectory SOURCE_TOOLS.'
35    echo '                   SOURCE_TOOLS has to contain valgrind2grep and has to be writeable for the user'
36    echo ''
37    echo '      $ARB_VALGRIND_SOURCE_ROOT       down from here the script scans for sources'
38    echo '                                      (defaults to $ARBHOME if empty)'
39    echo ''
40    echo 'Note: I use this from inside emacs as follows:'
41    echo '          M-x compile'
42    echo '      with:'
43    echo '          (cd $ARBHOME;make nt) && arb_valgrind -l arb_ntree ~/ARB/demo.arb'
44    echo ''
45    echo 'There are scripts for older valgrind versions: '
46    ls -al $ARBHOME/SOURCE_TOOLS/arb_valgrind_*
47    echo ''
48
49else
50    if [ -z $ARB_VALGRIND_SOURCE_ROOT ] ; then
51        ARB_VALGRIND_SOURCE_ROOT=$ARBHOME
52    fi
53
54    DIR=$ARBHOME/SOURCE_TOOLS
55    LIST=$DIR/valgrind2grep.lst
56
57    UPDATE=0
58    RUN=0
59    CALLERS=0
60    SUPPX='--suppress-common'
61    FILTER='.*'
62    LEAK_CHECK=''
63    TOOL='--tool=memcheck'
64    ATTACH=''
65    QUIET=''
66    LOG_STDOUT=''
67    LOG_STDERR=''
68    ERROR_EXITCODE=''
69
70    if [ ! -f $LIST ] ; then
71        UPDATE=1
72    fi
73    if [ $1 = "update" ] ; then
74        UPDATE=1
75    else
76        RUN=1
77        SCAN_ARGS=1
78
79        while [ $SCAN_ARGS = 1 ] ; do
80            SCAN_ARGS=0
81            if [ "$1" = "-m" ] ; then
82                TOOL='--tool=massif'
83                shift 1
84                SCAN_ARGS=1
85            fi
86            if [ "$1" = "-c" ] ; then
87                CALLERS=$2
88                shift 2
89                SCAN_ARGS=1
90            fi
91            if [ "$1" = "-f" ] ; then
92                FILTER=$2
93                shift 2
94                SCAN_ARGS=1
95            fi
96            if [ "$1" = "-l" ] ; then
97                LEAK_CHECK="$LEAK_CHECK --leak-check=yes"
98                # LEAK_CHECK="$LEAK_CHECK --leak-resolution=high"
99                LEAK_CHECK="$LEAK_CHECK --leak-resolution=med"
100                shift 1
101                SCAN_ARGS=1
102            fi
103            if [ "$1" = "-r" ] ; then
104                LEAK_CHECK="$LEAK_CHECK --show-reachable=yes"
105                shift 1
106                SCAN_ARGS=1
107            fi
108            if [ "$1" = "-A" ] ; then
109                SUPPX=''
110                shift 1
111                SCAN_ARGS=1
112            fi
113            if [ "$1" = "-q" ] ; then
114                QUIET='--quiet'
115                shift 1
116                SCAN_ARGS=1
117            fi
118            if [ "$1" = "-D" ] ; then
119                ATTACH='--db-attach=yes'
120                shift 1
121                SCAN_ARGS=1
122            fi
123            if [ "$1" = "-L" ] ; then
124                LOG_STDOUT=$2
125                shift 2
126                SCAN_ARGS=1
127            fi
128            if [ "$1" = "-E" ] ; then
129                LOG_STDERR=$2
130                shift 2
131                SCAN_ARGS=1
132            fi
133            if [ "$1" = "-e" ] ; then
134                ERROR_EXITCODE='--error-exitcode=123'
135                shift 1
136                SCAN_ARGS=1
137            fi
138        done
139    fi
140
141
142    if [ "X$LEAK_CHECK" = "X" ] ; then
143        LEAK_CHECK="--leak-check=no"
144    fi
145
146    if [ $UPDATE = 1 ] ; then
147        echo "Creating list of source files starting in $ARB_VALGRIND_SOURCE_ROOT ..."
148        find $ARB_VALGRIND_SOURCE_ROOT \! -path "*\{arch\}*" -a \
149                                        \(      -name "*.[ch]" -o \
150                                                -name "*.[ch]xx" -o \
151                                                -name "*.[ch]pp" -o \
152                                                -name "*.cc" -o \
153                                                -name "*.hh" \) \
154                > $LIST
155        echo 'done.'
156    fi
157    EXITCODE=0
158    if [ $RUN = 1 ] ; then
159        echo "Running valgrind on '$*' ..."
160        echo "CALLERS='$CALLERS'"
161        echo "FILTER ='$FILTER'"
162        VG_CALLERS=$[$CALLERS+5]
163        VG_OPTS=""
164        VG_OPTS="$VG_OPTS --error-limit=yes"
165        VG_OPTS="$VG_OPTS $ERROR_EXITCODE"
166        # VG_OPTS="$VG_OPTS --track-origins=yes" # ulalala ... eats MUUUUCH memory
167        VG_OPTS="$VG_OPTS --track-fds=yes" # track filedescriptors open on exit
168        VG_OPTS="$VG_OPTS --show-below-main=yes" # valgrind below main (e.g. in static initialization)
169
170        # suppressions:
171        SUPP=/usr/lib/valgrind/debian-libc6-dbg.supp
172        if [ -f $SUPP ]; then
173            VG_OPTS="$VG_OPTS --suppressions=$SUPP" # common libc6 errors
174        fi
175        VG_OPTS="$VG_OPTS --suppressions=${ARBHOME}/SOURCE_TOOLS/arb.supp"        # common arb errors
176        VG_OPTS="$VG_OPTS --suppressions=${ARBHOME}/SOURCE_TOOLS/arb_motif.supp"  # arb-motif specific (ARB_MOTIF)
177        # VG_OPTS="$VG_OPTS --suppressions=${ARBHOME}/SOURCE_TOOLS/arb_gtk.supp"    # arb-gtk specific (ARB_GTK)
178
179        VG_OPTS="$VG_OPTS --gen-suppressions=all" # automatically generate suppressions
180
181        VG_CMD="valgrind $QUIET $TOOL -v $VG_OPTS --num-callers=$VG_CALLERS $SHOW_REACHABLE $LEAK_CHECK $ATTACH"
182        echo "VG_CMD='$VG_CMD $@'"
183        if [ "$ATTACH" = "" ]; then
184            POSTDUMP_STDOUT=0
185            POSTDUMP_STDERR=0
186            if [ -z "$LOG_STDOUT" ]; then
187                LOG_STDOUT=/tmp/arb_valgrind_$USER_$$.stdout
188                POSTDUMP_STDOUT=1
189            fi
190            if [ -z "$LOG_STDERR" ]; then
191                LOG_STDERR=/tmp/arb_valgrind_$USER_$$.stderr
192                POSTDUMP_STDERR=1
193            fi
194            $VG_CMD --log-fd=3 "$@" 3>&1 >$LOG_STDOUT 2>$LOG_STDERR | $DIR/valgrind2grep $CALLERS "$FILTER" $SUPPX
195            EXITCODE=${PIPESTATUS[0]}
196
197            if [ "$POSTDUMP_STDOUT" = "1" ]; then
198                echo "-------------------- [stdout of '$@' ]"
199                cat $LOG_STDOUT
200                rm $LOG_STDOUT
201            fi
202            if [ "$POSTDUMP_STDERR" = "1" ]; then
203                echo "-------------------- [stderr of '$@' ]"
204                cat $LOG_STDERR
205                rm $LOG_STDERR
206            fi
207            if [ "$POSTDUMP_STDOUT" = "1" -o "$POSTDUMP_STDERR" = "1" ]; then
208                echo "-------------------- [end of output]"
209            fi
210        else
211            $VG_CMD "$@"
212            EXITCODE=$?
213        fi
214        echo "valgrind done (exitcode=$EXITCODE)"
215    fi
216    exit $EXITCODE
217fi
Note: See TracBrowser for help on using the repository browser.