Klockwork使用记录

Klockwork遇到的错误:

如果klocwork 执行完之后,对应的web上没有 log 出现:

1. 可能是生成时 ,配置的端口号或网址不对。

2. 查看kwinject 生成的kwinject.out, 看是否有内容(比如build_xxx.sh里的编译路径或命令没有对,编译失败就不会显示报错,只会导致kwinject.out没有内容);没有内容的话会导致后面的都会出错。

 

klockwork通常检测执行的步骤:

echo "make clean xxx" >> build_xxx.sh (可以写入更多的make 命令行到build_xxx.sh, 因为klockwork是根据这里面的命令行来检测问题的)

kwinject ./build_xxx.sh

kwbuildproject --url http://localhost:8090/vcd_test -o kwtables kwinject.out --force

kwadmin load vcd_test kwtables/ --url http://localhost:8090

kwadmin rename-build vcd_test build_1 CL464370_vcd_test --url http://localhost:8090

 

klockwork的三个服务:

#klocwork check

license 服务 Checking License Server
数据库服务 Checking Database Server
web服务和分析引擎 Checking Klocwork Server

 

Klocwork的配置:

1. klocwork 服务的端口设置, 数据库端口设置:[projects_root]/config/admin.conf 中设置, e.g. /home/klocwork/klocwork/projects_root/config/admin.conf

2. klocwork 的所有的logs都在[projects_root]/logs中, e.g. /home/klocwork/klocwork/projects_root/logs, 对应三个服务的log是database.log, klockwork.log, license.log.

3. kwinject.out文件:

 

 

使用klocwork  Build 分析C/C++项目:

1. kwinject 见识编译命令执行过程来获取编译参数; 这个命令会生成文件kwinject.out, 其中存放了编译命令所使用的参数,用于后续的分析。

  kwinject 命令一般不会重复编译没有修改过的源代码,所以一般应该先将以前编译产生的数据文件进行清理, 再使用kwinject调用编译命令, 

  e.g. #make clean

    #kwinject make all

  或者将编译命令写入文件, 然后执行kwinject ./build.sh

  当生成的kwinject.out里有路径等各种参数时, 就可以执行下一步了。

2. 如果第一次分析该项目,需要先用kwadmin 创建项目, 或者直接在网页端创建。

  #kwadmin create-project PROJECT_NAME

  kwadmin --help 可以查看具体信息:  

复制代码
klocwork@idcqaklocwork:~$ kwadmin --help
kwadmin - Klocwork Management Console - Command Line Interface
Klocwork 2021.2 Build 21.2.0.74
Copyright (c) Perforce Software, Inc. All rights reserved.
Detailed information about the use and provenance of publicly available software within this product can be found under the header "Lethin either the web-based or local help for this product.
Use 'kwadmin <subcommand> --help' to see help for specific command

Common options:
    --help           - print this help message
    --version        - print version information
    --host <string>  - specify Klocwork Server host
    --port <integer> - specify Klocwork Server port (default: 0)
    --ssl            - use secure Klocwork Server connection
    --url <string>   - specify Klocwork Server URL: <http(s)://host:port/>. Use
                       as alternative to --host, --port and --ssl options
    --verbose-exec   - Print all commands executed
    --verbose, -v    - Print verbose information
    --color, -q      - Show colored output

Usage:  kwadmin <subcommand> [options]
        kwadmin <subcommand> @<arguments file>

Commands:
        create-project - Create empty project with given name
        delete-build - Delete build from project
        delete-config - Delete config file from project
        delete-project - Delete project and all its builds
        duplicate-project - Create duplicate of given project
        get-build-properties - Prints build properties
        get-project-properties - Print all project properties
        get-projects-root - Get current projects root
        import-config - Import config file into project
        list-builds - Print list of existing builds for particular project
        list-config-files - List config files, configs - files in different formats affecting result of the build and reports
        list-config-types - List config types, configs - files in different formats affecting result of the build and reports
        list-projects - Print list of available projects
        load - Load new build for selected project
        lock-project-version - Lock Project Version
        rename-build - Rename project build
        rename-project - Rename project
        set-project-property - Set project property
        unlock-project-version - Unlock Project Version
复制代码

3. 分析项目:

  #kwbuildproject --url http://server_ip:8090/PROJECT_NAME -f -o table kwinject.out

    //-o 表示输出参数,此命令执行后,会将输出分析结果到名为table 的目录中; -f 表示强制输出到-o 指定的目录, 如果该目录不为空,则先清空。

    e.g. #kwbuildproject --url http://localhost:8090/$Project -o kwtables kwinject.out --force

4. 加载数据到数据库:

  #kwadmin --url http://server_ip:8090 load  PROJECT_NAME table

  e.g. #kwadmin load vcd_test kwtables/ --url http://localhost:8090

 

 

 kwservice set-service-property license host 192.168.11x.xxx

 kwservice set-service-property database host 192.168.11x.xxx

kwservice set-service-property klocwork host 192.168.11x.xxx 决定这三个service 在哪个主机上运行, 会去修改/home/klocwork/klocwork/projects_root/config/admin.conf, 然后通过kwserivce restart 生效(若是就在当前机器,也可以kwservice set-service-property xxxx host localhost) 

 

some ref: 

https://wenku.baidu.com/view/588f3ae49dc3d5bbfd0a79563c1ec5da50e2d6fc.html
https://blog.csdn.net/lhf_tiger/article/details/9814853
https://max.book118.com/html/2015/0326/13825092.shtm

https://max.book118.com/html/2022/0524/5301101202004232.shtm

静态分析:
https://ww2.mathworks.cn/discovery/static-code-analysis.html
https://blog.csdn.net/Pokemogo/article/details/111468385

经常遇到的一些问题:

  • 编译的时候报的warning一定要清理,这通常也是klocwork会报的issues
  • 子函数返回值有可能为NULL的话,在使用返回值的时候一定要检查返回值是不是为空并进行相应处理。
  • 在使用malloc/calloc/DWLcalloc分配资源之后,都要检查分配到的指针是不是为空并进行相应处理,然后,需要确保在每一个出口(尤其是非正常出口)调用free释放这些资源。
  • 位操作时,要注意操作数是不是相同位数的数据类型,可以使用强制类型转换保持操作数类型一致。
  • 所有的变量在使用前都应该初始化,为保险起见,最好在定义的地方立即初始化。
    • 在使用结构变量时,应该对结构域的每一项进行检查以保证不会在未初始化之前使用它们。
  • 有一些变量的值是从码流里解析出来的,或者从字符串里读出来的,那么它的值就可能存在风险,比如应用为数组下标,循环计数,或者除数......对这些值必须进行安全性检查,或者至少在使用之前进行安全性检查(避免数组下标越界,循环计数太大,除数为0等情况出现)。

 

posted @   123容之  阅读(1987)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示