@@ -16,12 +16,32 @@ to the basic data structures and workflow needed for contributing to
1616
1717## Initial setup
1818
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:
2024
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 ` .
2545
2646Ensure that [ graphviz] [ graphviz ] is installed on your system (in
2747particular, 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
3050 # In the src directory
3151 doxygen doxyfile
3252 # View the documentation in a web browser
33- firefox doxy /html/index.html
53+ firefox ~/code/cbmc/doc /html/index.html
3454
3555If you've never used doxygen documentation before, get familiar with the
3656layout. Open the generated HTML page in a web browser; search for the
3757class ` goto_programt ` in the search bar, and jump to the documentation
3858for that class; and read through the copious documentation.
3959
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-
5360[ cbmc-repo ] : https://github.com/diffblue/cbmc/
5461[ doxygen ] : http://www.stack.nl/~dimitri/doxygen/
5562[ graphviz ] : http://www.graphviz.org/
56- [ feh ] : https://feh.finalrewind.org/
57-
5863
5964
6065## Whirlwind tour of the tools
6166
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
6368contribute only to CBMC, it is important to be familiar with several
6469other of cprover's auxiliary tools.
6570
6671
6772### Compiling with ` goto-cc `
6873
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.
7576Find or write a moderately-interesting C program; we'll call it ` main.c ` .
7677Run the following commands:
7778
@@ -102,16 +103,10 @@ structured programming constructs.
102103
103104Find or write a small C program (2 or 3 functions, each containing a few
104105varied 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:
112107
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
115110
116111(the invocation of ` tail ` is used to filter out the first line of
117112` 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
148143** Task:** Add a ` --greet ` switch to ` goto-instrument ` , taking an optional
149144argument, with the following behaviour:
150145
151- $ goto-instrument --greet main
146+ $ goto-instrument --greet main.goto
152147 hello, world!
153148 $ goto-instrument --greet Leperina main
154149 hello, Leperina!
0 commit comments