summaryrefslogtreecommitdiffstats
path: root/llvm/tools/dsymutil/DebugMap.cpp
diff options
context:
space:
mode:
authorFrederic Riss <friss@apple.com>2014-12-12 17:31:24 +0000
committerFrederic Riss <friss@apple.com>2014-12-12 17:31:24 +0000
commit231f714e5441f73394f5c0421bb3f0f83ffd7ad2 (patch)
treee788406b68fac3f9def8c6b0aef8d215c196fa4e /llvm/tools/dsymutil/DebugMap.cpp
parent1f7402a14ef90c5dad38483fad33a13fa2218937 (diff)
downloadbcm5719-llvm-231f714e5441f73394f5c0421bb3f0f83ffd7ad2.tar.gz
bcm5719-llvm-231f714e5441f73394f5c0421bb3f0f83ffd7ad2.zip
Initial dsymutil tool commit.
The goal of this tool is to replicate Darwin's dsymutil functionality based on LLVM. dsymutil is a DWARF linker. Darwin's linker (ld64) does not link the debug information, it leaves it in the object files in relocatable form, but embbeds a `debug map` into the executable that describes where to find the debug information and how to relocate it. When releasing/archiving a binary, dsymutil is called to link all the DWARF information into a `dsym bundle` that can distributed/stored along with the binary. With this commit, the LLVM based dsymutil is just able to parse the STABS debug maps embedded by ld64 in linked binaries (and not all of them, for example archives aren't supported yet). Note that the tool directory is called dsymutil, but the executable is currently called llvm-dsymutil. This discrepancy will disappear once the tool will be feature complete. At this point the executable will be renamed to dsymutil, but until then you do not want it to override the system one. Differential Revision: http://reviews.llvm.org/D6242 llvm-svn: 224134
Diffstat (limited to 'llvm/tools/dsymutil/DebugMap.cpp')
-rw-r--r--llvm/tools/dsymutil/DebugMap.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/llvm/tools/dsymutil/DebugMap.cpp b/llvm/tools/dsymutil/DebugMap.cpp
new file mode 100644
index 00000000000..c8375171ee2
--- /dev/null
+++ b/llvm/tools/dsymutil/DebugMap.cpp
@@ -0,0 +1,81 @@
+//===- tools/dsymutil/DebugMap.cpp - Generic debug map representation -----===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "DebugMap.h"
+
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
+#include <algorithm>
+
+namespace llvm {
+namespace dsymutil {
+
+using namespace llvm::object;
+
+DebugMapObject::DebugMapObject(StringRef ObjectFilename)
+ : Filename(ObjectFilename) {}
+
+bool DebugMapObject::addSymbol(StringRef Name, uint64_t ObjectAddress,
+ uint64_t LinkedAddress) {
+ auto InsertResult = Symbols.insert(
+ std::make_pair(Name, SymbolMapping(ObjectAddress, LinkedAddress)));
+ return InsertResult.second;
+}
+
+void DebugMapObject::print(raw_ostream &OS) const {
+ OS << getObjectFilename() << ":\n";
+ // Sort the symbols in alphabetical order, like llvm-nm (and to get
+ // deterministic output for testing).
+ typedef std::pair<StringRef, SymbolMapping> Entry;
+ std::vector<Entry> Entries;
+ Entries.reserve(Symbols.getNumItems());
+ for (const auto &Sym : make_range(Symbols.begin(), Symbols.end()))
+ Entries.push_back(std::make_pair(Sym.getKey(), Sym.getValue()));
+ std::sort(
+ Entries.begin(), Entries.end(),
+ [](const Entry &LHS, const Entry &RHS) { return LHS.first < RHS.first; });
+ for (const auto &Sym : Entries) {
+ OS << format("\t%016" PRIx64 " => %016" PRIx64 "\t%s\n",
+ Sym.second.ObjectAddress, Sym.second.BinaryAddress,
+ Sym.first.data());
+ }
+ OS << '\n';
+}
+
+#ifndef NDEBUG
+void DebugMapObject::dump() const { print(errs()); }
+#endif
+
+DebugMapObject &DebugMap::addDebugMapObject(StringRef ObjectFilePath) {
+ Objects.emplace_back(new DebugMapObject(ObjectFilePath));
+ return *Objects.back();
+}
+
+const DebugMapObject::SymbolMapping *
+DebugMapObject::lookupSymbol(StringRef SymbolName) const {
+ StringMap<SymbolMapping>::const_iterator Sym = Symbols.find(SymbolName);
+ if (Sym == Symbols.end())
+ return nullptr;
+ return &Sym->getValue();
+}
+
+void DebugMap::print(raw_ostream &OS) const {
+ OS << "DEBUG MAP: object addr => executable addr\tsymbol name\n";
+ for (const auto &Obj : objects())
+ Obj->print(OS);
+ OS << "END DEBUG MAP\n";
+}
+
+#ifndef NDEBUG
+void DebugMap::dump() const { print(errs()); }
+#endif
+}
+}
OpenPOWER on IntegriCloud