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