Index: include/llvm/MC/MCObjectFileInfo.h =================================================================== --- include/llvm/MC/MCObjectFileInfo.h +++ include/llvm/MC/MCObjectFileInfo.h @@ -123,6 +123,9 @@ /// Section for newer gnu pubtypes. MCSection *DwarfGnuPubTypesSection; + // Section for Swift AST + MCSection *DwarfSwiftASTSection; + MCSection *COFFDebugSymbolsSection; MCSection *COFFDebugTypesSection; @@ -267,6 +270,7 @@ MCSection *getDwarfAddrSection() const { return DwarfAddrSection; } MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; } MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; } + MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; } MCSection *getCOFFDebugSymbolsSection() const { return COFFDebugSymbolsSection; Index: lib/MC/MCObjectFileInfo.cpp =================================================================== --- lib/MC/MCObjectFileInfo.cpp +++ lib/MC/MCObjectFileInfo.cpp @@ -214,6 +214,11 @@ Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG, SectionKind::getMetadata(), "types_begin"); + // Swift AST Section + DwarfSwiftASTSection = + Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG, + SectionKind::getMetadata()); + DwarfAbbrevSection = Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG, SectionKind::getMetadata(), "section_abbrev"); Index: tools/dsymutil/BinaryHolder.h =================================================================== --- tools/dsymutil/BinaryHolder.h +++ tools/dsymutil/BinaryHolder.h @@ -66,6 +66,12 @@ MapArchiveAndGetMemberBuffers(StringRef Filename, sys::TimePoint Timestamp); + void changeBackingMemoryBuffer(std::unique_ptr &&MemBuf); + ErrorOr getObjfileForArch(const Triple &T); + +public: + BinaryHolder(bool Verbose) : Verbose(Verbose) {} + /// Return the MemoryBufferRef that holds the memory mapping for the /// given \p Filename. This function will try to parse archive /// member specifications of the form /path/to/archive.a(member.o). @@ -79,12 +85,6 @@ GetMemoryBuffersForFile(StringRef Filename, sys::TimePoint Timestamp); - void changeBackingMemoryBuffer(std::unique_ptr &&MemBuf); - ErrorOr getObjfileForArch(const Triple &T); - -public: - BinaryHolder(bool Verbose) : Verbose(Verbose) {} - /// Get the ObjectFiles designated by the \p Filename. This /// might be an archive member specification of the form /// /path/to/archive.a(member.o). Index: tools/dsymutil/DebugMap.h =================================================================== --- tools/dsymutil/DebugMap.h +++ tools/dsymutil/DebugMap.h @@ -94,7 +94,8 @@ /// debug map. DebugMapObject & addDebugMapObject(StringRef ObjectFilePath, - sys::TimePoint Timestamp); + sys::TimePoint Timestamp, + uint8_t Type); const Triple &getTriple() const { return BinaryTriple; } @@ -154,6 +155,8 @@ return Timestamp; } + uint8_t getType() const { return Type; } + iterator_range::const_iterator> symbols() const { return make_range(Symbols.begin(), Symbols.end()); } @@ -166,12 +169,13 @@ friend class DebugMap; /// DebugMapObjects can only be constructed by the owning DebugMap. DebugMapObject(StringRef ObjectFilename, - sys::TimePoint Timestamp); + sys::TimePoint Timestamp, uint8_t Type); std::string Filename; sys::TimePoint Timestamp; StringMap Symbols; DenseMap AddressToMapping; + uint8_t Type; /// For YAMLIO support. ///@{ Index: tools/dsymutil/DebugMap.cpp =================================================================== --- tools/dsymutil/DebugMap.cpp +++ tools/dsymutil/DebugMap.cpp @@ -21,8 +21,9 @@ using namespace llvm::object; DebugMapObject::DebugMapObject(StringRef ObjectFilename, - sys::TimePoint Timestamp) - : Filename(ObjectFilename), Timestamp(Timestamp) {} + sys::TimePoint Timestamp, + uint8_t Type) + : Filename(ObjectFilename), Timestamp(Timestamp), Type(Type) {} bool DebugMapObject::addSymbol(StringRef Name, Optional ObjectAddress, uint64_t LinkedAddress, uint32_t Size) { @@ -64,8 +65,9 @@ DebugMapObject & DebugMap::addDebugMapObject(StringRef ObjectFilePath, - sys::TimePoint Timestamp) { - Objects.emplace_back(new DebugMapObject(ObjectFilePath, Timestamp)); + sys::TimePoint Timestamp, + uint8_t Type) { + Objects.emplace_back(new DebugMapObject(ObjectFilePath, Timestamp, Type)); return *Objects.back(); } @@ -241,7 +243,7 @@ } } - dsymutil::DebugMapObject Res(Path, sys::toTimePoint(Timestamp)); + dsymutil::DebugMapObject Res(Path, sys::toTimePoint(Timestamp), MachO::N_OSO); for (auto &Entry : Entries) { auto &Mapping = Entry.second; Optional ObjAddress; Index: tools/dsymutil/DwarfLinker.cpp =================================================================== --- tools/dsymutil/DwarfLinker.cpp +++ tools/dsymutil/DwarfLinker.cpp @@ -525,6 +525,9 @@ /// Emit the string table described by \p Pool. void emitStrings(const NonRelocatableStringpool &Pool); + /// Emit the swift_ast section stored in \p Buffers. + void emitSwiftAST(const std::vector &Buffers); + /// Emit debug_ranges for \p FuncRange by translating the /// original \p Entries. void emitRangesEntries( @@ -708,6 +711,14 @@ StringRef(Entry->getKey().data(), Entry->getKey().size() + 1)); } +/// Emit the swift_ast section stored in \p Buffers. +void DwarfStreamer::emitSwiftAST(const std::vector &Buffers) { + Asm->OutStreamer->SwitchSection(MOFI->getDwarfSwiftASTSection()); + for (auto Buf : Buffers) { + Asm->OutStreamer->EmitBytes(Buf.getBuffer()); + } +} + /// Emit the debug_range section contents for \p FuncRange by /// translating the original \p Entries. The debug_range section /// format is totally trivial, consisting just of pairs of address @@ -3325,8 +3336,8 @@ else sys::path::append(Path, Filename); BinaryHolder ObjHolder(Options.Verbose); - auto &Obj = - ModuleMap.addDebugMapObject(Path, sys::TimePoint()); + auto &Obj = ModuleMap.addDebugMapObject( + Path, sys::TimePoint(), MachO::N_OSO); auto ErrOrObj = loadObject(ObjHolder, Obj, ModuleMap); if (!ErrOrObj) { // Try and emit more helpful warnings by applying some heuristics. @@ -3471,6 +3482,18 @@ if (Options.Verbose) outs() << "DEBUG MAP OBJECT: " << Obj->getObjectFilename() << "\n"; + + // N_AST objects (swiftmodule files) should get dumped directly into the + // appropriate DWARF section + if (Obj->getType() == MachO::N_AST) { + auto ErrOrMemBufferRefs = BinHolder.GetMemoryBuffersForFile( + Obj->getObjectFilename(), Obj->getTimestamp()); + if (auto Err = ErrOrMemBufferRefs.getError()) + continue; + Streamer->emitSwiftAST(ErrOrMemBufferRefs.get()); + continue; + } + auto ErrOrObj = loadObject(BinHolder, *Obj, Map); if (!ErrOrObj) continue; Index: tools/dsymutil/MachODebugMapParser.cpp =================================================================== --- tools/dsymutil/MachODebugMapParser.cpp +++ tools/dsymutil/MachODebugMapParser.cpp @@ -135,7 +135,8 @@ Err.message() + "\n"); } - CurrentDebugMapObject = &Result->addDebugMapObject(Path, Timestamp); + CurrentDebugMapObject = + &Result->addDebugMapObject(Path, Timestamp, MachO::N_OSO); loadCurrentObjectFileSymbols(*ErrOrAchObj); } @@ -349,6 +350,13 @@ if (Type == MachO::N_OSO) return switchToNewDebugMapObject(Name, sys::toTimePoint(Value)); + if (Type == MachO::N_AST) { + SmallString<80> Path(PathPrefix); + sys::path::append(Path, Name); + Result->addDebugMapObject(Path, sys::toTimePoint(Value), Type); + return; + } + // If the last N_OSO object file wasn't found, // CurrentDebugMapObject will be null. Do not update anything // until we find the next valid N_OSO entry.