Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -178,6 +178,11 @@ return *line_table; } +static FileSpec::Style GuessPathStyleOrNative(llvm::StringRef p) { + llvm::Optional style = FileSpec::GuessPathStyle(p); + return style ? *style : FileSpec::Style::native; +} + static FileSpecList ParseSupportFilesFromPrologue(const lldb::ModuleSP &module, const llvm::DWARFDebugLine::Prologue &prologue, @@ -186,8 +191,6 @@ FileSpecList support_files; support_files.Append(first_file); - llvm::Optional compile_dir_style = - FileSpec::GuessPathStyle(compile_dir); const size_t number_of_files = prologue.FileNames.size(); for (size_t idx = 1; idx <= number_of_files; ++idx) { std::string original_file; @@ -200,26 +203,22 @@ continue; } - FileSpec::Style style = FileSpec::Style::native; - if (compile_dir_style) { - style = *compile_dir_style; - } else if (llvm::Optional file_style = - FileSpec::GuessPathStyle(original_file)) { - style = *file_style; - } - std::string remapped_file; if (!prologue.getFileNameByIndex( idx, compile_dir, llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, remapped_file)) { // Always add an entry so the indexes remain correct. - support_files.EmplaceBack(original_file, style); + support_files.EmplaceBack(original_file, + FileSpec::GuessPathStyle(original_file) + .getValueOr(FileSpec::Style::native)); continue; } module->RemapSourceFile(llvm::StringRef(original_file), remapped_file); - support_files.EmplaceBack(remapped_file, style); + support_files.EmplaceBack(remapped_file, + FileSpec::GuessPathStyle(remapped_file) + .getValueOr(FileSpec::Style::native)); } return support_files; Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -1041,6 +1041,24 @@ sys::path::is_absolute(Path, sys::path::Style::windows); } +/// If given an absolute path, guess the path style. +static sys::path::Style GuessPathStyle(StringRef Path) { + bool Posix = sys::path::is_absolute(Path, sys::path::Style::posix); + bool Windows = sys::path::is_absolute(Path, sys::path::Style::windows); + // This is a relative path. + if (!Posix && !Windows) + return sys::path::Style::native; + // This is a valid absolute path for both Windows and Posix. + if (Posix && Windows) + return sys::path::Style::native; + if (Posix) + return sys::path::Style::posix; + if (Windows) + return sys::path::Style::windows; + + llvm_unreachable("All combinations should have been handled."); +} + bool DWARFDebugLine::Prologue::getFileNameByIndex(uint64_t FileIndex, StringRef CompDir, FileLineInfoKind Kind, @@ -1070,11 +1088,11 @@ // We know that FileName is not absolute, the only way to have an // absolute path at this point would be if IncludeDir is absolute. if (!CompDir.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir)) - sys::path::append(FilePath, CompDir); + sys::path::append(FilePath, GuessPathStyle(CompDir), CompDir); } // sys::path::append skips empty strings. - sys::path::append(FilePath, IncludeDir, FileName); + sys::path::append(FilePath, GuessPathStyle(IncludeDir), IncludeDir, FileName); Result = FilePath.str(); return true; }