| 1 | //===-- lldb-target-fuzzer.cpp - Fuzz target creation ---------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "utils/TempFile.h" |
| 10 | |
| 11 | #include "lldb/API/SBDebugger.h" |
| 12 | #include "lldb/API/SBTarget.h" |
| 13 | |
| 14 | using namespace lldb; |
| 15 | using namespace lldb_fuzzer; |
| 16 | using namespace llvm; |
| 17 | |
| 18 | extern "C"int LLVMFuzzerInitialize(int *argc, char ***argv) { |
| 19 | SBDebugger::Initialize(); |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | extern "C"int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) { |
| 24 | std::unique_ptr<TempFile> file = TempFile::Create(data, size); |
| 25 | if (!file) |
| 26 | return 1; |
| 27 | |
| 28 | SBDebugger debugger = SBDebugger::Create(source_init_files: false); |
| 29 | SBTarget target = debugger.CreateTarget(file->GetPath().data()); |
| 30 | debugger.DeleteTarget(target); |
| 31 | SBDebugger::Destroy(debugger); |
| 32 | SBModule::GarbageCollectAllocatedModules(); |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 |
