diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -417,6 +417,9 @@ /// into "SectionedAddress Address" DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); + /// Add Skeleton CU for DWO CU. + Error addSkeletonCU(DWARFUnit *Unit); + private: /// Parse a macro[.dwo] or macinfo[.dwo] section. std::unique_ptr diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -249,7 +249,6 @@ } protected: - const DWARFUnitHeader &getHeader() const { return Header; } /// Size in bytes of the parsed unit header. uint32_t getHeaderSize() const { return Header.getSize(); } @@ -277,6 +276,7 @@ virtual ~DWARFUnit(); + const DWARFUnitHeader &getHeader() const { return Header; } bool isDWOUnit() const { return IsDWO; } DWARFContext& getContext() const { return Context; } const DWARFSection &getInfoSection() const { return InfoSection; } diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -2000,3 +2000,24 @@ auto CUs = compile_units(); return CUs.empty() ? 0 : (*CUs.begin())->getAddressByteSize(); } + +Error DWARFContext::addSkeletonCU(DWARFUnit *Unit) { + if (this->DWOUnits.empty()) { + return createError("Not DWO Unit.", + errorCodeToError(object_error::parse_failed)); + } + + auto &DCtx = Unit->getContext(); + auto &DObj = DCtx.getDWARFObj(); + auto *NUnit = NormalUnits.addUnit(std::make_unique( + DCtx, Unit->getInfoSection(), Unit->getHeader(), DCtx.getDebugAbbrev(), &DObj.getRangesSection(), + &DObj.getLocSection(), DObj.getStrSection(), + DObj.getStrOffsetsSection(), &DObj.getAddrSection(), + DObj.getLineSection(), DCtx.isLittleEndian(), false, + NormalUnits)); + + auto AddrOffsetSectionBase = Unit->getAddrOffsetSectionBase(); + if (AddrOffsetSectionBase) + NUnit->setAddrOffsetSection(&DObj.getAddrSection(), *AddrOffsetSectionBase); + return Error::success(); +} diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -544,6 +544,8 @@ DWARFCompileUnit *DWOCU = DWOContext->getDWOCompileUnitForHash(*DWOId); if (!DWOCU) return false; + if(Error Err = DWOContext->addSkeletonCU(this)) + return false; DWO = std::shared_ptr(std::move(DWOContext), DWOCU); // Share .debug_addr and .debug_ranges section with compile unit in .dwo if (AddrOffsetSectionBase)