xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp (revision 8bcb0991864975618c09697b1aca10683346d9f0)
10b57cec5SDimitry Andric //===- SymbolizableObjectFile.cpp -----------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // Implementation of SymbolizableObjectFile class.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "SymbolizableObjectFile.h"
140b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h"
150b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
160b57cec5SDimitry Andric #include "llvm/ADT/Triple.h"
170b57cec5SDimitry Andric #include "llvm/BinaryFormat/COFF.h"
180b57cec5SDimitry Andric #include "llvm/DebugInfo/DWARF/DWARFContext.h"
190b57cec5SDimitry Andric #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
200b57cec5SDimitry Andric #include "llvm/Object/COFF.h"
210b57cec5SDimitry Andric #include "llvm/Object/ObjectFile.h"
220b57cec5SDimitry Andric #include "llvm/Object/SymbolSize.h"
230b57cec5SDimitry Andric #include "llvm/Support/Casting.h"
240b57cec5SDimitry Andric #include "llvm/Support/DataExtractor.h"
250b57cec5SDimitry Andric #include "llvm/Support/Error.h"
260b57cec5SDimitry Andric #include <algorithm>
270b57cec5SDimitry Andric #include <cstdint>
280b57cec5SDimitry Andric #include <memory>
290b57cec5SDimitry Andric #include <string>
300b57cec5SDimitry Andric #include <system_error>
310b57cec5SDimitry Andric #include <utility>
320b57cec5SDimitry Andric #include <vector>
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric using namespace llvm;
350b57cec5SDimitry Andric using namespace object;
360b57cec5SDimitry Andric using namespace symbolize;
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric static DILineInfoSpecifier
390b57cec5SDimitry Andric getDILineInfoSpecifier(FunctionNameKind FNKind) {
400b57cec5SDimitry Andric   return DILineInfoSpecifier(
410b57cec5SDimitry Andric       DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, FNKind);
420b57cec5SDimitry Andric }
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric ErrorOr<std::unique_ptr<SymbolizableObjectFile>>
450b57cec5SDimitry Andric SymbolizableObjectFile::create(const object::ObjectFile *Obj,
46*8bcb0991SDimitry Andric                                std::unique_ptr<DIContext> DICtx,
47*8bcb0991SDimitry Andric                                bool UntagAddresses) {
480b57cec5SDimitry Andric   assert(DICtx);
490b57cec5SDimitry Andric   std::unique_ptr<SymbolizableObjectFile> res(
50*8bcb0991SDimitry Andric       new SymbolizableObjectFile(Obj, std::move(DICtx), UntagAddresses));
510b57cec5SDimitry Andric   std::unique_ptr<DataExtractor> OpdExtractor;
520b57cec5SDimitry Andric   uint64_t OpdAddress = 0;
530b57cec5SDimitry Andric   // Find the .opd (function descriptor) section if any, for big-endian
540b57cec5SDimitry Andric   // PowerPC64 ELF.
550b57cec5SDimitry Andric   if (Obj->getArch() == Triple::ppc64) {
560b57cec5SDimitry Andric     for (section_iterator Section : Obj->sections()) {
57*8bcb0991SDimitry Andric       Expected<StringRef> NameOrErr = Section->getName();
58*8bcb0991SDimitry Andric       if (!NameOrErr)
59*8bcb0991SDimitry Andric         return errorToErrorCode(NameOrErr.takeError());
60*8bcb0991SDimitry Andric 
61*8bcb0991SDimitry Andric       if (*NameOrErr == ".opd") {
620b57cec5SDimitry Andric         Expected<StringRef> E = Section->getContents();
630b57cec5SDimitry Andric         if (!E)
640b57cec5SDimitry Andric           return errorToErrorCode(E.takeError());
650b57cec5SDimitry Andric         OpdExtractor.reset(new DataExtractor(*E, Obj->isLittleEndian(),
660b57cec5SDimitry Andric                                              Obj->getBytesInAddress()));
670b57cec5SDimitry Andric         OpdAddress = Section->getAddress();
680b57cec5SDimitry Andric         break;
690b57cec5SDimitry Andric       }
700b57cec5SDimitry Andric     }
710b57cec5SDimitry Andric   }
720b57cec5SDimitry Andric   std::vector<std::pair<SymbolRef, uint64_t>> Symbols =
730b57cec5SDimitry Andric       computeSymbolSizes(*Obj);
740b57cec5SDimitry Andric   for (auto &P : Symbols)
750b57cec5SDimitry Andric     res->addSymbol(P.first, P.second, OpdExtractor.get(), OpdAddress);
760b57cec5SDimitry Andric 
770b57cec5SDimitry Andric   // If this is a COFF object and we didn't find any symbols, try the export
780b57cec5SDimitry Andric   // table.
790b57cec5SDimitry Andric   if (Symbols.empty()) {
800b57cec5SDimitry Andric     if (auto *CoffObj = dyn_cast<COFFObjectFile>(Obj))
810b57cec5SDimitry Andric       if (auto EC = res->addCoffExportSymbols(CoffObj))
820b57cec5SDimitry Andric         return EC;
830b57cec5SDimitry Andric   }
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric   std::vector<std::pair<SymbolDesc, StringRef>> &Fs = res->Functions,
860b57cec5SDimitry Andric                                                 &Os = res->Objects;
870b57cec5SDimitry Andric   auto Uniquify = [](std::vector<std::pair<SymbolDesc, StringRef>> &S) {
880b57cec5SDimitry Andric     // Sort by (Addr,Size,Name). If several SymbolDescs share the same Addr,
890b57cec5SDimitry Andric     // pick the one with the largest Size. This helps us avoid symbols with no
900b57cec5SDimitry Andric     // size information (Size=0).
910b57cec5SDimitry Andric     llvm::sort(S);
920b57cec5SDimitry Andric     auto I = S.begin(), E = S.end(), J = S.begin();
930b57cec5SDimitry Andric     while (I != E) {
940b57cec5SDimitry Andric       auto OI = I;
950b57cec5SDimitry Andric       while (++I != E && OI->first.Addr == I->first.Addr) {
960b57cec5SDimitry Andric       }
970b57cec5SDimitry Andric       *J++ = I[-1];
980b57cec5SDimitry Andric     }
990b57cec5SDimitry Andric     S.erase(J, S.end());
1000b57cec5SDimitry Andric   };
1010b57cec5SDimitry Andric   Uniquify(Fs);
1020b57cec5SDimitry Andric   Uniquify(Os);
1030b57cec5SDimitry Andric 
1040b57cec5SDimitry Andric   return std::move(res);
1050b57cec5SDimitry Andric }
1060b57cec5SDimitry Andric 
1070b57cec5SDimitry Andric SymbolizableObjectFile::SymbolizableObjectFile(const ObjectFile *Obj,
108*8bcb0991SDimitry Andric                                                std::unique_ptr<DIContext> DICtx,
109*8bcb0991SDimitry Andric                                                bool UntagAddresses)
110*8bcb0991SDimitry Andric     : Module(Obj), DebugInfoContext(std::move(DICtx)),
111*8bcb0991SDimitry Andric       UntagAddresses(UntagAddresses) {}
1120b57cec5SDimitry Andric 
1130b57cec5SDimitry Andric namespace {
1140b57cec5SDimitry Andric 
1150b57cec5SDimitry Andric struct OffsetNamePair {
1160b57cec5SDimitry Andric   uint32_t Offset;
1170b57cec5SDimitry Andric   StringRef Name;
1180b57cec5SDimitry Andric 
1190b57cec5SDimitry Andric   bool operator<(const OffsetNamePair &R) const {
1200b57cec5SDimitry Andric     return Offset < R.Offset;
1210b57cec5SDimitry Andric   }
1220b57cec5SDimitry Andric };
1230b57cec5SDimitry Andric 
1240b57cec5SDimitry Andric } // end anonymous namespace
1250b57cec5SDimitry Andric 
1260b57cec5SDimitry Andric std::error_code SymbolizableObjectFile::addCoffExportSymbols(
1270b57cec5SDimitry Andric     const COFFObjectFile *CoffObj) {
1280b57cec5SDimitry Andric   // Get all export names and offsets.
1290b57cec5SDimitry Andric   std::vector<OffsetNamePair> ExportSyms;
1300b57cec5SDimitry Andric   for (const ExportDirectoryEntryRef &Ref : CoffObj->export_directories()) {
1310b57cec5SDimitry Andric     StringRef Name;
1320b57cec5SDimitry Andric     uint32_t Offset;
1330b57cec5SDimitry Andric     if (auto EC = Ref.getSymbolName(Name))
1340b57cec5SDimitry Andric       return EC;
1350b57cec5SDimitry Andric     if (auto EC = Ref.getExportRVA(Offset))
1360b57cec5SDimitry Andric       return EC;
1370b57cec5SDimitry Andric     ExportSyms.push_back(OffsetNamePair{Offset, Name});
1380b57cec5SDimitry Andric   }
1390b57cec5SDimitry Andric   if (ExportSyms.empty())
1400b57cec5SDimitry Andric     return std::error_code();
1410b57cec5SDimitry Andric 
1420b57cec5SDimitry Andric   // Sort by ascending offset.
1430b57cec5SDimitry Andric   array_pod_sort(ExportSyms.begin(), ExportSyms.end());
1440b57cec5SDimitry Andric 
1450b57cec5SDimitry Andric   // Approximate the symbol sizes by assuming they run to the next symbol.
1460b57cec5SDimitry Andric   // FIXME: This assumes all exports are functions.
1470b57cec5SDimitry Andric   uint64_t ImageBase = CoffObj->getImageBase();
1480b57cec5SDimitry Andric   for (auto I = ExportSyms.begin(), E = ExportSyms.end(); I != E; ++I) {
1490b57cec5SDimitry Andric     OffsetNamePair &Export = *I;
1500b57cec5SDimitry Andric     // FIXME: The last export has a one byte size now.
1510b57cec5SDimitry Andric     uint32_t NextOffset = I != E ? I->Offset : Export.Offset + 1;
1520b57cec5SDimitry Andric     uint64_t SymbolStart = ImageBase + Export.Offset;
1530b57cec5SDimitry Andric     uint64_t SymbolSize = NextOffset - Export.Offset;
1540b57cec5SDimitry Andric     SymbolDesc SD = {SymbolStart, SymbolSize};
1550b57cec5SDimitry Andric     Functions.emplace_back(SD, Export.Name);
1560b57cec5SDimitry Andric   }
1570b57cec5SDimitry Andric   return std::error_code();
1580b57cec5SDimitry Andric }
1590b57cec5SDimitry Andric 
1600b57cec5SDimitry Andric std::error_code SymbolizableObjectFile::addSymbol(const SymbolRef &Symbol,
1610b57cec5SDimitry Andric                                                   uint64_t SymbolSize,
1620b57cec5SDimitry Andric                                                   DataExtractor *OpdExtractor,
1630b57cec5SDimitry Andric                                                   uint64_t OpdAddress) {
1640b57cec5SDimitry Andric   // Avoid adding symbols from an unknown/undefined section.
1650b57cec5SDimitry Andric   const ObjectFile *Obj = Symbol.getObject();
1660b57cec5SDimitry Andric   Expected<section_iterator> Sec = Symbol.getSection();
1670b57cec5SDimitry Andric   if (!Sec || (Obj && Obj->section_end() == *Sec))
1680b57cec5SDimitry Andric     return std::error_code();
1690b57cec5SDimitry Andric   Expected<SymbolRef::Type> SymbolTypeOrErr = Symbol.getType();
1700b57cec5SDimitry Andric   if (!SymbolTypeOrErr)
1710b57cec5SDimitry Andric     return errorToErrorCode(SymbolTypeOrErr.takeError());
1720b57cec5SDimitry Andric   SymbolRef::Type SymbolType = *SymbolTypeOrErr;
1730b57cec5SDimitry Andric   if (SymbolType != SymbolRef::ST_Function && SymbolType != SymbolRef::ST_Data)
1740b57cec5SDimitry Andric     return std::error_code();
1750b57cec5SDimitry Andric   Expected<uint64_t> SymbolAddressOrErr = Symbol.getAddress();
1760b57cec5SDimitry Andric   if (!SymbolAddressOrErr)
1770b57cec5SDimitry Andric     return errorToErrorCode(SymbolAddressOrErr.takeError());
1780b57cec5SDimitry Andric   uint64_t SymbolAddress = *SymbolAddressOrErr;
179*8bcb0991SDimitry Andric   if (UntagAddresses) {
180*8bcb0991SDimitry Andric     // For kernel addresses, bits 56-63 need to be set, so we sign extend bit 55
181*8bcb0991SDimitry Andric     // into bits 56-63 instead of masking them out.
182*8bcb0991SDimitry Andric     SymbolAddress &= (1ull << 56) - 1;
183*8bcb0991SDimitry Andric     SymbolAddress = (int64_t(SymbolAddress) << 8) >> 8;
184*8bcb0991SDimitry Andric   }
1850b57cec5SDimitry Andric   if (OpdExtractor) {
1860b57cec5SDimitry Andric     // For big-endian PowerPC64 ELF, symbols in the .opd section refer to
1870b57cec5SDimitry Andric     // function descriptors. The first word of the descriptor is a pointer to
1880b57cec5SDimitry Andric     // the function's code.
1890b57cec5SDimitry Andric     // For the purposes of symbolization, pretend the symbol's address is that
1900b57cec5SDimitry Andric     // of the function's code, not the descriptor.
1910b57cec5SDimitry Andric     uint64_t OpdOffset = SymbolAddress - OpdAddress;
192*8bcb0991SDimitry Andric     if (OpdExtractor->isValidOffsetForAddress(OpdOffset))
193*8bcb0991SDimitry Andric       SymbolAddress = OpdExtractor->getAddress(&OpdOffset);
1940b57cec5SDimitry Andric   }
1950b57cec5SDimitry Andric   Expected<StringRef> SymbolNameOrErr = Symbol.getName();
1960b57cec5SDimitry Andric   if (!SymbolNameOrErr)
1970b57cec5SDimitry Andric     return errorToErrorCode(SymbolNameOrErr.takeError());
1980b57cec5SDimitry Andric   StringRef SymbolName = *SymbolNameOrErr;
1990b57cec5SDimitry Andric   // Mach-O symbol table names have leading underscore, skip it.
2000b57cec5SDimitry Andric   if (Module->isMachO() && !SymbolName.empty() && SymbolName[0] == '_')
2010b57cec5SDimitry Andric     SymbolName = SymbolName.drop_front();
2020b57cec5SDimitry Andric   // FIXME: If a function has alias, there are two entries in symbol table
2030b57cec5SDimitry Andric   // with same address size. Make sure we choose the correct one.
2040b57cec5SDimitry Andric   auto &M = SymbolType == SymbolRef::ST_Function ? Functions : Objects;
2050b57cec5SDimitry Andric   SymbolDesc SD = { SymbolAddress, SymbolSize };
2060b57cec5SDimitry Andric   M.emplace_back(SD, SymbolName);
2070b57cec5SDimitry Andric   return std::error_code();
2080b57cec5SDimitry Andric }
2090b57cec5SDimitry Andric 
2100b57cec5SDimitry Andric // Return true if this is a 32-bit x86 PE COFF module.
2110b57cec5SDimitry Andric bool SymbolizableObjectFile::isWin32Module() const {
2120b57cec5SDimitry Andric   auto *CoffObject = dyn_cast<COFFObjectFile>(Module);
2130b57cec5SDimitry Andric   return CoffObject && CoffObject->getMachine() == COFF::IMAGE_FILE_MACHINE_I386;
2140b57cec5SDimitry Andric }
2150b57cec5SDimitry Andric 
2160b57cec5SDimitry Andric uint64_t SymbolizableObjectFile::getModulePreferredBase() const {
2170b57cec5SDimitry Andric   if (auto *CoffObject = dyn_cast<COFFObjectFile>(Module))
2180b57cec5SDimitry Andric     return CoffObject->getImageBase();
2190b57cec5SDimitry Andric   return 0;
2200b57cec5SDimitry Andric }
2210b57cec5SDimitry Andric 
2220b57cec5SDimitry Andric bool SymbolizableObjectFile::getNameFromSymbolTable(SymbolRef::Type Type,
2230b57cec5SDimitry Andric                                                     uint64_t Address,
2240b57cec5SDimitry Andric                                                     std::string &Name,
2250b57cec5SDimitry Andric                                                     uint64_t &Addr,
2260b57cec5SDimitry Andric                                                     uint64_t &Size) const {
2270b57cec5SDimitry Andric   const auto &Symbols = Type == SymbolRef::ST_Function ? Functions : Objects;
2280b57cec5SDimitry Andric   std::pair<SymbolDesc, StringRef> SD{{Address, UINT64_C(-1)}, StringRef()};
2290b57cec5SDimitry Andric   auto SymbolIterator = llvm::upper_bound(Symbols, SD);
2300b57cec5SDimitry Andric   if (SymbolIterator == Symbols.begin())
2310b57cec5SDimitry Andric     return false;
2320b57cec5SDimitry Andric   --SymbolIterator;
2330b57cec5SDimitry Andric   if (SymbolIterator->first.Size != 0 &&
2340b57cec5SDimitry Andric       SymbolIterator->first.Addr + SymbolIterator->first.Size <= Address)
2350b57cec5SDimitry Andric     return false;
2360b57cec5SDimitry Andric   Name = SymbolIterator->second.str();
2370b57cec5SDimitry Andric   Addr = SymbolIterator->first.Addr;
2380b57cec5SDimitry Andric   Size = SymbolIterator->first.Size;
2390b57cec5SDimitry Andric   return true;
2400b57cec5SDimitry Andric }
2410b57cec5SDimitry Andric 
2420b57cec5SDimitry Andric bool SymbolizableObjectFile::shouldOverrideWithSymbolTable(
2430b57cec5SDimitry Andric     FunctionNameKind FNKind, bool UseSymbolTable) const {
2440b57cec5SDimitry Andric   // When DWARF is used with -gline-tables-only / -gmlt, the symbol table gives
2450b57cec5SDimitry Andric   // better answers for linkage names than the DIContext. Otherwise, we are
2460b57cec5SDimitry Andric   // probably using PEs and PDBs, and we shouldn't do the override. PE files
2470b57cec5SDimitry Andric   // generally only contain the names of exported symbols.
2480b57cec5SDimitry Andric   return FNKind == FunctionNameKind::LinkageName && UseSymbolTable &&
2490b57cec5SDimitry Andric          isa<DWARFContext>(DebugInfoContext.get());
2500b57cec5SDimitry Andric }
2510b57cec5SDimitry Andric 
2520b57cec5SDimitry Andric DILineInfo
2530b57cec5SDimitry Andric SymbolizableObjectFile::symbolizeCode(object::SectionedAddress ModuleOffset,
2540b57cec5SDimitry Andric                                       FunctionNameKind FNKind,
2550b57cec5SDimitry Andric                                       bool UseSymbolTable) const {
2560b57cec5SDimitry Andric   if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection)
2570b57cec5SDimitry Andric     ModuleOffset.SectionIndex =
2580b57cec5SDimitry Andric         getModuleSectionIndexForAddress(ModuleOffset.Address);
2590b57cec5SDimitry Andric   DILineInfo LineInfo = DebugInfoContext->getLineInfoForAddress(
2600b57cec5SDimitry Andric       ModuleOffset, getDILineInfoSpecifier(FNKind));
2610b57cec5SDimitry Andric 
2620b57cec5SDimitry Andric   // Override function name from symbol table if necessary.
2630b57cec5SDimitry Andric   if (shouldOverrideWithSymbolTable(FNKind, UseSymbolTable)) {
2640b57cec5SDimitry Andric     std::string FunctionName;
2650b57cec5SDimitry Andric     uint64_t Start, Size;
2660b57cec5SDimitry Andric     if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset.Address,
2670b57cec5SDimitry Andric                                FunctionName, Start, Size)) {
2680b57cec5SDimitry Andric       LineInfo.FunctionName = FunctionName;
2690b57cec5SDimitry Andric     }
2700b57cec5SDimitry Andric   }
2710b57cec5SDimitry Andric   return LineInfo;
2720b57cec5SDimitry Andric }
2730b57cec5SDimitry Andric 
2740b57cec5SDimitry Andric DIInliningInfo SymbolizableObjectFile::symbolizeInlinedCode(
2750b57cec5SDimitry Andric     object::SectionedAddress ModuleOffset, FunctionNameKind FNKind,
2760b57cec5SDimitry Andric     bool UseSymbolTable) const {
2770b57cec5SDimitry Andric   if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection)
2780b57cec5SDimitry Andric     ModuleOffset.SectionIndex =
2790b57cec5SDimitry Andric         getModuleSectionIndexForAddress(ModuleOffset.Address);
2800b57cec5SDimitry Andric   DIInliningInfo InlinedContext = DebugInfoContext->getInliningInfoForAddress(
2810b57cec5SDimitry Andric       ModuleOffset, getDILineInfoSpecifier(FNKind));
2820b57cec5SDimitry Andric 
2830b57cec5SDimitry Andric   // Make sure there is at least one frame in context.
2840b57cec5SDimitry Andric   if (InlinedContext.getNumberOfFrames() == 0)
2850b57cec5SDimitry Andric     InlinedContext.addFrame(DILineInfo());
2860b57cec5SDimitry Andric 
2870b57cec5SDimitry Andric   // Override the function name in lower frame with name from symbol table.
2880b57cec5SDimitry Andric   if (shouldOverrideWithSymbolTable(FNKind, UseSymbolTable)) {
2890b57cec5SDimitry Andric     std::string FunctionName;
2900b57cec5SDimitry Andric     uint64_t Start, Size;
2910b57cec5SDimitry Andric     if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset.Address,
2920b57cec5SDimitry Andric                                FunctionName, Start, Size)) {
2930b57cec5SDimitry Andric       InlinedContext.getMutableFrame(InlinedContext.getNumberOfFrames() - 1)
2940b57cec5SDimitry Andric           ->FunctionName = FunctionName;
2950b57cec5SDimitry Andric     }
2960b57cec5SDimitry Andric   }
2970b57cec5SDimitry Andric 
2980b57cec5SDimitry Andric   return InlinedContext;
2990b57cec5SDimitry Andric }
3000b57cec5SDimitry Andric 
3010b57cec5SDimitry Andric DIGlobal SymbolizableObjectFile::symbolizeData(
3020b57cec5SDimitry Andric     object::SectionedAddress ModuleOffset) const {
3030b57cec5SDimitry Andric   DIGlobal Res;
3040b57cec5SDimitry Andric   getNameFromSymbolTable(SymbolRef::ST_Data, ModuleOffset.Address, Res.Name,
3050b57cec5SDimitry Andric                          Res.Start, Res.Size);
3060b57cec5SDimitry Andric   return Res;
3070b57cec5SDimitry Andric }
3080b57cec5SDimitry Andric 
3090b57cec5SDimitry Andric std::vector<DILocal> SymbolizableObjectFile::symbolizeFrame(
3100b57cec5SDimitry Andric     object::SectionedAddress ModuleOffset) const {
3110b57cec5SDimitry Andric   if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection)
3120b57cec5SDimitry Andric     ModuleOffset.SectionIndex =
3130b57cec5SDimitry Andric         getModuleSectionIndexForAddress(ModuleOffset.Address);
3140b57cec5SDimitry Andric   return DebugInfoContext->getLocalsForAddress(ModuleOffset);
3150b57cec5SDimitry Andric }
3160b57cec5SDimitry Andric 
3170b57cec5SDimitry Andric /// Search for the first occurence of specified Address in ObjectFile.
3180b57cec5SDimitry Andric uint64_t SymbolizableObjectFile::getModuleSectionIndexForAddress(
3190b57cec5SDimitry Andric     uint64_t Address) const {
3200b57cec5SDimitry Andric 
3210b57cec5SDimitry Andric   for (SectionRef Sec : Module->sections()) {
3220b57cec5SDimitry Andric     if (!Sec.isText() || Sec.isVirtual())
3230b57cec5SDimitry Andric       continue;
3240b57cec5SDimitry Andric 
3250b57cec5SDimitry Andric     if (Address >= Sec.getAddress() &&
3260b57cec5SDimitry Andric         Address < Sec.getAddress() + Sec.getSize())
3270b57cec5SDimitry Andric       return Sec.getIndex();
3280b57cec5SDimitry Andric   }
3290b57cec5SDimitry Andric 
3300b57cec5SDimitry Andric   return object::SectionedAddress::UndefSection;
3310b57cec5SDimitry Andric }
332