Skip to content

Instantly share code, notes, and snippets.

@tueda
Created May 22, 2024 23:06
Show Gist options
  • Save tueda/a33934738300771664e9699a27c7b3df to your computer and use it in GitHub Desktop.
Save tueda/a33934738300771664e9699a27c7b3df to your computer and use it in GitHub Desktop.
Generate Valgrind suppression file.
#!/bin/bash
# Save Valgrind output to a temporary file
valgrind_output=$(mktemp)
# Run Valgrind and save its output to the temporary file
# Capture only standard error output
valgrind --leak-check=full --gen-suppressions=all "$@" 2> "$valgrind_output" 1>/dev/null
# Output the suppression entries to standard output
awk '
/^{/ {brace_count++}
brace_count > 0 {
if ($0 ~ /<insert_a_suppression_name_here>/) {
suppression_count++
sub(/<insert_a_suppression_name_here>/, "my_suppression_" suppression_count)
}
print
}
/^}/ {brace_count--}
' "$valgrind_output"
# Delete the temporary file
rm "$valgrind_output"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment