blob: 53c74df40280f4b96c6464229e865b936d264124 [file] [log] [blame]
Alexey Samsonovd804a1e2015-05-28 18:35:18 +00001//===-- llvm-dwarfdump-fuzzer.cpp - Fuzz the llvm-dwarfdump tool ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief This file implements a function that runs llvm-dwarfdump
12/// on a single input. This function is then linked into the Fuzzer library.
13///
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"
19
20using namespace llvm;
21using namespace object;
22
Kostya Serebryanydd4c61f2017-08-29 01:14:05 +000023extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
Alexey Samsonovd804a1e2015-05-28 18:35:18 +000024 std::unique_ptr<MemoryBuffer> Buff = MemoryBuffer::getMemBuffer(
25 StringRef((const char *)data, size), "", false);
26
David Majnemer2da76642016-05-31 01:24:33 +000027 Expected<std::unique_ptr<ObjectFile>> ObjOrErr =
Alexey Samsonovd804a1e2015-05-28 18:35:18 +000028 ObjectFile::createObjectFile(Buff->getMemBufferRef());
David Majnemer2da76642016-05-31 01:24:33 +000029 if (auto E = ObjOrErr.takeError()) {
30 consumeError(std::move(E));
Kostya Serebryanydd4c61f2017-08-29 01:14:05 +000031 return 0;
David Majnemer2da76642016-05-31 01:24:33 +000032 }
Alexey Samsonovd804a1e2015-05-28 18:35:18 +000033 ObjectFile &Obj = *ObjOrErr.get();
Rafael Espindola3ee9e112017-07-19 23:34:59 +000034 std::unique_ptr<DIContext> DICtx = DWARFContext::create(Obj);
George Karpenkov0ac90d32017-08-23 00:40:58 +000035
36
37 DIDumpOptions opts;
38 opts.DumpType = DIDT_All;
39 DICtx->dump(nulls(), opts);
Kostya Serebryanydd4c61f2017-08-29 01:14:05 +000040 return 0;
Alexey Samsonovd804a1e2015-05-28 18:35:18 +000041}