关于包装器可执行文件,我已经为 PostgreSQL 找到了以下脚本。(我已经删除了各种特定于 postgres 的部分,例如发现提供的 valgrind 抑制文件)。
#!/bin/bash
set -e -u -x
# Pop top two elements from path; the first is added by pg_regress
# and the next is us.
function join_by { local IFS="$1"; shift; echo "$*"; }
IFS=':' read -r -a PATHA <<< "$PATH"
export PATH=$(join_by ":" "${PATHA[@]:2}")
NEXT_POSTGRES=$(which postgres)
if [ "${NEXT_POSTGRES}" -ef "./valgrind/postgres" ]; then
echo "ERROR: attempt to execute self"
exit 1
fi
echo "Running ${NEXT_POSTGRES} under Valgrind"
valgrind --leak-check=full --show-leak-kinds=definite,possible \
--gen-suppressions=all --verbose --time-stamp=yes \
--log-file=valgrind-$$-%p.log --trace-children=yes \
--track-origins=yes --read-var-info=yes --malloc-fill=8f \
--free-fill=9f --num-callers=30 postgres "$@"
注意PATH
操作以确保我们不会再次尝试postgres
从同一个地方执行。在这种情况下,包装脚本也必须准确命名,postgres
因此我必须确保它不会递归执行它自己。
另一种方法是使用whatis -a
在路径中查找下一个可执行文件并直接运行它。但我发现这对我的用例造成了其他问题。
顺便说一句,如果您收到类似的错误
valgrind: mmap(0x58000000, 2347008) failed in UME with error 22 (Invalid argument).
valgrind: this can be caused by executables with very large text, data or bss segments.
...那么您很可能会错误地尝试在 valgrind 下运行 valgrind 。