Valgrind
$ valgrind 社区开源 低风险valgrind 对已编译二进制进行动态插桩,用于捕获内存泄漏、越界读写、数据竞争(memcheck、helgrind)或分析调用图(callgrind)。支持通过 --error-exitcode=1 与 --xml=yes --xml-file=... 非交互运行,但在现代 macOS 与 Windows 上基本不可用。
brew install valgrind 本地 Linux 动态二进制插桩分析框架,无 MCP 替代方案。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持 --error-exitcode=1 与 --xml=yes --xml-file=... 非交互运行,但不支持 JSON 输出,且会使程序运行变慢 10–30 倍。
- Supports
--xml=yesfor memcheck structured output - No JSON output; stderr mixes target output with Valgrind logs unless redirected
零网络与凭证风险;在本地 JIT 虚拟机中插桩运行目标程序(目标程序自身的本地副作用仍会发生)。
- Local binary analysis; target program side effects still apply
Linux(x86_64/arm64)环境标配,但现代 macOS(尤其是 Apple Silicon)与原生 Windows 缺乏支持。
- Primarily Linux-only in practice; macOS support lags/unmaintained
Linux 下免重编译排查内存错误的经典利器,不过若可重编译源码,ASan/UBSan 通常快一个数量级。
- Requires no recompilation, though 10–30x runtime slowdown applies
托管于 valgrind.org(sourceware.org)的长期 GPLv2 项目,保持年度稳定发布。
- Mature open-source project on sourceware.org
官方 HTML 手册与 --help 内容完备,但诊断解读与抑制文件规则门槛较高。
- Detailed official manual at valgrind.org
安全边界、鉴权与放权指南
无需凭证;在本地对 ELF 二进制执行动态插桩分析。
GPL-2.0-or-later 开源分析套件,完全免费。
# Valgrind Agent Rules - Always pass `--error-exitcode=1 --leak-check=full` when gating CI or C/C++ fixes. - Use `--xml=yes --xml-file=<path>` for structured parsing and `--quiet` to avoid verbose stderr banners. - Do not expect `valgrind` to run on macOS Apple Silicon or native Windows; use Linux or ASan/LSan instead.
Agent 高频安全命令配方
只读查询(安全推荐)
valgrind --tool=memcheck --leak-check=full --error-exitcode=1 --quiet ./build/app
在 memcheck 下运行 ./build/app,抑制冗余启动信息,发现内存错误时返回退出码 1。
受控写入与预演
valgrind --tool=memcheck --leak-check=full --xml=yes --xml-file=valgrind.xml ./build/app
将结构化的 memcheck XML 错误报告写入 valgrind.xml。
核心优势
- + 无需重新编译即可检测内存泄漏、释放后使用与未初始化读取。
- +
--error-exitcode=1与--xml=yes --xml-file=...支持确定性 CI 校验。
注意事项与踩坑点
- ! 现代硬件上基本仅限 Linux(不支持 Apple Silicon macOS 与原生 Windows)。
- ! 存在 10–30 倍运行开销,且不提供原生 JSON 输出。