Index: lldb/trunk/include/lldb/Utility/FileSpec.h =================================================================== --- lldb/trunk/include/lldb/Utility/FileSpec.h +++ lldb/trunk/include/lldb/Utility/FileSpec.h @@ -19,7 +19,7 @@ // Project includes #include "lldb/Utility/ConstString.h" -#include "llvm/ADT/StringRef.h" // for StringRef +#include "llvm/ADT/StringRef.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/Path.h" @@ -605,6 +605,6 @@ static void format(const lldb_private::FileSpec &F, llvm::raw_ostream &Stream, StringRef Style); }; -} +} // namespace llvm #endif // liblldb_FileSpec_h_ Index: lldb/trunk/source/Core/Debugger.cpp =================================================================== --- lldb/trunk/source/Core/Debugger.cpp +++ lldb/trunk/source/Core/Debugger.cpp @@ -605,8 +605,8 @@ const FileSpec &file_spec) { Status error; - static ConstString g_dylibext("dylib"); - static ConstString g_solibext("so"); + static ConstString g_dylibext(".dylib"); + static ConstString g_solibext(".so"); if (!baton) return FileSpec::eEnumerateDirectoryResultQuit; Index: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -2047,8 +2047,8 @@ // custom extension and file name makes it highly unlikely that this will // collide with anything else. ConstString file_extension = m_file.GetFileNameExtension(); - bool skip_oatdata_oatexec = file_extension == ConstString("oat") || - file_extension == ConstString("odex"); + bool skip_oatdata_oatexec = file_extension == ConstString(".oat") || + file_extension == ConstString(".odex"); ArchSpec arch; GetArchitecture(arch); Index: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -305,7 +305,7 @@ const FileSpec &dst_file_spec) { // For oat file we can try to fetch additional debug info from the device ConstString extension = module_sp->GetFileSpec().GetFileNameExtension(); - if (extension != ConstString("oat") && extension != ConstString("odex")) + if (extension != ConstString(".oat") && extension != ConstString(".odex")) return Status( "Symbol file downloading only supported for oat and odex files"); Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp @@ -431,8 +431,8 @@ FileSpec::EnumerateDirectoryResult PlatformDarwinKernel::FindKDKandSDKDirectoriesInDirectory( void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { - static ConstString g_sdk_suffix = ConstString("sdk"); - static ConstString g_kdk_suffix = ConstString("kdk"); + static ConstString g_sdk_suffix = ConstString(".sdk"); + static ConstString g_kdk_suffix = ConstString(".kdk"); PlatformDarwinKernel *thisp = (PlatformDarwinKernel *)baton; if (ft == llvm::sys::fs::file_type::directory_file && @@ -492,8 +492,8 @@ PlatformDarwinKernel::GetKernelsAndKextsInDirectoryHelper( void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec, bool recurse) { - static ConstString g_kext_suffix = ConstString("kext"); - static ConstString g_dsym_suffix = ConstString("dSYM"); + static ConstString g_kext_suffix = ConstString(".kext"); + static ConstString g_dsym_suffix = ConstString(".dSYM"); static ConstString g_bundle_suffix = ConstString("Bundle"); ConstString file_spec_extension = file_spec.GetFileNameExtension(); Index: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp =================================================================== --- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -2590,9 +2590,9 @@ // strip .py or .pyc extension ConstString extension = target_file.GetFileNameExtension(); if (extension) { - if (::strcmp(extension.GetCString(), "py") == 0) + if (llvm::StringRef(extension.GetCString()) == ".py") basename.resize(basename.length() - 3); - else if (::strcmp(extension.GetCString(), "pyc") == 0) + else if (llvm::StringRef(extension.GetCString()) == ".pyc") basename.resize(basename.length() - 4); } } else { 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 @@ -1653,7 +1653,7 @@ // (corresponding to .dwo) so we simply skip it. if (m_obj_file->GetFileSpec() .GetFileNameExtension() - .GetStringRef() == "dwo" && + .GetStringRef() == ".dwo" && llvm::StringRef(m_obj_file->GetFileSpec().GetPath()) .endswith(dwo_module_spec.GetFileSpec().GetPath())) { continue; Index: lldb/trunk/source/Utility/FileSpec.cpp =================================================================== --- lldb/trunk/source/Utility/FileSpec.cpp +++ lldb/trunk/source/Utility/FileSpec.cpp @@ -12,15 +12,15 @@ #include "lldb/Utility/Stream.h" #include "lldb/Utility/TildeExpressionResolver.h" -#include "llvm/ADT/SmallString.h" // for SmallString -#include "llvm/ADT/SmallVector.h" // for SmallVectorTemplat... +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/Triple.h" // for Triple -#include "llvm/ADT/Twine.h" // for Twine -#include "llvm/Support/ErrorOr.h" // for ErrorOr +#include "llvm/ADT/Triple.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Program.h" -#include "llvm/Support/raw_ostream.h" // for raw_ostream, fs +#include "llvm/Support/raw_ostream.h" #include // for replace, min, unique #include // for error_code @@ -50,7 +50,7 @@ } const char *GetPathSeparators(FileSpec::Style style) { - return PathStyleIsPosix(style) ? "/" : "\\/"; + return llvm::sys::path::get_separator(style).data(); } char GetPreferredPathSeparator(FileSpec::Style style) { @@ -67,30 +67,6 @@ std::replace(path.begin(), path.end(), '/', '\\'); } - -bool PathIsRelative(llvm::StringRef path, FileSpec::Style style) { - - if (path.empty()) - return false; - - if (PathStyleIsPosix(style)) { - // If the path doesn't start with '/' or '~', return true - switch (path[0]) { - case '/': - case '~': - return false; - default: - return true; - } - } else { - if (path.size() >= 2 && path[1] == ':') - return false; - if (path[0] == '/') - return false; - return true; - } - return false; -} } // end anonymous namespace @@ -239,7 +215,7 @@ return false; } - + } //------------------------------------------------------------------ // Assignment operator. @@ -286,15 +262,19 @@ if (resolved.empty()) { // If we have no path after normalization set the path to the current // directory. This matches what python does and also a few other path - // utilities. + // utilities. m_filename.SetString("."); return; } - m_filename.SetString(llvm::sys::path::filename(resolved, m_style)); - llvm::StringRef dir = llvm::sys::path::parent_path(resolved, m_style); - if (!dir.empty()) - m_directory.SetString(dir); + // Split path into filename and directory. We rely on the underlying char + // pointer to be nullptr when the components are empty. + llvm::StringRef filename = llvm::sys::path::filename(resolved, m_style); + if(!filename.empty()) + m_filename.SetString(filename); + llvm::StringRef directory = llvm::sys::path::parent_path(resolved, m_style); + if(!directory.empty()) + m_directory.SetString(directory); } void FileSpec::SetFile(llvm::StringRef path, bool resolve, @@ -441,16 +421,15 @@ } bool FileSpec::Equal(const FileSpec &a, const FileSpec &b, bool full) { - // case sensitivity of equality test const bool case_sensitive = a.IsCaseSensitive() || b.IsCaseSensitive(); - + const bool filenames_equal = ConstString::Equals(a.m_filename, b.m_filename, case_sensitive); if (!filenames_equal) - return false; + return false; if (!full && (a.GetDirectory().IsEmpty() || b.GetDirectory().IsEmpty())) return filenames_equal; @@ -523,7 +502,7 @@ return true; // We have already resolved this path // SetFile(...) will set m_is_resolved correctly if it can resolve the path - SetFile(GetPath(false), true); + SetFile(GetPath(false), true, m_style); return m_is_resolved; } @@ -606,25 +585,17 @@ } ConstString FileSpec::GetFileNameExtension() const { - if (m_filename) { - const char *filename = m_filename.GetCString(); - const char *dot_pos = strrchr(filename, '.'); - if (dot_pos && dot_pos[1] != '\0') - return ConstString(dot_pos + 1); - } - return ConstString(); + llvm::SmallString<64> current_path; + current_path.append(m_filename.GetStringRef().begin(), + m_filename.GetStringRef().end()); + return ConstString(llvm::sys::path::extension(current_path, m_style)); } ConstString FileSpec::GetFileNameStrippingExtension() const { - const char *filename = m_filename.GetCString(); - if (filename == NULL) - return ConstString(); - - const char *dot_pos = strrchr(filename, '.'); - if (dot_pos == NULL) - return m_filename; - - return ConstString(filename, dot_pos - filename); + llvm::SmallString<64> current_path; + current_path.append(m_filename.GetStringRef().begin(), + m_filename.GetStringRef().end()); + return ConstString(llvm::sys::path::stem(current_path, m_style)); } //------------------------------------------------------------------ @@ -753,7 +724,7 @@ const bool resolve = false; if (m_filename.IsEmpty() && m_directory.IsEmpty()) { - SetFile(component, resolve); + SetFile(component, resolve, m_style); return; } @@ -810,7 +781,7 @@ return false; static RegularExpression g_source_file_regex(llvm::StringRef( - "^([cC]|[mM]|[mM][mM]|[cC][pP][pP]|[cC]\\+\\+|[cC][xX][xX]|[cC][cC]|[" + "^.([cC]|[mM]|[mM][mM]|[cC][pP][pP]|[cC]\\+\\+|[cC][xX][xX]|[cC][cC]|[" "cC][pP]|[sS]|[aA][sS][mM]|[fF]|[fF]77|[fF]90|[fF]95|[fF]03|[fF][oO][" "rR]|[fF][tT][nN]|[fF][pP][pP]|[aA][dD][aA]|[aA][dD][bB]|[aA][dD][sS])" "$")); @@ -818,13 +789,23 @@ } bool FileSpec::IsRelative() const { - if (m_directory) - return PathIsRelative(m_directory.GetStringRef(), m_style); - else - return PathIsRelative(m_filename.GetStringRef(), m_style); + return !IsAbsolute(); } -bool FileSpec::IsAbsolute() const { return !FileSpec::IsRelative(); } +bool FileSpec::IsAbsolute() const { + llvm::SmallString<64> current_path; + GetPath(current_path, false); + + // Early return if the path is empty. + if (current_path.empty()) + return false; + + // We consider paths starting with ~ to be absolute. + if (current_path[0] == '~') + return true; + + return llvm::sys::path::is_absolute(current_path, m_style); +} void llvm::format_provider::format(const FileSpec &F, raw_ostream &Stream, Index: lldb/trunk/unittests/Utility/FileSpecTest.cpp =================================================================== --- lldb/trunk/unittests/Utility/FileSpecTest.cpp +++ lldb/trunk/unittests/Utility/FileSpecTest.cpp @@ -30,6 +30,16 @@ EXPECT_EQ(nullptr, fs_posix_root.GetDirectory().GetCString()); EXPECT_STREQ("/", fs_posix_root.GetFilename().GetCString()); + FileSpec fs_net_drive("//net", false, FileSpec::Style::posix); + EXPECT_STREQ("//net", fs_net_drive.GetCString()); + EXPECT_EQ(nullptr, fs_net_drive.GetDirectory().GetCString()); + EXPECT_STREQ("//net", fs_net_drive.GetFilename().GetCString()); + + FileSpec fs_net_root("//net/", false, FileSpec::Style::posix); + EXPECT_STREQ("//net/", fs_net_root.GetCString()); + EXPECT_STREQ("//net", fs_net_root.GetDirectory().GetCString()); + EXPECT_STREQ("/", fs_net_root.GetFilename().GetCString()); + FileSpec fs_windows_drive("F:", false, FileSpec::Style::windows); EXPECT_STREQ("F:", fs_windows_drive.GetCString()); EXPECT_EQ(nullptr, fs_windows_drive.GetDirectory().GetCString()); @@ -281,7 +291,6 @@ "/a/b", "/a/b/", "//", - "//a", "//a/", "//a/b", "//a/b/",