summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/llvm-dwarfdump
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/llvm-dwarfdump')
-rw-r--r--contrib/llvm/tools/llvm-dwarfdump/LLVMBuild.txt22
-rw-r--r--contrib/llvm/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt14
-rw-r--r--contrib/llvm/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp34
-rw-r--r--contrib/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp113
4 files changed, 183 insertions, 0 deletions
diff --git a/contrib/llvm/tools/llvm-dwarfdump/LLVMBuild.txt b/contrib/llvm/tools/llvm-dwarfdump/LLVMBuild.txt
new file mode 100644
index 0000000..a9dca3e
--- /dev/null
+++ b/contrib/llvm/tools/llvm-dwarfdump/LLVMBuild.txt
@@ -0,0 +1,22 @@
+;===- ./tools/llvm-dwarfdump/LLVMBuild.txt ---------------------*- Conf -*--===;
+;
+; The LLVM Compiler Infrastructure
+;
+; This file is distributed under the University of Illinois Open Source
+; License. See LICENSE.TXT for details.
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+; http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+
+[component_0]
+type = Tool
+name = llvm-dwarfdump
+parent = Tools
+required_libraries = DebugInfoDWARF Object
diff --git a/contrib/llvm/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt b/contrib/llvm/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt
new file mode 100644
index 0000000..1de35a3
--- /dev/null
+++ b/contrib/llvm/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(LLVM_LINK_COMPONENTS
+ DebugInfoDWARF
+ Object
+ Support
+ )
+
+add_llvm_executable(llvm-dwarfdump-fuzzer
+ EXCLUDE_FROM_ALL
+ llvm-dwarfdump-fuzzer.cpp
+ )
+
+target_link_libraries(llvm-dwarfdump-fuzzer
+ LLVMFuzzer
+ )
diff --git a/contrib/llvm/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp b/contrib/llvm/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp
new file mode 100644
index 0000000..af0ac36
--- /dev/null
+++ b/contrib/llvm/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp
@@ -0,0 +1,34 @@
+//===-- llvm-dwarfdump-fuzzer.cpp - Fuzz the llvm-dwarfdump 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-dwarfdump
+/// on a single input. This function is then linked into the Fuzzer library.
+///
+//===----------------------------------------------------------------------===//
+#include "llvm/DebugInfo/DIContext.h"
+#include "llvm/DebugInfo/DWARF/DWARFContext.h"
+#include "llvm/Object/ObjectFile.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+using namespace llvm;
+using namespace object;
+
+extern "C" void LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
+ std::unique_ptr<MemoryBuffer> Buff = MemoryBuffer::getMemBuffer(
+ StringRef((const char *)data, size), "", false);
+
+ ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
+ ObjectFile::createObjectFile(Buff->getMemBufferRef());
+ if (!ObjOrErr)
+ return;
+ ObjectFile &Obj = *ObjOrErr.get();
+ std::unique_ptr<DIContext> DICtx(new DWARFContextInMemory(Obj));
+ DICtx->dump(nulls(), DIDT_All);
+}
diff --git a/contrib/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/contrib/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
new file mode 100644
index 0000000..c1cb021
--- /dev/null
+++ b/contrib/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -0,0 +1,113 @@
+//===-- llvm-dwarfdump.cpp - Debug info dumping utility for llvm ----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This program is a utility that works like "dwarfdump".
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/DebugInfo/DIContext.h"
+#include "llvm/DebugInfo/DWARF/DWARFContext.h"
+#include "llvm/Object/ObjectFile.h"
+#include "llvm/Object/RelocVisitor.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/raw_ostream.h"
+#include <algorithm>
+#include <cstring>
+#include <list>
+#include <string>
+#include <system_error>
+
+using namespace llvm;
+using namespace object;
+
+static cl::list<std::string>
+InputFilenames(cl::Positional, cl::desc("<input object files>"),
+ cl::ZeroOrMore);
+
+static cl::opt<DIDumpType>
+DumpType("debug-dump", cl::init(DIDT_All),
+ cl::desc("Dump of debug sections:"),
+ cl::values(
+ clEnumValN(DIDT_All, "all", "Dump all debug sections"),
+ clEnumValN(DIDT_Abbrev, "abbrev", ".debug_abbrev"),
+ clEnumValN(DIDT_AbbrevDwo, "abbrev.dwo", ".debug_abbrev.dwo"),
+ clEnumValN(DIDT_AppleNames, "apple_names", ".apple_names"),
+ clEnumValN(DIDT_AppleTypes, "apple_types", ".apple_types"),
+ clEnumValN(DIDT_AppleNamespaces, "apple_namespaces", ".apple_namespaces"),
+ clEnumValN(DIDT_AppleObjC, "apple_objc", ".apple_objc"),
+ clEnumValN(DIDT_Aranges, "aranges", ".debug_aranges"),
+ clEnumValN(DIDT_Info, "info", ".debug_info"),
+ clEnumValN(DIDT_InfoDwo, "info.dwo", ".debug_info.dwo"),
+ clEnumValN(DIDT_Types, "types", ".debug_types"),
+ clEnumValN(DIDT_TypesDwo, "types.dwo", ".debug_types.dwo"),
+ clEnumValN(DIDT_Line, "line", ".debug_line"),
+ clEnumValN(DIDT_LineDwo, "line.dwo", ".debug_line.dwo"),
+ clEnumValN(DIDT_Loc, "loc", ".debug_loc"),
+ clEnumValN(DIDT_LocDwo, "loc.dwo", ".debug_loc.dwo"),
+ clEnumValN(DIDT_Frames, "frames", ".debug_frame"),
+ clEnumValN(DIDT_Ranges, "ranges", ".debug_ranges"),
+ clEnumValN(DIDT_Pubnames, "pubnames", ".debug_pubnames"),
+ clEnumValN(DIDT_Pubtypes, "pubtypes", ".debug_pubtypes"),
+ clEnumValN(DIDT_GnuPubnames, "gnu_pubnames", ".debug_gnu_pubnames"),
+ clEnumValN(DIDT_GnuPubtypes, "gnu_pubtypes", ".debug_gnu_pubtypes"),
+ clEnumValN(DIDT_Str, "str", ".debug_str"),
+ clEnumValN(DIDT_StrDwo, "str.dwo", ".debug_str.dwo"),
+ clEnumValN(DIDT_StrOffsetsDwo, "str_offsets.dwo", ".debug_str_offsets.dwo"),
+ clEnumValEnd));
+
+static void DumpInput(StringRef Filename) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> BuffOrErr =
+ MemoryBuffer::getFileOrSTDIN(Filename);
+
+ if (std::error_code EC = BuffOrErr.getError()) {
+ errs() << Filename << ": " << EC.message() << "\n";
+ return;
+ }
+ std::unique_ptr<MemoryBuffer> Buff = std::move(BuffOrErr.get());
+
+ ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
+ ObjectFile::createObjectFile(Buff->getMemBufferRef());
+ if (std::error_code EC = ObjOrErr.getError()) {
+ errs() << Filename << ": " << EC.message() << '\n';
+ return;
+ }
+ ObjectFile &Obj = *ObjOrErr.get();
+
+ std::unique_ptr<DIContext> DICtx(new DWARFContextInMemory(Obj));
+
+ outs() << Filename
+ << ":\tfile format " << Obj.getFileFormatName() << "\n\n";
+ // Dump the complete DWARF structure.
+ DICtx->dump(outs(), DumpType);
+}
+
+int main(int argc, char **argv) {
+ // Print a stack trace if we signal out.
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+
+ cl::ParseCommandLineOptions(argc, argv, "llvm dwarf dumper\n");
+
+ // Defaults to a.out if no filenames specified.
+ if (InputFilenames.size() == 0)
+ InputFilenames.push_back("a.out");
+
+ std::for_each(InputFilenames.begin(), InputFilenames.end(), DumpInput);
+
+ return 0;
+}
OpenPOWER on IntegriCloud