mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-13 19:40:26 +00:00
Make DWARFDebugLine use StringRef for directory/file tables. NFC
Differential Revision: http://reviews.llvm.org/D32728 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301940 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3322bb7af5
commit
ac4b289dce
@ -30,7 +30,7 @@ public:
|
|||||||
struct FileNameEntry {
|
struct FileNameEntry {
|
||||||
FileNameEntry() = default;
|
FileNameEntry() = default;
|
||||||
|
|
||||||
const char *Name = nullptr;
|
StringRef Name = StringRef();
|
||||||
uint64_t DirIdx = 0;
|
uint64_t DirIdx = 0;
|
||||||
uint64_t ModTime = 0;
|
uint64_t ModTime = 0;
|
||||||
uint64_t Length = 0;
|
uint64_t Length = 0;
|
||||||
@ -63,7 +63,7 @@ public:
|
|||||||
/// The number assigned to the first special opcode.
|
/// The number assigned to the first special opcode.
|
||||||
uint8_t OpcodeBase;
|
uint8_t OpcodeBase;
|
||||||
std::vector<uint8_t> StandardOpcodeLengths;
|
std::vector<uint8_t> StandardOpcodeLengths;
|
||||||
std::vector<const char *> IncludeDirectories;
|
std::vector<StringRef> IncludeDirectories;
|
||||||
std::vector<FileNameEntry> FileNames;
|
std::vector<FileNameEntry> FileNames;
|
||||||
|
|
||||||
bool IsDWARF64;
|
bool IsDWARF64;
|
||||||
|
@ -58,6 +58,28 @@ public:
|
|||||||
/// NULL will be returned.
|
/// NULL will be returned.
|
||||||
const char *getCStr(uint32_t *offset_ptr) const;
|
const char *getCStr(uint32_t *offset_ptr) const;
|
||||||
|
|
||||||
|
/// Extract a C string from \a *OffsetPtr.
|
||||||
|
///
|
||||||
|
/// Returns a StringRef for the C String from the data at the offset
|
||||||
|
/// pointed to by \a OffsetPtr. A variable length NULL terminated C
|
||||||
|
/// string will be extracted and the \a OffsetPtr will be
|
||||||
|
/// updated with the offset of the byte that follows the NULL
|
||||||
|
/// terminator byte.
|
||||||
|
///
|
||||||
|
/// \param[in,out] OffsetPtr
|
||||||
|
/// A pointer to an offset within the data that will be advanced
|
||||||
|
/// by the appropriate number of bytes if the value is extracted
|
||||||
|
/// correctly. If the offset is out of bounds or there are not
|
||||||
|
/// enough bytes to extract this value, the offset will be left
|
||||||
|
/// unmodified.
|
||||||
|
///
|
||||||
|
/// \return
|
||||||
|
/// A StringRef for the C string value in the data. If the offset
|
||||||
|
/// pointed to by \a OffsetPtr is out of bounds, or if the
|
||||||
|
/// offset plus the length of the C string is out of bounds,
|
||||||
|
/// a default-initialized StringRef will be returned.
|
||||||
|
StringRef getCStrRef(uint32_t *OffsetPtr) const;
|
||||||
|
|
||||||
/// Extract an unsigned integer of size \a byte_size from \a
|
/// Extract an unsigned integer of size \a byte_size from \a
|
||||||
/// *offset_ptr.
|
/// *offset_ptr.
|
||||||
///
|
///
|
||||||
|
@ -107,25 +107,22 @@ bool DWARFDebugLine::Prologue::parse(DataExtractor DebugLineData,
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (*OffsetPtr < EndPrologueOffset) {
|
while (*OffsetPtr < EndPrologueOffset) {
|
||||||
const char *S = DebugLineData.getCStr(OffsetPtr);
|
StringRef S = DebugLineData.getCStrRef(OffsetPtr);
|
||||||
if (S && S[0])
|
if (S.empty())
|
||||||
IncludeDirectories.push_back(S);
|
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
|
IncludeDirectories.push_back(S);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*OffsetPtr < EndPrologueOffset) {
|
while (*OffsetPtr < EndPrologueOffset) {
|
||||||
const char *Name = DebugLineData.getCStr(OffsetPtr);
|
StringRef Name = DebugLineData.getCStrRef(OffsetPtr);
|
||||||
if (Name && Name[0]) {
|
if (Name.empty())
|
||||||
FileNameEntry FileEntry;
|
|
||||||
FileEntry.Name = Name;
|
|
||||||
FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
|
|
||||||
FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
|
|
||||||
FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
|
|
||||||
FileNames.push_back(FileEntry);
|
|
||||||
} else {
|
|
||||||
break;
|
break;
|
||||||
}
|
FileNameEntry FileEntry;
|
||||||
|
FileEntry.Name = Name;
|
||||||
|
FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
|
||||||
|
FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
|
||||||
|
FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
|
||||||
|
FileNames.push_back(FileEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*OffsetPtr != EndPrologueOffset) {
|
if (*OffsetPtr != EndPrologueOffset) {
|
||||||
@ -637,7 +634,7 @@ bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
|
|||||||
if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
|
if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
|
||||||
return false;
|
return false;
|
||||||
const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
|
const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
|
||||||
const char *FileName = Entry.Name;
|
StringRef FileName = Entry.Name;
|
||||||
if (Kind != FileLineInfoKind::AbsoluteFilePath ||
|
if (Kind != FileLineInfoKind::AbsoluteFilePath ||
|
||||||
sys::path::is_absolute(FileName)) {
|
sys::path::is_absolute(FileName)) {
|
||||||
Result = FileName;
|
Result = FileName;
|
||||||
@ -646,7 +643,7 @@ bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
|
|||||||
|
|
||||||
SmallString<16> FilePath;
|
SmallString<16> FilePath;
|
||||||
uint64_t IncludeDirIndex = Entry.DirIdx;
|
uint64_t IncludeDirIndex = Entry.DirIdx;
|
||||||
const char *IncludeDir = "";
|
StringRef IncludeDir;
|
||||||
// Be defensive about the contents of Entry.
|
// Be defensive about the contents of Entry.
|
||||||
if (IncludeDirIndex > 0 &&
|
if (IncludeDirIndex > 0 &&
|
||||||
IncludeDirIndex <= Prologue.IncludeDirectories.size())
|
IncludeDirIndex <= Prologue.IncludeDirectories.size())
|
||||||
|
@ -128,6 +128,16 @@ const char *DataExtractor::getCStr(uint32_t *offset_ptr) const {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringRef DataExtractor::getCStrRef(uint32_t *OffsetPtr) const {
|
||||||
|
uint32_t Start = *OffsetPtr;
|
||||||
|
StringRef::size_type Pos = Data.find('\0', Start);
|
||||||
|
if (Pos != StringRef::npos) {
|
||||||
|
*OffsetPtr = Pos + 1;
|
||||||
|
return StringRef(Data.data() + Start, Pos - Start);
|
||||||
|
}
|
||||||
|
return StringRef();
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t DataExtractor::getULEB128(uint32_t *offset_ptr) const {
|
uint64_t DataExtractor::getULEB128(uint32_t *offset_ptr) const {
|
||||||
uint64_t result = 0;
|
uint64_t result = 0;
|
||||||
if (Data.empty())
|
if (Data.empty())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user