Giter VIP home page Giter VIP logo

ericsson / codechecker Goto Github PK

View Code? Open in Web Editor NEW
2.1K 54.0 347.0 38.59 MB

CodeChecker is an analyzer tooling, defect database and viewer extension for the Clang Static Analyzer and Clang Tidy

Home Page: https://codechecker.readthedocs.io

License: Apache License 2.0

Python 74.57% CSS 0.12% Shell 0.07% HTML 0.12% Thrift 1.45% JavaScript 5.36% Mako 0.03% C++ 0.66% Objective-C 0.27% Makefile 1.48% C 1.64% Dockerfile 0.10% Java 0.01% TypeScript 0.01% Go 0.01% Vue 14.05% SCSS 0.05% Starlark 0.01% C# 0.01% Smalltalk 0.01%
clang cpp c clang-tidy static-analysis linux results-viewer macosx codechecker llvm

codechecker's Introduction


CodeChecker
CodeChecker

Github Action Gitter Documentation Status OpenSSF Scorecard Score

CodeChecker is a static analysis infrastructure built on the LLVM/Clang Static Analyzer toolchain, replacing scan-build in a Linux or macOS (OS X) development environment.

Web interface showing list of analysed projects and bugs

๐Ÿ’ก Check out our DEMO showing some analysis results of open-source projects!

Main features

Command line C/C++ Analysis

  • Executes Clang-Tidy, Clang Static Analyzer with Cross-Translation Unit analysis, Statistical Analysis (when checkers are available), Cppcheck, and the GCC Static Analyzer.
  • Creates the JSON compilation database by wiretapping any build process (e.g., CodeChecker log -b "make").
  • Automatically analyzes GCC cross-compiled projects: detecting GCC or Clang compiler configuration and forming the corresponding clang analyzer invocations.
  • Incremental analysis: Only the changed files and its dependencies need to be reanalyzed.
  • False positive suppression with a possibility to add review comments.
  • Result visualization in command line or in static HTML.

Web-based report storage

  • You can store & visualize thousands of analysis reports of many analyzers like Clang Static Analyzer (C/C++), Clang Tidy (C/C++), Facebook Infer (C/C++, Java), Clang Sanitizers (C/C++), Spotbugs (Java), Pylint (Python), Eslint (Javascript) ...
    For a complete list see Supported Analyzers
  • Web application for viewing discovered code defects with a streamlined, easy experience (with PostgreSQL, or SQLite backend).
  • Gerrit and GitLab integration Shows analysis results as GitLab or Gerrit reviews.
  • Filterable (defect checker name, severity, source paths, ...) and comparable (calculates difference between two analyses of the project, showing which bugs have been fixed and which are newly introduced) result viewing.
  • Diff mode: This shows the list of bugs that have been introduced since your last analyzer execution.
  • Results can be shared with fellow developers, the comments and review system helps communication of code defects.
  • Easily implementable Thrift-based server-client communication used for storing and querying of discovered defects.
  • Support for multiple bug visualization frontends, such as the web application, a command-line tool and an Eclipse plugin.

Command line features

CodeChecker command has many subcommands which can be used for example to log and analyze your projects, print the results or start a web server. For full list see the following table or check the help message of this command (CodeChecker --help):

CodeChecker subcommand Description
analyze Execute the supported code analyzers for the files recorded in a JSON Compilation Database.
analyzer-version Print the version of CodeChecker analyzer package that is being used.
analyzers List supported and available analyzers.
check Perform analysis on a project and print results to standard output.
checkers List the checkers available for code analysis.
cmd View analysis results on a running server from the command line.
fixit Apply automatic fixes based on the suggestions of the analyzers.
log Run a build command, collect the executed compilation commands and store them in a JSON file.
parse Print analysis summary and results in a human-readable format.
server Start and manage the CodeChecker Web server.
store Save analysis results to a database.
version Print the version of CodeChecker package that is being used.
web-version Print the version of CodeChecker server package that is being used.

CodeChecker cmd subcommand also has many other subcommands which can be used to get data (products, runs, results, statistics) from a running CodeChecker server. For full list see the following table or check the help message of this subcommand (CodeChecker cmd --help):

CodeChecker cmd subcommand Description
runs List the available analysis runs.
history Show run history of multiple runs.
results List analysis result (finding) summary for a given run.
diff Compare two analysis runs and show the difference.
sum Show statistics of checkers.
token Access subcommands related to configuring personal access tokens managed by a CodeChecker server.
del Delete analysis runs.
update Update an analysis run.
suppress Manage and import suppressions of reports on a CodeChecker server.
products Access subcommands related to configuring the products managed by a CodeChecker server.
components Access subcommands related to configuring the source components managed by a CodeChecker server.
login Authenticate into CodeChecker servers that require privileges.
export Export comments and review statuses from CodeChecker.
import Import comments and review statuses into CodeChecker.

Usage flow

Usage diagram

  • Step 1: CodeChecker log runs the given build command and records the executed compilation steps. These steps are written to an output file (Compilation Database) in a JSON format.
  • Step 2: CodeChecker analyze uses the previously created JSON Compilation Database to perform an analysis on the project, outputting analysis results in a machine-readable (plist) format.
  • Step 3: In this step, you can do multiple things:
    • Parse and pretty-print the summary and results from analysis result files (CodeChecker parse).
    • Store the results to a running CodeChecker server (CodeChecker store).
    • Compare two analysis results/runs to show the results that differ between the two (CodeChecker cmd diff).
    • etc.

For more information how to use CodeChecker see our user guide.

User documentation

C/C++ Analysis

Web based report management

Storage of reports from analyzer tools

CodeChecker can be used as a generic tool for visualizing analyzer results.

The following tools are supported:

Language Analyzer
C/C++ Clang Static Analyzer
Clang Tidy
Clang Sanitizers
Cppcheck
Facebook Infer
Coccinelle
Smatch
Kernel-Doc
Sparse
cpplint
C# Roslynator.DotNet.Cli
Java SpotBugs
Facebook Infer
Python Pylint
Pyflakes
JavaScript ESLint
TypeScript TSLint
Go Golint
Markdown Markdownlint
Sphinx

For details see supported code analyzers documentation and the Report Converter Tool.

Common Tools

Useful tools that can also be used outside CodeChecker.

Helper Scripts

Install guide

Install CodeChecker via pip

CodeChecker is available on the pypi and can be installed with the following command:

pip3 install codechecker

Note: this package can be installed on Linux, OSX and Windows systems where pip3 command is available. On OSX, intercept-build must be installed for logging (CodeChecker log). On Windows, logging is not available.

Installing CodeChecker via the snap package manager

CodeChecker is available on the Snap Store and can be installed with the following command:

sudo snap install codechecker --classic

Note: Unfortunately, the snap package supports only lower-case command names. For this reason, you need to use codechecker command instead of CodeChecker everywhere. For a full list of available commands in the codechecker snap package, run snap info codechecker.

Linux

For a detailed dependency list, and for instructions on how to install newer Clang and Clang-Tidy versions, please see Requirements. The following commands are used to bootstrap CodeChecker on Ubuntu 20.04 LTS:

# Install mandatory dependencies for a development and analysis environment.
# NOTE: clang or clang-tidy can be any sufficiently fresh version, and need not
#       come from package manager!
#       In case of Cppcheck, the minimal supported version is 1.80.
#       In case of gcc, the minimal supported version is 13.0.0.
sudo apt-get install clang clang-tidy cppcheck g++ build-essential curl
      gcc-multilib git python3-dev python3-venv python3-setuptools

# Install nodejs dependency for web. In case of Debian/Ubuntu you can use the
# following commands. For more information see the official docs:
# https://nodejs.org/en/download/package-manager/
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

# Check out CodeChecker source code.
git clone https://github.com/Ericsson/CodeChecker.git --depth 1 ~/codechecker
cd ~/codechecker

# Create a Python virtualenv and set it as your environment.
# NOTE: if you want to develop CodeChecker, use the `venv_dev` target instead
# of `venv`.
make venv
source $PWD/venv/bin/activate

# [Optional] If you want to use external authentication methods (LDAP / PAM)
# follow the instructions in
# docs/web/authentication.md#external-authentication-methods

# Build and install a CodeChecker package.
make package

# For ease of access, add the build directory to PATH.
export PATH="$PWD/build/CodeChecker/bin:$PATH"

cd ..

Notes:

  • By default, make package will build ldlogger shared objects for 32bit and 64bit too. If you would like to build and package 64 bit only shared objects and ldlogger binary you can set BUILD_LOGGER_64_BIT_ONLY environment variable to YES before the package build: BUILD_LOGGER_64_BIT_ONLY=YES make package.
  • By default, the make package will build the UI code if it's not built yet or the UI code is changed. If you wouldn't like to build the UI code you can set the BUILD_UI_DIST environment variable to NO before the package build: BUILD_UI_DIST=NO make package.
  • Use make standalone_package instead of make package to avoid having to manually activate the environment before running CodeChecker.

Upgrading environment after system or Python upgrade

If you have upgraded your system's Python to a newer version (e.g., from 3.8 to 3.11 โ€“ this is the case when upgrading Ubuntu from 20.04 LTS to 22.04 LTS), the installed environment will not work out-of-the-box. To fix this issue, run the following command to upgrade your checker_env too:

cd ~/codechecker/venv
python3 -m venv .

Mac OS X

For installation instructions for Mac OS X see Mac OS X Installation Guide documentation.

Docker

To run the CodeChecker server in Docker see the Docker documentation. You can find the CodeChecker web-server container at the Docker Hub.

Visual Studio Code plugin

You can install and use CodeChecker VSCode extension from the Visual Studio Marketplace or from Open VSX.

Main features:

  • Run CodeChecker analysis from the editor and see the results automatically.
  • Re-analyze the current file when saved.
  • Commands and build tasks for running CodeChecker as part of a build system.
  • Browse through the found reports and show the reproduction steps directly in the code.
  • Navigate between the reproduction steps.

VSCode plugin

For more information how to install and use this plugin see the repository of this extension.

GitHub Actions CI

CodeChecker executed in GitHub Actions

CodeChecker can be executed via a reusable GitHub action for your project! You need only specify the build command, as if you would run the analysis locally.

For more information, check out the CodeChecker Static Analysis action on the GitHub Actions Marketplace.

Analyze your first project

Setting up the environment in your Terminal

These steps must always be taken in a new command prompt you wish to execute analysis in.

source ~/codechecker/venv/bin/activate

# Path of CodeChecker package
# NOTE: SKIP this line if you want to always specify CodeChecker's full path.
export PATH=~/codechecker/build/CodeChecker/bin:$PATH

# Path of the built LLVM/Clang
# NOTE: SKIP this line if clang is available in your PATH as an installed Linux package.
export PATH=~/<user path>/build/bin:$PATH

Execute analysis

Analyze your project with the check command:

CodeChecker check -b "cd ~/your-project && make clean && make" -o ./results

check will print an overview of the issues found in your project by the analyzers. The reports will be stored in the ./results directory in plist XML format.

Export the reports as static HTML files

You can visualize the results as static HTML by executing

CodeChecker parse -e html ./results -o ./reports_html

An index page will be generated with a list of all repors in ./reports_html/index.html

Optionally store the results in Web server & view the results

If you have hundreds of results, you may want to store them on the web server with a database backend.

Start a CodeChecker web and storage server in another terminal or as a background process. By default, it will listen on localhost:8001.

The SQLite database containing the reports will be placed in your workspace directory (~/.codechecker by default), which can be provided via the -w flag.

CodeChecker server

Store your analysis reports onto the server to be able to use the Web Viewer.

CodeChecker store ./results -n my-project

Open the CodeChecker Web Viewer in your browser, and you should be greeted with a web application showing you the analysis results.

Developer documentations

Conference papers, presentations

codechecker's People

Contributors

balazske avatar bruntib avatar cservakt avatar csordasmarton avatar dependabot[bot] avatar dkrupp avatar gamesh411 avatar gkunz avatar gyorb avatar hpwxf avatar igalex avatar irishrover avatar itzurabhi avatar jay24rajput avatar jimis avatar justindhillon avatar labuwx avatar lorincbalog avatar martong avatar milanlakhani avatar omahs avatar rnkovacs avatar steakhal avatar sylvestre avatar szelethus avatar tmsblgh avatar vodorok avatar whisperity avatar xazax-hun avatar zomen2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codechecker's Issues

quick check

It should be possible to quickly check a small project (set of files) for bugs without storing the results into the postgres db.

The defect list should appear on the console without the bug paths, only showing the source location of the last step of the bugpath, checker name, bug message.

Only the build command should be the required command line parameter:

CodeChecker quickcheck -b "make"

Better skip file handling

A "bug" should be skipped if its path's last point/step should be skipped according to a skip file (given by --skip command line option).

support execution of clang tidy

CodeChecker can only run Clang SA, but there are many checkers implemented in Clang Tidy.

Codechecker shall be able to wrap
-config parameters
-checker enable/disable list
and parse the output of Clang tidy in exactly the same format as Clang SA

webgui: show the number of results per checker

Show in the run overview page, in the checker filter dropdown in parenthesis how many hits are in the run, per checker.

Also show the same information for bug priority and suppressed, unsuppressed list.

allow for patterns in skip file - or add whitelist strategy

Thanks for this tool! Looking awesome right now ๐Ÿ‘

My aim is to provide a skip file for CodeChecker within my project's source tree. But I want to only parse my own code and not optional and potential 3rd-party libraries. Thus, I can not put in absolute paths such as /usr/include. As well it's not possible to exclude specific files in the project's source tree (e.g. <PROJECT>/include/3rdparty) as I can not make any assumptions on the location of the project tree.

I tried specifying patterns such as eigen3/, */eigen3, /boost or */boost in a skip file. But that did not work. Only absolute paths such as /usr/include/eigen3 are working.

It would be awesome being able to exclude paths based on patterns or - even better - whitelist only specific files or paths only in the project's source tree.

whitelist for directories and files

sometimes it is useful to specify in a file the directories
from where files need to be checked.

this is especially problematic if the project takes file from many places of the filesystem.

change default cleanup behaviour

currently codechecker by default does not clean up the temporary plist files after the check, only if
'-c' clean argument is set
this should be changed to a new default behaviour:
by default the temporary files should be deleted during the check and only kept if it is explicitly set in the command line by a keep-temporary files option

database version mismatch message should be error level log

now can only be seen in debug mode.

[2048] <139634032555776> - report_server.run_server() [CC SERVER] - Creating new database schema done in 0
[2048] <139634032555776> - report_server.run_server() [CC SERVER] - Version mismatch. Expected database version: v4.0
[2048] <139634032555776> - report_server.run_server() [CC SERVER] - Version from the database is: v3.0
[2048] <139634032555776> - report_server.run_server() [CC SERVER] - Please update your database.
[1997] <139634032555776> - client.start_server() [CLIENT] - Waiting for checker server to start.
[1997] <139634032555776> - client.start_server() [CLIENT] - Waiting for checker server to start.
[1997] <139634032555776> - client.start_server() [CLIENT] - Waiting for checker server to start.
[1997] <139634032555776> - client.start_server() [CLIENT] - Failed to start checker server.

check for browser compatibility

We should check if the browser the gui is opened in is compatible with the WEBGUI and its dependencies (dojo, codemirror, jsplumb, jquery, etc.)

show in a popup the minimum required browser version only in case the used browser is not compatible with codechecker.

enable clang analyzer option pass through

introduce a new configuration parameter to
CodeChecker check
subcommand to pass through parameters to clang.

-e Pass extra parameters to clang.

this could be useful to specify parameters such as -analyzer-opt-analyze-headers or -analyzer-max-loop etc.

Selectable compiler binary at package build

Introduce a command line parameter
--clang /path/to/clang/binary

to specify to codechecker which clang binary should be used.
If this parameter is not specified, then the path specified config.json file should be used.

introduce env variables for common commandline parameters

it would be useful to be possible to give command line parameters as env variables
this would make the command line shorter.

if command line is specified it should override env var and default settings:
default->env-var->command line (override sequence)

in case of enable/disable checker list: the default should be extended by either the env var or the command line param

these params should have env var equivalent:
-workspace
-dbport
-dbhost
-dbuser
-dbname
-enable/disable checker list
-viewport
-suppress file path

if the env var is speficied then the CodeChecker script should list their values when started.

introduce permalinks on the web interface

it would be useful if the important views of the web GUI would have permalink URLs.
the following should have permalinks:-
-run-list
-bug list overview including filters
-view of a concrete defect
-a concrete page of the documentation and user guide

Then it would be possible the to send the the defect reports in email or use the browser back button.

add Clang SA configuration file

It should be possible to specify a config file to
CodeChecker check subcommand
where the checker specific configuration can be added.

Preferably in json format:

[  
   {  
      "checker_name":[  
         {  
            "parameter_name":"value"
         },
         {  
            "parameter_name":"value"
         }
      ]
   }
]

For example:

[  
   {  
      "NonPrivateDataChecker":[  
         {  
            "exclude_structs":"true"
         }
      ]
   }
]

suppress bug in source code

The following annotation format should be applied above the line where the bug was reported.
The list should contain checker names or the 'all' keyword if all bugs should be suppressed during the analysis.

// codechecker_suppress[checker_name1, checker_name2] reason for suppress
// is that checker is faulty.
int i=0;
or
// codechecker_suppress[all] reason for suppress

The "reason for suppress" field should be given by the user and it is a free text that can contain any character. Only whitespace characters are not accepted. If the "reason for suppress" field is missing, a warning message will be generated in the suppress_comment the bug database.
Reasons specified in multiple lines are accepted.

../config/original_env.pickle is not writable

Codechecker check crashed with the following:

Traceback (most recent call last):
File "/Codechecker/cc_bin/CodeChecker", line 28, in
with open(original_env_file, 'wb') as env_save:
IOError: [Errno 13] Permission denied: '/Codechecker/cc_bin/../config/original_env.pickle'

Proposed Solution:
The binary package directory in general is not writable.
Use the /tmp directory for temp files.
for example /tmp/codechecker_[username]

do not log compiler wrapper scripts

introduce an env variable to the logger to log only the execution of elf binaries (gcc, g++ are binaries)

the name of the env variable should be ๐ŸŽฑ
CC_LOG_BIN_ONLY
default 1

checker: when adding a new report do not check uniqueness based on the hash

when we add a new hit in the database, we check the uniqueness of the report based on the hash alone.
if there is a hash clash, then we do not add the report to the database.
however this could lead to missing reports when there is a hash clash. it is a problem especially when the bug is reported in the global namespace, because there is no named declaration context (and the filenanme is not in the hash).

check uniqueness based on hash first, then if there is a clash, check the checker name, file name and bug position.

Parsing of the build.log fails when a command has \"\

For example, the program that I am trying to build has this define:
-DDEFAULT_ICU_PLUGINS="/usr/local/lib/icu"\

Codechecker will fail this:
[ERROR] - The compile database is not valid.
[ERROR] - Invalid \escape: line 29848 column 786 (char 10574627)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.