Skip to content

Commit

Permalink
[doc] Revise howto
Browse files Browse the repository at this point in the history
Howto follow modifications on command line userinterface.
  • Loading branch information
zomen2 committed Mar 11, 2021
1 parent b06dfaa commit 3c84826
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 117 deletions.
5 changes: 1 addition & 4 deletions docs/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ sources := $(wildcard $(source_dir)/*.cpp)
objects := $(patsubst $(source_dir)/%.cpp,$(object_dir)/%.cpp.o,$(sources))
depends := $(patsubst $(source_dir)/%.cpp,$(object_dir)/%.cpp.d,$(sources))

CXX = clang++-11
CC = clang-11
CXXFLAGS = -MMD -MP -g -std=c++20 -Weverything -Wno-c++98-compat
CXXFLAGS = -MMD -MP -g -std=c++17 -Wall -Wno-c++98-compat -Werror
CXXFLAGS += -I $(include_dir)
LINKFLAGS := -L /usr/lib/x86_64-linux-gnu -l boost_program_options

all: $(runnable)

Expand Down
9 changes: 0 additions & 9 deletions docs/examples/incl/ArgParser.hpp

This file was deleted.

6 changes: 6 additions & 0 deletions docs/examples/incl/divide.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef DIVIDE_HPP
#define DIVIDE_HPP

double divide(long numerator, long denominator);

#endif // DIVIDE_HPP
46 changes: 0 additions & 46 deletions docs/examples/src/argparser.cpp

This file was deleted.

6 changes: 6 additions & 0 deletions docs/examples/src/divide.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "divide.hpp"

double divide(long numerator, long denominator)
{
return double(numerator) / double(denominator);
}
60 changes: 15 additions & 45 deletions docs/examples/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,57 +1,27 @@
#include "ArgParser.hpp"
#include "divide.hpp"

#include <boost/program_options/variables_map.hpp>

#include <ctype.h>
#include <iostream>
#include <memory>

namespace {

int convertCompressionLevel(char level)
{
if (isdigit(level)) {
return (int(level) - int('0'));
} else {
switch (level) {
case 'n':
case 'N':
return 0;
case 'l':
case 'L':
return 2;
case 'm':
case 'M':
return 5;
case 'h':
case 'H':
return 9;
default:
return -1;
}
}
}

}
#include <stdlib.h>
#include <vector>

int main(int argc, char* argv[])
{
std::cout << "CodeChecker example program." << '\n';
std::unique_ptr<boost::program_options::variables_map> programOptionMap =
parseArguments(argc, argv);
if (programOptionMap == nullptr) {
return 0;
}

int compressionLevel;
compressionLevel = convertCompressionLevel(
(*programOptionMap)["compression"].as<char>());
if (compressionLevel < 0) {
std::cerr << "Invalid compression level was set." << '\n';
return 1;
std::vector<int> params;
for (int i = 1; i < argc; ++i) {
long value = strtol(argv[i], nullptr, 10);
if (errno) {
std::cerr << "Invalid parameter at position " << i << ".\n";
return 1;
} else {
params.push_back(int(value));
}
}

std::cout << "Compression level was set to " << compressionLevel << ".\n";
auto result = divide(params[0], params[1]);

std::cout << "Division result is: " << result << ".\n";

return 0;
}
Binary file modified docs/images/static_html.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 26 additions & 13 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ It invokes Clang Static Analyzer and Clang-Tidy tools to analyze your code.
- [Definition of "run"<a name="run-definition"></a>](#definition-of-run)
- [Step 6: Fine tune Analysis configuration <a name="step-6"></a>](#step-6-fine-tune-analysis-configuration-)
- [Analysis Failures <a name="step-6"></a>](#analysis-failures-)
- [Avoiding or Suppressing False positives <a name="false-positives"></a>](#avoiding-or-suppressing-false-positives-)
- [Avoiding or Suppressing False positives<a name="false-positives"></a>](#avoiding-or-suppressing-false-positives)
- [Ignore modules from your analysis <a name="ignore-modules"></a>](#ignore-modules-from-your-analysis-)
- [Enable/Disable Checkers <a name="enable-disable-checkers"></a>](#enabledisable-checkers-)
- [Configure Checkers<a name="configure-checkers"></a>](#configure-checkers)
Expand Down Expand Up @@ -89,15 +89,15 @@ compiler calls and save commands in a *compilation database* file.
This compilation database is an input of the next analysis step.

```sh
CodeChecker log --build "make" --build compile_commands.json
CodeChecker log --build "make" --build ./compile_commands.json
```

### Check the contents of compile_commands.json file<a name="check-compile-commands"></a>
If everything goes well it should contain the `g++` calls. (If you use clang
then `clang` calls.)

```sh
cat compile_commands.json
cat ./compile_commands.json
```

**What to do if the `compile_commands.json` is empty?**
Expand All @@ -120,14 +120,23 @@ created, you can analyze your project.

### Run the analysis<a name="run-the-analysis"></a>
```sh
CodeChecker analyze --output ./reports compile_commands.json
CodeChecker analyze --output ./reports compile_commands.json --enable sensitive
```

However the compilation of the project (here the example program) is performed
by `g++`, the CodeChecker uses `clang` to analyze sources of the project.
During analysis, CodeChecker compiles/analyses sources again. The analysis
process generally uses more time.

In the above command the `--enable sensitive` means that a subset of checker
are run. `sensitive` is a predefined "group" of checkers. The further info on
available checkers use

```sh
CodeChecker checkers --help
```
command.

The `./reports` directory is the "database" of CodeChecker that allows to
manage further working steps.

Expand Down Expand Up @@ -168,7 +177,13 @@ running:
```sh
CodeChecker parse --print-steps ./reports
...
TODO: Cut the output of example prog. analysis here.
[LOW] /home/zomen/ws/Checker/CodeChecker.my/docs/examples/src/main.cpp:4:10: inclusion of deprecated C++ header 'stdlib.h'; consider using 'cstdlib' instead [modernize-deprecated-headers]
#include <stdlib.h>
^
Report hash: 67e36f780b2af8460365de8eb2c037c2
Steps:
1, main.cpp:4:10: <cstdlib> (fixit)
2, main.cpp:4:10: inclusion of deprecated C++ header 'stdlib.h'; consider using 'cstdlib' instead
...
```

Expand All @@ -187,7 +202,6 @@ To view the results in a browser run:
findings that are stored in separate `HTML` files (one per analyzed build
action).

TODO: Change image following new example program.
![Analysis results in static HTML files](images/static_html.png)

TODO: Edit the next paragraph.
Expand Down Expand Up @@ -219,14 +233,13 @@ following command after having analysis reports in `reports` directory:
CodeChecker fixit ./reports
```

TODO: Synchronize with source code.
In this example we will fix an issue automatically. It changes the source and
you can try the incremental build feature on modified source. The next command
fixes ... line of `main.cpp`.
In this example we will fix only one issue automatically. It changes the source
and you can try the incremental build feature on modified source. The next
command fixes 4th line of `main.cpp`.

```sh
CodeChecker fixit --checker-name readability-implicit-bool-conversion \
--apply ./reports
CodeChecker fixit --checker-name modernize-deprecated-headers --apply \
./reports
```

Without `--apply` option CodeChecker will not modify the source.
Expand Down Expand Up @@ -362,7 +375,7 @@ Possible reasons for failed analysis:
One can use this macro to selectively exclude code the analyzer examines.
* Clang crashed during the analysis.

### Avoiding or Suppressing False positives <a name="false-positives"></a>
### Avoiding or Suppressing False positives<a name="false-positives"></a>
Sometimes the analyzer reports correct code as incorrect. These findings are
called false positives. Having a false positive indicates that the analyzer
does not understand some properties of the code.
Expand Down

0 comments on commit 3c84826

Please sign in to comment.