[Lldb-commits] [lldb] r346375 - [FileSystem] Add convenience method to check for directories.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 7 16:14:50 PST 2018


Author: jdevlieghere
Date: Wed Nov  7 16:14:50 2018
New Revision: 346375

URL: http://llvm.org/viewvc/llvm-project?rev=346375&view=rev
Log:
[FileSystem] Add convenience method to check for directories.

Replace calls to LLVM's is_directory with calls to LLDB's FileSytem
class. For this I introduced a new convenience method that, like the
other methods, takes either a path or filespec. This still uses the LLVM
functions under the hood.

Differential revision: https://reviews.llvm.org/D54135

Modified:
    lldb/trunk/include/lldb/Host/FileSystem.h
    lldb/trunk/source/API/SBPlatform.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Core/ModuleList.cpp
    lldb/trunk/source/Host/common/FileSystem.cpp
    lldb/trunk/source/Host/common/Symbols.cpp
    lldb/trunk/source/Host/macosx/Symbols.cpp
    lldb/trunk/source/Host/macosx/objcxx/Host.mm
    lldb/trunk/source/Host/macosx/objcxx/HostInfoMacOSX.mm
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
    lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
    lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
    lldb/trunk/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
    lldb/trunk/source/Target/TargetList.cpp

Modified: lldb/trunk/include/lldb/Host/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSystem.h (original)
+++ lldb/trunk/include/lldb/Host/FileSystem.h Wed Nov  7 16:14:50 2018
@@ -88,6 +88,12 @@ public:
   bool Readable(const llvm::Twine &path) const;
   /// @}
 
+  /// Returns whether the given path is a directory.
+  /// @{
+  bool IsDirectory(const FileSpec &file_spec) const;
+  bool IsDirectory(const llvm::Twine &path) const;
+  /// @}
+
   /// Make the given file path absolute.
   /// @{
   std::error_code MakeAbsolute(llvm::SmallVectorImpl<char> &path) const;

Modified: lldb/trunk/source/API/SBPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBPlatform.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/API/SBPlatform.cpp (original)
+++ lldb/trunk/source/API/SBPlatform.cpp Wed Nov  7 16:14:50 2018
@@ -366,7 +366,7 @@ SBError SBPlatform::Put(SBFileSpec &src,
     if (src.Exists()) {
       uint32_t permissions = FileSystem::Instance().GetPermissions(src.ref());
       if (permissions == 0) {
-        if (llvm::sys::fs::is_directory(src.ref().GetPath()))
+        if (FileSystem::Instance().IsDirectory(src.ref()))
           permissions = eFilePermissionsDirectoryDefault;
         else
           permissions = eFilePermissionsFileDefault;

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Wed Nov  7 16:14:50 2018
@@ -1448,7 +1448,7 @@ void Module::SetSymbolFileFileSpec(const
         // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to
         // check this
 
-        if (llvm::sys::fs::is_directory(file.GetPath())) {
+        if (FileSystem::Instance().IsDirectory(file)) {
           std::string new_path(file.GetPath());
           std::string old_path(obj_file->GetFileSpec().GetPath());
           if (old_path.find(new_path) == 0) {

Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Wed Nov  7 16:14:50 2018
@@ -859,7 +859,7 @@ Status ModuleList::GetSharedModule(const
       auto search_path_spec = module_search_paths_ptr->GetFileSpecAtIndex(idx);
       FileSystem::Instance().Resolve(search_path_spec);
       namespace fs = llvm::sys::fs;
-      if (!fs::is_directory(search_path_spec.GetPath()))
+      if (!FileSystem::Instance().IsDirectory(search_path_spec))
         continue;
       search_path_spec.AppendPathComponent(
           module_spec.GetFileSpec().GetFilename().AsCString());

Modified: lldb/trunk/source/Host/common/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSystem.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/common/FileSystem.cpp Wed Nov  7 16:14:50 2018
@@ -124,6 +124,17 @@ bool FileSystem::Readable(const FileSpec
   return Readable(file_spec.GetPath());
 }
 
+bool FileSystem::IsDirectory(const Twine &path) const {
+  ErrorOr<vfs::Status> status = m_fs->status(path);
+  if (!status)
+    return false;
+  return status->isDirectory();
+}
+
+bool FileSystem::IsDirectory(const FileSpec &file_spec) const {
+  return IsDirectory(file_spec.GetPath());
+}
+
 void FileSystem::EnumerateDirectory(Twine path, bool find_directories,
                                     bool find_files, bool find_other,
                                     EnumerateDirectoryCallbackType callback,

Modified: lldb/trunk/source/Host/common/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Symbols.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Symbols.cpp (original)
+++ lldb/trunk/source/Host/common/Symbols.cpp Wed Nov  7 16:14:50 2018
@@ -311,7 +311,7 @@ FileSpec Symbols::LocateExecutableSymbol
     for (size_t idx = 0; idx < num_directories; ++idx) {
       FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx);
       FileSystem::Instance().Resolve(dirspec);
-      if (!llvm::sys::fs::is_directory(dirspec.GetPath()))
+      if (!FileSystem::Instance().IsDirectory(dirspec))
         continue;
 
       std::vector<std::string> files;

Modified: lldb/trunk/source/Host/macosx/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Symbols.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Symbols.cpp (original)
+++ lldb/trunk/source/Host/macosx/Symbols.cpp Wed Nov  7 16:14:50 2018
@@ -109,7 +109,7 @@ int LocateMacOSXFilesUsingDebugSymbols(c
             if (path[0] == '~')
               FileSystem::Instance().Resolve(dsym_filespec);
 
-            if (llvm::sys::fs::is_directory(dsym_filespec.GetPath())) {
+            if (FileSystem::Instance().IsDirectory(dsym_filespec)) {
               dsym_filespec =
                   Symbols::FindSymbolFileInBundle(dsym_filespec, uuid, arch);
               ++items_found;

Modified: lldb/trunk/source/Host/macosx/objcxx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/objcxx/Host.mm?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/objcxx/Host.mm (original)
+++ lldb/trunk/source/Host/macosx/objcxx/Host.mm Wed Nov  7 16:14:50 2018
@@ -101,7 +101,7 @@ using namespace lldb_private;
 bool Host::GetBundleDirectory(const FileSpec &file,
                               FileSpec &bundle_directory) {
 #if defined(__APPLE__)
-  if (llvm::sys::fs::is_directory(file.GetPath())) {
+  if (FileSystem::Instance().IsDirectory(file)) {
     char path[PATH_MAX];
     if (file.GetPath(path, sizeof(path))) {
       CFCBundle bundle(path);
@@ -118,7 +118,7 @@ bool Host::GetBundleDirectory(const File
 
 bool Host::ResolveExecutableInBundle(FileSpec &file) {
 #if defined(__APPLE__)
-  if (llvm::sys::fs::is_directory(file.GetPath())) {
+  if (FileSystem::Instance().IsDirectory(file)) {
     char path[PATH_MAX];
     if (file.GetPath(path, sizeof(path))) {
       CFCBundle bundle(path);

Modified: lldb/trunk/source/Host/macosx/objcxx/HostInfoMacOSX.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/objcxx/HostInfoMacOSX.mm?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/objcxx/HostInfoMacOSX.mm (original)
+++ lldb/trunk/source/Host/macosx/objcxx/HostInfoMacOSX.mm Wed Nov  7 16:14:50 2018
@@ -141,7 +141,7 @@ bool HostInfoMacOSX::ComputeSupportExeDi
     raw_path.append("/../bin");
     FileSpec support_dir_spec(raw_path);
     FileSystem::Instance().Resolve(support_dir_spec);
-    if (!llvm::sys::fs::is_directory(support_dir_spec.GetPath())) {
+    if (!FileSystem::Instance().IsDirectory(support_dir_spec)) {
       Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
       if (log)
         log->Printf("HostInfoMacOSX::%s(): failed to find support directory",

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp Wed Nov  7 16:14:50 2018
@@ -43,7 +43,7 @@ static bool DefaultComputeClangDirectory
 #if defined(__APPLE__)
 
 static bool VerifyClangPath(const llvm::Twine &clang_path) {
-  if (llvm::sys::fs::is_directory(clang_path))
+  if (FileSystem::Instance().IsDirectory(clang_path))
     return true;
   Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
   if (log)

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp Wed Nov  7 16:14:50 2018
@@ -601,7 +601,7 @@ ClangModulesDeclVendor::Create(Target &t
   {
     FileSpec clang_resource_dir = GetClangResourceDir();
 
-    if (llvm::sys::fs::is_directory(clang_resource_dir.GetPath())) {
+    if (FileSystem::Instance().IsDirectory(clang_resource_dir.GetPath())) {
       compiler_invocation_arguments.push_back("-resource-dir");
       compiler_invocation_arguments.push_back(clang_resource_dir.GetPath());
     }

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Wed Nov  7 16:14:50 2018
@@ -1208,7 +1208,7 @@ const char *PlatformDarwin::GetDeveloper
           developer_dir_path[i] = '\0';
 
           FileSpec devel_dir(developer_dir_path);
-          if (llvm::sys::fs::is_directory(devel_dir.GetPath())) {
+          if (FileSystem::Instance().IsDirectory(devel_dir)) {
             developer_dir_path_valid = true;
           }
         }
@@ -1435,7 +1435,7 @@ FileSpec PlatformDarwin::FindSDKInXcodeF
                                                   const FileSpec &sdks_spec) {
   // Look inside Xcode for the required installed iOS SDK version
 
-  if (!llvm::sys::fs::is_directory(sdks_spec.GetPath())) {
+  if (!FileSystem::Instance().IsDirectory(sdks_spec)) {
     return FileSpec();
   }
 
@@ -1451,7 +1451,7 @@ FileSpec PlatformDarwin::FindSDKInXcodeF
       sdks_spec.GetPath(), find_directories, find_files, find_other,
       DirectoryEnumerator, &enumerator_info);
 
-  if (llvm::sys::fs::is_directory(enumerator_info.found_path.GetPath()))
+  if (FileSystem::Instance().IsDirectory(enumerator_info.found_path))
     return enumerator_info.found_path;
   else
     return FileSpec();
@@ -1596,7 +1596,7 @@ void PlatformDarwin::AddClangModuleCompi
     sysroot_spec = GetSDKDirectoryForModules(sdk_type);
   }
 
-  if (llvm::sys::fs::is_directory(sysroot_spec.GetPath())) {
+  if (FileSystem::Instance().IsDirectory(sysroot_spec.GetPath())) {
     options.push_back("-isysroot");
     options.push_back(sysroot_spec.GetPath());
   }

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp Wed Nov  7 16:14:50 2018
@@ -379,7 +379,7 @@ void PlatformDarwinKernel::CollectKextAn
   // Add simple directory /Applications/Xcode.app/Contents/Developer/../Symbols
   FileSpec possible_dir(developer_dir + "/../Symbols");
   FileSystem::Instance().Resolve(possible_dir);
-  if (llvm::sys::fs::is_directory(possible_dir.GetPath()))
+  if (FileSystem::Instance().IsDirectory(possible_dir))
     m_search_directories.push_back(possible_dir);
 
   // Add simple directory of the current working directory
@@ -396,7 +396,7 @@ void PlatformDarwinKernel::GetUserSpecif
   for (uint32_t i = 0; i < user_dirs_count; i++) {
     FileSpec dir = user_dirs.GetFileSpecAtIndex(i);
     FileSystem::Instance().Resolve(dir);
-    if (llvm::sys::fs::is_directory(dir.GetPath())) {
+    if (FileSystem::Instance().IsDirectory(dir)) {
       m_search_directories.push_back(dir);
     }
   }
@@ -413,7 +413,7 @@ void PlatformDarwinKernel::AddRootSubdir
   for (int i = 0; subdirs[i] != nullptr; i++) {
     FileSpec testdir(dir + subdirs[i]);
     FileSystem::Instance().Resolve(testdir);
-    if (llvm::sys::fs::is_directory(testdir.GetPath()))
+    if (FileSystem::Instance().IsDirectory(testdir))
       thisp->m_search_directories.push_back(testdir);
   }
 
@@ -542,11 +542,11 @@ PlatformDarwinKernel::GetKernelsAndKexts
     // Look to see if there is a PlugIns subdir with more kexts
     FileSpec contents_plugins(file_spec.GetPath() + "/Contents/PlugIns");
     std::string search_here_too;
-    if (llvm::sys::fs::is_directory(contents_plugins.GetPath())) {
+    if (FileSystem::Instance().IsDirectory(contents_plugins)) {
       search_here_too = contents_plugins.GetPath();
     } else {
       FileSpec plugins(file_spec.GetPath() + "/PlugIns");
-      if (llvm::sys::fs::is_directory(plugins.GetPath())) {
+      if (FileSystem::Instance().IsDirectory(plugins)) {
         search_here_too = plugins.GetPath();
       }
     }
@@ -618,7 +618,7 @@ bool PlatformDarwinKernel::KextHasdSYMSi
   std::string filename = dsym_fspec.GetFilename().AsCString();
   filename += ".dSYM";
   dsym_fspec.GetFilename() = ConstString(filename);
-  if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) {
+  if (FileSystem::Instance().IsDirectory(dsym_fspec)) {
     return true;
   }
   // Should probably get the CFBundleExecutable here or call
@@ -633,7 +633,7 @@ bool PlatformDarwinKernel::KextHasdSYMSi
   deep_bundle_str += ".dSYM";
   dsym_fspec.SetFile(deep_bundle_str, FileSpec::Style::native);
   FileSystem::Instance().Resolve(dsym_fspec);
-  if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) {
+  if (FileSystem::Instance().IsDirectory(dsym_fspec)) {
     return true;
   }
 
@@ -644,7 +644,7 @@ bool PlatformDarwinKernel::KextHasdSYMSi
   shallow_bundle_str += ".dSYM";
   dsym_fspec.SetFile(shallow_bundle_str, FileSpec::Style::native);
   FileSystem::Instance().Resolve(dsym_fspec);
-  if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) {
+  if (FileSystem::Instance().IsDirectory(dsym_fspec)) {
     return true;
   }
   return false;
@@ -658,7 +658,7 @@ bool PlatformDarwinKernel::KernelHasdSYM
   std::string filename = kernel_binary.GetFilename().AsCString();
   filename += ".dSYM";
   kernel_dsym.GetFilename() = ConstString(filename);
-  if (llvm::sys::fs::is_directory(kernel_dsym.GetPath())) {
+  if (FileSystem::Instance().IsDirectory(kernel_dsym)) {
     return true;
   }
   return false;

Modified: lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp Wed Nov  7 16:14:50 2018
@@ -65,7 +65,7 @@ Status NativeProcessProtocol::Launch(
   FileSpec working_dir(launch_info.GetWorkingDirectory());
   if (working_dir) {
     FileInstance::Instance().Resolve(working_dir);
-    if (!llvm::sys::fs::is_directory(working_dir.GetPath())) {
+    if (!FileSystem::Instance().IsDirectory(working_dir)) {
       error.SetErrorStringWithFormat("No such file or directory: %s",
                                    working_dir.GetCString());
       return error;

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp Wed Nov  7 16:14:50 2018
@@ -374,10 +374,9 @@ Status ProcessFreeBSD::DoLaunch(Module *
   assert(m_monitor == NULL);
 
   FileSpec working_dir = launch_info.GetWorkingDirectory();
-  namespace fs = llvm::sys::fs;
   if (working_dir) {
     FileSystem::Instance().Resolve(working_dir);
-    if (!fs::is_directory(working_dir.GetPath())) {
+    if (!FileSystem::Instance().IsDirectory(working_dir.GetPath())) {
       error.SetErrorStringWithFormat("No such file or directory: %s",
                                    working_dir.GetCString());
       return error;

Modified: lldb/trunk/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/Common/ProcessWindows.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/Common/ProcessWindows.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/Common/ProcessWindows.cpp Wed Nov  7 16:14:50 2018
@@ -254,7 +254,7 @@ Status ProcessWindows::DoLaunch(Module *
   namespace fs = llvm::sys::fs;
   if (working_dir) {
     FileSystem::Instance().Resolve(working_dir);
-    if (!fs::is_directory(working_dir.GetPath())) {
+    if (!FileSystem::Instance().IsDirectory(working_dir)) {
       result.SetErrorStringWithFormat("No such file or directory: %s",
                                       working_dir.GetCString());
       return result;

Modified: lldb/trunk/source/Target/TargetList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/TargetList.cpp?rev=346375&r1=346374&r2=346375&view=diff
==============================================================================
--- lldb/trunk/source/Target/TargetList.cpp (original)
+++ lldb/trunk/source/Target/TargetList.cpp Wed Nov  7 16:14:50 2018
@@ -364,7 +364,7 @@ Status TargetList::CreateTargetInternal(
   char resolved_bundle_exe_path[PATH_MAX];
   resolved_bundle_exe_path[0] = '\0';
   if (file) {
-    if (llvm::sys::fs::is_directory(file.GetPath()))
+    if (FileSystem::Instance().IsDirectory(file))
       user_exe_path_is_bundle = true;
 
     if (file.IsRelative() && !user_exe_path.empty()) {




More information about the lldb-commits mailing list