29 using namespace dwarf;
35 struct ContentDescriptor {
47 TotalLength = PrologueLength = 0;
49 MinInstLength = MaxOpsPerInst = DefaultIsStmt = LineBase = LineRange = 0;
52 StandardOpcodeLengths.clear();
53 IncludeDirectories.clear();
58 OS <<
"Line table prologue:\n"
59 <<
format(
" total_length: 0x%8.8" PRIx64
"\n", TotalLength)
60 <<
format(
" version: %u\n", getVersion());
61 if (getVersion() >= 5)
62 OS <<
format(
" address_size: %u\n", getAddressSize())
63 <<
format(
" seg_select_size: %u\n", SegSelectorSize);
64 OS <<
format(
" prologue_length: 0x%8.8" PRIx64
"\n", PrologueLength)
65 <<
format(
" min_inst_length: %u\n", MinInstLength)
66 <<
format(getVersion() >= 4 ?
"max_ops_per_inst: %u\n" :
"", MaxOpsPerInst)
67 <<
format(
" default_is_stmt: %u\n", DefaultIsStmt)
68 <<
format(
" line_base: %i\n", LineBase)
69 <<
format(
" line_range: %u\n", LineRange)
70 <<
format(
" opcode_base: %u\n", OpcodeBase);
72 for (
uint32_t I = 0;
I != StandardOpcodeLengths.size(); ++
I)
73 OS <<
format(
"standard_opcode_lengths[%s] = %u\n",
76 if (!IncludeDirectories.empty())
77 for (
uint32_t I = 0;
I != IncludeDirectories.size(); ++
I)
78 OS <<
format(
"include_directories[%3u] = '",
I + 1)
79 << IncludeDirectories[
I] <<
"'\n";
81 if (!FileNames.empty()) {
82 OS <<
" Dir Mod Time File Len File Name\n"
83 <<
" ---- ---------- ---------- -----------"
87 OS <<
format(
"file_names[%3u] %4" PRIu64
" ",
I + 1, FileEntry.
DirIdx)
88 <<
format(
"0x%8.8" PRIx64
" 0x%8.8" PRIx64
" ", FileEntry.
ModTime,
90 << FileEntry.
Name <<
'\n';
98 uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
99 std::vector<StringRef> &IncludeDirectories,
100 std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
101 while (*OffsetPtr < EndPrologueOffset) {
105 IncludeDirectories.push_back(S);
108 while (*OffsetPtr < EndPrologueOffset) {
117 FileNames.push_back(FileEntry);
124 static ContentDescriptors
126 uint64_t EndPrologueOffset) {
127 ContentDescriptors Descriptors;
128 int FormatCount = DebugLineData.
getU8(OffsetPtr);
129 bool HasPath =
false;
130 for (
int I = 0;
I != FormatCount; ++
I) {
131 if (*OffsetPtr >= EndPrologueOffset)
132 return ContentDescriptors();
133 ContentDescriptor Descriptor;
137 if (Descriptor.Type == dwarf::DW_LNCT_path)
139 Descriptors.push_back(Descriptor);
141 return HasPath ? Descriptors : ContentDescriptors();
146 uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
148 std::vector<StringRef> &IncludeDirectories,
149 std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
151 ContentDescriptors DirDescriptors =
153 if (DirDescriptors.empty())
157 int DirEntryCount = DebugLineData.
getU8(OffsetPtr);
158 for (
int I = 0;
I != DirEntryCount; ++
I) {
159 if (*OffsetPtr >= EndPrologueOffset)
161 for (
auto Descriptor : DirDescriptors) {
163 switch (Descriptor.Type) {
165 if (!Value.
extractValue(DebugLineData, OffsetPtr,
nullptr))
167 IncludeDirectories.push_back(Value.
getAsCString().getValue());
170 if (!Value.
skipValue(DebugLineData, OffsetPtr, FormParams))
177 ContentDescriptors FileDescriptors =
179 if (FileDescriptors.empty())
183 int FileEntryCount = DebugLineData.
getU8(OffsetPtr);
184 for (
int I = 0;
I != FileEntryCount; ++
I) {
185 if (*OffsetPtr >= EndPrologueOffset)
188 for (
auto Descriptor : FileDescriptors) {
190 if (!Value.
extractValue(DebugLineData, OffsetPtr,
nullptr))
192 switch (Descriptor.Type) {
196 case DW_LNCT_directory_index:
199 case DW_LNCT_timestamp:
210 FileNames.push_back(FileEntry);
217 const uint64_t PrologueOffset = *OffsetPtr;
220 TotalLength = DebugLineData.
getU32(OffsetPtr);
221 if (TotalLength == UINT32_MAX) {
223 TotalLength = DebugLineData.
getU64(OffsetPtr);
224 }
else if (TotalLength >= 0xffffff00) {
227 FormParams.Version = DebugLineData.
getU16(OffsetPtr);
228 if (getVersion() < 2)
231 if (getVersion() >= 5) {
232 FormParams.AddrSize = DebugLineData.
getU8(OffsetPtr);
234 "Line table header and data extractor disagree");
235 SegSelectorSize = DebugLineData.
getU8(OffsetPtr);
238 PrologueLength = DebugLineData.
getUnsigned(OffsetPtr, sizeofPrologueLength());
239 const uint64_t EndPrologueOffset = PrologueLength + *OffsetPtr;
240 MinInstLength = DebugLineData.
getU8(OffsetPtr);
241 if (getVersion() >= 4)
242 MaxOpsPerInst = DebugLineData.
getU8(OffsetPtr);
243 DefaultIsStmt = DebugLineData.
getU8(OffsetPtr);
244 LineBase = DebugLineData.
getU8(OffsetPtr);
245 LineRange = DebugLineData.
getU8(OffsetPtr);
246 OpcodeBase = DebugLineData.
getU8(OffsetPtr);
248 StandardOpcodeLengths.reserve(OpcodeBase - 1);
250 uint8_t OpLen = DebugLineData.
getU8(OffsetPtr);
251 StandardOpcodeLengths.push_back(OpLen);
254 if (getVersion() >= 5) {
256 getFormParams(), IncludeDirectories, FileNames)) {
258 "warning: parsing line table prologue at 0x%8.8" PRIx64
259 " found an invalid directory or file table description at"
260 " 0x%8.8" PRIx64
"\n", PrologueOffset, (uint64_t)*OffsetPtr);
265 IncludeDirectories, FileNames);
267 if (*OffsetPtr != EndPrologueOffset) {
269 "warning: parsing line table prologue at 0x%8.8" PRIx64
270 " should have ended at 0x%8.8" PRIx64
271 " but it ended at 0x%8.8" PRIx64
"\n",
272 PrologueOffset, EndPrologueOffset, (uint64_t)*OffsetPtr);
283 EpilogueBegin =
false;
293 IsStmt = DefaultIsStmt;
297 EpilogueBegin =
false;
301 OS <<
"Address Line Column File ISA Discriminator Flags\n"
302 <<
"------------------ ------ ------ ------ --- ------------- "
307 OS <<
format(
"0x%16.16" PRIx64
" %6u %6u",
Address, Line, Column)
308 <<
format(
" %6u %3u %13u ",
File, Isa, Discriminator)
309 << (IsStmt ?
" is_stmt" :
"") << (
BasicBlock ?
" basic_block" :
"")
310 << (PrologueEnd ?
" prologue_end" :
"")
311 << (EpilogueBegin ?
" epilogue_begin" :
"")
312 << (EndSequence ?
" end_sequence" :
"") <<
'\n';
332 Row::dumpTableHeader(OS);
333 for (
const Row &R : Rows) {
345 DWARFDebugLine::ParsingState::ParsingState(
struct LineTable *
LT)
347 resetRowAndSequence();
350 void DWARFDebugLine::ParsingState::resetRowAndSequence() {
351 Row.reset(LineTable->Prologue.DefaultIsStmt);
355 void DWARFDebugLine::ParsingState::appendRowToMatrix(
uint32_t Offset) {
363 LineTable->appendRow(Row);
364 if (Row.EndSequence) {
369 LineTable->appendSequence(
Sequence);
377 LineTableConstIter Pos = LineTableMap.find(Offset);
378 if (Pos != LineTableMap.end())
386 std::pair<LineTableIter, bool> Pos =
387 LineTableMap.insert(LineTableMapTy::value_type(Offset,
LineTable()));
390 if (!LT->
parse(DebugLineData, &Offset))
398 const uint32_t DebugLineOffset = *OffsetPtr;
404 *OffsetPtr = DebugLineOffset;
411 ParsingState State(
this);
413 while (*OffsetPtr < EndOffset) {
414 uint8_t Opcode = DebugLineData.
getU8(OffsetPtr);
420 uint64_t Len = DebugLineData.
getULEB128(OffsetPtr);
421 uint32_t ArgSize = Len - (*OffsetPtr - ExtOffset);
423 uint8_t SubOpcode = DebugLineData.
getU8(OffsetPtr);
425 case DW_LNE_end_sequence:
433 State.Row.EndSequence =
true;
434 State.appendRowToMatrix(*OffsetPtr);
435 State.resetRowAndSequence();
438 case DW_LNE_set_address:
448 case DW_LNE_define_file:
479 case DW_LNE_set_discriminator:
480 State.Row.Discriminator = DebugLineData.
getULEB128(OffsetPtr);
486 (*OffsetPtr) += ArgSize;
496 State.appendRowToMatrix(*OffsetPtr);
499 case DW_LNS_advance_pc:
507 case DW_LNS_advance_line:
510 State.Row.Line += DebugLineData.
getSLEB128(OffsetPtr);
513 case DW_LNS_set_file:
516 State.Row.File = DebugLineData.
getULEB128(OffsetPtr);
519 case DW_LNS_set_column:
522 State.Row.Column = DebugLineData.
getULEB128(OffsetPtr);
525 case DW_LNS_negate_stmt:
528 State.Row.IsStmt = !State.Row.IsStmt;
531 case DW_LNS_set_basic_block:
534 State.Row.BasicBlock =
true;
537 case DW_LNS_const_add_pc:
551 uint64_t AddrOffset =
553 State.Row.Address += AddrOffset;
557 case DW_LNS_fixed_advance_pc:
567 State.Row.Address += DebugLineData.
getU16(OffsetPtr);
570 case DW_LNS_set_prologue_end:
573 State.Row.PrologueEnd =
true;
576 case DW_LNS_set_epilogue_begin:
579 State.Row.EpilogueBegin =
true;
585 State.Row.Isa = DebugLineData.
getULEB128(OffsetPtr);
595 for (uint8_t
I = 0;
I < OpcodeLength; ++
I)
635 uint64_t AddrOffset =
639 State.Row.Line += LineOffset;
640 State.Row.Address += AddrOffset;
641 State.appendRowToMatrix(*OffsetPtr);
643 State.Row.Discriminator = 0;
647 if (!State.Sequence.Empty) {
648 fprintf(stderr,
"warning: last sequence in debug line table is not"
653 if (!Sequences.empty()) {
670 return UnknownRowIndex;
680 if (RowPos == LastRow) {
684 if (RowPos->Address > Address) {
685 if (RowPos == FirstRow)
686 return UnknownRowIndex;
694 if (Sequences.empty())
695 return UnknownRowIndex;
704 if (SeqPos == LastSeq) {
705 FoundSeq = Sequences.back();
706 }
else if (SeqPos->LowPC == Address) {
709 if (SeqPos == FirstSeq)
710 return UnknownRowIndex;
711 FoundSeq = *(SeqPos - 1);
713 return findRowInSeq(FoundSeq, Address);
717 uint64_t Address, uint64_t
Size, std::vector<uint32_t> &Result)
const {
718 if (Sequences.empty())
720 uint64_t EndAddr = Address +
Size;
728 if (SeqPos == LastSeq || SeqPos->LowPC != Address) {
729 if (SeqPos == FirstSeq)
733 if (!SeqPos->containsPC(Address))
741 while (SeqPos != LastSeq && SeqPos->LowPC < EndAddr) {
746 if (SeqPos == StartPos)
747 FirstRowIndex = findRowInSeq(CurSeq, Address);
750 uint32_t LastRowIndex = findRowInSeq(CurSeq, EndAddr - 1);
751 if (LastRowIndex == UnknownRowIndex)
754 assert(FirstRowIndex != UnknownRowIndex);
755 assert(LastRowIndex != UnknownRowIndex);
757 for (
uint32_t I = FirstRowIndex;
I <= LastRowIndex; ++
I) {
774 std::string &Result)
const {
779 if (Kind != FileLineInfoKind::AbsoluteFilePath ||
786 uint64_t IncludeDirIndex = Entry.
DirIdx;
789 if (IncludeDirIndex > 0 &&
796 if (CompDir && Kind == FileLineInfoKind::AbsoluteFilePath &&
802 Result = FilePath.
str();
810 uint32_t RowIndex = lookupAddress(Address);
814 const auto &Row = Rows[RowIndex];
815 if (!getFileNameByIndex(Row.
File, CompDir, Kind, Result.
FileName))
SequenceVector::const_iterator SequenceIter
uint64_t LowPC
Sequence describes instructions at address range [LowPC, HighPC) and is described by line table rows ...
const LineTable * getLineTable(uint32_t Offset) const
Row(bool DefaultIsStmt=false)
bool parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr)
Parse prologue and all rows.
static bool orderByAddress(const Row &LHS, const Row &RHS)
StringRef LNStandardString(unsigned Standard)
bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, std::string &Result) const
Extracts filename by its index in filename table in prologue.
uint8_t MinInstLength
The size in bytes of the smallest target machine instruction.
uint32_t Line
An unsigned integer indicating a source line number.
DILineInfo - a format-neutral container for source line information.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Represents a series of contiguous machine instructions.
uint64_t Address
The program-counter value corresponding to a machine instruction generated by the compiler...
void postAppend()
Called after a row is appended to the matrix.
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
uint8_t LineRange
This parameter affects the meaning of the special opcodes. See below.
uint8_t OpcodeBase
The number assigned to the first special opcode.
void reset(bool DefaultIsStmt)
const T & getValue() const LLVM_LVALUE_FUNCTION
bool parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr)
uint64_t TotalLength
The size in bytes of the statement information for this compilation unit (not including the total_len...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
static ContentDescriptors parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, uint64_t EndPrologueOffset)
static void parseV2DirFileTables(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, uint64_t EndPrologueOffset, std::vector< StringRef > &IncludeDirectories, std::vector< DWARFDebugLine::FileNameEntry > &FileNames)
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
LLVM Basic Block Representation.
uint16_t File
An unsigned integer indicating the identity of the source file corresponding to a machine instruction...
void dump(raw_ostream &OS) const
void dump(raw_ostream &OS) const
void dump(raw_ostream &OS) const
Standard .debug_line state machine structure.
uint16_t Column
An unsigned integer indicating a column number within a source line.
bool hasFileAtIndex(uint64_t FileIndex) const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
uint32_t sizeofTotalLength() const
bool lookupAddressRange(uint64_t Address, uint64_t Size, std::vector< uint32_t > &Result) const
static void dumpTableHeader(raw_ostream &OS)
std::vector< uint8_t > StandardOpcodeLengths
StringRef str() const
Explicit conversion to StringRef.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
static bool parseV5DirFileTables(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, uint64_t EndPrologueOffset, const DWARFFormParams &FormParams, std::vector< StringRef > &IncludeDirectories, std::vector< DWARFDebugLine::FileNameEntry > &FileNames)
static void clear(coro::Shape &Shape)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
std::vector< FileNameEntry > FileNames
uint32_t lookupAddress(uint64_t Address) const
Returns the index of the row with file/line info for a given address, or UnknownRowIndex if there is ...
uint32_t Discriminator
An unsigned integer representing the DWARF path discriminator value for this location.
RowVector::const_iterator RowIter
static bool orderByLowPC(const Sequence &LHS, const Sequence &RHS)
bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
Sequence
A sequence of states that a pointer may go through in which an objc_retain and objc_release are actua...
bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, DILineInfo &Result) const
Fills the Result argument with the file and line information corresponding to Address.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
int8_t LineBase
This parameter affects the meaning of the special opcodes. See below.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool containsPC(uint64_t PC) const
StringRef - Represent a constant reference to a string, i.e.
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
const LineTable * getOrParseLineTable(const DWARFDataExtractor &DebugLineData, uint32_t Offset)
std::vector< StringRef > IncludeDirectories