Skip to content

Commit 1b50bdc

Browse files
committed
Squashed commits from Prerequisite PR diffblue#4482 -- Do not review
1 parent b77b5b0 commit 1b50bdc

File tree

124 files changed

+3732
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+3732
-298
lines changed

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ jobs:
200200
install:
201201
- ccache -z
202202
- ccache --max-size=1G
203-
- cmake -H. -Bbuild '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_CXX_COMPILER=/usr/bin/g++-7' '-DCMAKE_CXX_FLAGS=-DNAMED_SUB_IS_FORWARD_LIST'
203+
- cmake -H. -Bbuild '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_CXX_COMPILER=/usr/bin/g++-7' '-DCMAKE_CXX_FLAGS=-DNAMED_SUB_IS_FORWARD_LIST' '-DWITH_MEMORY_ANALYZER=On'
204204
- git submodule update --init --recursive
205205
- cmake --build build -- -j4
206206
script: (cd build; bin/unit "[core][irept]")
@@ -228,7 +228,7 @@ jobs:
228228
install:
229229
- ccache -z
230230
- ccache --max-size=1G
231-
- cmake -H. -Bbuild '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_CXX_COMPILER=/usr/bin/g++-7' '-DCMAKE_USE_CUDD=true' -DCMAKE_CXX_FLAGS="-DBDD_GUARDS"
231+
- cmake -H. -Bbuild '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_CXX_COMPILER=/usr/bin/g++-7' '-DCMAKE_USE_CUDD=true' -DCMAKE_CXX_FLAGS="-DBDD_GUARDS" '-DWITH_MEMORY_ANALYZER=On'
232232
- git submodule update --init --recursive
233233
- cmake --build build -- -j4
234234
script: (cd build; ctest -V -L CORE -j2)
@@ -264,7 +264,7 @@ jobs:
264264
install:
265265
- ccache -z
266266
- ccache --max-size=1G
267-
- cmake -H. -Bbuild '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_CXX_COMPILER=/usr/bin/clang++-7' '-DCMAKE_CXX_FLAGS=-Qunused-arguments'
267+
- cmake -H. -Bbuild '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_CXX_COMPILER=/usr/bin/clang++-7' '-DCMAKE_CXX_FLAGS=-Qunused-arguments' '-DWITH_MEMORY_ANALYZER=On'
268268
- git submodule update --init --recursive
269269
- cmake --build build -- -j4
270270
script: (cd build; ctest -V -L CORE -j2)
@@ -330,6 +330,7 @@ install:
330330
- make -C src minisat2-download
331331
- make -C src/ansi-c library_check
332332
- make -C src/cpp library_check
333+
- if [ $TRAVIS_OS_NAME=linux ] ; then env WITH_MEMORY_ANALYZER=1 ; fi ;
333334
- make -C src "CXX=${COMPILER} ${EXTRA_CXXFLAGS}" -j3
334335
- make -C jbmc/src "CXX=${COMPILER} ${EXTRA_CXXFLAGS}" -j3
335336

@@ -338,8 +339,8 @@ script:
338339
- env UBSAN_OPTIONS=print_stacktrace=1 make -C regression test-parallel "CXX=${COMPILER} ${EXTRA_CXXFLAGS}" -j2 JOBS=2
339340
- UBSAN_OPTIONS=print_stacktrace=1 make -C regression/cbmc test-paths-lifo
340341
- env PATH=$PATH:`pwd`/src/solvers UBSAN_OPTIONS=print_stacktrace=1 make -C regression/cbmc test-cprover-smt2
341-
- make -C unit "CXX=${COMPILER} ${EXTRA_CXXFLAGS}" -j2
342-
- make -C unit test
342+
- env make -C unit "CXX=${COMPILER} ${EXTRA_CXXFLAGS}" -j2
343+
- env make -C unit test
343344
- env UBSAN_OPTIONS=print_stacktrace=1 make -C jbmc/regression test-parallel "CXX=${COMPILER} ${EXTRA_CXXFLAGS}" -j2 JOBS=2
344345
- make -C jbmc/unit "CXX=${COMPILER} ${EXTRA_CXXFLAGS}" -j2
345346
- make -C jbmc/unit test

CMakeLists.txt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,28 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
104104
endif()
105105
endif()
106106

107+
function(cprover_default_properties)
108+
set(CBMC_CXX_STANDARD 11)
109+
set(CBMC_CXX_STANDARD_REQUIRED true)
110+
set(CBMC_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY
111+
"Developer ID Application: Daniel Kroening")
112+
113+
set_target_properties(
114+
${ARGN}
115+
PROPERTIES
116+
CXX_STANDARD ${CBMC_CXX_STANDARD}
117+
CXX_STANDARD_REQUIRED ${CBMC_CXX_STANDARD_REQUIRED}
118+
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CBMC_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY})
119+
endfunction()
120+
121+
option(WITH_MEMORY_ANALYZER OFF
122+
"build the memory analyzer")
123+
107124
add_subdirectory(src)
108125
add_subdirectory(regression)
109126
add_subdirectory(unit)
110127

111-
set(CBMC_CXX_STANDARD 11)
112-
set(CBMC_CXX_STANDARD_REQUIRED true)
113-
set(CBMC_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY
114-
"Developer ID Application: Daniel Kroening")
115-
116-
set_target_properties(
128+
cprover_default_properties(
117129
analyses
118130
ansi-c
119131
assembler
@@ -144,13 +156,7 @@ set_target_properties(
144156
testing-utils
145157
unit
146158
util
147-
xml
148-
149-
PROPERTIES
150-
CXX_STANDARD ${CBMC_CXX_STANDARD}
151-
CXX_STANDARD_REQUIRED ${CBMC_CXX_STANDARD_REQUIRED}
152-
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CBMC_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY}
153-
)
159+
xml)
154160

155161
option(WITH_JBMC "Build the JBMC Java front-end" ON)
156162
if(WITH_JBMC)

doc/cprover-manual/memory-analyzer.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[CPROVER Manual TOC](../../)
2+
3+
## Memory Analyzer
4+
5+
The memory analyzer is a front-end for running and querying GDB in order to
6+
obtain a state of the input program. A common application would be to obtain a
7+
snapshot of a program under analysis at a particular state of execution. Such a
8+
snapshot could be useful on its own: to query about values of particular
9+
variables. Furthermore, since that snapshot is a state of a valid concrete
10+
execution, it can also be used for subsequent analyses.
11+
12+
## Usage
13+
14+
We assume that the user wants to inspect a binary executable compiled with
15+
debugging symbols and a symbol table information understandable by CBMC, e.g.
16+
(having `goto-gcc` on the `PATH`):
17+
18+
```sh
19+
$ goto-gcc -g -std=c11 input_program.c -o input_program_exe
20+
```
21+
22+
Calling `goto-gcc` instead of simply compiling with `gcc` produces an ELF binary
23+
with a goto section that contains the goto model (goto program + symbol table).
24+
25+
The user can choose to either run GDB from a core-file `--core-file cf` or to a
26+
break-point `--breakpoint bp` (and only one of those). The tool also expects a
27+
comma-separated list of symbols to be analysed `--symbols s1, s2, ..`. Given its
28+
dependence on GDB, `memory-analyzer` is a Unix-only tool. The tool calls `gdb`
29+
to obtain the snapshot which is why the `-g` option is necessary for the program
30+
symbols to be visible.
31+
32+
Take for example the following program:
33+
34+
```C
35+
// main.c
36+
void checkpoint() {}
37+
38+
int array[] = {1, 2, 3};
39+
40+
int main()
41+
{
42+
array[1] = 4;
43+
44+
checkpoint();
45+
46+
return 0;
47+
}
48+
```
49+
50+
Say we are interested in the evaluation of `array` at the call-site of
51+
`checkpoint`. We compile the program with
52+
53+
```sh
54+
$ goto-gcc -g -std=c11 main.c -o main_exe
55+
```
56+
57+
And then we call `memory-analyzer` with:
58+
59+
```sh
60+
$ memory-analyzer --breakpoint checkpoint --symbols array main_exe
61+
```
62+
63+
to obtain as output:
64+
65+
```
66+
{
67+
array = { 1, 4, 3 };
68+
}
69+
```
70+
71+
Finally, to obtain an output in JSON format, e.g. for further analyses by
72+
`goto-harness` pass the additional option `--json-ui` together with requesting
73+
the output to be a symbol table by `--symtab-snapshot`.
74+
75+
```sh
76+
$ memory-analyzer --symtab-snapshot --json-ui \
77+
--breakpoint checkpoint --symbols array main_exe > snapshot.json
78+
```

jbmc/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ add_custom_target(java-models-library ALL
88
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/java-models-library
99
)
1010

11-
set_target_properties(
11+
cprover_default_properties(
1212
java_bytecode
1313
java-models-library
1414
jbmc
@@ -20,9 +20,4 @@ set_target_properties(
2020
java-testing-utils
2121
java-unit
2222
miniz
23-
24-
PROPERTIES
25-
CXX_STANDARD ${CBMC_CXX_STANDARD}
26-
CXX_STANDARD_REQUIRED ${CBMC_CXX_STANDARD_REQUIRED}
27-
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CBMC_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY}
2823
)

regression/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ add_subdirectory(systemc)
5151
add_subdirectory(contracts)
5252
add_subdirectory(goto-harness)
5353
add_subdirectory(goto-cc-file-local)
54+
55+
if(WITH_MEMORY_ANALYZER)
56+
add_subdirectory(snapshot-harness)
57+
add_subdirectory(memory-analyzer)
58+
endif()

regression/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ DIRS = cbmc \
2424
cbmc-cpp \
2525
goto-cc-goto-analyzer \
2626
systemc \
27-
contracts \
27+
contracts
2828
# Empty last line
2929

30+
ifeq ($(WITH_MEMORY_ANALYZER),1)
31+
DIRS += snapshot-harness \
32+
memory-analyzer
33+
endif
34+
3035
# Run all test directories in sequence
3136
.PHONY: test
3237
test:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_test_pl_tests(
2+
"../chain.sh \
3+
$<TARGET_FILE:memory-analyzer> \
4+
../../../build/bin/goto-gcc")

regression/memory-analyzer/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
default: clean tests.log
2+
3+
MEMORY_ANALYZER_EXE=../../../src/memory-analyzer/memory-analyzer
4+
GOTO_GCC_EXE=../../../src/goto-cc/goto-gcc
5+
6+
clean:
7+
find -name '*.exe' -execdir $(RM) '{}' \;
8+
find -name '*.out' -execdir $(RM) '{}' \;
9+
$(RM) tests.log
10+
11+
test:
12+
@../test.pl -e -p -c "../chain.sh $(MEMORY_ANALYZER_EXE) $(GOTO_GCC_EXE)"
13+
14+
tests.log: ../test.pl
15+
@../test.pl -e -p -c "../chain.sh $(MEMORY_ANALYZER_EXE) $(GOTO_GCC_EXE)"
16+
17+
show:
18+
@for dir in *; do \
19+
if [ -d "$$dir" ]; then \
20+
vim -o "$$dir/*.c" "$$dir/*.out"; \
21+
fi; \
22+
done;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//Copyright 2018 Author: Malte Mues <[email protected]>
2+
3+
/// \file
4+
/// This file test array support in the memory-analyzer.
5+
/// A more detailed description of the test idea is in example3.h.
6+
/// setup() prepares the data structure.
7+
/// manipulate_data() is the hook used for the test,
8+
/// where gdb reaches the breakpoint.
9+
/// main() is just the required boilerplate around this methods,
10+
/// to make the compiled result executable.
11+
12+
#include "arrays.h"
13+
14+
#include <stdio.h>
15+
#include <stdlib.h>
16+
#include <string.h>
17+
18+
void setup()
19+
{
20+
test_struct = malloc(sizeof(struct a_typet));
21+
for(int i = 0; i < 10; i++)
22+
{
23+
test_struct->config[i] = i + 10;
24+
}
25+
for(int i = 0; i < 10; i++)
26+
{
27+
test_struct->values[i] = 0xf3;
28+
}
29+
for(int i = 10; i < 20; i++)
30+
{
31+
test_struct->values[i] = 0x3f;
32+
}
33+
for(int i = 20; i < 30; i++)
34+
{
35+
test_struct->values[i] = 0x01;
36+
}
37+
for(int i = 30; i < 40; i++)
38+
{
39+
test_struct->values[i] = 0x01;
40+
}
41+
for(int i = 40; i < 50; i++)
42+
{
43+
test_struct->values[i] = 0xff;
44+
}
45+
for(int i = 50; i < 60; i++)
46+
{
47+
test_struct->values[i] = 0x00;
48+
}
49+
for(int i = 60; i < 70; i++)
50+
{
51+
test_struct->values[i] = 0xab;
52+
}
53+
messaget option1 = {.text = "accept"};
54+
for(int i = 0; i < 4; i++)
55+
{
56+
char *value = malloc(sizeof(char *));
57+
sprintf(value, "unique%i", i);
58+
entryt your_options = {
59+
.id = 1, .options[0] = option1, .options[1].text = value};
60+
your_options.id = i + 12;
61+
test_struct->childs[i].id = your_options.id;
62+
test_struct->childs[i].options[0] = your_options.options[0];
63+
test_struct->childs[i].options[1].text = your_options.options[1].text;
64+
}
65+
test_struct->initialized = true;
66+
}
67+
68+
int manipulate_data()
69+
{
70+
for(int i = 0; i < 4; i++)
71+
{
72+
free(test_struct->childs[i].options[1].text);
73+
test_struct->childs[i].options[1].text = "decline";
74+
}
75+
}
76+
77+
int main()
78+
{
79+
setup();
80+
manipulate_data();
81+
return 0;
82+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//Copyright 2018 Author: Malte Mues <[email protected]>
2+
3+
/// \file
4+
/// Example3 test explicitly the array support.
5+
/// It ensures, that arrays are handled right.
6+
/// The different typedefs have been used, to make sure the memory-analyzer
7+
/// is aware of the different appeareances in the gdb responses.
8+
9+
#include <stdbool.h>
10+
11+
struct a_sub_sub_typet
12+
{
13+
char *text;
14+
};
15+
16+
typedef struct a_sub_sub_typet messaget;
17+
18+
struct a_sub_typet
19+
{
20+
int id;
21+
messaget options[2];
22+
};
23+
24+
struct a_typet
25+
{
26+
int config[10];
27+
bool initialized;
28+
unsigned char values[70];
29+
struct a_sub_typet childs[4];
30+
} * test_struct;
31+
32+
typedef struct a_sub_typet entryt;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FUTURE
2+
arrays.exe
3+
--breakpoint manipulate_data --symbols test_struct
4+
analyzing symbol: test_struct
5+
GENERATED CODE:
6+
\{
7+
char _test_struct_childs0_options0_text_1\[\]="accept";
8+
char _test_struct_childs0_options1_text_2\[\]="unique0";
9+
char _test_struct_childs1_options1_text_3\[\]="unique1";
10+
char _test_struct_childs2_options1_text_4\[\]="unique2";
11+
char _test_struct_childs3_options1_text_5\[\]="unique3";
12+
struct a_typet test_struct_0=\{ .config=\{ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 \}, .initalized=0,
13+
.values=\{ 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171 \}, .childs=\{ \{ .id=12, .options=\{ \{ .text=\(char \*\)&_test_struct_childs0_options0_text_1 \},
14+
\{ .text=\(char \*\)&_test_struct_childs0_options1_text_2 \} \} \},
15+
\{ .id=13, .options=\{ \{ .text=\(char \*\)&_test_struct_childs0_options0_text_1 \},
16+
\{ .text=\(char \*\)&_test_struct_childs1_options1_text_3 \} \} \},
17+
\{ .id=14, .options=\{ \{ .text=\(char \*\)&_test_struct_childs0_options0_text_1 \},
18+
\{ .text=\(char \*\)&_test_struct_childs2_options1_text_4 \} \} \},
19+
\{ .id=15, .options=\{ \{ .text=\(char \*\)&_test_struct_childs0_options0_text_1 \},
20+
\{ .text=\(char \*\)&_test_struct_childs3_options1_text_5 \} \} \} \} \};
21+
test_struct = &test_struct_0;
22+
\}
23+
^EXIT=0$
24+
^SIGNAL=0$

0 commit comments

Comments
 (0)