### Example of starting two servers with different configurations Source: https://github.com/ericsson/codechecker/blob/master/docs/web/user_guide.md Example demonstrating how to start two CodeChecker servers with different SQLite databases but the same configuration directory, using different ports. ```sh CodeChecker server --sqlite ~/major_bugs.sqlite -f ~/.codechecker -p 8001 CodeChecker server --sqlite ~/minor_bugs.sqlite -f ~/.codechecker -p 8002 ``` -------------------------------- ### Install Guide Source: https://github.com/ericsson/codechecker/blob/master/analyzer/tools/statistics_collector/README.md Commands to set up a Python virtual environment and install the post-process-stats package. ```sh # Create a Python virtualenv and set it as your environment. make venv source $PWD/venv/bin/activate # Build and install post-process-stats package. make package ``` -------------------------------- ### Install guide Source: https://github.com/ericsson/codechecker/blob/master/docs/tools/report-converter.md Instructions for setting up a Python virtual environment and installing the report-converter package. ```shell # Create a Python virtualenv and set it as your environment. make venv source $PWD/venv/bin/activate # Build and install report-converter package. make package ``` -------------------------------- ### Set up Virtual Environment and Install CodeChecker Source: https://github.com/ericsson/codechecker/blob/master/docs/web/postgresql_setup.md Activates the virtual environment, builds, and installs a CodeChecker package, and adds the build directory to the PATH. ```sh # Set the created virtualenv as your environment. source $PWD/venv/bin/activate # 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" ``` -------------------------------- ### Example analyzer config options output Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Example output showing loop-related analyzer configuration options for clangsa. ```text clangsa:cfg-loopexit (bool) Whether or not the end of the loop information should be included in the CFG. (default: false) clangsa:unroll-loops (bool) Whether the analysis should try to unroll loops with known bounds. (default: false) clangsa:widen-loops (bool) Whether the analysis should try to widen loops. (default: false) ``` -------------------------------- ### Start CodeChecker Server with PostgreSQL Source: https://github.com/ericsson/codechecker/blob/master/docs/web/postgresql_setup.md Starts a CodeChecker server specifying the configuration database's connection arguments for PostgreSQL. ```sh CodeChecker server --postgresql \ --db-host localhost --db-port 5432 \ --db-username codechecker --db-name codechecker_config ``` -------------------------------- ### Install PostgreSQL Dependencies Source: https://github.com/ericsson/codechecker/blob/master/docs/web/postgresql_setup.md Installs the necessary PostgreSQL packages and Python development headers on Ubuntu. ```sh # Get the extra PostgreSQL packages. sudo apt-get install libpq-dev postgresql \ postgresql-client-common postgresql-common \ python-dev # Setup databases for CodeChecker. # # By default, only the installer-created 'postgres' user has access to # database-specific binaries and actions. # Switch to this daemon user. sudo -i -u postgres # Create a new user to be used for connecting to the database. # (The password will be prompted for, and read from the standard input.) createuser --login --pwprompt codechecker # NOTE: For production systems, certain extra access control configuration # should be done to make sure database access is secure. Refer to the # PostgreSQL manual on connection control. # Create the configuration database for CodeChecker. createdb codechecker_config # The newly created user must have privileges on its own database. psql -c "GRANT ALL PRIVILEGES ON DATABASE codechecker_config TO codechecker;" # Return to your normal shell via: exit # PGPASSFILE environment variable should be set to a 'pgpass' file. # For format and further information see PostgreSQL documentation: # http://www.postgresql.org/docs/current/static/libpq-pgpass.html echo "*:5432:*:codechecker:my_password" >> ~/.pgpass chmod 0600 ~/.pgpass ``` -------------------------------- ### Navigate to the examples directory Source: https://github.com/ericsson/codechecker/blob/master/docs/usage.md Change the current directory to the 'docs/examples' directory within the repository. ```shell cd /docs/examples ``` -------------------------------- ### CCache Usage Examples Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Examples of how CCache can be invoked with a compiler. ```bash ccache g++ -DHELLO=world main.cpp ``` ```bash ccache -DHELLO=world main.cpp ``` -------------------------------- ### Quick Start Source: https://github.com/ericsson/codechecker/blob/master/tools/report-converter/README.md Steps to set up a Python virtual environment and install the report-converter package. ```bash # Create a Python virtualenv and set it as your environment make venv source $PWD/venv/bin/activate # Build and install report-converter package make package ``` -------------------------------- ### Source component file format example 1 Source: https://github.com/ericsson/codechecker/blob/master/docs/web/user_guide.md An example demonstrating the format of a source component file, using '+' and '-' prefixes to include or exclude file paths. ```text -/dont/list/results/in/directory/* -/dont/list/this.file +/dir/list/in/directory/* +/dir/list.this.file ``` -------------------------------- ### Source component file format example 2 Source: https://github.com/ericsson/codechecker/blob/master/docs/web/user_guide.md A second example illustrating the use of path glob patterns and inclusion/exclusion rules in a source component file. ```text +*/test* +*/test_files/* +*/test_data/* -*/test_p* ``` -------------------------------- ### Environment Setup Source: https://github.com/ericsson/codechecker/blob/master/scripts/thrift/README.md Steps to create a Python virtual environment, install the thrift package, and download/install CodeChecker API packages. ```shell python3 -m venv venv source $PWD/venv/bin/activate pip3 install thrift==0.22.0 wget https://github.com/Ericsson/codechecker/raw/v6.19.1/web/api/py/codechecker_api/dist/codechecker_api.tar.gz && \ pip3 install codechecker_api.tar.gz && \ rm -rf codechecker_api.tar.gz wget https://github.com/Ericsson/codechecker/raw/v6.19.1/web/api/py/codechecker_api_shared/dist/codechecker_api_shared.tar.gz && \ pip3 install codechecker_api_shared.tar.gz && \ rm -rf codechecker_api_shared.tar.gz ``` -------------------------------- ### Example of configuring a super-user in server_config.json Source: https://github.com/ericsson/codechecker/blob/master/docs/web/user_guide.md Example JSON snippet showing how to set a super-user ('admin') within the 'authentication' section of the server_config.json file. ```json "authentication": { "enabled" : true, "super_user" : "admin", ... } ``` -------------------------------- ### Compiler path matching examples Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Examples demonstrating how CodeChecker captures compiler calls based on path matching rules. ```bash my/gcc/compiler/g++ main.cpp # Not captured because there is no match. my/gcc/compiler/gcc-7 main.c # Captured because "gcc" is infix of "gcc-7". /usr/bin/g++ main.cpp # Captured because "/bin/g++" is postfix of the compiler path. /usr/bin/g++-7 main.cpp # Not captured because "/bin/g++" is not postfix of the compiler path. /clang # Will not log clang++ calls only the clang binary calls will be captured. clang # Will capture clang-tidy (which is not wanted) calls too because of a partial match. ``` -------------------------------- ### Example Analysis and Parsing Commands Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Demonstrates how to run an analysis and then parse the results. ```sh CodeChecker analyze ../codechecker_myProject_build.log -o my_plists ``` ```sh CodeChecker parse ./my_plists ``` -------------------------------- ### Enable debug log at server start Source: https://github.com/ericsson/codechecker/blob/master/docs/logging.md Example of enabling debug logging when starting the CodeChecker server. ```sh Codechecker server ... --verbose debug ``` -------------------------------- ### Client Configuration File Example Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Example of a JSON configuration file used to specify CodeChecker command-line arguments for the 'analyze' subcommand. ```json { "analyze": [ "--enable=core.DivideZero", "--enable=core.CallAndMessage", "--analyzer-config", "clangsa:unroll-loops=true", "--checker-config", "clang-tidy:google-readability-function-size.StatementThreshold=100", "--report-hash", "context-free-v2", "--verbose=debug", "--clean" ] } ``` -------------------------------- ### Absolute path examples in skipfile Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Examples of absolute path patterns in a skipfile. ```plaintext -/skip/all/files/in/directory/* -/do/not/check/this.file +/dir/do.check.this.file -/dir/* ``` -------------------------------- ### Basic analyze command examples Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Examples of how to invoke the CodeChecker analyze command with different inputs. ```sh CodeChecker analyze ../codechecker_myProject_build.log -o my_plists CodeChecker analyze main.cpp -o my_plists CodeChecker analyze project_root -o my_plists ``` -------------------------------- ### Analyze project Source: https://github.com/ericsson/codechecker/blob/master/web/server/vue-cli/src/assets/userguide/userguide.md Example command to analyze a project. ```sh CodeChecker analyze \ -o ./reports \ -e sensitive \ ./compilation_database.json ``` -------------------------------- ### CodeChecker analyzer configuration example Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Example JSON snippet showing how to configure the paths for clangsa and clang-tidy binaries in the CodeChecker package layout. ```json "analyzers" : { "clangsa" : "/path/to/clang/bin/clang-8", "clang-tidy" : "/path/to/clang/bin/clang-tidy-8" } ``` -------------------------------- ### Running CodeChecker log with BitBake Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Example of running CodeChecker log to capture compiler calls made by BitBake. ```bash CodeChecker log -o ../compile_commands.json -b "bitbake myProject" ``` -------------------------------- ### Range Object Structure Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Example JSON structure for a Range object, specifying start and end line and column numbers for a location. ```json { "start_line": 8, "start_col": 14, "end_line": 8, "end_col": 14 } ``` -------------------------------- ### Install merge-clang-extdef-mappings Source: https://github.com/ericsson/codechecker/blob/master/analyzer/tools/merge_clang_extdef_mappings/README.md Instructions to create a Python virtual environment, build, and install the merge-clang-extdef-mappings package. ```shell # Create a Python virtualenv and set it as your environment. make venv source $PWD/venv/bin/activate # Build and install merge-clang-extdef-mappings package. make package ``` -------------------------------- ### Example suppression file Source: https://github.com/ericsson/codechecker/blob/master/docs/web/user_guide.md An example of a suppression file with entries. ```plaintext 1a7ddce6d69b031310dd7ad2ff330b53||suppress.cpp||foo2 simple||false_positive 45a2fef6845f54eaf070ad03d19c7981||suppress.cpp||foo3 simple||intentional 9fb26da7f3224ec0c63cfe3617c8a14e||suppress.cpp||foo4 simple||confirmed ``` -------------------------------- ### Start CodeChecker server Source: https://github.com/ericsson/codechecker/blob/master/docs/usage.md Command to start the CodeChecker server locally with a workspace and specified port. ```shell cd CodeChecker server --workspace ./ws --port 8555 ``` -------------------------------- ### Skip list example Source: https://github.com/ericsson/codechecker/blob/master/docs/usage.md Example of a skip list file to tell CodeChecker which files to analyze and which to ignore. ```shell #skip.list: +*main.cpp -* ``` -------------------------------- ### Client Configuration File Example Source: https://github.com/ericsson/codechecker/blob/master/docs/web/user_guide.md This JSON file demonstrates how to configure CodeChecker command-line arguments, specifically for the 'store' command, using a configuration file instead of direct command-line parameters. ```json { "store": [ "--name=my_run", "--tag=my_tag", "--url=http://codechecker.my:9090/MyProduct" ] } ``` -------------------------------- ### intercept-build Example Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Example of using intercept-build with a build command containing a space character. ```bash intercept-build bash -c 'g++ -DVARIABLE="hello world" main.cpp' ``` -------------------------------- ### Example GCC Command Source: https://github.com/ericsson/codechecker/blob/master/analyzer/tools/build-logger/README.md Example of calling gcc from a sub-shell after setting up the build logger. ```bash bash -c "gcc -c something.c" ``` -------------------------------- ### Relative or partial path examples in skipfile Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Examples of relative or partial path patterns in a skipfile. ```plaintext +*/my_project/my_lib_to_skip/important_file.cpp -*/my_project/my_lib_to_skip* -*/my_project/3pplib/* +*/my_project/* ``` -------------------------------- ### Start server command Source: https://github.com/ericsson/codechecker/blob/master/docs/feature_comparison.md The command-line command `CodeChecker server` is used to start a CodeChecker server. ```bash CodeChecker server ``` -------------------------------- ### macOS El Capitan 10.11, Sierra 10.12, and High Sierra 10.13 Installation Commands Source: https://github.com/ericsson/codechecker/blob/master/docs/install_macosx.md Commands to download and install dependencies, fetch source code, set up a Python virtual environment, build, and install CodeChecker on macOS. ```shell # Download and install dependencies. brew update brew install gcc git pip3 install virtualenv # Install the latest clang see: https://formulae.brew.sh/formula/llvm brew install llvm@10.0.0 # Install npm brew install npm # Fetch 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. make venv_osx source $PWD/venv/bin/activate # 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 .. ``` -------------------------------- ### Add Product Configuration Source: https://github.com/ericsson/codechecker/blob/master/docs/web/postgresql_setup.md Adds a product configuration for the CodeChecker server, specifying PostgreSQL connection details for the analysis database. ```sh CodeChecker cmd products add Default --name "Default Product" \ --postgresql \ --db-host localhost --db-port 5432 \ --db-username codechecker --db-name default_product ``` -------------------------------- ### Example command line with configuration file Source: https://github.com/ericsson/codechecker/blob/master/docs/config_file.md Demonstrates how a command line invocation with a config file translates to expanded arguments. ```sh CodeChecker analyze \ compilation.json \ -o ./reports \ --enable=core.DivideZero \ --enable=core.CallAndMessage \ --analyzer-config clangsa:unroll-loops=true \ --checker-config clang-tidy:google-readability-function-size.StatementThreshold=100 \ --report-hash context-free-v2 \ --verbose debug \ --clean ``` -------------------------------- ### Example session for debugging a clang crash Source: https://github.com/ericsson/codechecker/blob/master/scripts/debug_tools/README.md This example demonstrates the steps to set up and run the debug tools for a standard clang crash. ```bash $ export WS=/your_own_path $ cd reports/failed $ unzip main.c_4c7feffae4c2b887abcdc37a3c88b2e5.plist.zip $ $WS/CodeChecker/debug_tools/prepare_analyzer_cmd.py --clang $WS/llvm/build/debug/bin/clang $ bash analyzer-command_DEBUG ``` -------------------------------- ### Fine-tuning --enable-all Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md Example of using --enable-all with subsequent --enable and --disable arguments to further customize checker selection. ```sh --enable-all --enable alpha --disable misc ``` -------------------------------- ### CC_LOGGER_GCC_LIKE Path Example Source: https://github.com/ericsson/codechecker/blob/master/analyzer/tools/build-logger/README.md Example demonstrating how paths are handled in CC_LOGGER_GCC_LIKE. ```bash export CC_LOGGER_GCC_LIKE="gcc:/bin/g++:clang:clang++:/cc:c++" # "gcc" has to be infix of the compiler's name because it contains no slash. # "/bin/g++" has to be postfix of the compiler's path because it contains slash. my/gcc/compiler/g++ main.cpp # Not captured because there is no match. my/gcc/compiler/gcc-7 main.c # Captured because "gcc" is infix of "gcc-7". /usr/bin/g++ main.cpp # Captured because "/bin/g++" is postfix of the compiler path. /usr/bin/g++-7 main.cpp # Not captured because "/bin/g++" is not postfix of the compiler path. # For an exact compiler binary name match start the binary name with a "/". /clang # Will not log clang++ calls only the clang binary calls will be captured. clang # Will capture clang-tidy (which is not wanted) calls too because of a partial match. ``` -------------------------------- ### MacroExpansion Object Example Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/user_guide.md An example of the JSON structure for a MacroExpansion object, detailing fields like name, file, line, column, message, and range. ```json { "name": "DIV", "file": { "id": "/home/username/dummy/simple/main.cpp", "path": "projects/dummy/main.cpp", "original_path": "/home/username/projects/dummy/main.cpp" }, "line": 5, "column": 10, "message": "1 / p", "range": { "start_line": 5, "start_col": 10, "end_line": 5, "end_col": 10 } } ``` -------------------------------- ### Store analysis results Source: https://github.com/ericsson/codechecker/blob/master/web/server/vue-cli/src/assets/userguide/userguide.md Example command to store analysis results to a run. ```sh CodeChecker store \ --name master_xerces \ --url https://my.codechecker.server.com/xerces ./reports ``` -------------------------------- ### Build Project Source: https://github.com/ericsson/codechecker/blob/master/analyzer/tools/build-logger/README.md Command to build the project. ```bash make all test ``` -------------------------------- ### List available checkers Source: https://github.com/ericsson/codechecker/blob/master/docs/usage.md Commands to list and get details about available checkers. ```sh # List available checkers. CodeChecker checkers --help ``` ```sh # Show more information about the checkers. CodeChecker checkers --details ``` ```sh # List profiles. CodeChecker checkers --profile --details ``` ```sh # List checkers which are in the sensitive profile. CodeChecker checkers --profile sensitive --details ``` -------------------------------- ### Setting the superuser Source: https://github.com/ericsson/codechecker/blob/master/docs/web/permissions.md Example of how to set the superuser in the server configuration file. ```json "authentication": { "enabled" : true, "super_user" : "admin", ... ``` -------------------------------- ### Sparse Example Source: https://github.com/ericsson/codechecker/blob/master/docs/tools/report-converter.md This example demonstrates how to run Sparse on kernel sources, redirect its output to a file, and then use 'report-converter' to create a CodeChecker report directory from the analyzer result. ```shell # Change Directory to your project cd path/to/linux/kernel/repository # Run Sparse make C=1 2>&1 | tee sparse.out # Use 'report-converter' to create a CodeChecker report directory from the # analyzer result of Sparse report-converter -t sparse -o ./codechecker_sparse_reports ./sparse.out # Store the Sparse reports with CodeChecker. CodeChecker store ./codechecker_sparse_reports -n sparse ``` -------------------------------- ### Setting up the environment in your Terminal Source: https://github.com/ericsson/codechecker/blob/master/docs/README.md Steps to set up the environment in a new command prompt for analysis. ```shell 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=~//build/bin:$PATH ``` -------------------------------- ### Create Analysis Database Source: https://github.com/ericsson/codechecker/blob/master/docs/web/postgresql_setup.md Creates an additional database for storing analysis reports and grants privileges to the server user. ```sh # Switch to the daemon user. sudo -i -u postgres # Create database and give rights to the server user. createdb default_product # The newly created user must have privileges on its own database. psql -c "GRANT ALL PRIVILEGES ON DATABASE default_product TO codechecker;" ``` -------------------------------- ### Store analysis results with description Source: https://github.com/ericsson/codechecker/blob/master/web/server/vue-cli/src/assets/userguide/userguide.md Example command to store analysis results with a custom description. ```sh CodeChecker store \ --name xerces \ --description "Analysis results of the Xerces-C++ project." \ --url https://my.codechecker.server.com/xerces \ ./reports ``` -------------------------------- ### Linux: Build from source - Checkout and setup Source: https://github.com/ericsson/codechecker/blob/master/docs/README.md Checks out CodeChecker source code, creates a Python virtual environment, and activates it. ```sh # 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 ``` -------------------------------- ### Sphinx Example Source: https://github.com/ericsson/codechecker/blob/master/docs/tools/report-converter.md This example shows how to run Sphinx on kernel sources, redirect its output to a file, and then use 'report-converter' to create a CodeChecker report directory from the analyzer result. ```shell # Change Directory to your project cd path/to/linux/kernel/repository # Run Sphinx # Note: The output of the following command will be both of sphinx and kernel-doc, # but the parser will parse only sphinx output make htmldocs 2>&1 | tee sphinx.out # Use 'report-converter' to create a CodeChecker report directory from the # analyzer result of Sphinx report-converter -t sphinx -o ./codechecker_sphinx_reports ./sphinx.out # Store the Sphinx reports with CodeChecker. CodeChecker store ./codechecker_sphinx_reports -n sphinx ``` -------------------------------- ### Version information JSON format Source: https://github.com/ericsson/codechecker/blob/master/docs/web/user_guide.md Example JSON output for version information. ```json { "analyzer": { "base_package_version": "6.19.0", "package_build_date": "2021-12-15T16:07", "git_commit": "ed16b5d58f75002b465ea0944be0abf071f0b958", "git_tag": "6.19" }, "web": { "base_package_version": "6.19.0", "package_build_date": "2021-12-15T16:07", "git_commit": "ed16b5d58f75002b465ea0944be0abf071f0b958", "git_tag": "6.19", "server_api_version": [ "6.47" ], "client_api_version": "6.47" } } ``` -------------------------------- ### Daily Analysis with tmux Source: https://github.com/ericsson/codechecker/blob/master/docs/usage.md Example commands for performing daily analysis, storing results, and diffing between runs. ```shell CodeChecker log --build "make" --output compile_commands.json ``` ```shell CodeChecker analyze ./compile_commands.json --output ./reports-daily ``` ```shell CodeChecker store ./reports --url http://localhost:8555/Default --name tmux_master_$(date +"%Y_%m_%d") ``` ```shell CodeChecker cmd diff --basename tmux_master_2017_08_28 --newname tmux_master_2017_08_29 --new --url http://localhost:8555/Default ``` ```shell CodeChecker cmd diff --basename tmux_master_2017_08_28 --newname tmux_master_2017_08_29 --new --url http://localhost:8555/Default --output json ``` -------------------------------- ### Alternative implementation using __clang_analyzer__ Source: https://github.com/ericsson/codechecker/blob/master/docs/analyzer/false_positives.md Example showing how to provide an alternative implementation that is easier for the analyzer to model using the __clang_analyzer__ macro. ```cpp unsigned f(unsigned x) { return (x >> 1) & 1; } ``` ```cpp #ifndef __clang_analyzer__ unsigned f(unsigned x) { return (x >> 1) & 1; } #else unsigned f(unsigned x) { return (x / 2) % 2; } #endif ```