Index: lldb/trunk/include/lldb/Utility/FileSpec.h =================================================================== --- lldb/trunk/include/lldb/Utility/FileSpec.h +++ lldb/trunk/include/lldb/Utility/FileSpec.h @@ -545,27 +545,6 @@ ConstString GetLastPathComponent() const; - enum EnumerateDirectoryResult { - eEnumerateDirectoryResultNext, // Enumerate next entry in the current - // directory - eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a - // directory or symlink, or next if not - eEnumerateDirectoryResultQuit // Stop directory enumerations at any level - }; - - typedef EnumerateDirectoryResult (*EnumerateDirectoryCallbackType)( - void *baton, llvm::sys::fs::file_type file_type, const FileSpec &spec); - - static void EnumerateDirectory(llvm::StringRef dir_path, - bool find_directories, bool find_files, - bool find_other, - EnumerateDirectoryCallbackType callback, - void *callback_baton); - - typedef std::function - DirectoryCallback; - protected: //------------------------------------------------------------------ // Convenience method for setting the file without changing the style. Index: lldb/trunk/source/Core/Debugger.cpp =================================================================== --- lldb/trunk/source/Core/Debugger.cpp +++ lldb/trunk/source/Core/Debugger.cpp @@ -21,6 +21,7 @@ #include "lldb/DataFormatters/DataVisualization.h" #include "lldb/Expression/REPL.h" #include "lldb/Host/File.h" // for File, File::kInv... +#include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" #include "lldb/Host/Terminal.h" #include "lldb/Host/ThreadLauncher.h" @@ -604,16 +605,16 @@ return false; } -static FileSpec::EnumerateDirectoryResult +static FileSystem::EnumerateDirectoryResult LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, - const FileSpec &file_spec) { + llvm::StringRef path) { Status error; static ConstString g_dylibext(".dylib"); static ConstString g_solibext(".so"); if (!baton) - return FileSpec::eEnumerateDirectoryResultQuit; + return FileSystem::eEnumerateDirectoryResultQuit; Debugger *debugger = (Debugger *)baton; @@ -624,18 +625,18 @@ // file type information. if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file || ft == fs::file_type::type_unknown) { - FileSpec plugin_file_spec(file_spec); + FileSpec plugin_file_spec(path, false); plugin_file_spec.ResolvePath(); if (plugin_file_spec.GetFileNameExtension() != g_dylibext && plugin_file_spec.GetFileNameExtension() != g_solibext) { - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } Status plugin_load_error; debugger->LoadPlugin(plugin_file_spec, plugin_load_error); - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } else if (ft == fs::file_type::directory_file || ft == fs::file_type::symlink_file || ft == fs::file_type::type_unknown) { @@ -643,10 +644,10 @@ // also do this for unknown as sometimes the directory enumeration might be // enumerating a file system that doesn't have correct file type // information. - return FileSpec::eEnumerateDirectoryResultEnter; + return FileSystem::eEnumerateDirectoryResultEnter; } - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } void Debugger::InstanceInitialize() { @@ -656,15 +657,17 @@ char dir_path[PATH_MAX]; if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) { if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) { - FileSpec::EnumerateDirectory(dir_path, find_directories, find_files, - find_other, LoadPluginCallback, this); + FileSystem::Instance().EnumerateDirectory(dir_path, find_directories, + find_files, find_other, + LoadPluginCallback, this); } } if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) { if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) { - FileSpec::EnumerateDirectory(dir_path, find_directories, find_files, - find_other, LoadPluginCallback, this); + FileSystem::Instance().EnumerateDirectory(dir_path, find_directories, + find_files, find_other, + LoadPluginCallback, this); } } Index: lldb/trunk/source/Core/PluginManager.cpp =================================================================== --- lldb/trunk/source/Core/PluginManager.cpp +++ lldb/trunk/source/Core/PluginManager.cpp @@ -10,6 +10,7 @@ #include "lldb/Core/PluginManager.h" #include "lldb/Core/Debugger.h" +#include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" #include "lldb/Interpreter/OptionValueProperties.h" #include "lldb/Utility/ConstString.h" // for ConstString @@ -89,9 +90,9 @@ return reinterpret_cast(reinterpret_cast(VPtr)); } -static FileSpec::EnumerateDirectoryResult +static FileSystem::EnumerateDirectoryResult LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, - const FileSpec &file_spec) { + llvm::StringRef path) { // PluginManager *plugin_manager = (PluginManager *)baton; Status error; @@ -102,11 +103,11 @@ // file type information. if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file || ft == fs::file_type::type_unknown) { - FileSpec plugin_file_spec(file_spec); + FileSpec plugin_file_spec(path, false); plugin_file_spec.ResolvePath(); if (PluginIsLoaded(plugin_file_spec)) - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; else { PluginInfo plugin_info; @@ -138,7 +139,7 @@ // plug-in info so we don't try to load it again and again. SetPluginInfo(plugin_file_spec, plugin_info); - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } } } @@ -149,10 +150,10 @@ // also do this for unknown as sometimes the directory enumeration might be // enumerating a file system that doesn't have correct file type // information. - return FileSpec::eEnumerateDirectoryResultEnter; + return FileSystem::eEnumerateDirectoryResultEnter; } - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } void PluginManager::Initialize() { @@ -163,15 +164,17 @@ char dir_path[PATH_MAX]; if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) { if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) { - FileSpec::EnumerateDirectory(dir_path, find_directories, find_files, - find_other, LoadPluginCallback, nullptr); + FileSystem::Instance().EnumerateDirectory(dir_path, find_directories, + find_files, find_other, + LoadPluginCallback, nullptr); } } if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) { if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) { - FileSpec::EnumerateDirectory(dir_path, find_directories, find_files, - find_other, LoadPluginCallback, nullptr); + FileSystem::Instance().EnumerateDirectory(dir_path, find_directories, + find_files, find_other, + LoadPluginCallback, nullptr); } } #endif Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp @@ -247,19 +247,20 @@ return error; } -static FileSpec::EnumerateDirectoryResult +static FileSystem::EnumerateDirectoryResult EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, - const FileSpec &file_spec) { + llvm::StringRef path) { if (ft == llvm::sys::fs::file_type::directory_file) { + FileSpec file_spec(path, false); const char *filename = file_spec.GetFilename().GetCString(); if (filename && strncmp(filename, "AppleTVSimulator", strlen("AppleTVSimulator")) == 0) { ::snprintf((char *)baton, PATH_MAX, "%s", filename); - return FileSpec::eEnumerateDirectoryResultQuit; + return FileSystem::eEnumerateDirectoryResultQuit; } } - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } const char *PlatformAppleTVSimulator::GetSDKDirectoryAsCString() { @@ -277,9 +278,9 @@ bool find_directories = true; bool find_files = false; bool find_other = false; - FileSpec::EnumerateDirectory(sdks_directory, find_directories, find_files, - find_other, EnumerateDirectoryCallback, - sdk_dirname); + FileSystem::Instance().EnumerateDirectory( + sdks_directory, find_directories, find_files, find_other, + EnumerateDirectoryCallback, sdk_dirname); if (sdk_dirname[0]) { m_sdk_directory = sdks_directory; Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp @@ -247,19 +247,20 @@ return error; } -static FileSpec::EnumerateDirectoryResult +static FileSystem::EnumerateDirectoryResult EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, - const FileSpec &file_spec) { + llvm::StringRef path) { if (ft == llvm::sys::fs::file_type::directory_file) { + FileSpec file_spec(path, false); const char *filename = file_spec.GetFilename().GetCString(); if (filename && strncmp(filename, "AppleWatchSimulator", strlen("AppleWatchSimulator")) == 0) { ::snprintf((char *)baton, PATH_MAX, "%s", filename); - return FileSpec::eEnumerateDirectoryResultQuit; + return FileSystem::eEnumerateDirectoryResultQuit; } } - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } const char *PlatformAppleWatchSimulator::GetSDKDirectoryAsCString() { @@ -277,9 +278,9 @@ bool find_directories = true; bool find_files = false; bool find_other = false; - FileSpec::EnumerateDirectory(sdks_directory, find_directories, find_files, - find_other, EnumerateDirectoryCallback, - sdk_dirname); + FileSystem::Instance().EnumerateDirectory( + sdks_directory, find_directories, find_files, find_other, + EnumerateDirectoryCallback, sdk_dirname); if (sdk_dirname[0]) { m_sdk_directory = sdks_directory; Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -16,6 +16,7 @@ // Other libraries and framework includes // Project includes #include "Plugins/Platform/POSIX/PlatformPOSIX.h" +#include "lldb/Host/FileSystem.h" #include "lldb/Utility/FileSpec.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/FileSystem.h" @@ -111,9 +112,9 @@ SDKType sdk_type; }; - static lldb_private::FileSpec::EnumerateDirectoryResult + static lldb_private::FileSystem::EnumerateDirectoryResult DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type, - const lldb_private::FileSpec &spec); + llvm::StringRef path); static lldb_private::FileSpec FindSDKInXcodeForModules(SDKType sdk_type, Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1417,16 +1417,17 @@ return false; } -FileSpec::EnumerateDirectoryResult PlatformDarwin::DirectoryEnumerator( - void *baton, llvm::sys::fs::file_type file_type, const FileSpec &spec) { +FileSystem::EnumerateDirectoryResult PlatformDarwin::DirectoryEnumerator( + void *baton, llvm::sys::fs::file_type file_type, llvm::StringRef path) { SDKEnumeratorInfo *enumerator_info = static_cast(baton); + FileSpec spec(path, false); if (SDKSupportsModules(enumerator_info->sdk_type, spec)) { enumerator_info->found_path = spec; - return FileSpec::EnumerateDirectoryResult::eEnumerateDirectoryResultNext; + return FileSystem::EnumerateDirectoryResult::eEnumerateDirectoryResultNext; } - return FileSpec::EnumerateDirectoryResult::eEnumerateDirectoryResultNext; + return FileSystem::EnumerateDirectoryResult::eEnumerateDirectoryResultNext; } FileSpec PlatformDarwin::FindSDKInXcodeForModules(SDKType sdk_type, @@ -1445,9 +1446,9 @@ enumerator_info.sdk_type = sdk_type; - FileSpec::EnumerateDirectory(sdks_spec.GetPath(), find_directories, - find_files, find_other, DirectoryEnumerator, - &enumerator_info); + FileSystem::Instance().EnumerateDirectory( + sdks_spec.GetPath(), find_directories, find_files, find_other, + DirectoryEnumerator, &enumerator_info); if (llvm::sys::fs::is_directory(enumerator_info.found_path.GetPath())) return enumerator_info.found_path; Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h @@ -106,26 +106,25 @@ void AddSDKSubdirsToSearchPaths(const std::string &dir); - static lldb_private::FileSpec::EnumerateDirectoryResult + static lldb_private::FileSystem::EnumerateDirectoryResult FindKDKandSDKDirectoriesInDirectory(void *baton, llvm::sys::fs::file_type ft, - const lldb_private::FileSpec &file_spec); + llvm::StringRef path); void SearchForKextsAndKernelsRecursively(); - static lldb_private::FileSpec::EnumerateDirectoryResult - GetKernelsAndKextsInDirectoryWithRecursion( - void *baton, llvm::sys::fs::file_type ft, - const lldb_private::FileSpec &file_spec); - - static lldb_private::FileSpec::EnumerateDirectoryResult - GetKernelsAndKextsInDirectoryNoRecursion( - void *baton, llvm::sys::fs::file_type ft, - const lldb_private::FileSpec &file_spec); + static lldb_private::FileSystem::EnumerateDirectoryResult + GetKernelsAndKextsInDirectoryWithRecursion(void *baton, + llvm::sys::fs::file_type ft, + llvm::StringRef path); + + static lldb_private::FileSystem::EnumerateDirectoryResult + GetKernelsAndKextsInDirectoryNoRecursion(void *baton, + llvm::sys::fs::file_type ft, + llvm::StringRef path); - static lldb_private::FileSpec::EnumerateDirectoryResult + static lldb_private::FileSystem::EnumerateDirectoryResult GetKernelsAndKextsInDirectoryHelper(void *baton, llvm::sys::fs::file_type ft, - const lldb_private::FileSpec &file_spec, - bool recurse); + llvm::StringRef path, bool recurse); static std::vector SearchForExecutablesRecursively(const std::string &dir); @@ -148,7 +147,7 @@ const lldb_private::ArchSpec &arch, lldb::ModuleSP &exe_module_sp); - // Most of the ivars are assembled under FileSpec::EnumerateDirectory calls + // Most of the ivars are assembled under FileSystem::EnumerateDirectory calls // where the // function being called for each file/directory must be static. We'll pass a // this pointer 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 @@ -424,25 +424,26 @@ const bool find_directories = true; const bool find_files = false; const bool find_other = false; - FileSpec::EnumerateDirectory(dir.c_str(), find_directories, find_files, - find_other, FindKDKandSDKDirectoriesInDirectory, - this); + FileSystem::Instance().EnumerateDirectory( + dir.c_str(), find_directories, find_files, find_other, + FindKDKandSDKDirectoriesInDirectory, this); } // Helper function to find *.sdk and *.kdk directories in a given directory. -FileSpec::EnumerateDirectoryResult +FileSystem::EnumerateDirectoryResult PlatformDarwinKernel::FindKDKandSDKDirectoriesInDirectory( - void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { + void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path) { static ConstString g_sdk_suffix = ConstString(".sdk"); static ConstString g_kdk_suffix = ConstString(".kdk"); PlatformDarwinKernel *thisp = (PlatformDarwinKernel *)baton; + FileSpec file_spec(path, false); if (ft == llvm::sys::fs::file_type::directory_file && (file_spec.GetFileNameExtension() == g_sdk_suffix || file_spec.GetFileNameExtension() == g_kdk_suffix)) { AddRootSubdirsToSearchPaths(thisp, file_spec.GetPath()); } - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } // Recursively search trough m_search_directories looking for kext and kernel @@ -454,7 +455,7 @@ const bool find_directories = true; const bool find_files = true; const bool find_other = true; // I think eFileTypeSymbolicLink are "other"s. - FileSpec::EnumerateDirectory( + FileSystem::Instance().EnumerateDirectory( dir.GetPath().c_str(), find_directories, find_files, find_other, GetKernelsAndKextsInDirectoryWithRecursion, this); } @@ -464,7 +465,7 @@ const bool find_directories = true; const bool find_files = true; const bool find_other = true; // I think eFileTypeSymbolicLink are "other"s. - FileSpec::EnumerateDirectory( + FileSystem::Instance().EnumerateDirectory( dir.GetPath().c_str(), find_directories, find_files, find_other, GetKernelsAndKextsInDirectoryNoRecursion, this); } @@ -478,25 +479,27 @@ // // Recurse into any subdirectories found. -FileSpec::EnumerateDirectoryResult +FileSystem::EnumerateDirectoryResult PlatformDarwinKernel::GetKernelsAndKextsInDirectoryWithRecursion( - void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { - return GetKernelsAndKextsInDirectoryHelper(baton, ft, file_spec, true); + void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path) { + return GetKernelsAndKextsInDirectoryHelper(baton, ft, path, true); } -FileSpec::EnumerateDirectoryResult +FileSystem::EnumerateDirectoryResult PlatformDarwinKernel::GetKernelsAndKextsInDirectoryNoRecursion( - void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { - return GetKernelsAndKextsInDirectoryHelper(baton, ft, file_spec, false); + void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path) { + return GetKernelsAndKextsInDirectoryHelper(baton, ft, path, false); } -FileSpec::EnumerateDirectoryResult +FileSystem::EnumerateDirectoryResult PlatformDarwinKernel::GetKernelsAndKextsInDirectoryHelper( - void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec, + void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path, bool recurse) { static ConstString g_kext_suffix = ConstString(".kext"); static ConstString g_dsym_suffix = ConstString(".dSYM"); static ConstString g_bundle_suffix = ConstString("Bundle"); + + FileSpec file_spec(path, false); ConstString file_spec_extension = file_spec.GetFileNameExtension(); Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); @@ -528,7 +531,7 @@ } thisp->m_kernel_binaries_without_dsyms.push_back(file_spec); } - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } } else if (ft == llvm::sys::fs::file_type::directory_file && file_spec_extension == g_kext_suffix) { @@ -549,13 +552,13 @@ const bool find_directories = true; const bool find_files = false; const bool find_other = false; - FileSpec::EnumerateDirectory( + FileSystem::Instance().EnumerateDirectory( search_here_too.c_str(), find_directories, find_files, find_other, recurse ? GetKernelsAndKextsInDirectoryWithRecursion : GetKernelsAndKextsInDirectoryNoRecursion, baton); } - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } // Don't recurse into dSYM/kext/bundle directories if (recurse && file_spec_extension != g_dsym_suffix && @@ -563,9 +566,9 @@ file_spec_extension != g_bundle_suffix) { if (log_verbose) log_verbose->Printf ("PlatformDarwinKernel descending into directory '%s'", file_spec.GetPath().c_str()); - return FileSpec::eEnumerateDirectoryResultEnter; + return FileSystem::eEnumerateDirectoryResultEnter; } else { - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } } Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h @@ -84,10 +84,10 @@ const SDKDirectoryInfo *GetSDKDirectoryForCurrentOSVersion(); - static lldb_private::FileSpec::EnumerateDirectoryResult - GetContainedFilesIntoVectorOfStringsCallback( - void *baton, llvm::sys::fs::file_type ft, - const lldb_private::FileSpec &file_spec); + static lldb_private::FileSystem::EnumerateDirectoryResult + GetContainedFilesIntoVectorOfStringsCallback(void *baton, + llvm::sys::fs::file_type ft, + llvm::StringRef path); uint32_t FindFileInAllSDKs(const char *platform_file_path, lldb_private::FileSpecList &file_list); Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp @@ -139,12 +139,13 @@ return error; } -FileSpec::EnumerateDirectoryResult +FileSystem::EnumerateDirectoryResult PlatformRemoteDarwinDevice::GetContainedFilesIntoVectorOfStringsCallback( - void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { + void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path) { ((PlatformRemoteDarwinDevice::SDKDirectoryInfoCollection *)baton) - ->push_back(PlatformRemoteDarwinDevice::SDKDirectoryInfo(file_spec)); - return FileSpec::eEnumerateDirectoryResultNext; + ->push_back( + PlatformRemoteDarwinDevice::SDKDirectoryInfo(FileSpec(path, false))); + return FileSystem::eEnumerateDirectoryResultNext; } bool PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded() { @@ -175,10 +176,10 @@ const bool find_other = false; SDKDirectoryInfoCollection builtin_sdk_directory_infos; - FileSpec::EnumerateDirectory(m_device_support_directory, find_directories, - find_files, find_other, - GetContainedFilesIntoVectorOfStringsCallback, - &builtin_sdk_directory_infos); + FileSystem::Instance().EnumerateDirectory( + m_device_support_directory, find_directories, find_files, find_other, + GetContainedFilesIntoVectorOfStringsCallback, + &builtin_sdk_directory_infos); // Only add SDK directories that have symbols in them, some SDKs only // contain developer disk images and no symbols, so they aren't useful to @@ -214,13 +215,13 @@ } char path[PATH_MAX]; if (local_sdk_cache.GetPath(path, sizeof(path))) { - FileSpec::EnumerateDirectory( - path, find_directories, find_files, find_other, - GetContainedFilesIntoVectorOfStringsCallback, - &m_sdk_directory_infos); - const uint32_t num_sdk_infos = m_sdk_directory_infos.size(); - // First try for an exact match of major, minor and update - for (uint32_t i = num_installed; i < num_sdk_infos; ++i) { + FileSystem::Instance().EnumerateDirectory( + path, find_directories, find_files, find_other, + GetContainedFilesIntoVectorOfStringsCallback, + &m_sdk_directory_infos); + const uint32_t num_sdk_infos = m_sdk_directory_infos.size(); + // First try for an exact match of major, minor and update + for (uint32_t i = num_installed; i < num_sdk_infos; ++i) { m_sdk_directory_infos[i].user_cached = true; if (log) { log->Printf("PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded " @@ -235,10 +236,10 @@ const char *addtional_platform_dirs = getenv("PLATFORM_SDK_DIRECTORY"); if (addtional_platform_dirs) { SDKDirectoryInfoCollection env_var_sdk_directory_infos; - FileSpec::EnumerateDirectory(addtional_platform_dirs, find_directories, - find_files, find_other, - GetContainedFilesIntoVectorOfStringsCallback, - &env_var_sdk_directory_infos); + FileSystem::Instance().EnumerateDirectory( + addtional_platform_dirs, find_directories, find_files, find_other, + GetContainedFilesIntoVectorOfStringsCallback, + &env_var_sdk_directory_infos); FileSpec sdk_symbols_symlink_fspec; for (const auto &sdk_directory_info : env_var_sdk_directory_infos) { sdk_symbols_symlink_fspec = sdk_directory_info.directory; Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp @@ -253,18 +253,19 @@ return error; } -static FileSpec::EnumerateDirectoryResult +static FileSystem::EnumerateDirectoryResult EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, - const FileSpec &file_spec) { + llvm::StringRef path) { if (ft == llvm::sys::fs::file_type::directory_file) { + FileSpec file_spec(path, false); const char *filename = file_spec.GetFilename().GetCString(); if (filename && strncmp(filename, "iPhoneSimulator", strlen("iPhoneSimulator")) == 0) { ::snprintf((char *)baton, PATH_MAX, "%s", filename); - return FileSpec::eEnumerateDirectoryResultQuit; + return FileSystem::eEnumerateDirectoryResultQuit; } } - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } const char *PlatformiOSSimulator::GetSDKDirectoryAsCString() { @@ -282,9 +283,9 @@ bool find_directories = true; bool find_files = false; bool find_other = false; - FileSpec::EnumerateDirectory(sdks_directory, find_directories, find_files, - find_other, EnumerateDirectoryCallback, - sdk_dirname); + FileSystem::Instance().EnumerateDirectory( + sdks_directory, find_directories, find_files, find_other, + EnumerateDirectoryCallback, sdk_dirname); if (sdk_dirname[0]) { m_sdk_directory = sdks_directory; Index: lldb/trunk/source/Target/Platform.cpp =================================================================== --- lldb/trunk/source/Target/Platform.cpp +++ lldb/trunk/source/Target/Platform.cpp @@ -552,16 +552,17 @@ Status error; }; -static FileSpec::EnumerateDirectoryResult +static FileSystem::EnumerateDirectoryResult RecurseCopy_Callback(void *baton, llvm::sys::fs::file_type ft, - const FileSpec &src) { + llvm::StringRef path) { RecurseCopyBaton *rc_baton = (RecurseCopyBaton *)baton; + FileSpec src(path, false); namespace fs = llvm::sys::fs; switch (ft) { case fs::file_type::fifo_file: case fs::file_type::socket_file: // we have no way to copy pipes and sockets - ignore them and continue - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; break; case fs::file_type::directory_file: { @@ -574,7 +575,7 @@ if (error.Fail()) { rc_baton->error.SetErrorStringWithFormat( "unable to setup directory %s on remote end", dst_dir.GetCString()); - return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out + return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out } // now recurse @@ -586,13 +587,13 @@ recurse_dst.GetDirectory().SetCString(dst_dir.GetPath().c_str()); RecurseCopyBaton rc_baton2 = {recurse_dst, rc_baton->platform_ptr, Status()}; - FileSpec::EnumerateDirectory(src_dir_path, true, true, true, - RecurseCopy_Callback, &rc_baton2); + FileSystem::Instance().EnumerateDirectory(src_dir_path, true, true, true, + RecurseCopy_Callback, &rc_baton2); if (rc_baton2.error.Fail()) { rc_baton->error.SetErrorString(rc_baton2.error.AsCString()); - return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out + return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out } - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } break; case fs::file_type::symlink_file: { @@ -606,15 +607,15 @@ rc_baton->error = FileSystem::Instance().Readlink(src, src_resolved); if (rc_baton->error.Fail()) - return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out + return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out rc_baton->error = rc_baton->platform_ptr->CreateSymlink(dst_file, src_resolved); if (rc_baton->error.Fail()) - return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out + return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } break; case fs::file_type::regular_file: { @@ -625,15 +626,15 @@ Status err = rc_baton->platform_ptr->PutFile(src, dst_file); if (err.Fail()) { rc_baton->error.SetErrorString(err.AsCString()); - return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out + return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out } - return FileSpec::eEnumerateDirectoryResultNext; + return FileSystem::eEnumerateDirectoryResultNext; } break; default: rc_baton->error.SetErrorStringWithFormat( "invalid file detected during copy: %s", src.GetPath().c_str()); - return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out + return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out break; } llvm_unreachable("Unhandled file_type!"); @@ -719,8 +720,8 @@ recurse_dst.GetDirectory().SetCString(fixed_dst.GetCString()); std::string src_dir_path(src.GetPath()); RecurseCopyBaton baton = {recurse_dst, this, Status()}; - FileSpec::EnumerateDirectory(src_dir_path, true, true, true, - RecurseCopy_Callback, &baton); + FileSystem::Instance().EnumerateDirectory( + src_dir_path, true, true, true, RecurseCopy_Callback, &baton); return baton.error; } } break; Index: lldb/trunk/source/Utility/FileSpec.cpp =================================================================== --- lldb/trunk/source/Utility/FileSpec.cpp +++ lldb/trunk/source/Utility/FileSpec.cpp @@ -602,39 +602,6 @@ return m_filename.MemorySize() + m_directory.MemorySize(); } -void FileSpec::EnumerateDirectory(llvm::StringRef dir_path, - bool find_directories, bool find_files, - bool find_other, - EnumerateDirectoryCallbackType callback, - void *callback_baton) { - namespace fs = llvm::sys::fs; - std::error_code EC; - fs::recursive_directory_iterator Iter(dir_path, EC); - fs::recursive_directory_iterator End; - for (; Iter != End && !EC; Iter.increment(EC)) { - const auto &Item = *Iter; - llvm::ErrorOr Status = Item.status(); - if (!Status) - break; - if (!find_files && fs::is_regular_file(*Status)) - continue; - if (!find_directories && fs::is_directory(*Status)) - continue; - if (!find_other && fs::is_other(*Status)) - continue; - - FileSpec Spec(Item.path(), false); - auto Result = callback(callback_baton, Status->type(), Spec); - if (Result == eEnumerateDirectoryResultQuit) - return; - if (Result == eEnumerateDirectoryResultNext) { - // Default behavior is to recurse. Opt out if the callback doesn't want - // this behavior. - Iter.no_push(); - } - } -} - FileSpec FileSpec::CopyByAppendingPathComponent(llvm::StringRef component) const { FileSpec ret = *this;