27using namespace object;
28using namespace symbolize;
32 std::unique_ptr<DIContext> DICtx,
33 bool UntagAddresses) {
35 std::unique_ptr<SymbolizableObjectFile> res(
37 std::unique_ptr<DataExtractor> OpdExtractor;
47 if (*NameOrErr ==
".opd") {
53 OpdAddress = Section->getAddress();
58 std::vector<std::pair<SymbolRef, uint64_t>> Symbols =
60 for (
auto &
P : Symbols)
62 res->addSymbol(
P.first,
P.second, OpdExtractor.get(), OpdAddress))
67 if (Symbols.empty()) {
68 if (
auto *CoffObj = dyn_cast<COFFObjectFile>(Obj))
69 if (
Error E = res->addCoffExportSymbols(CoffObj))
73 std::vector<SymbolDesc> &SS = res->Symbols;
78 auto I = SS.begin(), E = SS.end(), J = SS.begin();
81 while (++
I != E && OI->Addr ==
I->Addr) {
85 SS.erase(J, SS.end());
87 return std::move(res);
90SymbolizableObjectFile::SymbolizableObjectFile(
const ObjectFile *Obj,
91 std::unique_ptr<DIContext> DICtx,
94 UntagAddresses(UntagAddresses) {}
98struct OffsetNamePair {
102 bool operator<(
const OffsetNamePair &R)
const {
109Error SymbolizableObjectFile::addCoffExportSymbols(
112 std::vector<OffsetNamePair> ExportSyms;
116 if (
auto EC =
Ref.getSymbolName(
Name))
120 ExportSyms.push_back(OffsetNamePair{
Offset,
Name});
122 if (ExportSyms.empty())
131 for (
auto I = ExportSyms.begin(), E = ExportSyms.end();
I != E; ++
I) {
137 Symbols.push_back({SymbolStart, SymbolSize,
Export.Name, 0});
149 if (!SymbolNameOrErr)
161 FileSymbols.emplace_back(ELFSymIdx, SymbolName);
167 if (!SymbolTypeOrErr)
185 if (Flags & SymbolRef::SF_FormatSpecific)
193 if (!SymbolAddressOrErr)
195 uint64_t SymbolAddress = *SymbolAddressOrErr;
196 if (UntagAddresses) {
199 SymbolAddress &= (1ull << 56) - 1;
200 SymbolAddress = (int64_t(SymbolAddress) << 8) >> 8;
208 uint64_t OpdOffset = SymbolAddress - OpdAddress;
210 SymbolAddress = OpdExtractor->
getAddress(&OpdOffset);
218 Symbols.push_back({SymbolAddress, SymbolSize,
SymbolName, ELFSymIdx});
224 auto *CoffObject = dyn_cast<COFFObjectFile>(
Module);
229 if (
auto *CoffObject = dyn_cast<COFFObjectFile>(
Module))
230 return CoffObject->getImageBase();
234bool SymbolizableObjectFile::getNameFromSymbolTable(
236 std::string &FileName)
const {
239 if (SymbolIterator == Symbols.begin())
242 if (SymbolIterator->Size != 0 &&
243 SymbolIterator->Addr + SymbolIterator->Size <=
Address)
245 Name = SymbolIterator->Name.str();
246 Addr = SymbolIterator->Addr;
247 Size = SymbolIterator->Size;
249 if (SymbolIterator->ELFLocalSymIdx != 0) {
256 std::make_pair(SymbolIterator->ELFLocalSymIdx,
StringRef()));
257 if (It != FileSymbols.begin())
258 FileName = It[-1].second.str();
263bool SymbolizableObjectFile::shouldOverrideWithSymbolTable(
269 return FNKind == FunctionNameKind::LinkageName && UseSymbolTable &&
270 isa<DWARFContext>(DebugInfoContext.get());
276 bool UseSymbolTable)
const {
279 getModuleSectionIndexForAddress(ModuleOffset.
Address);
281 DebugInfoContext->getLineInfoForAddress(ModuleOffset, LineInfoSpecifier);
284 if (shouldOverrideWithSymbolTable(LineInfoSpecifier.
FNKind, UseSymbolTable)) {
285 std::string FunctionName, FileName;
287 if (getNameFromSymbolTable(ModuleOffset.
Address, FunctionName, Start,
Size,
303 getModuleSectionIndexForAddress(ModuleOffset.
Address);
305 ModuleOffset, LineInfoSpecifier);
312 if (shouldOverrideWithSymbolTable(LineInfoSpecifier.
FNKind, UseSymbolTable)) {
313 std::string FunctionName, FileName;
315 if (getNameFromSymbolTable(ModuleOffset.
Address, FunctionName, Start,
Size,
332 std::string FileName;
338 DILineInfo DL = DebugInfoContext->getLineInfoForDataAddress(ModuleOffset);
350 getModuleSectionIndexForAddress(ModuleOffset.
Address);
351 return DebugInfoContext->getLocalsForAddress(ModuleOffset);
354std::vector<object::SectionedAddress>
356 std::vector<object::SectionedAddress> Result;
357 for (
const SymbolDesc &
Sym : Symbols) {
358 if (
Sym.Name == Symbol) {
370uint64_t SymbolizableObjectFile::getModuleSectionIndexForAddress(
374 if (!Sec.isText() || Sec.isVirtual())
377 if (
Address >= Sec.getAddress() &&
378 Address < Sec.getAddress() + Sec.getSize())
379 return Sec.getIndex();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A format-neutral container for inlined code description.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
A Module instance is used to store all the information related to an LLVM module.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
DataRefImpl getRawDataRefImpl() const
bool isLittleEndian() const
iterator_range< export_directory_iterator > export_directories() const
uint64_t getImageBase() const
uint64_t getFlags() const
uint8_t getELFType() const
uint8_t getBinding() const
This class is the base class for all object file types.
virtual section_iterator section_end() const =0
virtual uint8_t getBytesInAddress() const =0
The number of bytes used to represent an address in this object file format.
section_iterator_range sections() const
virtual Triple::ArchType getArch() const =0
This is a value type class that represents a single section in the list of sections in the object fil...
This is a value type class that represents a single symbol in the list of symbols in the object file.
DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override
DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset, DILineInfoSpecifier LineInfoSpecifier, bool UseSymbolTable) const override
static Expected< std::unique_ptr< SymbolizableObjectFile > > create(const object::ObjectFile *Obj, std::unique_ptr< DIContext > DICtx, bool UntagAddresses)
std::vector< object::SectionedAddress > findSymbol(StringRef Symbol, uint64_t Offset) const override
uint64_t getModulePreferredBase() const override
std::vector< DILocal > symbolizeFrame(object::SectionedAddress ModuleOffset) const override
bool isWin32Module() const override
DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset, DILineInfoSpecifier LineInfoSpecifier, bool UseSymbolTable) const override
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
@ IMAGE_FILE_MACHINE_I386
std::vector< std::pair< SymbolRef, uint64_t > > computeSymbolSizes(const ObjectFile &O)
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
void stable_sort(R &&Range)
@ Export
Export information to summary.
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
@ Ref
The access may reference the value stored in memory.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
Implement std::hash so that hash_code can be used in STL containers.
Container for description of a global variable.
Controls which fields of DILineInfo container should be filled with data.
A format-neutral container for source line information.
static constexpr const char *const BadString
std::optional< uint64_t > StartAddress
static const uint64_t UndefSection
struct llvm::object::DataRefImpl::@368 d