Skip to content

Commit de0ce98

Browse files
committed
[DebugLine] Don't try to guess the path style
In r368879 I made an attempt to guess the path style from the files in the line table. After some consideration I now think this is a poor idea. This patch undoes that behavior and instead adds an optional argument to specify the path style. This allows us to make that decision elsewhere where we have more information. In case of LLDB based on the Unit. llvm-svn: 369072
1 parent 4660ea9 commit de0ce98

File tree

3 files changed

+23
-45
lines changed

3 files changed

+23
-45
lines changed

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,10 @@ ParseLLVMLineTable(lldb_private::DWARFContext &context,
178178
return *line_table;
179179
}
180180

181-
static FileSpecList
182-
ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
183-
const llvm::DWARFDebugLine::Prologue &prologue,
184-
llvm::StringRef compile_dir = {},
185-
FileSpec first_file = {}) {
181+
static FileSpecList ParseSupportFilesFromPrologue(
182+
const lldb::ModuleSP &module,
183+
const llvm::DWARFDebugLine::Prologue &prologue, FileSpec::Style style,
184+
llvm::StringRef compile_dir = {}, FileSpec first_file = {}) {
186185
FileSpecList support_files;
187186
support_files.Append(first_file);
188187

@@ -191,8 +190,8 @@ ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
191190
std::string original_file;
192191
if (!prologue.getFileNameByIndex(
193192
idx, compile_dir,
194-
llvm::DILineInfoSpecifier::FileLineInfoKind::Default,
195-
original_file)) {
193+
llvm::DILineInfoSpecifier::FileLineInfoKind::Default, original_file,
194+
style)) {
196195
// Always add an entry so the indexes remain correct.
197196
support_files.EmplaceBack();
198197
continue;
@@ -202,18 +201,14 @@ ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
202201
if (!prologue.getFileNameByIndex(
203202
idx, compile_dir,
204203
llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
205-
remapped_file)) {
204+
remapped_file, style)) {
206205
// Always add an entry so the indexes remain correct.
207-
support_files.EmplaceBack(original_file,
208-
FileSpec::GuessPathStyle(original_file)
209-
.getValueOr(FileSpec::Style::native));
206+
support_files.EmplaceBack(original_file, style);
210207
continue;
211208
}
212209

213210
module->RemapSourceFile(llvm::StringRef(original_file), remapped_file);
214-
support_files.EmplaceBack(remapped_file,
215-
FileSpec::GuessPathStyle(remapped_file)
216-
.getValueOr(FileSpec::Style::native));
211+
support_files.EmplaceBack(remapped_file, style);
217212
}
218213

219214
return support_files;
@@ -893,8 +888,8 @@ SymbolFileDWARF::GetTypeUnitSupportFiles(DWARFTypeUnit &tu) {
893888
"SymbolFileDWARF::GetTypeUnitSupportFiles failed to parse "
894889
"the line table prologue");
895890
} else {
896-
list =
897-
ParseSupportFilesFromPrologue(GetObjectFile()->GetModule(), prologue);
891+
list = ParseSupportFilesFromPrologue(GetObjectFile()->GetModule(),
892+
prologue, tu.GetPathStyle());
898893
}
899894
}
900895
return list;
@@ -1013,7 +1008,7 @@ bool SymbolFileDWARF::ParseLineTable(CompileUnit &comp_unit) {
10131008
}
10141009

10151010
comp_unit.SetSupportFiles(ParseSupportFilesFromPrologue(
1016-
comp_unit.GetModule(), line_table->Prologue,
1011+
comp_unit.GetModule(), line_table->Prologue, dwarf_cu->GetPathStyle(),
10171012
dwarf_cu->GetCompilationDirectory().GetCString(), FileSpec(comp_unit)));
10181013

10191014
return true;

llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
1919
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
2020
#include "llvm/Support/MD5.h"
21+
#include "llvm/Support/Path.h"
2122
#include <cstdint>
2223
#include <map>
2324
#include <string>
@@ -128,9 +129,11 @@ class DWARFDebugLine {
128129

129130
bool hasFileAtIndex(uint64_t FileIndex) const;
130131

131-
bool getFileNameByIndex(uint64_t FileIndex, StringRef CompDir,
132-
DILineInfoSpecifier::FileLineInfoKind Kind,
133-
std::string &Result) const;
132+
bool
133+
getFileNameByIndex(uint64_t FileIndex, StringRef CompDir,
134+
DILineInfoSpecifier::FileLineInfoKind Kind,
135+
std::string &Result,
136+
sys::path::Style Style = sys::path::Style::native) const;
134137

135138
void clear();
136139
void dump(raw_ostream &OS, DIDumpOptions DumpOptions) const;

llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
1717
#include "llvm/Support/Errc.h"
1818
#include "llvm/Support/Format.h"
19-
#include "llvm/Support/Path.h"
2019
#include "llvm/Support/WithColor.h"
2120
#include "llvm/Support/raw_ostream.h"
2221
#include <algorithm>
@@ -1041,28 +1040,9 @@ static bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {
10411040
sys::path::is_absolute(Path, sys::path::Style::windows);
10421041
}
10431042

1044-
/// If given an absolute path, guess the path style.
1045-
static sys::path::Style GuessPathStyle(StringRef Path) {
1046-
bool Posix = sys::path::is_absolute(Path, sys::path::Style::posix);
1047-
bool Windows = sys::path::is_absolute(Path, sys::path::Style::windows);
1048-
// This is a relative path.
1049-
if (!Posix && !Windows)
1050-
return sys::path::Style::native;
1051-
// This is a valid absolute path for both Windows and Posix.
1052-
if (Posix && Windows)
1053-
return sys::path::Style::native;
1054-
if (Posix)
1055-
return sys::path::Style::posix;
1056-
if (Windows)
1057-
return sys::path::Style::windows;
1058-
1059-
llvm_unreachable("All combinations should have been handled.");
1060-
}
1061-
1062-
bool DWARFDebugLine::Prologue::getFileNameByIndex(uint64_t FileIndex,
1063-
StringRef CompDir,
1064-
FileLineInfoKind Kind,
1065-
std::string &Result) const {
1043+
bool DWARFDebugLine::Prologue::getFileNameByIndex(
1044+
uint64_t FileIndex, StringRef CompDir, FileLineInfoKind Kind,
1045+
std::string &Result, sys::path::Style Style) const {
10661046
if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
10671047
return false;
10681048
const FileNameEntry &Entry = getFileNameEntry(FileIndex);
@@ -1088,11 +1068,11 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(uint64_t FileIndex,
10881068
// We know that FileName is not absolute, the only way to have an
10891069
// absolute path at this point would be if IncludeDir is absolute.
10901070
if (!CompDir.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
1091-
sys::path::append(FilePath, GuessPathStyle(CompDir), CompDir);
1071+
sys::path::append(FilePath, Style, CompDir);
10921072
}
10931073

10941074
// sys::path::append skips empty strings.
1095-
sys::path::append(FilePath, GuessPathStyle(IncludeDir), IncludeDir, FileName);
1075+
sys::path::append(FilePath, Style, IncludeDir, FileName);
10961076
Result = FilePath.str();
10971077
return true;
10981078
}

0 commit comments

Comments
 (0)