31 #include <system_error>
36 using namespace object;
37 using namespace symbolize;
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 {
102 std::error_code SymbolizableObjectFile::addCoffExportSymbols(
103 const COFFObjectFile *CoffObj) {
105 std::vector<OffsetNamePair> ExportSyms;
106 for (
const ExportDirectoryEntryRef &Ref : CoffObj->export_directories()) {
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();
123 uint64_t ImageBase = CoffObj->getImageBase();
124 for (
auto I = ExportSyms.begin(),
E = ExportSyms.end();
I !=
E; ++
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();
184 if (
auto *CoffObject = dyn_cast<COFFObjectFile>(
Module))
185 return CoffObject->getImageBase();
193 uint64_t &
Size)
const {
195 if (SymbolMap.empty())
197 SymbolDesc SD = {
Address, Address };
198 auto SymbolIterator = SymbolMap.upper_bound(SD);
199 if (SymbolIterator == SymbolMap.begin())
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());
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;
Represents either an error or a value T.
DILineInfo * getMutableFrame(unsigned Index)
A Module instance is used to store all the information related to an LLVM module. ...
This class is the base class for all object file types.
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)
virtual unsigned getArch() const =0
Export information to summary.
DILineInfo - a format-neutral container for source line information.
DIInliningInfo symbolizeInlinedCode(uint64_t ModuleOffset, FunctionNameKind FNKind, bool UseSymbolTable) const override
Tagged union holding either a T or a Error.
uint32_t getNumberOfFrames() const
bool isWin32Module() const override
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...
uint16_t getMachine() const
DILineInfoSpecifier - controls which fields of DILineInfo container should be filled with data...
DILineInfo symbolizeCode(uint64_t ModuleOffset, FunctionNameKind FNKind, bool UseSymbolTable) const override
DIInliningInfo - a format-neutral container for inlined code description.
section_iterator_range sections() const
std::vector< std::pair< SymbolRef, uint64_t > > computeSymbolSizes(const ObjectFile &O)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isLittleEndian() const
bool operator<(int64_t V1, const APSInt &V2)
uint64_t getModulePreferredBase() const override
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.
DIGlobal symbolizeData(uint64_t ModuleOffset) const override
DIGlobal - container for description of a global variable.