From 43d7320e7111784c613634e73f50c631a1b0b303 Mon Sep 17 00:00:00 2001 From: Chelsea Cassanova Date: Fri, 26 Aug 2022 18:27:35 -0500 Subject: [PATCH] [lldb][docs] Add documentation for LLDB fuzzers This commit adds a new page to the LLDB HTML documentation for the LLDB fuzzers. The page primarily explains what the fuzzers are as well as how to build them, run them and investigate and reproduce bugs. Differential revision: https://reviews.llvm.org/D132148 --- lldb/docs/index.rst | 1 + lldb/docs/resources/fuzzing.rst | 68 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 lldb/docs/resources/fuzzing.rst diff --git a/lldb/docs/index.rst b/lldb/docs/index.rst index d1fa627..0d87318 100644 --- a/lldb/docs/index.rst +++ b/lldb/docs/index.rst @@ -150,6 +150,7 @@ interesting areas to contribute to lldb. resources/contributing resources/build resources/test + resources/fuzzing resources/bots resources/caveats diff --git a/lldb/docs/resources/fuzzing.rst b/lldb/docs/resources/fuzzing.rst new file mode 100644 index 0000000..7c106f4 --- /dev/null +++ b/lldb/docs/resources/fuzzing.rst @@ -0,0 +1,68 @@ +Fuzzing LLDB +============ + +Overview +-------- + +LLDB has fuzzers that provide automated `fuzz testing `_ for different components of LLDB. The fuzzers are built with `libFuzzer `_ . Currently, there are fuzzers for target creation, LLDB's command interpreter and LLDB's expression evaluator. + +Building the fuzzers +-------------------- + +Building the LLDB fuzzers requires a build configuration that has the address sanitizer and sanitizer coverage enabled. In addition to your regular CMake arguments, you will need these argumets to build the fuzzers: + +:: + -DLLVM_USE_SANITIZER='Address' \ + -DLLVM_USE_SANITIZE_COVERAGE=On \ + -DCLANG_ENABLE_PROTO_FUZZER=ON + +More information on libFuzzer's sanitizer coverage is available here: ``_ + +If you want to debug LLDB itself when you find a bug using the fuzzers, use the CMake option ``-DCMAKE_BUILD_TYPE='RelWithDebInfo'`` + +To build a fuzzer, run the desired ninja command for the fuzzer(s) you want to build: + +:: + $ ninja lldb-target-fuzzer + $ ninja lldb-commandinterpreter-fuzzer + $ ninja lldb-expression-fuzzer + +Once built, the binaries for the fuzzers will exist in the ``bin`` directory of your build folder. + +Continuous integration +---------------------- + +Currently, there are plans to integrate the LLDB fuzzers into the `OSS Fuzz `_ project for continuous integration. + +Running the fuzzers +------------------- + +If you want to run the fuzzers locally, you can run the binaries that were generated with ninja from the build directory: + +:: + $ ./bin/lldb-target-fuzzer + $ ./bin/lldb-commandinterpreter-fuzzer + $ ./bin/lldb-expression-fuzzer + +This will run the fuzzer binaries directly, and you can use the `libFuzzer options `_ to customize how the fuzzers are run. + +Another way to run the fuzzers is to use a ninja target that will both build the fuzzers and then run them immediately after. These custom targets run each fuzzer with command-line arguments that provide better fuzzing for the components being tested. Running the fuzzers this way will also create directories that will store any inputs that caused LLDB to crash, timeout or run out of memory. The directories are created for each fuzzer. + +To run the custom ninja targets, run the command for your desired fuzzer: + +:: + $ ninja fuzz-lldb-target + $ ninja fuzz-lldb-commandinterpreter + $ ninja fuzz-lldb-expression + +Investigating and reproducing bugs +---------------------------------- + +When the fuzzers find an input that causes LLDB to crash, timeout or run out of memory, the input is saved to a file in the build directory. When running the fuzzer binaries directly this input is stored in a file named ``-``. + +When running the fuzzers using the custom ninja targets shown above, the inputs will be stored in ``fuzzer-artifacts/-artifacts``, which is created in your build directory. The input files will have the name ``--``. + +If you want to reproduce the issue found by a fuzzer once you have gotten the input, you can pass the individual input to the fuzzer binary as a command-line argument: + +:: + $ ./ -- 2.7.4