--- /dev/null
+RUN: llvm-dsymutil -v -oso-prepend-path=%p %p/Inputs/basic.macho.x86_64 | FileCheck %s
+RUN: llvm-dsymutil -v -oso-prepend-path=%p %p/Inputs/basic-lto.macho.x86_64 | FileCheck %s --check-prefix=CHECK-LTO
+RUN: llvm-dsymutil -v -oso-prepend-path=%p %p/Inputs/basic-archive.macho.x86_64 | FileCheck %s --check-prefix=CHECK-ARCHIVE
+
+This test check the basic Dwarf linking process through the debug dumps.
+
+CHECK: DEBUG MAP OBJECT: {{.*}}basic1.macho.x86_64.o
+CHECK: Input compilation unit:
+CHECK-NEXT: TAG_compile_unit
+CHECK-NOT: TAG
+CHECK: AT_name {{.*}}basic1.c
+CHECK: DEBUG MAP OBJECT: {{.*}}basic2.macho.x86_64.o
+CHECK: Input compilation unit:
+CHECK-NEXT: TAG_compile_unit
+CHECK-NOT: TAG
+CHECK: AT_name {{.*}}basic2.c
+CHECK: DEBUG MAP OBJECT: {{.*}}basic3.macho.x86_64.o
+CHECK: Input compilation unit:
+CHECK-NEXT: TAG_compile_unit
+CHECK-NOT: TAG
+CHECK: AT_name {{.*}}basic3.c
+
+
+CHECK-LTO: DEBUG MAP OBJECT: {{.*}}basic-lto.macho.x86_64.o
+CHECK-LTO: Input compilation unit:
+CHECK-LTO-NEXT: TAG_compile_unit
+CHECK-LTO-NOT: TAG
+CHECK-LTO: AT_name {{.*}}basic1.c
+CHECK-LTO: Input compilation unit:
+CHECK-LTO-NEXT: TAG_compile_unit
+CHECK-LTO-NOT: TAG
+CHECK-LTO: AT_name {{.*}}basic2.c
+CHECK-LTO: Input compilation unit:
+CHECK-LTO-NEXT: TAG_compile_unit
+CHECK-LTO-NOT: TAG
+CHECK-LTO: AT_name {{.*}}basic3.c
+
+
+CHECK-ARCHIVE: DEBUG MAP OBJECT: {{.*}}basic1.macho.x86_64.o
+CHECK-ARCHIVE: Input compilation unit:
+CHECK-ARCHIVE-NEXT: TAG_compile_unit
+CHECK-ARCHIVE-NOT: TAG
+CHECK-ARCHIVE: AT_name {{.*}}basic1.c
+CHECK-ARCHIVE: DEBUG MAP OBJECT: {{.*}}libbasic.a(basic2.macho.x86_64.o)
+CHECK-ARCHIVE: Input compilation unit:
+CHECK-ARCHIVE-NEXT: TAG_compile_unit
+CHECK-ARCHIVE-NOT: TAG
+CHECK-ARCHIVE: AT_name {{.*}}basic2.c
+CHECK-ARCHIVE: DEBUG MAP OBJECT: {{.*}}libbasic.a(basic3.macho.x86_64.o)
+CHECK-ARCHIVE: Input compilation unit:
+CHECK-ARCHIVE-NEXT: TAG_compile_unit
+CHECK-ARCHIVE-NOT: TAG
+CHECK-ARCHIVE: AT_name {{.*}}basic3.c
+
//
//===----------------------------------------------------------------------===//
#include "DebugMap.h"
+
+#include "BinaryHolder.h"
+#include "DebugMap.h"
#include "dsymutil.h"
+#include "llvm/DebugInfo/DWARFContext.h"
+#include "llvm/DebugInfo/DWARFDebugInfoEntry.h"
+#include <string>
namespace llvm {
namespace dsymutil {
-bool linkDwarf(StringRef OutputFilename, const DebugMap &DM, bool Verbose) {
- // Do nothing for now.
+namespace {
+
+/// \brief The core of the Dwarf linking logic.
+class DwarfLinker {
+public:
+ DwarfLinker(StringRef OutputFilename, bool Verbose)
+ : OutputFilename(OutputFilename), Verbose(Verbose), BinHolder(Verbose) {}
+
+ /// \brief Link the contents of the DebugMap.
+ bool link(const DebugMap &);
+
+private:
+ std::string OutputFilename;
+ bool Verbose;
+ BinaryHolder BinHolder;
+};
+
+bool DwarfLinker::link(const DebugMap &Map) {
+
+ if (Map.begin() == Map.end()) {
+ errs() << "Empty debug map.\n";
+ return false;
+ }
+
+ for (const auto &Obj : Map.objects()) {
+ if (Verbose)
+ outs() << "DEBUG MAP OBJECT: " << Obj->getObjectFilename() << "\n";
+ auto ErrOrObj = BinHolder.GetObjectFile(Obj->getObjectFilename());
+ if (std::error_code EC = ErrOrObj.getError()) {
+ errs() << Obj->getObjectFilename() << ": " << EC.message() << "\n";
+ continue;
+ }
+
+ DWARFContextInMemory DwarfContext(*ErrOrObj);
+
+ for (const auto &CU : DwarfContext.compile_units()) {
+ auto *CUDie = CU->getCompileUnitDIE(false);
+ if (Verbose) {
+ outs() << "Input compilation unit:";
+ CUDie->dump(outs(), CU.get(), 0);
+ }
+ }
+ }
+
return true;
}
}
+
+bool linkDwarf(StringRef OutputFilename, const DebugMap &DM, bool Verbose) {
+ DwarfLinker Linker(OutputFilename, Verbose);
+ return Linker.link(DM);
+}
+}
}