mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 08:43:03 +00:00
doc: more about sanitizers
* README-hacking.md: here.
This commit is contained in:
@@ -464,38 +464,55 @@ Use the `javaexec.sh` script. For instance to run the parser of test case
|
|||||||
|
|
||||||
## Using Sanitizers
|
## Using Sanitizers
|
||||||
Address sanitizer (ASAN) and undefined-behavior sanitizer (UBSAN) are very
|
Address sanitizer (ASAN) and undefined-behavior sanitizer (UBSAN) are very
|
||||||
useful. Here's one way to set ASAN up with GCC 10 on Mac Ports
|
useful. Here's one way to set them up with GCC 10 on Mac Ports
|
||||||
|
|
||||||
1. Configure with
|
1. Configure with
|
||||||
|
```
|
||||||
$ ./configure -C --enable-gcc-warnings \
|
$ ./configure -C --enable-gcc-warnings \
|
||||||
CPPFLAGS='-isystem /opt/local/include' \
|
CPPFLAGS='-isystem /opt/local/include' \
|
||||||
CC='gcc-mp-10 -fsanitize=address' \
|
CC='gcc-mp-10 -fsanitize=address -fsanitize=undefined' \
|
||||||
CFLAGS='-ggdb' \
|
CFLAGS='-ggdb' \
|
||||||
CXX='g++-mp-10.0 -fsanitize=address' \
|
CXX='g++-mp-10.0 -fsanitize=address -fsanitize=undefined' \
|
||||||
CXXFLAGS='-ggdb' \
|
CXXFLAGS='-ggdb' \
|
||||||
LDFLAGS='-L/opt/local/lib'
|
LDFLAGS='-L/opt/local/lib'
|
||||||
|
```
|
||||||
|
|
||||||
2. Compile
|
2. Compile
|
||||||
|
|
||||||
3. Generate debug symbols:
|
3. Generate debug symbols:
|
||||||
|
|
||||||
$ dsymutil src/bison
|
```
|
||||||
|
$ dsymutil src/bison
|
||||||
|
```
|
||||||
|
|
||||||
4. Run the tests with leak detection enabled
|
4. Run the tests with leak detection enabled
|
||||||
(`ASAN_OPTIONS=detect_leaks=1`). E.g. for counterexamples:
|
(`ASAN_OPTIONS=detect_leaks=1`). E.g. for counterexamples:
|
||||||
|
```
|
||||||
$ make check-local TESTSUITEFLAGS='-j5 -k cex' ASAN_OPTIONS=detect_leaks=1
|
$ make check-local TESTSUITEFLAGS='-j5 -k cex' ASAN_OPTIONS=detect_leaks=1
|
||||||
|
```
|
||||||
|
|
||||||
5. You might need a suppression file. See
|
5. You might need a suppression file. See
|
||||||
https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer#suppressions.
|
https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer#suppressions.
|
||||||
With G++ on a Mac, you might need a suppression file (say
|
With G++ on a Mac, you might need a suppression file (say `leak.supp`)
|
||||||
leak.suppression) that contains:
|
that contains:
|
||||||
|
|
||||||
|
```
|
||||||
leak:std::clog
|
leak:std::clog
|
||||||
|
```
|
||||||
|
|
||||||
and pass the additional flags
|
and pass the additional flags
|
||||||
`LSAN_OPTIONS=suppressions=$PWD/leak.suppressions,print_suppressions=0`
|
`LSAN_OPTIONS=suppressions=$PWD/leak.supp,print_suppressions=0`
|
||||||
|
|
||||||
|
6. To run the debugger, you might want something like this:
|
||||||
|
```
|
||||||
|
$ YYDEBUG=1 \
|
||||||
|
UBSAN_OPTIONS=print_stacktrace=1 \
|
||||||
|
LSAN_OPTIONS=suppressions=$PWD/leak.supp,print_suppressions=0 \
|
||||||
|
ASAN_OPTIONS=detect_leaks=1 \
|
||||||
|
lldb -- ./_build/tests/testsuite.dir/712/glr-regr2a ./_build/tests/testsuite.dir/712/input1.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
In lldb to set a break on ubsan, try `rbreak ^__ubsan_handle_`.
|
||||||
|
|
||||||
## make maintainer-check-valgrind
|
## make maintainer-check-valgrind
|
||||||
This target uses valgrind both to check bison, and the generated parsers.
|
This target uses valgrind both to check bison, and the generated parsers.
|
||||||
|
|||||||
Reference in New Issue
Block a user