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_
15 #include "lldb/Utility/ConstString.h"
16 #include "lldb/Utility/Status.h"
18 namespace lldb_private {
20 class PathMappingList {
22 typedef void (*ChangedCallback)(const PathMappingList &path_list,
25 //------------------------------------------------------------------
26 // Constructors and Destructors
27 //------------------------------------------------------------------
30 PathMappingList(ChangedCallback callback, void *callback_baton);
32 PathMappingList(const PathMappingList &rhs);
36 const PathMappingList &operator=(const PathMappingList &rhs);
38 void Append(const ConstString &path, const ConstString &replacement,
41 void Append(const PathMappingList &rhs, bool notify);
43 void Clear(bool notify);
45 // By default, dump all pairs.
46 void Dump(Stream *s, int pair_index = -1);
48 bool IsEmpty() const { return m_pairs.empty(); }
50 size_t GetSize() const { return m_pairs.size(); }
52 bool GetPathsAtIndex(uint32_t idx, ConstString &path,
53 ConstString &new_path) const;
55 void Insert(const ConstString &path, const ConstString &replacement,
56 uint32_t insert_idx, bool notify);
58 bool Remove(size_t index, bool notify);
60 bool Remove(const ConstString &path, bool notify);
62 bool Replace(const ConstString &path, const ConstString &replacement,
65 bool Replace(const ConstString &path, const ConstString &replacement,
66 uint32_t index, bool notify);
67 bool RemapPath(const ConstString &path, ConstString &new_path) const;
69 //------------------------------------------------------------------
70 /// Remaps a source file given \a path into \a new_path.
72 /// Remaps \a path if any source remappings match. This function
73 /// does NOT stat the file system so it can be used in tight loops
74 /// where debug info is being parsed.
77 /// The original source file path to try and remap.
79 /// @param[out] new_path
80 /// The newly remapped filespec that is may or may not exist.
83 /// /b true if \a path was successfully located and \a new_path
84 /// is filled in with a new source path, \b false otherwise.
85 //------------------------------------------------------------------
86 bool RemapPath(llvm::StringRef path, std::string &new_path) const;
87 bool RemapPath(const char *, std::string &) const = delete;
89 bool ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const;
91 //------------------------------------------------------------------
92 /// Finds a source file given a file spec using the path remappings.
94 /// Tries to resolve \a orig_spec by checking the path remappings.
95 /// It makes sure the file exists by checking with the file system,
96 /// so this call can be expensive if the remappings are on a network
97 /// or are even on the local file system, so use this function
98 /// sparingly (not in a tight debug info parsing loop).
100 /// @param[in] orig_spec
101 /// The original source file path to try and remap.
103 /// @param[out] new_spec
104 /// The newly remapped filespec that is guaranteed to exist.
107 /// /b true if \a orig_spec was successfully located and
108 /// \a new_spec is filled in with an existing file spec,
109 /// \b false otherwise.
110 //------------------------------------------------------------------
111 bool FindFile(const FileSpec &orig_spec, FileSpec &new_spec) const;
113 uint32_t FindIndexForPath(const ConstString &path) const;
115 uint32_t GetModificationID() const { return m_mod_id; }
118 typedef std::pair<ConstString, ConstString> pair;
119 typedef std::vector<pair> collection;
120 typedef collection::iterator iterator;
121 typedef collection::const_iterator const_iterator;
123 iterator FindIteratorForPath(const ConstString &path);
125 const_iterator FindIteratorForPath(const ConstString &path) const;
128 ChangedCallback m_callback;
129 void *m_callback_baton;
130 uint32_t m_mod_id; // Incremented anytime anything is added or removed.
133 } // namespace lldb_private
135 #endif // liblldb_PathMappingList_h_