Frederic Riss | 231f714 | 2014-12-12 17:31:24 +0000 | [diff] [blame] | 1 | //===- tools/dsymutil/DwarfLinker.cpp - Dwarf debug info linker -----------===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | #include "DebugMap.h" |
Frederic Riss | d345518 | 2015-01-28 18:27:01 +0000 | [diff] [blame^] | 10 | |
| 11 | #include "BinaryHolder.h" |
| 12 | #include "DebugMap.h" |
Frederic Riss | 231f714 | 2014-12-12 17:31:24 +0000 | [diff] [blame] | 13 | #include "dsymutil.h" |
Frederic Riss | d345518 | 2015-01-28 18:27:01 +0000 | [diff] [blame^] | 14 | #include "llvm/DebugInfo/DWARFContext.h" |
| 15 | #include "llvm/DebugInfo/DWARFDebugInfoEntry.h" |
| 16 | #include <string> |
Frederic Riss | 231f714 | 2014-12-12 17:31:24 +0000 | [diff] [blame] | 17 | |
| 18 | namespace llvm { |
| 19 | namespace dsymutil { |
| 20 | |
Frederic Riss | d345518 | 2015-01-28 18:27:01 +0000 | [diff] [blame^] | 21 | namespace { |
| 22 | |
| 23 | /// \brief The core of the Dwarf linking logic. |
| 24 | class DwarfLinker { |
| 25 | public: |
| 26 | DwarfLinker(StringRef OutputFilename, bool Verbose) |
| 27 | : OutputFilename(OutputFilename), Verbose(Verbose), BinHolder(Verbose) {} |
| 28 | |
| 29 | /// \brief Link the contents of the DebugMap. |
| 30 | bool link(const DebugMap &); |
| 31 | |
| 32 | private: |
| 33 | std::string OutputFilename; |
| 34 | bool Verbose; |
| 35 | BinaryHolder BinHolder; |
| 36 | }; |
| 37 | |
| 38 | bool DwarfLinker::link(const DebugMap &Map) { |
| 39 | |
| 40 | if (Map.begin() == Map.end()) { |
| 41 | errs() << "Empty debug map.\n"; |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | for (const auto &Obj : Map.objects()) { |
| 46 | if (Verbose) |
| 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"; |
| 51 | continue; |
| 52 | } |
| 53 | |
| 54 | DWARFContextInMemory DwarfContext(*ErrOrObj); |
| 55 | |
| 56 | for (const auto &CU : DwarfContext.compile_units()) { |
| 57 | auto *CUDie = CU->getCompileUnitDIE(false); |
| 58 | if (Verbose) { |
| 59 | outs() << "Input compilation unit:"; |
| 60 | CUDie->dump(outs(), CU.get(), 0); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
Frederic Riss | 231f714 | 2014-12-12 17:31:24 +0000 | [diff] [blame] | 65 | return true; |
| 66 | } |
| 67 | } |
Frederic Riss | d345518 | 2015-01-28 18:27:01 +0000 | [diff] [blame^] | 68 | |
| 69 | bool linkDwarf(StringRef OutputFilename, const DebugMap &DM, bool Verbose) { |
| 70 | DwarfLinker Linker(OutputFilename, Verbose); |
| 71 | return Linker.link(DM); |
| 72 | } |
| 73 | } |
Frederic Riss | 231f714 | 2014-12-12 17:31:24 +0000 | [diff] [blame] | 74 | } |