File indexing completed on 2026-05-10 08:42:53
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_TARGET_PATHMAPPINGLIST_H
0010 #define LLDB_TARGET_PATHMAPPINGLIST_H
0011
0012 #include "lldb/Utility/ConstString.h"
0013 #include "lldb/Utility/Status.h"
0014 #include "llvm/Support/Error.h"
0015 #include "llvm/Support/JSON.h"
0016 #include <map>
0017 #include <mutex>
0018 #include <optional>
0019 #include <vector>
0020
0021 namespace lldb_private {
0022
0023 class PathMappingList {
0024 public:
0025 typedef void (*ChangedCallback)(const PathMappingList &path_list,
0026 void *baton);
0027
0028 PathMappingList();
0029
0030 PathMappingList(ChangedCallback callback, void *callback_baton);
0031
0032 PathMappingList(const PathMappingList &rhs);
0033
0034 ~PathMappingList();
0035
0036 const PathMappingList &operator=(const PathMappingList &rhs);
0037
0038 void Append(llvm::StringRef path, llvm::StringRef replacement, bool notify);
0039
0040 void Append(const PathMappingList &rhs, bool notify);
0041
0042
0043
0044 bool AppendUnique(llvm::StringRef path, llvm::StringRef replacement,
0045 bool notify);
0046
0047 void Clear(bool notify);
0048
0049
0050 void Dump(Stream *s, int pair_index = -1);
0051
0052 llvm::json::Value ToJSON();
0053
0054 bool IsEmpty() const {
0055 std::lock_guard<std::mutex> lock(m_pairs_mutex);
0056 return m_pairs.empty();
0057 }
0058
0059 size_t GetSize() const {
0060 std::lock_guard<std::mutex> lock(m_pairs_mutex);
0061 return m_pairs.size();
0062 }
0063
0064 bool GetPathsAtIndex(uint32_t idx, ConstString &path,
0065 ConstString &new_path) const;
0066
0067 void Insert(llvm::StringRef path, llvm::StringRef replacement,
0068 uint32_t insert_idx, bool notify);
0069
0070 bool Remove(size_t index, bool notify);
0071
0072 bool Remove(ConstString path, bool notify);
0073
0074 bool Replace(llvm::StringRef path, llvm::StringRef replacement, bool notify);
0075
0076 bool Replace(llvm::StringRef path, llvm::StringRef replacement,
0077 uint32_t index, bool notify);
0078 bool RemapPath(ConstString path, ConstString &new_path) const;
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100 std::optional<FileSpec> RemapPath(llvm::StringRef path,
0101 bool only_if_exists = false) const;
0102 bool RemapPath(const char *, std::string &) const = delete;
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118 std::optional<llvm::StringRef> ReverseRemapPath(const FileSpec &file,
0119 FileSpec &fixed) const;
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 std::optional<FileSpec> FindFile(const FileSpec &orig_spec) const;
0135
0136 uint32_t GetModificationID() const {
0137 std::lock_guard<std::mutex> lock(m_pairs_mutex);
0138 return m_mod_id;
0139 }
0140
0141 protected:
0142 typedef std::pair<ConstString, ConstString> pair;
0143 typedef std::vector<pair> collection;
0144 typedef collection::iterator iterator;
0145 typedef collection::const_iterator const_iterator;
0146
0147 void AppendNoLock(llvm::StringRef path, llvm::StringRef replacement);
0148 uint32_t FindIndexForPathNoLock(llvm::StringRef path) const;
0149 void Notify(bool notify) const;
0150
0151 iterator FindIteratorForPath(ConstString path);
0152
0153 const_iterator FindIteratorForPath(ConstString path) const;
0154
0155 collection m_pairs;
0156 mutable std::mutex m_pairs_mutex;
0157
0158 ChangedCallback m_callback = nullptr;
0159 void *m_callback_baton = nullptr;
0160 mutable std::mutex m_callback_mutex;
0161
0162
0163
0164 uint32_t m_mod_id = 0;
0165 };
0166
0167 }
0168
0169 #endif