Ericsson / codechecker

CodeChecker is an analyzer tooling, defect database and viewer extension for static and dynamic analyzer tools.
https://codechecker.readthedocs.io
Apache License 2.0
2.28k stars 383 forks source link

how to use the custom checker in CodeChecker #3661

Open Logyiyi opened 2 years ago

Logyiyi commented 2 years ago

Now I have a custom checker and the usage is: scan-build -load-plugin myplugin/libCustomTaintChecker.so -enable-checker alpha.security.taint.CustomTaintPropagation -analyzer-config alpha.security.taint.CustomTaintPropagation:ConfigurationFile=path/to/conf [command options]

The '-load-plugin' command line is followed by .so file, but env var 'CC_CLANGSA_PLUGIN_DIR' in CodeChecker is a directory, I want to know how to use the custom checker in CodeChecker?

whisperity commented 2 years ago

A foreword is that the use of plugins are generally unsupported by the upstream community too, but @stekahal may have some more insight wrt. to this.

According to the code where this environment variable is used: https://github.com/Ericsson/codechecker/blob/b7619c59eddeb24015151262e1009ff796495789/analyzer/codechecker_analyzer/analyzers/clangsa/config_handler.py#L58-L61

You just need to give the directory where your .so resides. It will tell the analyser to load every .so under that directory.

If you have multiple .so in a directory, it might be useful if you put them into separate directories.


Alternatively, you can use the --saargs flag for analyze/check which will forward every argument in the specified text file verbatim to the CSA analyser invocations. You can also give --verbose debug_analyzer to verify what command-line the analyzer is executing with.

steakhal commented 2 years ago

This works for me:

CC_ANALYZERS_FROM_PATH=yes \
PATH="/path/to/llvm-project/build/bin:$PATH" \
CC_CLANGSA_PLUGIN_DIR=/path/to/myplugins \
CodeChecker checkers -o rows
# It lists not only the builtin checkers, but the plugin ones!

Where CC_CLANGSA_PLUGIN_DIR points to the directory holding the *.so plugin objects:

ls /path/to/myplugins
libmychecker-plugin.so

Note that clang does not preserve ABI compatibility across versions, thus you will need to recompile the plugin for the particular clang version you want to use it with.

steakhal commented 2 years ago

Might be related #3593.