summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-pdbutil/fuzzer/llvm-pdbutil-fuzzer.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-06-09 20:46:17 +0000
committerZachary Turner <zturner@google.com>2017-06-09 20:46:17 +0000
commitbd336e44d8ab60e0c1d7ef7703ba0ff5c51e43b5 (patch)
treef5e0c55de301a14315293533cd49afb31999d838 /llvm/tools/llvm-pdbutil/fuzzer/llvm-pdbutil-fuzzer.cpp
parente22b6969363d78bb2fb2d3c0778c2dbbcfaabcde (diff)
downloadbcm5719-llvm-bd336e44d8ab60e0c1d7ef7703ba0ff5c51e43b5.tar.gz
bcm5719-llvm-bd336e44d8ab60e0c1d7ef7703ba0ff5c51e43b5.zip
Rename llvm-pdbdump -> llvm-pdbutil.
This is to reflect the evolving nature of the tool as being useful for more than just dumping PDBs, as it can do many other things. Differential Revision: https://reviews.llvm.org/D34062 llvm-svn: 305106
Diffstat (limited to 'llvm/tools/llvm-pdbutil/fuzzer/llvm-pdbutil-fuzzer.cpp')
-rw-r--r--llvm/tools/llvm-pdbutil/fuzzer/llvm-pdbutil-fuzzer.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/llvm/tools/llvm-pdbutil/fuzzer/llvm-pdbutil-fuzzer.cpp b/llvm/tools/llvm-pdbutil/fuzzer/llvm-pdbutil-fuzzer.cpp
new file mode 100644
index 00000000000..4edb53e261f
--- /dev/null
+++ b/llvm/tools/llvm-pdbutil/fuzzer/llvm-pdbutil-fuzzer.cpp
@@ -0,0 +1,105 @@
+//===-- llvm-pdbutil-fuzzer.cpp - Fuzz the llvm-pdbutil tool --------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file implements a function that runs llvm-pdbutil
+/// on a single input. This function is then linked into the Fuzzer library.
+///
+//===----------------------------------------------------------------------===//
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/DebugInfo/CodeView/BinaryByteStream.h"
+#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
+#include "llvm/DebugInfo/CodeView/TypeDumper.h"
+#include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
+#include "llvm/DebugInfo/PDB/Raw/IPDBStreamData.h"
+#include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"
+#include "llvm/DebugInfo/PDB/Raw/ModuleDebugStream.h"
+#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
+#include "llvm/DebugInfo/PDB/Raw/RawSession.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/ScopedPrinter.h"
+
+using namespace llvm;
+
+namespace {
+// We need a class which behaves like an immutable BinaryByteStream, but whose
+// data
+// is backed by an llvm::MemoryBuffer. It also needs to own the underlying
+// MemoryBuffer, so this simple adapter is a good way to achieve that.
+class InputByteStream : public codeview::BinaryByteStream<false> {
+public:
+ explicit InputByteStream(std::unique_ptr<MemoryBuffer> Buffer)
+ : BinaryByteStream(ArrayRef<uint8_t>(Buffer->getBuffer().bytes_begin(),
+ Buffer->getBuffer().bytes_end())),
+ MemBuffer(std::move(Buffer)) {}
+
+ std::unique_ptr<MemoryBuffer> MemBuffer;
+};
+}
+
+extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
+ std::unique_ptr<MemoryBuffer> Buff = MemoryBuffer::getMemBuffer(
+ StringRef((const char *)data, size), "", false);
+
+ ScopedPrinter P(nulls());
+ codeview::CVTypeDumper TD(&P, false);
+
+ auto InputStream = llvm::make_unique<InputByteStream>(std::move(Buff));
+ std::unique_ptr<pdb::PDBFile> File(new pdb::PDBFile(std::move(InputStream)));
+ if (auto E = File->parseFileHeaders()) {
+ consumeError(std::move(E));
+ return 0;
+ }
+ if (auto E = File->parseStreamData()) {
+ consumeError(std::move(E));
+ return 0;
+ }
+
+ auto DbiS = File->getPDBDbiStream();
+ if (auto E = DbiS.takeError()) {
+ consumeError(std::move(E));
+ return 0;
+ }
+ auto TpiS = File->getPDBTpiStream();
+ if (auto E = TpiS.takeError()) {
+ consumeError(std::move(E));
+ return 0;
+ }
+ auto IpiS = File->getPDBIpiStream();
+ if (auto E = IpiS.takeError()) {
+ consumeError(std::move(E));
+ return 0;
+ }
+ auto InfoS = File->getPDBInfoStream();
+ if (auto E = InfoS.takeError()) {
+ consumeError(std::move(E));
+ return 0;
+ }
+ pdb::DbiStream &DS = DbiS.get();
+
+ for (auto &Modi : DS.modules()) {
+ auto ModStreamData = pdb::MappedBlockStream::createIndexedStream(
+ Modi.Info.getModuleStreamIndex(), *File, File->getAllocator());
+ if (!ModStreamData) {
+ consumeError(ModStreamData.takeError());
+ return 0;
+ }
+ pdb::ModuleDebugStreamRef ModS(Modi.Info, std::move(*ModStreamData));
+ if (auto E = ModS.reload()) {
+ consumeError(std::move(E));
+ return 0;
+ }
+ codeview::CVSymbolDumper SD(P, TD, nullptr, false);
+ bool HadError = false;
+ for (auto &S : ModS.symbols(&HadError)) {
+ SD.dump(S);
+ }
+ }
+ return 0;
+}
OpenPOWER on IntegriCloud