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 @@ -445,7 +445,16 @@ /// address. /// TODO: change input parameter from "uint64_t Address" /// into "SectionedAddress Address" - DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); + DWARFCompileUnit *getCompileUnitForCodeAddress(uint64_t Address); + + /// Return the compile unit which contains data with the provided address. + /// Note: This is more expensive than `getCompileUnitForAddress`, as if + /// `Address` isn't found in the CU ranges (which is cheap), then it falls + /// back to an expensive O(n) walk of all CU's looking for data that spans the + /// address. + /// TODO: change input parameter from "uint64_t Address" into + /// "SectionedAddress Address" + DWARFCompileUnit *getCompileUnitForDataAddress(uint64_t Address); /// Returns whether CU/TU should be populated manually. TU Index populated /// manually only for DWARF5. 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 @@ -1118,14 +1118,17 @@ NormalUnits.getUnitForOffset(Offset)); } -DWARFCompileUnit *DWARFContext::getCompileUnitForAddress(uint64_t Address) { - // First, get the offset of the compile unit. +DWARFCompileUnit *DWARFContext::getCompileUnitForCodeAddress(uint64_t Address) { + uint64_t CUOffset = getDebugAranges()->findAddress(Address); + return getCompileUnitForOffset(CUOffset); +} + +DWARFCompileUnit *DWARFContext::getCompileUnitForDataAddress(uint64_t Address) { uint64_t CUOffset = getDebugAranges()->findAddress(Address); - // Retrieve the compile unit. if (DWARFCompileUnit *OffsetCU = getCompileUnitForOffset(CUOffset)) return OffsetCU; - // Global variables are often not found by the above search, for one of two + // Global variables are often missed by the above search, for one of two // reasons: // 1. .debug_aranges may not include global variables. On clang, it seems we // put the globals in the aranges, but this isn't true for gcc. @@ -1146,7 +1149,7 @@ DWARFContext::DIEsForAddress DWARFContext::getDIEsForAddress(uint64_t Address) { DIEsForAddress Result; - DWARFCompileUnit *CU = getCompileUnitForAddress(Address); + DWARFCompileUnit *CU = getCompileUnitForCodeAddress(Address); if (!CU) return Result; @@ -1297,7 +1300,7 @@ std::vector DWARFContext::getLocalsForAddress(object::SectionedAddress Address) { std::vector Result; - DWARFCompileUnit *CU = getCompileUnitForAddress(Address.Address); + DWARFCompileUnit *CU = getCompileUnitForCodeAddress(Address.Address); if (!CU) return Result; @@ -1310,7 +1313,7 @@ DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Spec) { DILineInfo Result; - DWARFCompileUnit *CU = getCompileUnitForAddress(Address.Address); + DWARFCompileUnit *CU = getCompileUnitForCodeAddress(Address.Address); if (!CU) return Result; @@ -1331,7 +1334,7 @@ DILineInfo DWARFContext::getLineInfoForDataAddress(object::SectionedAddress Address) { DILineInfo Result; - DWARFCompileUnit *CU = getCompileUnitForAddress(Address.Address); + DWARFCompileUnit *CU = getCompileUnitForDataAddress(Address.Address); if (!CU) return Result; @@ -1346,7 +1349,7 @@ DILineInfoTable DWARFContext::getLineInfoForAddressRange( object::SectionedAddress Address, uint64_t Size, DILineInfoSpecifier Spec) { DILineInfoTable Lines; - DWARFCompileUnit *CU = getCompileUnitForAddress(Address.Address); + DWARFCompileUnit *CU = getCompileUnitForCodeAddress(Address.Address); if (!CU) return Lines; @@ -1402,7 +1405,7 @@ DILineInfoSpecifier Spec) { DIInliningInfo InliningInfo; - DWARFCompileUnit *CU = getCompileUnitForAddress(Address.Address); + DWARFCompileUnit *CU = getCompileUnitForCodeAddress(Address.Address); if (!CU) return InliningInfo;