Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:58

0001 //===-- RealpathPrefixes.h --------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_UTILITY_REALPATHPREFIXES_H
0010 #define LLDB_UTILITY_REALPATHPREFIXES_H
0011 
0012 #include "lldb/lldb-forward.h"
0013 #include "llvm/ADT/IntrusiveRefCntPtr.h"
0014 #include "llvm/Support/VirtualFileSystem.h"
0015 
0016 #include <optional>
0017 #include <string>
0018 #include <vector>
0019 
0020 namespace lldb_private {
0021 
0022 class RealpathPrefixes {
0023 public:
0024   /// \param[in] file_spec_list
0025   ///     Prefixes are obtained from FileSpecList, through FileSpec::GetPath(),
0026   ///     which ensures that the paths are normalized. For example:
0027   ///     "./foo/.." -> ""
0028   ///     "./foo/../bar" -> "bar"
0029   ///
0030   /// \param[in] fs
0031   ///     An optional filesystem to use for realpath'ing. If not set, the real
0032   ///     filesystem will be used.
0033   explicit RealpathPrefixes(const FileSpecList &file_spec_list,
0034                             llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
0035                                 llvm::vfs::getRealFileSystem());
0036 
0037   std::optional<FileSpec> ResolveSymlinks(const FileSpec &file_spec);
0038 
0039   // If/when Statistics.h/cpp is moved into Utility, we can remove these
0040   // methods, hold a (weak) pointer to `TargetStats` and directly increment
0041   // on that object.
0042   void IncreaseSourceRealpathAttemptCount() {
0043     ++m_source_realpath_attempt_count;
0044   }
0045   uint32_t GetSourceRealpathAttemptCount() const {
0046     return m_source_realpath_attempt_count;
0047   }
0048   void IncreaseSourceRealpathCompatibleCount() {
0049     ++m_source_realpath_compatible_count;
0050   }
0051   uint32_t GetSourceRealpathCompatibleCount() const {
0052     return m_source_realpath_compatible_count;
0053   }
0054 
0055 private:
0056   // Paths that start with one of the prefixes in this list will be realpath'ed
0057   // to resolve any symlinks.
0058   //
0059   // Wildcard prefixes:
0060   // - "" (empty string) will match all paths.
0061   // - "/" will match all absolute paths.
0062   std::vector<std::string> m_prefixes;
0063 
0064   // The filesystem to use for realpath'ing.
0065   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
0066 
0067   // The optional Target instance to gather statistics.
0068   lldb::TargetWP m_target;
0069 
0070   // Statistics that we temprarily hold here, to be gathered into TargetStats
0071   uint32_t m_source_realpath_attempt_count = 0;
0072   uint32_t m_source_realpath_compatible_count = 0;
0073 };
0074 
0075 } // namespace lldb_private
0076 
0077 #endif // LLDB_UTILITY_REALPATHPREFIXES_H