10#include <unordered_set>
53 return Addr == UINT32_MAX;
73 if (GsymFileIdx != UINT32_MAX)
78 DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File))
102 if (Die.
getTag() == dwarf::DW_TAG_inlined_subroutine)
109 switch (ParentDie.
getTag()) {
110 case dwarf::DW_TAG_namespace:
111 case dwarf::DW_TAG_structure_type:
112 case dwarf::DW_TAG_union_type:
113 case dwarf::DW_TAG_class_type:
114 case dwarf::DW_TAG_subprogram:
116 case dwarf::DW_TAG_lexical_block:
132static std::optional<uint32_t>
137 dwarf::DW_AT_linkage_name}),
146 if (!(Language == dwarf::DW_LANG_C_plus_plus ||
147 Language == dwarf::DW_LANG_C_plus_plus_03 ||
148 Language == dwarf::DW_LANG_C_plus_plus_11 ||
149 Language == dwarf::DW_LANG_C_plus_plus_14 ||
150 Language == dwarf::DW_LANG_ObjC_plus_plus ||
153 Language == dwarf::DW_LANG_C))
164 if (ParentDeclCtxDie) {
166 while (ParentDeclCtxDie) {
168 if (!ParentName.
empty()) {
172 if (ParentName.
front() ==
'<' && ParentName.
back() ==
'>')
188 bool CheckChildren =
true;
190 case dwarf::DW_TAG_subprogram:
192 CheckChildren =
Depth == 0;
194 case dwarf::DW_TAG_inlined_subroutine:
212 if (DwarfRange.LowPC < DwarfRange.HighPC)
213 Ranges.insert({DwarfRange.LowPC, DwarfRange.HighPC});
227 if (
Tag == dwarf::DW_TAG_inlined_subroutine) {
235 for (
const AddressRange &InlineRange : AllInlineRanges) {
238 if (InlineRange.empty()) {
251 if (AllParentRanges.
contains(InlineRange)) {
254 *Log <<
"error: inlined function DIE at "
256 <<
HEX64(InlineRange.start()) <<
" - "
257 <<
HEX64(InlineRange.end()) <<
") that isn't contained in "
258 <<
"any parent address ranges, this inline range will be "
267 if (EmptyCount == AllInlineRanges.size())
274 II.
Name = *NameIndex;
281 AllInlineRanges, WarnIfEmpty);
282 Parent.
Children.emplace_back(std::move(II));
285 if (
Tag == dwarf::DW_TAG_subprogram ||
Tag == dwarf::DW_TAG_lexical_block) {
289 AllParentRanges, WarnIfEmpty);
296 std::vector<uint32_t> RowVector;
299 const uint64_t RangeSize = EndAddress - StartAddress;
308 DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath);
309 if (FilePath.empty())
322 for (
uint32_t RowIndex : RowVector) {
326 uint64_t RowAddress = Row.Address.Address;
336 *Log <<
"error: DIE has a start address whose LowPC is between the "
337 "line table Row[" << RowIndex <<
"] with address "
338 <<
HEX64(RowAddress) <<
" and the next one.\n";
347 LineEntry LE(RowAddress, FileIdx, Row.Line);
348 if (RowIndex != RowVector[0] && Row.Address < PrevRow.
Address) {
356 if (FirstLE && *FirstLE == LE) {
358 *Log <<
"warning: duplicate line table detected for DIE:\n";
363 *Log <<
"error: line table has addresses that do not "
364 <<
"monotonically increase:\n";
365 for (
uint32_t RowIndex2 : RowVector)
375 if (LastLE && LastLE->File == FileIdx && LastLE->Line == Row.Line)
380 if (Row.EndSequence) {
399 case dwarf::DW_TAG_subprogram: {
401 if (!RangesOrError) {
412 <<
" has no name\n ";
447 if (
Range.LowPC != 0) {
451 *
OS <<
"warning: DIE has an address range whose start address "
452 "is not in any executable sections ("
454 <<
") and will not be processed:\n";
464 FI.
Name = *NameIndex;
470 FI.
Inline->Name = *NameIndex;
472 bool WarnIfEmpty =
true;
474 AllSubprogramRanges, WarnIfEmpty);
484 if (FI.
Inline->Children.empty()) {
485 if (WarnIfEmpty &&
OS && !Gsym.
isQuiet()) {
486 *
OS <<
"warning: DIE contains inline function information that has "
487 "no valid ranges, removing inline information:\n";
500 handleDie(
OS, CUI, ChildDie);
512 {dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
514 *
OS <<
"warning: Unable to retrieve DWO .debug_info section for "
522 if (NumThreads == 1) {
527 CUInfo CUI(DICtx, dyn_cast<DWARFCompileUnit>(
CU.get()));
528 handleDie(
OS, CUI, Die);
539 CU->getAbbreviations();
545 pool.
async([&
CU]() {
CU->getUnitDIE(
false ); });
553 CUInfo CUI(DICtx, dyn_cast<DWARFCompileUnit>(
CU.get()));
554 pool.
async([
this, CUI, &LogMutex,
OS, Die]()
mutable {
555 std::string ThreadLogStorage;
557 handleDie(
OS ? &ThreadOS:
nullptr, CUI, Die);
559 if (
OS && !ThreadLogStorage.empty()) {
561 std::lock_guard<std::mutex> guard(LogMutex);
562 *
OS << ThreadLogStorage;
571 *
OS <<
"Loaded " << FunctionsAddedCount <<
" functions from DWARF.\n";
576 Log <<
"Verifying GSYM file \"" << GsymPath <<
"\":\n";
580 return Gsym.takeError();
582 auto NumAddrs = Gsym->getNumAddresses();
584 DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
585 DILineInfoSpecifier::FunctionNameKind::LinkageName);
586 std::string gsymFilename;
588 auto FuncAddr = Gsym->getAddress(
I);
591 "failed to extract address[%i]",
I);
593 auto FI = Gsym->getFunctionInfo(*FuncAddr);
596 "failed to extract function info for address 0x%"
602 auto LR = Gsym->lookup(
Addr);
604 return LR.takeError();
606 auto DwarfInlineInfos =
608 uint32_t NumDwarfInlineInfos = DwarfInlineInfos.getNumberOfFrames();
609 if (NumDwarfInlineInfos == 0) {
610 DwarfInlineInfos.addFrame(
615 if (NumDwarfInlineInfos == 1 &&
616 DwarfInlineInfos.getFrame(0).FileName ==
"<invalid>") {
618 NumDwarfInlineInfos = 0;
620 if (NumDwarfInlineInfos > 0 &&
621 NumDwarfInlineInfos != LR->Locations.size()) {
622 Log <<
"error: address " <<
HEX64(
Addr) <<
" has "
623 << NumDwarfInlineInfos <<
" DWARF inline frames and GSYM has "
624 << LR->Locations.size() <<
"\n";
625 Log <<
" " << NumDwarfInlineInfos <<
" DWARF frames:\n";
626 for (
size_t Idx = 0;
Idx < NumDwarfInlineInfos; ++
Idx) {
627 const auto &dii = DwarfInlineInfos.getFrame(
Idx);
628 Log <<
" [" <<
Idx <<
"]: " << dii.FunctionName <<
" @ "
629 << dii.FileName <<
':' << dii.Line <<
'\n';
631 Log <<
" " << LR->Locations.size() <<
" GSYM frames:\n";
632 for (
size_t Idx = 0,
count = LR->Locations.size();
634 const auto &gii = LR->Locations[
Idx];
635 Log <<
" [" <<
Idx <<
"]: " << gii.Name <<
" @ " << gii.Dir
636 <<
'/' << gii.Base <<
':' << gii.Line <<
'\n';
639 Gsym->dump(Log, *FI);
645 const auto &gii = LR->Locations[
Idx];
646 if (
Idx < NumDwarfInlineInfos) {
647 const auto &dii = DwarfInlineInfos.getFrame(
Idx);
648 gsymFilename = LR->getSourceFile(
Idx);
650 if (dii.FunctionName.find(gii.Name.str()) != 0)
651 Log <<
"error: address " <<
HEX64(
Addr) <<
" DWARF function \""
652 << dii.FunctionName.c_str()
653 <<
"\" doesn't match GSYM function \"" << gii.Name <<
"\"\n";
655 if (dii.FileName != gsymFilename)
656 Log <<
"error: address " <<
HEX64(
Addr) <<
" DWARF path \""
657 << dii.FileName.c_str() <<
"\" doesn't match GSYM path \""
658 << gsymFilename.c_str() <<
"\"\n";
660 if (dii.Line != gii.Line)
661 Log <<
"error: address " <<
HEX64(
Addr) <<
" DWARF line "
662 << dii.Line <<
" != GSYM line " << gii.Line <<
"\n";
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A class that represents an address range.
bool contains(uint64_t Addr) const
bool contains(uint64_t Addr) const
The AddressRanges class helps normalize address range collections.
Collection::const_iterator insert(AddressRange Range)
A format-neutral container for inlined code description.
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
DIInliningInfo getInliningInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
DILineInfo getLineInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
compile_unit_range compile_units()
Get compile units in this context.
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *U)
Get a pointer to a parsed line table corresponding to a compile unit.
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
uint64_t getOffset() const
Get the absolute offset into the debug info or types section.
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
iterator_range< iterator > children() const
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
DWARFDie getParent() const
Get the parent of this DIE object.
std::optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
std::optional< DWARFFormValue > findRecursively(ArrayRef< dwarf::Attribute > Attrs) const
Extract the first value of any attribute in Attrs from this DIE and recurse into any DW_AT_specificat...
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_specification or DW_AT_abstract_origin references if necessary.
std::string getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const
dwarf::Tag getTag() const
void dump(raw_ostream &OS, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
Dump the DIE and all of its attributes to the supplied stream.
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
This dwarf writer support class manages information associated with a source file.
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.
reference get()
Returns a reference to the stored T value.
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
constexpr bool empty() const
empty - Check if the string is empty.
char back() const
back - Get the last character in the string.
constexpr size_t size() const
size - Get the string size.
char front() const
front - Get the first character in the string.
A ThreadPool for asynchronous parallel execution on a defined number of threads.
void wait()
Blocking wait for all the threads to complete and the queue to be empty.
auto async(Function &&F, Args &&...ArgList)
Asynchronous submission of a task to the pool.
GsymCreator is used to emit GSYM data to a stand alone file or section within a file.
void addFunctionInfo(FunctionInfo &&FI)
Add a function info to this GSYM creator.
uint32_t insertString(StringRef S, bool Copy=true)
Insert a string into the GSYM string table.
const std::optional< AddressRanges > GetValidTextRanges() const
Get the valid text ranges.
bool isQuiet() const
Whether the transformation should be quiet, i.e. not output warnings.
uint32_t insertFile(StringRef Path, sys::path::Style Style=sys::path::Style::native)
Insert a file into this GSYM creator.
size_t getNumFunctionInfos() const
Get the current number of FunctionInfo objects contained in this object.
bool IsValidTextAddress(uint64_t Addr) const
Check if an address is a valid code address.
static llvm::Expected< GsymReader > openFile(StringRef Path)
Construct a GsymReader from a file on disk.
LineTable class contains deserialized versions of line tables for each function's address ranges.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< uint64_t > toUnsigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
This is an optimization pass for GlobalISel generic memory operations.
ThreadPoolStrategy hardware_concurrency(unsigned ThreadCount=0)
Returns a default thread strategy where all available hardware resources are to be used,...
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
std::function< Expected< AddStreamFn >(unsigned Task, StringRef Key, const Twine &ModuleName)> FileCache
This is the type of a file cache.
void consumeError(Error Err)
Consume a Error without doing anything.
static DIDumpOptions getForSingleDIE()
Return default option set for printing a single DIE without children.
Controls which fields of DILineInfo container should be filled with data.
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size, std::vector< uint32_t > &Result) const
Standard .debug_line state machine structure.
object::SectionedAddress Address
The program-counter value corresponding to a machine instruction generated by the compiler and sectio...
const DWARFDebugLine::LineTable * LineTable
uint32_t DWARFToGSYMFileIndex(GsymCreator &Gsym, uint32_t DwarfFileIdx)
Convert a DWARF compile unit file index into a GSYM global file index.
CUInfo(DWARFContext &DICtx, DWARFCompileUnit *CU)
bool isHighestAddress(uint64_t Addr) const
Return true if Addr is the highest address for a given compile unit.
std::vector< uint32_t > FileCache
Function information in GSYM files encodes information for one contiguous address range.
std::optional< InlineInfo > Inline
uint64_t startAddress() const
uint64_t endAddress() const
uint32_t Name
String table offset in the string table.
std::optional< LineTable > OptLineTable
Inline information stores the name of the inline function along with an array of address ranges.
std::vector< InlineInfo > Children
uint32_t CallFile
1 based file index in the file table.
uint32_t CallLine
Source line number.
uint32_t Name
String table offset in the string table.
Line entries are used to encode the line tables in FunctionInfo objects.
static const uint64_t UndefSection