31 #include <system_error> 47 std::unique_ptr<DIContext> DICtx) {
48 std::unique_ptr<SymbolizableObjectFile> res(
50 std::unique_ptr<DataExtractor> OpdExtractor;
51 uint64_t OpdAddress = 0;
58 if (
auto EC =
Section->getName(Name))
61 if (
auto EC =
Section->getContents(Data))
65 OpdAddress =
Section->getAddress();
70 std::vector<std::pair<SymbolRef, uint64_t>> Symbols =
72 for (
auto &
P : Symbols)
73 res->addSymbol(
P.first,
P.second, OpdExtractor.get(), OpdAddress);
77 if (Symbols.empty()) {
78 if (
auto *CoffObj = dyn_cast<COFFObjectFile>(Obj))
79 if (
auto EC = res->addCoffExportSymbols(CoffObj))
82 return std::move(res);
85 SymbolizableObjectFile::SymbolizableObjectFile(
ObjectFile *Obj,
86 std::unique_ptr<DIContext> DICtx)
87 :
Module(Obj), DebugInfoContext(std::move(DICtx)) {}
91 struct OffsetNamePair {
95 bool operator<(
const OffsetNamePair &R)
const {
96 return Offset < R.Offset;
102 std::error_code SymbolizableObjectFile::addCoffExportSymbols(
105 std::vector<OffsetNamePair> ExportSyms;
109 if (
auto EC =
Ref.getSymbolName(Name))
111 if (
auto EC =
Ref.getExportRVA(Offset))
113 ExportSyms.push_back(OffsetNamePair{
Offset, Name});
115 if (ExportSyms.empty())
116 return std::error_code();
124 for (
auto I = ExportSyms.begin(),
E = ExportSyms.end();
I !=
E; ++
I) {
125 OffsetNamePair &Export = *
I;
127 uint32_t NextOffset =
I !=
E ?
I->Offset : Export.Offset + 1;
128 uint64_t SymbolStart = ImageBase + Export.Offset;
129 uint64_t SymbolSize = NextOffset - Export.Offset;
130 SymbolDesc SD = {SymbolStart, SymbolSize};
131 Functions.insert(std::make_pair(SD, Export.Name));
133 return std::error_code();
136 std::error_code SymbolizableObjectFile::addSymbol(
const SymbolRef &
Symbol,
139 uint64_t OpdAddress) {
141 if (!SymbolTypeOrErr)
145 return std::error_code();
147 if (!SymbolAddressOrErr)
149 uint64_t SymbolAddress = *SymbolAddressOrErr;
156 uint64_t OpdOffset = SymbolAddress - OpdAddress;
158 if (OpdOffset == OpdOffset32 &&
160 SymbolAddress = OpdExtractor->
getAddress(&OpdOffset32);
163 if (!SymbolNameOrErr)
167 if (
Module->isMachO() && !SymbolName.
empty() && SymbolName[0] ==
'_')
168 SymbolName = SymbolName.drop_front();
172 SymbolDesc SD = { SymbolAddress, SymbolSize };
173 M.insert(std::make_pair(SD, SymbolName));
174 return std::error_code();
178 bool SymbolizableObjectFile::isWin32Module()
const {
183 uint64_t SymbolizableObjectFile::getModulePreferredBase()
const {
184 if (
auto *CoffObject = dyn_cast<COFFObjectFile>(
Module))
185 return CoffObject->getImageBase();
193 uint64_t &
Size)
const {
198 auto SymbolIterator =
SymbolMap.upper_bound(SD);
202 if (SymbolIterator->first.Size != 0 &&
203 SymbolIterator->first.Addr + SymbolIterator->first.Size <= Address)
205 Name = SymbolIterator->second.str();
206 Addr = SymbolIterator->first.Addr;
207 Size = SymbolIterator->first.Size;
211 bool SymbolizableObjectFile::shouldOverrideWithSymbolTable(
218 isa<DWARFContext>(DebugInfoContext.get());
221 DILineInfo SymbolizableObjectFile::symbolizeCode(uint64_t ModuleOffset,
223 bool UseSymbolTable)
const {
225 if (DebugInfoContext) {
226 LineInfo = DebugInfoContext->getLineInfoForAddress(
230 if (shouldOverrideWithSymbolTable(FNKind, UseSymbolTable)) {
231 std::string FunctionName;
232 uint64_t Start,
Size;
234 FunctionName, Start, Size)) {
242 uint64_t ModuleOffset,
FunctionNameKind FNKind,
bool UseSymbolTable)
const {
245 if (DebugInfoContext)
246 InlinedContext = DebugInfoContext->getInliningInfoForAddress(
253 if (shouldOverrideWithSymbolTable(FNKind, UseSymbolTable)) {
254 std::string FunctionName;
255 uint64_t Start,
Size;
257 FunctionName, Start, Size)) {
259 ->FunctionName = FunctionName;
263 return InlinedContext;
266 DIGlobal SymbolizableObjectFile::symbolizeData(uint64_t ModuleOffset)
const {
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. ...
bool operator<(const DataRefImpl &a, const DataRefImpl &b)
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.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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.
section_iterator_range sections() const
uint32_t getNumberOfFrames() const
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.
DenseMap< SymbolStringPtr, JITEvaluatedSymbol > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
Expected< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
bool isLittleEndian() const
uint16_t getMachine() const
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...
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)
LLVM_NODISCARD bool empty() const
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.