是否有任何C语言静态分析器可以在C代码体中创建数据结构的图形图表?
我正在考虑DDD(数据显示调试器)中的数据显示,但这些工作来自源代码的静态分析.
任何图表符号欢迎(UML等),它可以在任何平台上运行.
谢谢.
对于我的应用程序,我想解析一个程序集并提取每个方法,并将方法的名称和源代码存储在我的一个对象中(我在我的代码中定义).
我应该在哪里开始实施?
编辑:从答案和评论我看到从程序集中获取源代码并不是那么容易.那么如果我想从当前解决方案中不存在的源代码文件中获取源代码(visual studio),我应该从哪里开始?
有没有办法快速搜索项目中某个特定函数的完整代码路径列表,以便找出某个某些上层函数是直接还是间接调用它?例如,一些可能的输出以确定是否MyLowLevelFunction可以从TargetFunction以下位置访问:
代码路径1
ModuleA2.TopLevelFunction |--ModuleA1.SomeFunction |----Utility.MyLowLevelFunction
代码路径2
ModuleB2.TopLevelFunction |--TargetModule.TargetFunction <-- This calls MyLowLevelFunction indirectly |----ModuleB1.SomeFunction |------Utility.MyLowLevelFunction
我有一个流畅,可扩展的验证助手,如:
Assert.That(aParameter).IsNotNull();
Run Code Online (Sandbox Code Playgroud)
它是可扩展的,因为That方法实际上是通用的(即<T>)并使用隐式类型来返回通用的IAssertCondition <T>对象.IsNotNull实际上是一种扩展方法.
无论如何,使用这种方法验证传递给方法的参数的问题是我得到CA1062警告,指示我在使用之前验证参数,当然,我已经在做了.
我阅读了Eric Smith的帖子(这里)关于使用ValidatedNotNullAttribute来告知FxCop该参数是否正在验证但是我不知道如何使用我所描述的流畅接口来实现这一点.
我的选择是什么,以便代码分析能够认识到上述陈述满足要求并且警告不会出现?
我想要实现的是将SonarQube分析集成到构建过程中,这样无论何时mvn clean install运行,都会使用SonarQube分析代码.我们希望将它用于本地分析以及用于构建Jenkins.如果发现新问题,那么构建应该失败(我们希望使用构建断路器插件).这样开发人员就会知道,通过他的代码,他将引入新的问题,并且必须修复它们才能使构建工作.
当我跑步时mvn sonar:sonar,分析需要30秒,这没关系.
但是,当我尝试将sonar目标绑定到maven构建阶段时,会出现问题.我绑定sonar到verify阶段.构建需要5分钟,这太长了.大约需要1分钟.没有SonarQube分析的构建本身需要30秒.
注意(可能有助于弄清楚问题是什么):运行构建的项目中有多个模块,我猜这就是问题所在.看起来sonar:sonar多次执行目标,每个子模块执行一次,并且多次分析整个项目(不仅是子模块).因此,我们有4个子模块,并且在构建期间生成了5次报告.
相反,我们只想分析整个项目一次,而不是5次.在为所有模块生成cobertura报告之后,在构建结束时运行此1分析也很重要.
那么,如何将SonarQube分析集成到构建中,以便在为所有子模块生成cobertura报告之后,它最终只分析一次我的多模块项目一次?
父pom中的SonarQube插件属性:
<!-- Sonar plugin properties -->
<sonar.jdbc.url>jdbc:url</sonar.jdbc.url>
<sonar.analysis.mode>preview</sonar.analysis.mode>
<sonar.issuesReport.html.enable>true</sonar.issuesReport.html.enable>
<sonar.issuesReport.console.enable>true</sonar.issuesReport.console.enable>
<sonar.host.url>sonar.host:9000</sonar.host.url>
<sonar.language>java</sonar.language>
<sonar.buildbreaker.skip>false</sonar.buildbreaker.skip>
<sonar.qualitygate>Sonar%20way%20with%20Findbugs</sonar.qualitygate>
<sonar.preview.includePlugins>buildbreaker</sonar.preview.includePlugins>
<sonar.exclusions>file:**/target/**</sonar.exclusions>
<branch>development</branch>
Run Code Online (Sandbox Code Playgroud)
项目中的插件配置:
<!-- Run cobertura analysis during package phase -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Run sonar analysis (preview mode) during verify phase. Cobertura reports need …Run Code Online (Sandbox Code Playgroud) 所以我试图运行一系列在RuleSet中定义的规则.RuleSet文件实际上是使用Sonarqube生成的 - 我已经选择了绝对的所有规则,包括FxCop,ReSharper和StyleCop规则.我正在开这样的FxCop:
C:/FxCop/FxCopCmd.exe /file:C:\TestProject\bin\TestProject.dll /ruleset:=C:\TestProject\testproject.ruleset /out:C:\TestProject\fxcop-report.xml /outxsl:none /forceoutput /searchgac /aspnet
Run Code Online (Sandbox Code Playgroud)
它正确启动,但我收到以下消息:
初始化Introspection引擎...
分析...
初始化Phoenix引擎......
分析...
分析完成.
*1总分析引擎异常.
XML输出包含以下内容:
<Exception Keyword="CA0001" Kind="Engine">
<Type>Phx.FatalError</Type>
<ExceptionMessage>Exception of type 'Phx.FatalError' was thrown.</ExceptionMessage>
<StackTrace> at Phx.FatalError.Dispatch()
at Phx.Logging.Diagnostics.DiagnosticMessage.LogMessage(Severity severity, DiagnosticInfo diagnosticInfo, SourceContext sourceContext, String descriptionString)
at Phx.PE.PEUtilities.UserError(String infoMessage)
at Phx.Pdb.ReaderImplementation.Open(Boolean loadTypeOnly)
at Phx.PEModuleUnit.LoadPdb()
at Phx.PE.ReaderPhase.CheckSymbolicInformation()
at Phx.PEModuleUnit.LoadGlobalSymbols()
at Phx.PEModuleUnit.LoadEncodedIRUnitList()
at Phx.PEModuleUnit.GetEnumerableContributionUnit(ContributionUnitEnumerationKind contributionUnitEnumerationKind)
at Phx.PEModuleUnit.GetEnumerableContributionUnit()
at Microsoft.FxCop.Engines.Phoenix.PreScanPass.GetFunctionUnits(PEModuleUnit peModuleUnit)
at Microsoft.FxCop.Engines.Phoenix.PreScanPass.Execute(ModuleUnit moduleUnit)
at Phx.Passes.Pass.DoPass(ModuleUnit moduleUnit)
at Phx.Passes.PassList.DoPassList(ModuleUnit moduleUnit)
at Microsoft.FxCop.Engines.Phoenix.PhoenixAnalysisEngine.Host.ExecutePasses(PEModuleUnit peModuleUnit)
at Microsoft.FxCop.Engines.Phoenix.PhoenixAnalysisEngine.AnalyzeInternal()
at Microsoft.FxCop.Engines.Phoenix.PhoenixAnalysisEngine.Analyze()
at …Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多有关Visual Studio代码分析警告C8386的内容,但是无法弄清楚我的代码中的这个特定问题。我将其简化为以下小程序:
unsigned int nNumItems = 0;
int main()
{
int *nWords=nullptr;
unsigned int nTotal;
nTotal = 3 + 2 * nNumItems;
nWords = new int[nTotal];
nWords[0] = 1;
nWords[1] = 2; // this is line 18, warning C6386
delete[] nWords;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
分析->运行代码分析->在解决方案中将给出以下警告:
file.cpp(18):警告C6386:写入'nWords'时缓冲区溢出:可写大小为'nTotal * 4'字节,但可能写入了'8'字节。
这是合法的吗?现在,如果我移动全局变量并将其设置为局部变量,警告将消失!
int main()
{
unsigned int nNumItems = 0;
...
}
Run Code Online (Sandbox Code Playgroud)
但是我不能像完整的代码那样执行此操作,这是一个成员变量。
同样,如果将nTotal的定义移到 “ new int ”中,我也可以删除警告:
nWords = new int[3 + 2 * nNumItems];
Run Code Online (Sandbox Code Playgroud)
但是我不能这样做,因为完整代码中的其他地方都引用了nWords。
这仅仅是Visual …
寻找适用于f#的开源工具已经看到了一些支持c#的工具:https : //pumascan.com/ https://security-code-scan.github.io/
但是找不到任何f#。只是想知道f#人们会做ci / cd并有一个用于静态分析的管道阶段,如果是的话,他们使用什么
我目前尝试使用生成器将Visual Studio 2017 的C ++核心准则检查器(CppCoreCheck)与元生成系统CMake集成在一起Visual Studio 15 2017 Win64。
以下示例说明了我的方法(我尝试将CMake源代码精简到最小)。
首先,我将所有编译器开关添加到了构建目标,以使用CppCoreCheck进行分析:
cmake_minimum_required(VERSION 3.12)
project(cppcorecheck-example)
find_package(Boost REQUIRED MODULE)
add_executable(app main.cpp)
target_link_libraries(app PRIVATE Boost::boost)
target_compile_options(app
PRIVATE
"/analyze"
"/analyze:WX-"
"/analyze:log" "cppcorecheck.xml"
"/analyze:stacksize" 16384
"/analyze:max_paths" 256
"/analyze:ruleset" "CppCoreCheckRules.ruleset"
"/analyze:plugin EspXEngine.dll"
)
Run Code Online (Sandbox Code Playgroud)
我正在使用以下内容main.cpp:
#include <boost/system/error_code.hpp>
int main() {
int arr[10]; // warning C26494
int* p = arr; // warning C26485
{
int* q = p + 1; // warning C26481
p = q++; // warning C26481
} …Run Code Online (Sandbox Code Playgroud) c++ cmake visual-studio static-code-analysis cpp-core-guidelines
我正在尝试更改有关 Sonarqube 设置的 Jenkins 工作。所以我打开了我的 Jenkins 作业配置,我看到了这样的东西
sonar.issue.ignore.multicriteria=e1,e2,e3,e4,e5
sonar.issue.ignore.multicriteria.e1.ruleKey=squid:S00112
sonar.issue.ignore.multicriteria.e1.resourceKey=**/*.java
Run Code Online (Sandbox Code Playgroud)
我正在 Sonarqube 文档中搜索 ruleKey "squid:S00112",但我找不到任何关于它的参考。
我需要添加更多规则来忽略。但我无法识别规则规则键值(如 ruleKey=squid:S00112)。