Files
clang-p2996/lldb/tools/lldb-fuzzer/lldb-target-fuzzer.cpp
Jonas Devlieghere 61efe14e21 [lldb] Add a fuzzer for target creation
This patch adds a generic fuzzer that interprets inputs as object files
and uses them to create a target in lldb. It is very similar to the
llvm-dwarfdump fuzzer which found a bunch of issues in libObject.

Differential revision: https://reviews.llvm.org/D122461
2022-03-25 09:34:00 -07:00

36 lines
1.0 KiB
C++

//===-- lldb-target-fuzzer.cpp - Fuzz target creation ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include <utils/TempFile.h>
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBTarget.h"
using namespace lldb;
using namespace lldb_fuzzer;
using namespace llvm;
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
SBDebugger::Initialize();
return 0;
}
extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
std::unique_ptr<TempFile> file = TempFile::Create(data, size);
if (!file)
return 1;
SBDebugger debugger = SBDebugger::Create(false);
SBTarget target = debugger.CreateTarget(file->GetPath().data());
debugger.DeleteTarget(target);
SBDebugger::Destroy(debugger);
SBModule::GarbageCollectAllocatedModules();
return 0;
}