30 #include <system_error> 46 std::unique_ptr<DIContext> DICtx,
47 bool UntagAddresses) {
49 std::unique_ptr<SymbolizableObjectFile> res(
51 std::unique_ptr<DataExtractor> OpdExtractor;
52 uint64_t OpdAddress = 0;
61 if (*NameOrErr ==
".opd") {
67 OpdAddress =
Section->getAddress();
72 std::vector<std::pair<SymbolRef, uint64_t>> Symbols =
74 for (
auto &
P : Symbols)
75 res->addSymbol(
P.first,
P.second, OpdExtractor.get(), OpdAddress);
79 if (Symbols.empty()) {
80 if (
auto *CoffObj = dyn_cast<COFFObjectFile>(Obj))
81 if (
auto EC = res->addCoffExportSymbols(CoffObj))
85 std::vector<std::pair<SymbolDesc, StringRef>> &Fs = res->Functions,
87 auto Uniquify = [](std::vector<std::pair<SymbolDesc, StringRef>> &S) {
92 auto I = S.begin(),
E = S.end(), J = S.begin();
95 while (++
I !=
E && OI->first.Addr ==
I->first.Addr) {
104 return std::move(res);
107 SymbolizableObjectFile::SymbolizableObjectFile(
const ObjectFile *Obj,
108 std::unique_ptr<DIContext> DICtx,
110 :
Module(Obj), DebugInfoContext(std::move(DICtx)),
111 UntagAddresses(UntagAddresses) {}
115 struct OffsetNamePair {
119 bool operator<(
const OffsetNamePair &R)
const {
120 return Offset < R.Offset;
126 std::error_code SymbolizableObjectFile::addCoffExportSymbols(
129 std::vector<OffsetNamePair> ExportSyms;
133 if (
auto EC =
Ref.getSymbolName(Name))
135 if (
auto EC =
Ref.getExportRVA(Offset))
137 ExportSyms.push_back(OffsetNamePair{
Offset, Name});
139 if (ExportSyms.empty())
140 return std::error_code();
148 for (
auto I = ExportSyms.begin(),
E = ExportSyms.end();
I !=
E; ++
I) {
149 OffsetNamePair &Export = *
I;
151 uint32_t NextOffset =
I !=
E ?
I->Offset : Export.Offset + 1;
152 uint64_t SymbolStart = ImageBase + Export.Offset;
153 uint64_t SymbolSize = NextOffset - Export.Offset;
154 SymbolDesc SD = {SymbolStart, SymbolSize};
155 Functions.emplace_back(SD, Export.Name);
157 return std::error_code();
160 std::error_code SymbolizableObjectFile::addSymbol(
const SymbolRef &
Symbol,
163 uint64_t OpdAddress) {
168 return std::error_code();
170 if (!SymbolTypeOrErr)
174 return std::error_code();
176 if (!SymbolAddressOrErr)
178 uint64_t SymbolAddress = *SymbolAddressOrErr;
179 if (UntagAddresses) {
182 SymbolAddress &= (1ull << 56) - 1;
183 SymbolAddress = (int64_t(SymbolAddress) << 8) >> 8;
191 uint64_t OpdOffset = SymbolAddress - OpdAddress;
193 SymbolAddress = OpdExtractor->
getAddress(&OpdOffset);
196 if (!SymbolNameOrErr)
200 if (
Module->isMachO() && !SymbolName.
empty() && SymbolName[0] ==
'_')
201 SymbolName = SymbolName.drop_front();
205 SymbolDesc SD = { SymbolAddress, SymbolSize };
206 M.emplace_back(SD, SymbolName);
207 return std::error_code();
211 bool SymbolizableObjectFile::isWin32Module()
const {
216 uint64_t SymbolizableObjectFile::getModulePreferredBase()
const {
217 if (
auto *CoffObject = dyn_cast<COFFObjectFile>(
Module))
218 return CoffObject->getImageBase();
226 uint64_t &
Size)
const {
230 if (SymbolIterator == Symbols.begin())
233 if (SymbolIterator->first.Size != 0 &&
234 SymbolIterator->first.Addr + SymbolIterator->first.Size <=
Address)
236 Name = SymbolIterator->second.str();
237 Addr = SymbolIterator->first.Addr;
238 Size = SymbolIterator->first.Size;
242 bool SymbolizableObjectFile::shouldOverrideWithSymbolTable(
249 isa<DWARFContext>(DebugInfoContext.get());
255 bool UseSymbolTable)
const {
258 getModuleSectionIndexForAddress(ModuleOffset.
Address);
259 DILineInfo LineInfo = DebugInfoContext->getLineInfoForAddress(
263 if (shouldOverrideWithSymbolTable(FNKind, UseSymbolTable)) {
264 std::string FunctionName;
265 uint64_t Start,
Size;
267 FunctionName, Start, Size)) {
276 bool UseSymbolTable)
const {
279 getModuleSectionIndexForAddress(ModuleOffset.
Address);
280 DIInliningInfo InlinedContext = DebugInfoContext->getInliningInfoForAddress(
288 if (shouldOverrideWithSymbolTable(FNKind, UseSymbolTable)) {
289 std::string FunctionName;
290 uint64_t Start,
Size;
292 FunctionName, Start, Size)) {
294 ->FunctionName = FunctionName;
298 return InlinedContext;
309 std::vector<DILocal> SymbolizableObjectFile::symbolizeFrame(
313 getModuleSectionIndexForAddress(ModuleOffset.
Address);
314 return DebugInfoContext->getLocalsForAddress(ModuleOffset);
318 uint64_t SymbolizableObjectFile::getModuleSectionIndexForAddress(
322 if (!Sec.isText() || Sec.isVirtual())
325 if (Address >= Sec.getAddress() &&
326 Address < Sec.getAddress() + Sec.getSize())
327 return Sec.getIndex();
Represents either an error or a value T.
DILineInfo * getMutableFrame(unsigned Index)
This class represents lattice values for constants.
Expected< StringRef > getName() const
A Module instance is used to store all the information related to an LLVM module. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
static const uint64_t UndefSection
This class is the base class for all object file types.
uint64_t getImageBase() const
void addFrame(const DILineInfo &Frame)
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Error takeError()
Take ownership of the stored error.
static DILineInfoSpecifier getDILineInfoSpecifier(FunctionNameKind FNKind)
A format-neutral container for source line information.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
The access may reference the value stored in memory.
Tagged union holding either a T or a Error.
bool operator<(const SectionedAddress &LHS, const SectionedAddress &RHS)
const ObjectFile * getObject() const
section_iterator_range sections() const
uint32_t getNumberOfFrames() const
Expected< section_iterator > getSection() const
Get section this symbol is defined in reference to.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
virtual uint8_t getBytesInAddress() const =0
The number of bytes used to represent an address in this object file format.
The instances of the Type class are immutable: once they are created, they are never changed...
Controls which fields of DILineInfo container should be filled with data.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
A format-neutral container for inlined code description.
Expected< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
bool isLittleEndian() const
uint16_t getMachine() const
void sort(IteratorTy Start, IteratorTy End)
Expected< SymbolRef::Type > getType() const
virtual Triple::ArchType getArch() const =0
std::vector< std::pair< SymbolRef, uint64_t > > computeSymbolSizes(const ObjectFile &O)
This is a value type class that represents a single symbol in the list of symbols in the object file...
virtual section_iterator section_end() const =0
iterator_range< export_directory_iterator > export_directories() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
Container for description of a global variable.
This is a value type class that represents a single section in the list of sections in the object fil...
auto upper_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...