|
| 1 | +#! /usr/bin/awk -f |
| 2 | +# A script to extract the actual suppression info from the output of (for example) valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all ./minimal |
| 3 | +# The desired bits are between ^{ and ^} (including the braces themselves). |
| 4 | +# The combined output should either be appended to /usr/lib/valgrind/default.supp, or placed in a .supp of its own |
| 5 | +# If the latter, either tell valgrind about it each time with --suppressions=<filename>, or add that line to ~/.valgrindrc |
| 6 | + |
| 7 | +# NB This script uses the |& operator, which I believe is gawk-specific. In case of failure, check that you're using gawk rather than some other awk |
| 8 | + |
| 9 | +# The script looks for suppressions. When it finds one it stores it temporarily in an array, |
| 10 | +# and also feeds it line by line to the external app 'md5sum' which generates a unique checksum for it. |
| 11 | +# The checksum is used as an index in a different array. If an item with that index already exists the suppression must be a duplicate and is discarded. |
| 12 | + |
| 13 | +BEGIN { suppression=0; md5sum = "md5sum" } |
| 14 | + # If the line begins with '{', it's the start of a supression; so set the var and initialise things |
| 15 | + /^{/ { |
| 16 | + suppression=1; i=0; next |
| 17 | + } |
| 18 | + # If the line begins with '}' its the end of a suppression |
| 19 | + /^}/ { |
| 20 | + if (suppression) |
| 21 | + { suppression=0; |
| 22 | + close(md5sum, "to") # We've finished sending data to md5sum, so close that part of the pipe |
| 23 | + ProcessInput() # Do the slightly-complicated stuff in functions |
| 24 | + delete supparray # We don't want subsequent suppressions to append to it! |
| 25 | + } |
| 26 | + } |
| 27 | + # Otherwise, it's a normal line. If we're inside a supression, store it, and pipe it to md5sum. Otherwise it's cruft, so ignore it |
| 28 | + { if (suppression) |
| 29 | + { |
| 30 | + supparray[++i] = $0 |
| 31 | + print |& md5sum |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + |
| 36 | +function ProcessInput() |
| 37 | +{ |
| 38 | + # Pipe the result from md5sum, then close it |
| 39 | + md5sum |& getline result |
| 40 | + close(md5sum) |
| 41 | + # gawk can't cope with enormous ints like $result would be, so stringify it first by prefixing a definite string |
| 42 | + resultstring = "prefix"result |
| 43 | + |
| 44 | + if (! (resultstring in chksum_array) ) |
| 45 | + { chksum_array[resultstring] = 0; # This checksum hasn't been seen before, so add it to the array |
| 46 | + OutputSuppression() # and output the contents of the suppression |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +function OutputSuppression() |
| 51 | +{ |
| 52 | + # A suppression is surrounded by '{' and '}'. Its data was stored line by line in the array |
| 53 | + print "{" |
| 54 | + for (n=1; n <= i; ++n) |
| 55 | + { print supparray[n] } |
| 56 | + print "}" |
| 57 | +} |
0 commit comments