CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

Valgrind

$ valgrind 社区开源 低风险
Valgrind · 代码托管与研发协同 · GPL-2.0-or-later · linux

valgrind 对已编译二进制进行动态插桩,用于捕获内存泄漏、越界读写、数据竞争(memcheck、helgrind)或分析调用图(callgrind)。支持通过 --error-exitcode=1 与 --xml=yes --xml-file=... 非交互运行,但在现代 macOS 与 Windows 上基本不可用。

FCRS-1.0 综合评分
64 /100
可用但有局限
中置信度 (源码/文档)
零摩擦安装命令
brew install valgrind
CLI vs MCP 选型建议 仅 CLI 可用

本地 Linux 动态二进制插桩分析框架,无 MCP 替代方案。

Agent 友好度体检单

— 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
— 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md

当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。

FCRS-1.0 六维评分拆解

Agent 友好度 15 / 25

支持 --error-exitcode=1 与 --xml=yes --xml-file=... 非交互运行,但不支持 JSON 输出,且会使程序运行变慢 10–30 倍。

  • Supports --xml=yes for memcheck structured output
  • No JSON output; stderr mixes target output with Valgrind logs unless redirected
安全与权限边界 18 / 25

零网络与凭证风险;在本地 JIT 虚拟机中插桩运行目标程序(目标程序自身的本地副作用仍会发生)。

  • Local binary analysis; target program side effects still apply
安装与运行摩擦 9 / 15

Linux(x86_64/arm64)环境标配,但现代 macOS(尤其是 Apple Silicon)与原生 Windows 缺乏支持。

  • Primarily Linux-only in practice; macOS support lags/unmaintained
能力覆盖与边际价值 11 / 15

Linux 下免重编译排查内存错误的经典利器,不过若可重编译源码,ASan/UBSan 通常快一个数量级。

  • Requires no recompilation, though 10–30x runtime slowdown applies
维护与来源背书 6 / 10

托管于 valgrind.org(sourceware.org)的长期 GPLv2 项目,保持年度稳定发布。

  • Mature open-source project on sourceware.org
文档与可验证性 5 / 10

官方 HTML 手册与 --help 内容完备,但诊断解读与抑制文件规则门槛较高。

  • Detailed official manual at valgrind.org

安全边界、鉴权与放权指南

鉴权方式
无需鉴权
凭证存储位置

无需凭证;在本地对 ELF 二进制执行动态插桩分析。

潜在副作用
只读查询 本地写入
费用与配额提示

GPL-2.0-or-later 开源分析套件,完全免费。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# 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。

受控写入与预演

运行 memcheck 并输出 XML 诊断报告
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 输出。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI