@@ -66,6 +66,26 @@ void DWARFDebugLine::ContentTypeTracker::trackContentType(
66
66
67
67
DWARFDebugLine::Prologue::Prologue () { clear (); }
68
68
69
+ bool DWARFDebugLine::Prologue::hasFileAtIndex (uint64_t FileIndex) const {
70
+ uint16_t DwarfVersion = getVersion ();
71
+ assert (DwarfVersion != 0 &&
72
+ " line table prologue has no dwarf version information" );
73
+ if (DwarfVersion >= 5 )
74
+ return FileIndex < FileNames.size ();
75
+ return FileIndex != 0 && FileIndex <= FileNames.size ();
76
+ }
77
+
78
+ const llvm::DWARFDebugLine::FileNameEntry &
79
+ DWARFDebugLine::Prologue::getFileNameEntry (uint64_t Index) const {
80
+ uint16_t DwarfVersion = getVersion ();
81
+ assert (DwarfVersion != 0 &&
82
+ " line table prologue has no dwarf version information" );
83
+ // In DWARF v5 the file names are 0-indexed.
84
+ if (DwarfVersion >= 5 )
85
+ return FileNames[Index];
86
+ return FileNames[Index - 1 ];
87
+ }
88
+
69
89
void DWARFDebugLine::Prologue::clear () {
70
90
TotalLength = PrologueLength = 0 ;
71
91
SegSelectorSize = 0 ;
@@ -968,30 +988,11 @@ bool DWARFDebugLine::LineTable::lookupAddressRangeImpl(
968
988
return true ;
969
989
}
970
990
971
- bool DWARFDebugLine::LineTable::hasFileAtIndex (uint64_t FileIndex) const {
972
- uint16_t DwarfVersion = Prologue.getVersion ();
973
- assert (DwarfVersion != 0 && " LineTable has no dwarf version information" );
974
- if (DwarfVersion >= 5 )
975
- return FileIndex < Prologue.FileNames .size ();
976
- return FileIndex != 0 && FileIndex <= Prologue.FileNames .size ();
977
- }
978
-
979
- const llvm::DWARFDebugLine::FileNameEntry &
980
- DWARFDebugLine::LineTable::getFileNameEntry (uint64_t Index) const {
981
- uint16_t DwarfVersion = Prologue.getVersion ();
982
- assert (DwarfVersion != 0 && " LineTable has no dwarf version information" );
983
- // In DWARF v5 the file names are 0-indexed.
984
- if (DwarfVersion >= 5 )
985
- return Prologue.FileNames [Index];
986
- else
987
- return Prologue.FileNames [Index - 1 ];
988
- }
989
-
990
991
Optional<StringRef> DWARFDebugLine::LineTable::getSourceByIndex (uint64_t FileIndex,
991
992
FileLineInfoKind Kind) const {
992
- if (Kind == FileLineInfoKind::None || !hasFileAtIndex (FileIndex))
993
+ if (Kind == FileLineInfoKind::None || !Prologue. hasFileAtIndex (FileIndex))
993
994
return None;
994
- const FileNameEntry &Entry = getFileNameEntry (FileIndex);
995
+ const FileNameEntry &Entry = Prologue. getFileNameEntry (FileIndex);
995
996
if (Optional<const char *> source = Entry.Source .getAsCString ())
996
997
return StringRef (*source);
997
998
return None;
@@ -1005,10 +1006,10 @@ static bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {
1005
1006
sys::path::is_absolute (Path, sys::path::Style ::windows);
1006
1007
}
1007
1008
1008
- bool DWARFDebugLine::LineTable ::getFileNameByIndex (uint64_t FileIndex,
1009
- const char * CompDir,
1010
- FileLineInfoKind Kind,
1011
- std::string &Result) const {
1009
+ bool DWARFDebugLine::Prologue ::getFileNameByIndex (uint64_t FileIndex,
1010
+ StringRef CompDir,
1011
+ FileLineInfoKind Kind,
1012
+ std::string &Result) const {
1012
1013
if (Kind == FileLineInfoKind::None || !hasFileAtIndex (FileIndex))
1013
1014
return false ;
1014
1015
const FileNameEntry &Entry = getFileNameEntry (FileIndex);
@@ -1022,20 +1023,18 @@ bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
1022
1023
SmallString<16 > FilePath;
1023
1024
StringRef IncludeDir;
1024
1025
// Be defensive about the contents of Entry.
1025
- if (Prologue.getVersion () >= 5 ) {
1026
- if (Entry.DirIdx < Prologue.IncludeDirectories .size ())
1027
- IncludeDir =
1028
- Prologue.IncludeDirectories [Entry.DirIdx ].getAsCString ().getValue ();
1026
+ if (getVersion () >= 5 ) {
1027
+ if (Entry.DirIdx < IncludeDirectories.size ())
1028
+ IncludeDir = IncludeDirectories[Entry.DirIdx ].getAsCString ().getValue ();
1029
1029
} else {
1030
- if (0 < Entry.DirIdx && Entry.DirIdx <= Prologue.IncludeDirectories .size ())
1031
- IncludeDir = Prologue.IncludeDirectories [Entry.DirIdx - 1 ]
1032
- .getAsCString ()
1033
- .getValue ();
1030
+ if (0 < Entry.DirIdx && Entry.DirIdx <= IncludeDirectories.size ())
1031
+ IncludeDir =
1032
+ IncludeDirectories[Entry.DirIdx - 1 ].getAsCString ().getValue ();
1034
1033
1035
1034
// We may still need to append compilation directory of compile unit.
1036
1035
// We know that FileName is not absolute, the only way to have an
1037
1036
// absolute path at this point would be if IncludeDir is absolute.
1038
- if (CompDir && !isPathAbsoluteOnWindowsOrPosix (IncludeDir))
1037
+ if (! CompDir. empty () && !isPathAbsoluteOnWindowsOrPosix (IncludeDir))
1039
1038
sys::path::append (FilePath, CompDir);
1040
1039
}
1041
1040
0 commit comments