1 //===-- llvm-dwarfdump-fuzzer.cpp - Fuzz the llvm-dwarfdump tool ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This file implements a function that runs llvm-dwarfdump
12 /// on a single input. This function is then linked into the Fuzzer library.
14 //===----------------------------------------------------------------------===//
15 #include "llvm/DebugInfo/DIContext.h"
16 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
17 #include "llvm/Object/ObjectFile.h"
18 #include "llvm/Support/MemoryBuffer.h"
21 using namespace object
;
23 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data
, size_t size
) {
24 std::unique_ptr
<MemoryBuffer
> Buff
= MemoryBuffer::getMemBuffer(
25 StringRef((const char *)data
, size
), "", false);
27 Expected
<std::unique_ptr
<ObjectFile
>> ObjOrErr
=
28 ObjectFile::createObjectFile(Buff
->getMemBufferRef());
29 if (auto E
= ObjOrErr
.takeError()) {
30 consumeError(std::move(E
));
33 ObjectFile
&Obj
= *ObjOrErr
.get();
34 std::unique_ptr
<DIContext
> DICtx
= DWARFContext::create(Obj
);
38 opts
.DumpType
= DIDT_All
;
39 DICtx
->dump(nulls(), opts
);