Document how to analyze Bitcoin Core using Clang Static Analysis, clang-tidy
and cppcheck
.
As requested by Sjors (#14676) and others :)
Document how to analyze Bitcoin Core using Clang Static Analysis, clang-tidy
and cppcheck
.
As requested by Sjors (#14676) and others :)
8+
9+```
10+$ git clone https://github.com/bitcoin/bitcoin
11+$ cd bitcoin/
12+$ ./autogen.sh
13+$ CC=clang CXX=clang++ ./configure --with-incompatible-bdb --disable-ccache
ccache
needs to be disabled.
47+$ make
48+$ cd ..
49+# Analyze source code files ...
50+$ cppcheck/bin/cppcheck --language=c++ -D__cplusplus -DCLIENT_VERSION_BUILD \
51+ -DCLIENT_VERSION_IS_RELEASE -DCLIENT_VERSION_MAJOR -DCLIENT_VERSION_MINOR \
52+ -DCLIENT_VERSION_REVISION -DCOPYRIGHT_YEAR -DDEBUG
heh, nice example!
0$ cppcheck/bin/cppcheck --language=c++ -D__cplusplus .../... src/net_processing.cpp
1src/net_processing.cpp:936:17: error: Same iterator is used with different containers 'mapOrphanTransactions' and 'itPrev.second'. [iterators1]
2 itPrev->second.erase(it);
3 ^
4src/limitedmap.h:72:39: style: Same iterators expression are used for algorithm. [sameIteratorExpression]
5 iterator itTarget = map.erase(itIn, itIn);
9+```
10+$ git clone https://github.com/bitcoin/bitcoin
11+$ cd bitcoin/
12+$ ./autogen.sh
13+$ CC=clang CXX=clang++ ./configure --with-incompatible-bdb --disable-ccache
14+$ scan-build --use-cc=clang --use-c++=clang++ make
scan-build: 'ccc-analyzer' does not exist at '/usr/local/bin/ccc-analyzer'
here and not finding a linux version.
29+$ make all
30+$ chmod +x bear/bear
31+$ cd ..
32+$ bear/bear/bear -l $(pwd)/bear/libear/libear.so make
33+# Analyze source code files ...
34+$ clang-tidy src/test/crypto_tests.cpp
There is also bitcoin-core/docs, if the devwiki or fanquake/core-review are insufficient places to put this.
In general I agree with @fanquake that documentation to compile with any imaginable compiler or checker or sanitizer or … should probably be maintained outside of this repository. The project here is too big and moving too slow to keep every single piece of documentation up-to-date at all times. Also, we should be considerate of the precious review resource in this repository and use it on Bitcoin Core itself and not on integration of Bitcoin Core with meta developer tools.
Feel free to take what you need from this PR and move to the appropriate place. Closing this PR :) @marcofalke
In general I agree with @fanquake that documentation to compile with any imaginable compiler or checker or sanitizer or … should probably be maintained outside of this repository. The project here is too big and moving too slow to keep every single piece of documentation up-to-date at all times. Also, we should be considerate of the precious review resource in this repository and use it on Bitcoin Core itself and not on integration of Bitcoin Core with meta developer tools.
Personally I think we as a project have historically vastly underused the available tooling that is typically used in security critical projects to tame C++ (sanitizers, etc.). In other words I don’t think we run the risk of using, integrating or documenting “too much” tooling (quite the opposite TBH!), but I see your point regarding moving the documentation to another repo :)
Feel free to take what you need from this PR and move to the appropriate place. Closing this PR :)
Thanks for this info @practicalswift. Like @fanquake, I’ve been compiling info like this in a separate repository for my own reference and anyone else who may find it helpful.
similar guides available, i.e I have one here: fanquake/core-review:clang-tools.md@
master
.
Thanks @fanquake for the reminder to spend more time looking at the excellent info in core-review.
practicalswift
jonatack
fanquake
MarcoFalke
Labels
Docs