1 //===- tools/dsymutil/DebugMap.cpp - Generic debug map representation -----===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/Support/DataTypes.h"
13 #include "llvm/Support/Format.h"
14 #include "llvm/Support/raw_ostream.h"
19 using namespace llvm::object;
21 DebugMapObject::DebugMapObject(StringRef ObjectFilename)
22 : Filename(ObjectFilename) {}
24 bool DebugMapObject::addSymbol(StringRef Name, uint64_t ObjectAddress,
25 uint64_t LinkedAddress) {
26 auto InsertResult = Symbols.insert(std::make_pair(Name,
27 SymbolMapping{ObjectAddress,
29 return InsertResult.second;
32 void DebugMapObject::print(raw_ostream& OS) const {
33 OS << getObjectFilename() << ":\n";
34 // Sort the symbols in alphabetical order, like llvm-nm (and to get
35 // deterministic output for testing).
36 typedef StringMapEntry<SymbolMapping> MapEntryTy;
37 std::vector<const MapEntryTy *> Entries;
38 Entries.reserve(Symbols.getNumItems());
39 for (auto SymIt = Symbols.begin(), End = Symbols.end(); SymIt != End; ++SymIt)
40 Entries.push_back(&*SymIt);
41 std::sort(Entries.begin(), Entries.end(),
42 [] (const MapEntryTy *LHS, const MapEntryTy *RHS) {
43 return LHS->getKey() < RHS->getKey();
45 for (const auto *Entry: Entries) {
46 const auto &Sym = Entry->getValue();
47 OS << format("\t%016" PRIx64 " => %016" PRIx64 "\t%s\n",
48 Sym.ObjectAddress, Sym.BinaryAddress, Entry->getKeyData());
54 void DebugMapObject::dump() const {
59 DebugMapObject& DebugMap::addDebugMapObject(StringRef ObjectFilePath) {
60 Objects.emplace_back(new DebugMapObject(ObjectFilePath));
61 return *Objects.back();
64 const DebugMapObject::SymbolMapping *
65 DebugMapObject::lookupSymbol(StringRef SymbolName) const {
66 StringMap<SymbolMapping>::const_iterator Sym = Symbols.find(SymbolName);
67 if (Sym == Symbols.end())
69 return &Sym->getValue();
72 void DebugMap::print(raw_ostream& OS) const {
73 OS << "DEBUG MAP: object addr => executable addr\tsymbol name\n";
74 for (const auto &Obj: objects())
76 OS << "END DEBUG MAP\n";
80 void DebugMap::dump() const {