Mercurial > hg > CbC > CbC_llvm
diff llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp @ 236:c4bab56944e8 llvm-original
LLVM 16
author | kono |
---|---|
date | Wed, 09 Nov 2022 17:45:10 +0900 |
parents | 79ff65ed7e25 |
children | 1f2b6ac9f198 |
line wrap: on
line diff
--- a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp Wed Jul 21 10:27:27 2021 +0900 +++ b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp Wed Nov 09 17:45:10 2022 +0900 @@ -10,6 +10,7 @@ #include <unordered_set> #include "llvm/DebugInfo/DIContext.h" +#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/Support/Error.h" #include "llvm/Support/ThreadPool.h" @@ -260,17 +261,15 @@ if (!CUI.LineTable->lookupAddressRange(SecAddress, RangeSize, RowVector)) { // If we have a DW_TAG_subprogram but no line entries, fall back to using // the DW_AT_decl_file an d DW_AT_decl_line if we have both attributes. - if (auto FileIdx = - dwarf::toUnsigned(Die.findRecursively({dwarf::DW_AT_decl_file}))) { - if (auto Line = - dwarf::toUnsigned(Die.findRecursively({dwarf::DW_AT_decl_line}))) { - LineEntry LE(StartAddress, CUI.DWARFToGSYMFileIndex(Gsym, *FileIdx), - *Line); - FI.OptLineTable = LineTable(); - FI.OptLineTable->push(LE); - // LE.Addr = EndAddress; - // FI.OptLineTable->push(LE); - } + std::string FilePath = Die.getDeclFile( + DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath); + if (FilePath.empty()) + return; + if (auto Line = + dwarf::toUnsigned(Die.findRecursively({dwarf::DW_AT_decl_line}))) { + LineEntry LE(StartAddress, Gsym.insertFile(FilePath), *Line); + FI.OptLineTable = LineTable(); + FI.OptLineTable->push(LE); } return; } @@ -289,12 +288,12 @@ // linker problems or LTO or other DWARF re-linking so it is worth emitting // an error, but not worth stopping the creation of the GSYM. if (!FI.Range.contains(RowAddress)) { - if (RowAddress < FI.Range.Start) { + if (RowAddress < FI.Range.start()) { Log << "error: DIE has a start address whose LowPC is between the " "line table Row[" << RowIndex << "] with address " << HEX64(RowAddress) << " and the next one.\n"; Die.dump(Log, 0, DIDumpOptions::getForSingleDIE()); - RowAddress = FI.Range.Start; + RowAddress = FI.Range.start(); } else { continue; } @@ -394,19 +393,18 @@ if (Range.LowPC != 0) { if (!Gsym.isQuiet()) { // Unexpected invalid address, emit a warning - Log << "warning: DIE has an address range whose start address is " - "not in any executable sections (" - << *Gsym.GetValidTextRanges() - << ") and will not be processed:\n"; - Die.dump(Log, 0, DIDumpOptions::getForSingleDIE()); + OS << "warning: DIE has an address range whose start address is " + "not in any executable sections (" + << *Gsym.GetValidTextRanges() + << ") and will not be processed:\n"; + Die.dump(OS, 0, DIDumpOptions::getForSingleDIE()); } } break; } FunctionInfo FI; - FI.setStartAddress(Range.LowPC); - FI.setEndAddress(Range.HighPC); + FI.Range = {Range.LowPC, Range.HighPC}; FI.Name = *NameIndex; if (CUI.LineTable) { convertFunctionLineTable(OS, CUI, Die, Gsym, FI); @@ -429,11 +427,28 @@ Error DwarfTransformer::convert(uint32_t NumThreads) { size_t NumBefore = Gsym.getNumFunctionInfos(); + auto getDie = [&](DWARFUnit &DwarfUnit) -> DWARFDie { + DWARFDie ReturnDie = DwarfUnit.getUnitDIE(false); + if (llvm::Optional<uint64_t> DWOId = DwarfUnit.getDWOId()) { + DWARFUnit *DWOCU = DwarfUnit.getNonSkeletonUnitDIE(false).getDwarfUnit(); + if (!DWOCU->isDWOUnit()) { + std::string DWOName = dwarf::toString( + DwarfUnit.getUnitDIE().find( + {dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}), + ""); + Log << "warning: Unable to retrieve DWO .debug_info section for " + << DWOName << "\n"; + } else { + ReturnDie = DWOCU->getUnitDIE(false); + } + } + return ReturnDie; + }; if (NumThreads == 1) { // Parse all DWARF data from this thread, use the same string/file table // for everything for (const auto &CU : DICtx.compile_units()) { - DWARFDie Die = CU->getUnitDIE(false); + DWARFDie Die = getDie(*CU); CUInfo CUI(DICtx, dyn_cast<DWARFCompileUnit>(CU.get())); handleDie(Log, CUI, Die); } @@ -458,7 +473,7 @@ // Now convert all DWARF to GSYM in a thread pool. std::mutex LogMutex; for (const auto &CU : DICtx.compile_units()) { - DWARFDie Die = CU->getUnitDIE(false /*CUDieOnly*/); + DWARFDie Die = getDie(*CU); if (Die) { CUInfo CUI(DICtx, dyn_cast<DWARFCompileUnit>(CU.get())); pool.async([this, CUI, &LogMutex, Die]() mutable { @@ -533,7 +548,7 @@ << LR->Locations.size() << "\n"; Log << " " << NumDwarfInlineInfos << " DWARF frames:\n"; for (size_t Idx = 0; Idx < NumDwarfInlineInfos; ++Idx) { - const auto dii = DwarfInlineInfos.getFrame(Idx); + const auto &dii = DwarfInlineInfos.getFrame(Idx); Log << " [" << Idx << "]: " << dii.FunctionName << " @ " << dii.FileName << ':' << dii.Line << '\n'; } @@ -553,7 +568,7 @@ ++Idx) { const auto &gii = LR->Locations[Idx]; if (Idx < NumDwarfInlineInfos) { - const auto dii = DwarfInlineInfos.getFrame(Idx); + const auto &dii = DwarfInlineInfos.getFrame(Idx); gsymFilename = LR->getSourceFile(Idx); // Verify function name if (dii.FunctionName.find(gii.Name.str()) != 0)