[lib/ObjectYAML] - Change interface to return `bool` instead of `int`. NFCI
[llvm-complete.git] / tools / llvm-dwarfdump / fuzzer / llvm-dwarfdump-fuzzer.cpp
blob1d74856c0fb8a619d3b51204432bc7a833ee928a
1 //===-- llvm-dwarfdump-fuzzer.cpp - Fuzz the llvm-dwarfdump tool ----------===//
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 /// \file
10 /// This file implements a function that runs llvm-dwarfdump
11 /// on a single input. This function is then linked into the Fuzzer library.
12 ///
13 //===----------------------------------------------------------------------===//
14 #include "llvm/DebugInfo/DIContext.h"
15 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
16 #include "llvm/Object/ObjectFile.h"
17 #include "llvm/Support/MemoryBuffer.h"
19 using namespace llvm;
20 using namespace object;
22 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
23 std::unique_ptr<MemoryBuffer> Buff = MemoryBuffer::getMemBuffer(
24 StringRef((const char *)data, size), "", false);
26 Expected<std::unique_ptr<ObjectFile>> ObjOrErr =
27 ObjectFile::createObjectFile(Buff->getMemBufferRef());
28 if (auto E = ObjOrErr.takeError()) {
29 consumeError(std::move(E));
30 return 0;
32 ObjectFile &Obj = *ObjOrErr.get();
33 std::unique_ptr<DIContext> DICtx = DWARFContext::create(Obj);
36 DIDumpOptions opts;
37 opts.DumpType = DIDT_All;
38 DICtx->dump(nulls(), opts);
39 return 0;