@@ -16,12 +16,32 @@ to the basic data structures and workflow needed for contributing to
16
16
17
17
## Initial setup
18
18
19
- Clone the [ CBMC repository] [ cbmc-repo ] and build it:
19
+ Clone the [ CBMC repository] [ cbmc-repo ] and build it. The build instructions are
20
+ written in a file called COMPILING.md in the top level of the repository. I
21
+ recommend that you build using CMake---this will place all of the CBMC tools in
22
+ a single directory, which you can add to your ` $PATH ` . For example, if you built
23
+ the codebase with the following two commands at the top level of the repository:
20
24
21
- git clone https://github.com/diffblue/cbmc.git
22
- cd cbmc/src
23
- make minisat2-download
24
- make
25
+ cmake -DCMAKE_BUILD_TYPE=Debug \
26
+ -DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
27
+ -DCMAKE_C_COMPILER=/usr/bin/clang \
28
+ -B build -S .
29
+ cmake --build build
30
+
31
+ then all the CBMC binaries will be built into ` build/bin ` , and you can run the
32
+ following commands to make CBMC invokable from your terminal.
33
+
34
+ # Assuming you cloned CBMC into ~/code
35
+ export PATH=~/code/cbmc/build/bin:$PATH
36
+ # Add to your shell's startup configuration file so that you don't have to run that command every time.
37
+ echo 'export PATH=~/code/cbmc/build/bin:$PATH' >> .bashrc
38
+
39
+ If you are using Make instead of CMake, the built binaries will be
40
+ scattered throughout the source tree. This tutorial uses the binaries
41
+ ` src/cbmc/cbmc ` , ` src/goto-instrument/goto-instrument ` , and
42
+ ` src/goto-cc/goto-gcc ` , so you will need to add each of those
43
+ directories to your ` $PATH ` , or symlink to those binaries from a
44
+ directory that is already in your ` $PATH ` .
25
45
26
46
Ensure that [ graphviz] [ graphviz ] is installed on your system (in
27
47
particular, you should be able to run a program called ` dot ` ). Install
@@ -30,48 +50,29 @@ particular, you should be able to run a program called `dot`). Install
30
50
# In the src directory
31
51
doxygen doxyfile
32
52
# View the documentation in a web browser
33
- firefox doxy /html/index.html
53
+ firefox ~/code/cbmc/doc /html/index.html
34
54
35
55
If you've never used doxygen documentation before, get familiar with the
36
56
layout. Open the generated HTML page in a web browser; search for the
37
57
class ` goto_programt ` in the search bar, and jump to the documentation
38
58
for that class; and read through the copious documentation.
39
59
40
- The build writes executable programs into several of the source
41
- directories. In this tutorial, we'll be using binaries inside the
42
- ` cbmc ` , ` goto-instrument ` , and ` goto-cc ` directories. Add these
43
- directories to your ` $PATH ` :
44
-
45
- # Assuming you cloned CBMC into ~/code
46
- export PATH=~/code/cbmc/src/goto-instrument:~/code/cbmc/src/goto-cc:~/code/cbmc/src/cbmc:$PATH
47
- # Add to your shell's startup configuration file so that you don't have to run that command every time.
48
- echo 'export PATH=~/code/cbmc/src/goto-instrument:~/code/cbmc/src/goto-cc:~/code/cbmc/src/cbmc:$PATH' >> .bashrc
49
-
50
- Optional: install an image viewer that can read images on stdin.
51
- I use [ feh] [ feh ] .
52
-
53
60
[ cbmc-repo ] : https://github.com/diffblue/cbmc/
54
61
[ doxygen ] : http://www.stack.nl/~dimitri/doxygen/
55
62
[ graphviz ] : http://www.graphviz.org/
56
- [ feh ] : https://feh.finalrewind.org/
57
-
58
63
59
64
60
65
## Whirlwind tour of the tools
61
66
62
- CBMC's code is located under the ` cbmc ` directory. Even if you plan to
67
+ CBMC's code is located under the ` src ` directory. Even if you plan to
63
68
contribute only to CBMC, it is important to be familiar with several
64
69
other of cprover's auxiliary tools.
65
70
66
71
67
72
### Compiling with ` goto-cc `
68
73
69
- There should be an executable file called ` goto-cc ` in the ` goto-cc `
70
- directory; make a symbolic link to it called ` goto-gcc ` :
71
-
72
- cd cbmc/src/goto-cc
73
- ln -s "$(pwd)/goto-cc" goto-gcc
74
-
74
+ If you built using CMake on Unix, you should be able to run the
75
+ ` goto-gcc ` command.
75
76
Find or write a moderately-interesting C program; we'll call it ` main.c ` .
76
77
Run the following commands:
77
78
@@ -102,16 +103,10 @@ structured programming constructs.
102
103
103
104
Find or write a small C program (2 or 3 functions, each containing a few
104
105
varied statements). Compile it using ` goto-gcc ` as above into an object
105
- file called ` main ` . If you installed ` feh ` , try the following command
106
- to dump a control-flow graph:
107
-
108
- goto-instrument --dot main | tail -n +2 | dot -Tpng | feh -
109
-
110
- If you didn't install ` feh ` , you can write the diagram to the file and
111
- then view it:
106
+ file called ` main ` . You can write the diagram to a file and then view it:
112
107
113
- goto-instrument --dot main | tail -n +2 | dot -Tpng > main.png
114
- Now open main.png with an image viewer
108
+ goto-instrument --dot main.goto | tail -n +2 | dot -Tpng > main.png
109
+ open main.png
115
110
116
111
(the invocation of ` tail ` is used to filter out the first line of
117
112
` goto-instrument ` output. If ` goto-instrument ` writes more or less
@@ -148,7 +143,7 @@ At some point in that function, there will be a long sequence of `if` statements
148
143
** Task:** Add a ` --greet ` switch to ` goto-instrument ` , taking an optional
149
144
argument, with the following behaviour:
150
145
151
- $ goto-instrument --greet main
146
+ $ goto-instrument --greet main.goto
152
147
hello, world!
153
148
$ goto-instrument --greet Leperina main
154
149
hello, Leperina!
0 commit comments