static-analysis
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese静态分析
Static Analysis
适用场景
Applicable Scenarios
- 提交前需要对代码进行静态分析,发现潜在缺陷。
- 汽车、医疗等行业需要 MISRA-C 2012 合规检查。
- 需要使用 cppcheck、clang-tidy 或 GCC 进行代码质量审查。
-fanalyzer - 需要对静态分析结果按严重级别分组查看摘要。
- Need to perform static analysis on code before submission to detect potential defects.
- Industries such as automotive and medical require MISRA-C 2012 compliance checks.
- Need to use cppcheck, clang-tidy, or GCC for code quality reviews.
-fanalyzer - Need to view summaries of static analysis results grouped by severity level.
必要输入
Necessary Inputs
- 源码目录路径。
- 至少一个可用的静态分析工具(cppcheck、clang-tidy 或 GCC 12+)。
- 可选的 路径(提升 clang-tidy 准确性)。
compile_commands.json - 可选的严重级别过滤和 MISRA 检查开关。
- Source code directory path.
- At least one available static analysis tool (cppcheck, clang-tidy, or GCC 12+).
- Optional path (improves clang-tidy accuracy).
compile_commands.json - Optional severity level filtering and MISRA check toggle.
自动探测
Auto Detection
- 模式检测 cppcheck、clang-tidy 和 arm-none-eabi-gcc 的可用性和版本。
--detect - GCC 需要 GCC 12+,脚本会检查版本号。
-fanalyzer - 自动搜索工作区中的 。
compile_commands.json
- The mode detects the availability and versions of cppcheck, clang-tidy, and arm-none-eabi-gcc.
--detect - GCC requires GCC 12+, and the script will check the version number.
-fanalyzer - Automatically searches for in the workspace.
compile_commands.json
执行步骤
Execution Steps
- 先阅读 references/usage.md,确认本次使用哪个分析工具。
- 若不确定工具是否可用,先运行 scripts/static_analyzer.py 的 模式。
--detect - 使用 运行 cppcheck 分析。
--cppcheck --source <dir> - 使用 运行 clang-tidy 分析。
--clang-tidy --source <dir> - 使用 运行 GCC analyzer 分析。
--gcc-analyzer --source <files> - 需要 MISRA 合规时,添加 参数启用 cppcheck MISRA addon。
--misra - 阅读 references/misra-quick-ref.md 了解常见 MISRA 违规。
- First read references/usage.md to confirm which analysis tool to use this time.
- If unsure whether the tool is available, first run the mode of scripts/static_analyzer.py.
--detect - Run cppcheck analysis with .
--cppcheck --source <dir> - Run clang-tidy analysis with .
--clang-tidy --source <dir> - Run GCC analyzer analysis with .
--gcc-analyzer --source <files> - When MISRA compliance is required, add the parameter to enable the cppcheck MISRA addon.
--misra - Read references/misra-quick-ref.md to learn about common MISRA violations.
失败分流
Failure Handling
- 当所有分析工具都不可用时,返回 。
environment-missing - 当指定的源码目录不存在时,返回 。
artifact-missing - 当 指定但无效时,返回
compile_commands.json。project-config-error - 当分析工具运行异常退出时,返回 。
target-response-abnormal
- Returns when all analysis tools are unavailable.
environment-missing - Returns when the specified source code directory does not exist.
artifact-missing - Returns when
project-config-erroris specified but invalid.compile_commands.json - Returns when the analysis tool exits abnormally.
target-response-abnormal
平台说明
Platform Notes
- cppcheck 和 clang-tidy 在三大平台均可用,通过包管理器安装。
- GCC 需要 GCC 12+,嵌入式交叉编译器版本可能较低。
-fanalyzer - 自带脚本使用 Python 标准库和 subprocess,跨平台兼容。
- cppcheck and clang-tidy are available on all three major platforms and can be installed via package managers.
- GCC requires GCC 12+, and embedded cross-compiler versions may be lower.
-fanalyzer - The built-in script uses Python standard libraries and subprocess, making it cross-platform compatible.
输出约定
Output Conventions
- 按严重级别(error、warning、style、information)分组输出发现。
- 每条发现包含文件路径、行号、规则 ID 和描述。
- 模式只输出统计数字。
--summary - MISRA 模式额外输出违反的规则编号。
- Output findings grouped by severity level (error, warning, style, information).
- Each finding includes file path, line number, rule ID, and description.
- The mode only outputs statistical figures.
--summary - MISRA mode additionally outputs the violated rule numbers.
交接关系
Handover Relationships
- 当发现严重缺陷需要修复后重新构建时,交给对应的 skill。
build-* - 当需要了解代码内存影响时,交给 。
memory-analysis
- When critical defects are found and require fixes before rebuilding, hand over to the corresponding skill.
build-* - When needing to understand the memory impact of the code, hand over to .
memory-analysis