llvm-dwarfdump-fuzzer.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //===-- 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. // //
  20. ///////////////////////////////////////////////////////////////////////////////
  21. using namespace llvm;
  22. using namespace object;
  23. extern "C" void LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
  24. std::unique_ptr<MemoryBuffer> Buff = MemoryBuffer::getMemBuffer(
  25. StringRef((const char *)data, size), "", false);
  26. ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
  27. ObjectFile::createObjectFile(Buff->getMemBufferRef());
  28. if (!ObjOrErr)
  29. return;
  30. ObjectFile &Obj = *ObjOrErr.get();
  31. std::unique_ptr<DIContext> DICtx(new DWARFContextInMemory(Obj));
  32. DICtx->dump(nulls(), DIDT_All);
  33. }