主要内容

本页翻译不是最新的。点击此处可查看最新英文版本。

polyspaceBugFinderServer

使用 MATLAB 脚本运行 Polyspace Bug Finder Server 分析

为了更轻松地编写脚本,请使用 polyspace.Project 对象运行 Polyspace® 分析。

说明

polyspaceBugFinderServer(optsObject) 对 MATLAB® 中的 Polyspace 选项对象运行分析。

示例

polyspaceBugFinderServer('-help') 显示选项,这些选项可以提供给 polyspaceBugFinderServer 命令以运行 Polyspace Bug Finder™ Server™ 分析。

polyspaceBugFinderServer('-sources',sourceFiles) 对在 sourceFiles 中指定的源文件运行 Polyspace Bug Finder Server 分析。

示例

polyspaceBugFinderServer('-sources',sourceFiles,Name,Value) 使用一个或多个 Name,Value 对组参量指定的附加选项对源文件运行 Polyspace Bug Finder Server 分析。

注意

在从 MATLAB 中运行 Polyspace 之前,必须将已安装的 Polyspace 与 MATLAB 相关联。请参阅将 Polyspace Server 产品与 MATLAB 集成

示例

示例

全部折叠

此示例显示了如何从 MATLAB 命令行运行 Polyspace 分析。对于此示例:

  • 使用位于目录 polyspaceroot/polyspace/examples/cxx/BugFinder_example/sources 中的源文件 numerical.c

  • 包括位于同一目录中的头文件。

创建一个选项对象并将源文件和包含文件夹添加到属性中。

opts = polyspace.Options;
opts.Sources = {fullfile(polyspaceroot, 'polyspace', 'examples',...
    'cxx', 'Bug_Finder_Example', 'sources', 'numerical.c')};;
opts.EnvironmentSettings.IncludeFolders = {fullfile(polyspaceroot, 'polyspace', 'examples',...
    'cxx', 'Bug_Finder_Example', 'sources')};
opts.ResultsDir = 'C:\Polyspace_Results';

Polyspace 在文件 C:\Polyspace_Sources\source.c 上运行,并将结果存储在 C:\Polyspace_Results 中。

运行 Polyspace Bug Finder Server 分析。

polyspaceBugFinderServer(opts);

此示例显示了如何使用 DOS/UNIX 选项在 MATLAB 中运行 Polyspace 分析。对于此示例:

  • 使用位于目录 polyspaceroot/polyspace/examples/cxx/BugFinder_example/sources 中的源文件 numerical.c

  • 包括位于同一目录中的头文件。

定义源文件和包含文件的位置。

src = fullfile(polyspaceroot, 'polyspace', 'examples',...
    'cxx', 'Bug_Finder_Example', 'sources', 'numerical.c');
inc = fullfile(polyspaceroot, 'polyspace', 'examples',...
    'cxx', 'Bug_Finder_Example', 'sources');
res = fullfile(pwd,'results');

要分析 numerical.c,请运行以下命令。

polyspaceBugFinderServer('-sources',src, ...
    '-I',inc, ...
    '-results-dir',res)

此示例显示了在 MATLAB 中自定义分析的两种不同方法。您可以通过更改选项对象中的属性或使用名称-值对组,自定义任意数量的附加选项。此处指定了检查 MISRA C™ 2012 编码规则。

创建变量以保存源文件路径和结果文件夹路径。您可以将这些变量用于任一分析方法。

sourceFileName = fullfile(polyspaceroot, 'polyspace','examples', 'cxx', 'Bug_Finder_Example','sources','dataflow.c');
resFolder1 = fullfile('Polyspace_Results_1');
resFolder2 = fullfile('Polyspace_Results_2');

使用选项对象分析编码规则。

opts = polyspace.Options();
opts.Sources = {sourceFileName};
opts.ResultsDir = resFolder1;
opts.CodingRulesCodeMetrics.EnableMisraC3 = true;
opts.CodingRulesCodeMetrics.MisraC3Subset = 'all';
polyspaceBugFinderServer(opts);

使用 DOS/UNIX 选项分析编码规则。

polyspaceBugFinderServer('-sources',sourceFileName,'-results-dir',resFolder2,'-misra3','all');

输入参数

全部折叠

Polyspace 选项对象名称,指定为对象句柄。

要创建选项对象,请使用 Polyspace 选项类 polyspace.Optionspolyspace.Project

示例: opts

以逗号分隔的 C 或 C++ 源文件名称,指定为单个字符向量。

如果文件不在当前文件夹中,则 sourceFiles 必须包含完整路径或相对路径。

示例: 'myFile.c', 'C:\mySources\myFile1.c,C:\mySources\myFile2.c'

名称-值参数

Name1=Value1,...,NameN=ValueN 的形式指定可选参量对组,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但对各个参量对组的顺序没有要求。

在 R2021a 之前,使用逗号分隔每个名称和值,并将 Name 用引号引起来。

示例: '-target','i386','-compiler','gnu4.6' 指定源代码用于 i386 目标,并包含 GCC 4.6 的非 ANSI C 语法。

有关选项名称和值,请参阅Polyspace Bug Finder 分析引擎选项的完整列表中的命令行信息部分。

版本历史记录

在 R2019a 中推出