LLDB  mainline
PathMappingList.h
Go to the documentation of this file.
1 //===-- PathMappingList.h ---------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_TARGET_PATHMAPPINGLIST_H
10 #define LLDB_TARGET_PATHMAPPINGLIST_H
11 
12 #include <map>
13 #include <vector>
15 #include "lldb/Utility/Status.h"
16 
17 namespace lldb_private {
18 
20 public:
21  typedef void (*ChangedCallback)(const PathMappingList &path_list,
22  void *baton);
23 
24  // Constructors and Destructors
26 
27  PathMappingList(ChangedCallback callback, void *callback_baton);
28 
29  PathMappingList(const PathMappingList &rhs);
30 
32 
33  const PathMappingList &operator=(const PathMappingList &rhs);
34 
35  void Append(llvm::StringRef path, llvm::StringRef replacement, bool notify);
36 
37  void Append(const PathMappingList &rhs, bool notify);
38 
39  void Clear(bool notify);
40 
41  // By default, dump all pairs.
42  void Dump(Stream *s, int pair_index = -1);
43 
44  bool IsEmpty() const { return m_pairs.empty(); }
45 
46  size_t GetSize() const { return m_pairs.size(); }
47 
48  bool GetPathsAtIndex(uint32_t idx, ConstString &path,
49  ConstString &new_path) const;
50 
51  void Insert(llvm::StringRef path, llvm::StringRef replacement,
52  uint32_t insert_idx, bool notify);
53 
54  bool Remove(size_t index, bool notify);
55 
56  bool Remove(ConstString path, bool notify);
57 
58  bool Replace(llvm::StringRef path, llvm::StringRef replacement, bool notify);
59 
60  bool Replace(llvm::StringRef path, llvm::StringRef replacement,
61  uint32_t index, bool notify);
62  bool RemapPath(ConstString path, ConstString &new_path) const;
63 
64  /// Remaps a source file given \a path into \a new_path.
65  ///
66  /// Remaps \a path if any source remappings match. This function
67  /// does NOT stat the file system so it can be used in tight loops
68  /// where debug info is being parsed.
69  ///
70  /// \param[in] path
71  /// The original source file path to try and remap.
72  ///
73  /// \param[in] only_if_exists
74  /// If \b true, besides matching \p path with the remapping rules, this
75  /// tries to check with the filesystem that the remapped file exists. If
76  /// no valid file is found, \b None is returned. This might be expensive,
77  /// specially on a network.
78  ///
79  /// If \b false, then the existence of the returned remapping is not
80  /// checked.
81  ///
82  /// \return
83  /// The remapped filespec that may or may not exist on disk.
84  llvm::Optional<FileSpec> RemapPath(llvm::StringRef path,
85  bool only_if_exists = false) const;
86  bool RemapPath(const char *, std::string &) const = delete;
87 
88  bool ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const;
89 
90  /// Finds a source file given a file spec using the path remappings.
91  ///
92  /// Tries to resolve \a orig_spec by checking the path remappings.
93  /// It makes sure the file exists by checking with the file system,
94  /// so this call can be expensive if the remappings are on a network
95  /// or are even on the local file system, so use this function
96  /// sparingly (not in a tight debug info parsing loop).
97  ///
98  /// \param[in] orig_spec
99  /// The original source file path to try and remap.
100  ///
101  /// \return
102  /// The newly remapped filespec that is guaranteed to exist.
103  llvm::Optional<FileSpec> FindFile(const FileSpec &orig_spec) const;
104 
105  uint32_t FindIndexForPath(llvm::StringRef path) const;
106 
107  uint32_t GetModificationID() const { return m_mod_id; }
108 
109 protected:
110  typedef std::pair<ConstString, ConstString> pair;
111  typedef std::vector<pair> collection;
112  typedef collection::iterator iterator;
113  typedef collection::const_iterator const_iterator;
114 
116 
118 
121  void *m_callback_baton = nullptr;
122  uint32_t m_mod_id = 0; // Incremented anytime anything is added or removed.
123 };
124 
125 } // namespace lldb_private
126 
127 #endif // LLDB_TARGET_PATHMAPPINGLIST_H
lldb_private::PathMappingList::iterator
collection::iterator iterator
Definition: PathMappingList.h:112
lldb_private::PathMappingList::const_iterator
collection::const_iterator const_iterator
Definition: PathMappingList.h:113
lldb_private::PathMappingList::GetPathsAtIndex
bool GetPathsAtIndex(uint32_t idx, ConstString &path, ConstString &new_path) const
Definition: PathMappingList.cpp:278
lldb_private::PathMappingList::collection
std::vector< pair > collection
Definition: PathMappingList.h:111
lldb_private::PathMappingList::GetSize
size_t GetSize() const
Definition: PathMappingList.h:46
lldb_private::PathMappingList::FindIndexForPath
uint32_t FindIndexForPath(llvm::StringRef path) const
Definition: PathMappingList.cpp:288
lldb_private::Stream
Definition: Stream.h:28
lldb_private::PathMappingList::Insert
void Insert(llvm::StringRef path, llvm::StringRef replacement, uint32_t insert_idx, bool notify)
Definition: PathMappingList.cpp:79
lldb_private::PathMappingList::~PathMappingList
~PathMappingList()
lldb_private::PathMappingList::PathMappingList
PathMappingList()
Definition: PathMappingList.cpp:40
lldb_private::PathMappingList::ChangedCallback
void(* ChangedCallback)(const PathMappingList &path_list, void *baton)
Definition: PathMappingList.h:21
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::PathMappingList::m_mod_id
uint32_t m_mod_id
Definition: PathMappingList.h:122
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::PathMappingList::Replace
bool Replace(llvm::StringRef path, llvm::StringRef replacement, bool notify)
Definition: PathMappingList.cpp:227
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::PathMappingList::Append
void Append(llvm::StringRef path, llvm::StringRef replacement, bool notify)
Definition: PathMappingList.cpp:60
lldb_private::PathMappingList::m_pairs
collection m_pairs
Definition: PathMappingList.h:119
lldb_private::PathMappingList::FindFile
llvm::Optional< FileSpec > FindFile(const FileSpec &orig_spec) const
Finds a source file given a file spec using the path remappings.
Definition: PathMappingList.cpp:216
lldb_private::PathMappingList::operator=
const PathMappingList & operator=(const PathMappingList &rhs)
Definition: PathMappingList.cpp:48
uint32_t
lldb_private::PathMappingList
Definition: PathMappingList.h:19
lldb_private::PathMappingList::m_callback
ChangedCallback m_callback
Definition: PathMappingList.h:120
lldb_private::PathMappingList::GetModificationID
uint32_t GetModificationID() const
Definition: PathMappingList.h:107
lldb_private::PathMappingList::pair
std::pair< ConstString, ConstString > pair
Definition: PathMappingList.h:110
Status.h
lldb_private::PathMappingList::m_callback_baton
void * m_callback_baton
Definition: PathMappingList.h:121
lldb_private::PathMappingList::IsEmpty
bool IsEmpty() const
Definition: PathMappingList.h:44
lldb_private::PathMappingList::Dump
void Dump(Stream *s, int pair_index=-1)
Definition: PathMappingList.cpp:118
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::PathMappingList::FindIteratorForPath
iterator FindIteratorForPath(ConstString path)
Definition: PathMappingList.cpp:266
ConstString.h
lldb_private::PathMappingList::Remove
bool Remove(size_t index, bool notify)
Definition: PathMappingList.cpp:104
lldb_private::PathMappingList::Clear
void Clear(bool notify)
Definition: PathMappingList.cpp:134
lldb_private::PathMappingList::RemapPath
bool RemapPath(ConstString path, ConstString &new_path) const
Definition: PathMappingList.cpp:142
lldb_private::PathMappingList::ReverseRemapPath
bool ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const
Definition: PathMappingList.cpp:200