brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 0e74d0b Raw
41 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file implements a function that runs llvm-dwarfdump11///  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"18 19using namespace llvm;20using namespace object;21 22extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {23  std::string Payload(reinterpret_cast<const char *>(data), size);24  std::unique_ptr<MemoryBuffer> Buff = MemoryBuffer::getMemBuffer(Payload);25 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;31  }32  ObjectFile &Obj = *ObjOrErr.get();33  std::unique_ptr<DIContext> DICtx = DWARFContext::create(Obj);34 35 36  DIDumpOptions opts;37  opts.DumpType = DIDT_All;38  DICtx->dump(nulls(), opts);39  return 0;40}41