1 //===-- PathMappingList.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_PathMappingList_h_
11 #define liblldb_PathMappingList_h_
17 // Other libraries and framework includes
18 #include "lldb/Utility/ConstString.h"
19 #include "lldb/Utility/Status.h"
22 namespace lldb_private {
24 class PathMappingList {
26 typedef void (*ChangedCallback)(const PathMappingList &path_list,
29 //------------------------------------------------------------------
30 // Constructors and Destructors
31 //------------------------------------------------------------------
34 PathMappingList(ChangedCallback callback, void *callback_baton);
36 PathMappingList(const PathMappingList &rhs);
40 const PathMappingList &operator=(const PathMappingList &rhs);
42 void Append(const ConstString &path, const ConstString &replacement,
45 void Append(const PathMappingList &rhs, bool notify);
47 void Clear(bool notify);
49 // By default, dump all pairs.
50 void Dump(Stream *s, int pair_index = -1);
52 bool IsEmpty() const { return m_pairs.empty(); }
54 size_t GetSize() const { return m_pairs.size(); }
56 bool GetPathsAtIndex(uint32_t idx, ConstString &path,
57 ConstString &new_path) const;
59 void Insert(const ConstString &path, const ConstString &replacement,
60 uint32_t insert_idx, bool notify);
62 bool Remove(size_t index, bool notify);
64 bool Remove(const ConstString &path, bool notify);
66 bool Replace(const ConstString &path, const ConstString &replacement,
69 bool Replace(const ConstString &path, const ConstString &replacement,
70 uint32_t index, bool notify);
71 bool RemapPath(const ConstString &path, ConstString &new_path) const;
73 //------------------------------------------------------------------
74 /// Remaps a source file given \a path into \a new_path.
76 /// Remaps \a path if any source remappings match. This function
77 /// does NOT stat the file system so it can be used in tight loops
78 /// where debug info is being parsed.
81 /// The original source file path to try and remap.
83 /// @param[out] new_path
84 /// The newly remapped filespec that is may or may not exist.
87 /// /b true if \a path was successfully located and \a new_path
88 /// is filled in with a new source path, \b false otherwise.
89 //------------------------------------------------------------------
90 bool RemapPath(llvm::StringRef path, std::string &new_path) const;
91 bool RemapPath(const char *, std::string &) const = delete;
93 bool ReverseRemapPath(const ConstString &path, ConstString &new_path) const;
95 //------------------------------------------------------------------
96 /// Finds a source file given a file spec using the path remappings.
98 /// Tries to resolve \a orig_spec by checking the path remappings.
99 /// It makes sure the file exists by checking with the file system,
100 /// so this call can be expensive if the remappings are on a network
101 /// or are even on the local file system, so use this function
102 /// sparingly (not in a tight debug info parsing loop).
104 /// @param[in] orig_spec
105 /// The original source file path to try and remap.
107 /// @param[out] new_spec
108 /// The newly remapped filespec that is guaranteed to exist.
111 /// /b true if \a orig_spec was successfully located and
112 /// \a new_spec is filled in with an existing file spec,
113 /// \b false otherwise.
114 //------------------------------------------------------------------
115 bool FindFile(const FileSpec &orig_spec, FileSpec &new_spec) const;
117 uint32_t FindIndexForPath(const ConstString &path) const;
119 uint32_t GetModificationID() const { return m_mod_id; }
122 typedef std::pair<ConstString, ConstString> pair;
123 typedef std::vector<pair> collection;
124 typedef collection::iterator iterator;
125 typedef collection::const_iterator const_iterator;
127 iterator FindIteratorForPath(const ConstString &path);
129 const_iterator FindIteratorForPath(const ConstString &path) const;
132 ChangedCallback m_callback;
133 void *m_callback_baton;
134 uint32_t m_mod_id; // Incremented anytime anything is added or removed.
137 } // namespace lldb_private
139 #endif // liblldb_PathMappingList_h_