1 //===-- PathMappingList.h ---------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_PathMappingList_h_
10 #define liblldb_PathMappingList_h_
14 #include "lldb/Utility/ConstString.h"
15 #include "lldb/Utility/Status.h"
17 namespace lldb_private {
19 class PathMappingList {
21 typedef void (*ChangedCallback)(const PathMappingList &path_list,
24 // Constructors and Destructors
27 PathMappingList(ChangedCallback callback, void *callback_baton);
29 PathMappingList(const PathMappingList &rhs);
33 const PathMappingList &operator=(const PathMappingList &rhs);
35 void Append(ConstString path, ConstString replacement,
38 void Append(const PathMappingList &rhs, bool notify);
40 void Clear(bool notify);
42 // By default, dump all pairs.
43 void Dump(Stream *s, int pair_index = -1);
45 bool IsEmpty() const { return m_pairs.empty(); }
47 size_t GetSize() const { return m_pairs.size(); }
49 bool GetPathsAtIndex(uint32_t idx, ConstString &path,
50 ConstString &new_path) const;
52 void Insert(ConstString path, ConstString replacement,
53 uint32_t insert_idx, bool notify);
55 bool Remove(size_t index, bool notify);
57 bool Remove(ConstString path, bool notify);
59 bool Replace(ConstString path, ConstString replacement,
62 bool Replace(ConstString path, ConstString replacement,
63 uint32_t index, bool notify);
64 bool RemapPath(ConstString path, ConstString &new_path) const;
66 /// Remaps a source file given \a path into \a new_path.
68 /// Remaps \a path if any source remappings match. This function
69 /// does NOT stat the file system so it can be used in tight loops
70 /// where debug info is being parsed.
73 /// The original source file path to try and remap.
75 /// \param[out] new_path
76 /// The newly remapped filespec that is may or may not exist.
79 /// /b true if \a path was successfully located and \a new_path
80 /// is filled in with a new source path, \b false otherwise.
81 bool RemapPath(llvm::StringRef path, std::string &new_path) const;
82 bool RemapPath(const char *, std::string &) const = delete;
84 bool ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const;
86 /// Finds a source file given a file spec using the path remappings.
88 /// Tries to resolve \a orig_spec by checking the path remappings.
89 /// It makes sure the file exists by checking with the file system,
90 /// so this call can be expensive if the remappings are on a network
91 /// or are even on the local file system, so use this function
92 /// sparingly (not in a tight debug info parsing loop).
94 /// \param[in] orig_spec
95 /// The original source file path to try and remap.
97 /// \param[out] new_spec
98 /// The newly remapped filespec that is guaranteed to exist.
101 /// /b true if \a orig_spec was successfully located and
102 /// \a new_spec is filled in with an existing file spec,
103 /// \b false otherwise.
104 bool FindFile(const FileSpec &orig_spec, FileSpec &new_spec) const;
106 uint32_t FindIndexForPath(ConstString path) const;
108 uint32_t GetModificationID() const { return m_mod_id; }
111 typedef std::pair<ConstString, ConstString> pair;
112 typedef std::vector<pair> collection;
113 typedef collection::iterator iterator;
114 typedef collection::const_iterator const_iterator;
116 iterator FindIteratorForPath(ConstString path);
118 const_iterator FindIteratorForPath(ConstString path) const;
121 ChangedCallback m_callback;
122 void *m_callback_baton;
123 uint32_t m_mod_id; // Incremented anytime anything is added or removed.
126 } // namespace lldb_private
128 #endif // liblldb_PathMappingList_h_