Author: Martin Storsjö Date: 2022-03-26T22:34:02+02:00 New Revision: b548f5847235118878c15caa8df1b89e75fc965b
URL: https://github.com/llvm/llvm-project/commit/b548f5847235118878c15caa8df1b89e75fc965b DIFF: https://github.com/llvm/llvm-project/commit/b548f5847235118878c15caa8df1b89e75fc965b.diff LOG: [lldb] Fix interpreting absolute Windows paths with forward slashes In practice, Windows paths can use either backslashes or forward slashes. This fixes an issue reported downstream at https://github.com/mstorsjo/llvm-mingw/issues/266. Differential Revision: https://reviews.llvm.org/D122389 Added: Modified: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp lldb/source/Utility/FileSpec.cpp lldb/unittests/Utility/FileSpecTest.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp index 085c9e9ce1a6e..295433ddb78b9 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -772,7 +772,8 @@ removeHostnameFromPathname(llvm::StringRef path_from_dwarf) { // check whether we have a windows path, and so the first character is a // drive-letter not a hostname. - if (host.size() == 1 && llvm::isAlpha(host[0]) && path.startswith("\\")) + if (host.size() == 1 && llvm::isAlpha(host[0]) && + (path.startswith("\\") || path.startswith("/"))) return path_from_dwarf; return path; diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp index 24f8c2b1c23fc..eed3bbd46026f 100644 --- a/lldb/source/Utility/FileSpec.cpp +++ b/lldb/source/Utility/FileSpec.cpp @@ -311,7 +311,8 @@ llvm::Optional<FileSpec::Style> FileSpec::GuessPathStyle(llvm::StringRef absolut if (absolute_path.startswith(R"(\\)")) return Style::windows; if (absolute_path.size() >= 3 && llvm::isAlpha(absolute_path[0]) && - absolute_path.substr(1, 2) == R"(:\)") + (absolute_path.substr(1, 2) == R"(:\)" || + absolute_path.substr(1, 2) == R"(:/)")) return Style::windows; return llvm::None; } diff --git a/lldb/unittests/Utility/FileSpecTest.cpp b/lldb/unittests/Utility/FileSpecTest.cpp index 64b72bec483e5..f92be63892cd9 100644 --- a/lldb/unittests/Utility/FileSpecTest.cpp +++ b/lldb/unittests/Utility/FileSpecTest.cpp @@ -196,9 +196,12 @@ TEST(FileSpecTest, GuessPathStyle) { EXPECT_EQ(FileSpec::Style::posix, FileSpec::GuessPathStyle("//net/bar.txt")); EXPECT_EQ(FileSpec::Style::windows, FileSpec::GuessPathStyle(R"(C:\foo.txt)")); + EXPECT_EQ(FileSpec::Style::windows, + FileSpec::GuessPathStyle(R"(C:/foo.txt)")); EXPECT_EQ(FileSpec::Style::windows, FileSpec::GuessPathStyle(R"(\\net\foo.txt)")); EXPECT_EQ(FileSpec::Style::windows, FileSpec::GuessPathStyle(R"(Z:\)")); + EXPECT_EQ(FileSpec::Style::windows, FileSpec::GuessPathStyle(R"(Z:/)")); EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("foo.txt")); EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("foo/bar.txt")); EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("Z:")); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits