1 //===- tools/dsymutil/DwarfLinker.cpp - Dwarf debug info linker -----------===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "BinaryHolder.h"
14 #include "llvm/DebugInfo/DWARFContext.h"
15 #include "llvm/DebugInfo/DWARFDebugInfoEntry.h"
23 /// \brief The core of the Dwarf linking logic.
26 DwarfLinker(StringRef OutputFilename, bool Verbose)
27 : OutputFilename(OutputFilename), Verbose(Verbose), BinHolder(Verbose) {}
29 /// \brief Link the contents of the DebugMap.
30 bool link(const DebugMap &);
33 std::string OutputFilename;
35 BinaryHolder BinHolder;
38 bool DwarfLinker::link(const DebugMap &Map) {
40 if (Map.begin() == Map.end()) {
41 errs() << "Empty debug map.\n";
45 for (const auto &Obj : Map.objects()) {
47 outs() << "DEBUG MAP OBJECT: " << Obj->getObjectFilename() << "\n";
48 auto ErrOrObj = BinHolder.GetObjectFile(Obj->getObjectFilename());
49 if (std::error_code EC = ErrOrObj.getError()) {
50 errs() << Obj->getObjectFilename() << ": " << EC.message() << "\n";
54 DWARFContextInMemory DwarfContext(*ErrOrObj);
56 for (const auto &CU : DwarfContext.compile_units()) {
57 auto *CUDie = CU->getCompileUnitDIE(false);
59 outs() << "Input compilation unit:";
60 CUDie->dump(outs(), CU.get(), 0);
69 bool linkDwarf(StringRef OutputFilename, const DebugMap &DM, bool Verbose) {
70 DwarfLinker Linker(OutputFilename, Verbose);
71 return Linker.link(DM);