]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/PathMappingList.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / PathMappingList.h
1 //===-- PathMappingList.h ---------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_PathMappingList_h_
11 #define liblldb_PathMappingList_h_
12
13 // C Includes
14 // C++ Includes
15 #include <map>
16 #include <vector>
17 // Other libraries and framework includes
18 #include "lldb/Utility/ConstString.h"
19 #include "lldb/Utility/Status.h"
20 // Project includes
21
22 namespace lldb_private {
23
24 class PathMappingList {
25 public:
26   typedef void (*ChangedCallback)(const PathMappingList &path_list,
27                                   void *baton);
28
29   //------------------------------------------------------------------
30   // Constructors and Destructors
31   //------------------------------------------------------------------
32   PathMappingList();
33
34   PathMappingList(ChangedCallback callback, void *callback_baton);
35
36   PathMappingList(const PathMappingList &rhs);
37
38   ~PathMappingList();
39
40   const PathMappingList &operator=(const PathMappingList &rhs);
41
42   void Append(const ConstString &path, const ConstString &replacement,
43               bool notify);
44
45   void Append(const PathMappingList &rhs, bool notify);
46
47   void Clear(bool notify);
48
49   // By default, dump all pairs.
50   void Dump(Stream *s, int pair_index = -1);
51
52   bool IsEmpty() const { return m_pairs.empty(); }
53
54   size_t GetSize() const { return m_pairs.size(); }
55
56   bool GetPathsAtIndex(uint32_t idx, ConstString &path,
57                        ConstString &new_path) const;
58
59   void Insert(const ConstString &path, const ConstString &replacement,
60               uint32_t insert_idx, bool notify);
61
62   bool Remove(size_t index, bool notify);
63
64   bool Remove(const ConstString &path, bool notify);
65
66   bool Replace(const ConstString &path, const ConstString &replacement,
67                bool notify);
68
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;
72
73   //------------------------------------------------------------------
74   /// Remaps a source file given \a path into \a new_path.
75   ///
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.
79   ///
80   /// @param[in] path
81   ///     The original source file path to try and remap.
82   ///
83   /// @param[out] new_path
84   ///     The newly remapped filespec that is may or may not exist.
85   ///
86   /// @return
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;
92
93   bool ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const;
94
95   //------------------------------------------------------------------
96   /// Finds a source file given a file spec using the path remappings.
97   ///
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).
103   ///
104   /// @param[in] orig_spec
105   ///     The original source file path to try and remap.
106   ///
107   /// @param[out] new_spec
108   ///     The newly remapped filespec that is guaranteed to exist.
109   ///
110   /// @return
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;
116
117   uint32_t FindIndexForPath(const ConstString &path) const;
118
119   uint32_t GetModificationID() const { return m_mod_id; }
120
121 protected:
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;
126
127   iterator FindIteratorForPath(const ConstString &path);
128
129   const_iterator FindIteratorForPath(const ConstString &path) const;
130
131   collection m_pairs;
132   ChangedCallback m_callback;
133   void *m_callback_baton;
134   uint32_t m_mod_id; // Incremented anytime anything is added or removed.
135 };
136
137 } // namespace lldb_private
138
139 #endif // liblldb_PathMappingList_h_