blob: 4af8efb03afe14b924d9346d4ff19288af7abd7b [file] [log] [blame]
Frederic Riss231f7142014-12-12 17:31:24 +00001//===- 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 Rissd3455182015-01-28 18:27:01 +000010
11#include "BinaryHolder.h"
12#include "DebugMap.h"
Frederic Riss231f7142014-12-12 17:31:24 +000013#include "dsymutil.h"
Frederic Rissd3455182015-01-28 18:27:01 +000014#include "llvm/DebugInfo/DWARFContext.h"
15#include "llvm/DebugInfo/DWARFDebugInfoEntry.h"
16#include <string>
Frederic Riss231f7142014-12-12 17:31:24 +000017
18namespace llvm {
19namespace dsymutil {
20
Frederic Rissd3455182015-01-28 18:27:01 +000021namespace {
22
23/// \brief The core of the Dwarf linking logic.
24class DwarfLinker {
25public:
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
32private:
33 std::string OutputFilename;
34 bool Verbose;
35 BinaryHolder BinHolder;
36};
37
38bool 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 Riss231f7142014-12-12 17:31:24 +000065 return true;
66}
67}
Frederic Rissd3455182015-01-28 18:27:01 +000068
69bool linkDwarf(StringRef OutputFilename, const DebugMap &DM, bool Verbose) {
70 DwarfLinker Linker(OutputFilename, Verbose);
71 return Linker.link(DM);
72}
73}
Frederic Riss231f7142014-12-12 17:31:24 +000074}