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(ConstString path, ConstString replacement,
36  bool notify);
37 
38  void Append(const PathMappingList &rhs, bool notify);
39 
40  void Clear(bool notify);
41 
42  // By default, dump all pairs.
43  void Dump(Stream *s, int pair_index = -1);
44 
45  bool IsEmpty() const { return m_pairs.empty(); }
46 
47  size_t GetSize() const { return m_pairs.size(); }
48 
49  bool GetPathsAtIndex(uint32_t idx, ConstString &path,
50  ConstString &new_path) const;
51 
52  void Insert(ConstString path, ConstString replacement,
53  uint32_t insert_idx, bool notify);
54 
55  bool Remove(size_t index, bool notify);
56 
57  bool Remove(ConstString path, bool notify);
58 
59  bool Replace(ConstString path, ConstString replacement,
60  bool notify);
61 
62  bool Replace(ConstString path, ConstString replacement,
63  uint32_t index, bool notify);
64  bool RemapPath(ConstString path, ConstString &new_path) const;
65 
66  /// Remaps a source file given \a path into \a new_path.
67  ///
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.
71  ///
72  /// \param[in] path
73  /// The original source file path to try and remap.
74  ///
75  /// \param[in] only_if_exists
76  /// If \b true, besides matching \p path with the remapping rules, this
77  /// tries to check with the filesystem that the remapped file exists. If
78  /// no valid file is found, \b None is returned. This might be expensive,
79  /// specially on a network.
80  ///
81  /// If \b false, then the existence of the returned remapping is not
82  /// checked.
83  ///
84  /// \return
85  /// The remapped filespec that may or may not exist on disk.
86  llvm::Optional<FileSpec> RemapPath(llvm::StringRef path,
87  bool only_if_exists = false) const;
88  bool RemapPath(const char *, std::string &) const = delete;
89 
90  bool ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const;
91 
92  /// Finds a source file given a file spec using the path remappings.
93  ///
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).
99  ///
100  /// \param[in] orig_spec
101  /// The original source file path to try and remap.
102  ///
103  /// \return
104  /// The newly remapped filespec that is guaranteed to exist.
105  llvm::Optional<FileSpec> FindFile(const FileSpec &orig_spec) const;
106 
108 
109  uint32_t GetModificationID() const { return m_mod_id; }
110 
111 protected:
112  typedef std::pair<ConstString, ConstString> pair;
113  typedef std::vector<pair> collection;
114  typedef collection::iterator iterator;
115  typedef collection::const_iterator const_iterator;
116 
118 
120 
123  void *m_callback_baton = nullptr;
124  uint32_t m_mod_id = 0; // Incremented anytime anything is added or removed.
125 };
126 
127 } // namespace lldb_private
128 
129 #endif // LLDB_TARGET_PATHMAPPINGLIST_H
lldb_private::PathMappingList::iterator
collection::iterator iterator
Definition: PathMappingList.h:114
lldb_private::PathMappingList::const_iterator
collection::const_iterator const_iterator
Definition: PathMappingList.h:115
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:113
lldb_private::PathMappingList::GetSize
size_t GetSize() const
Definition: PathMappingList.h:47
lldb_private::PathMappingList::Replace
bool Replace(ConstString path, ConstString replacement, bool notify)
Definition: PathMappingList.cpp:227
lldb_private::Stream
Definition: Stream.h:28
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::Append
void Append(ConstString path, ConstString replacement, bool notify)
Definition: PathMappingList.cpp:62
lldb_private::PathMappingList::m_mod_id
uint32_t m_mod_id
Definition: PathMappingList.h:124
lldb_private::PathMappingList::FindIndexForPath
uint32_t FindIndexForPath(ConstString path) const
Definition: PathMappingList.cpp:288
lldb_private::ConstString
Definition: ConstString.h:40
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::PathMappingList::m_pairs
collection m_pairs
Definition: PathMappingList.h:121
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:220
lldb_private::PathMappingList::operator=
const PathMappingList & operator=(const PathMappingList &rhs)
Definition: PathMappingList.cpp:50
uint32_t
lldb_private::PathMappingList
Definition: PathMappingList.h:19
lldb_private::PathMappingList::m_callback
ChangedCallback m_callback
Definition: PathMappingList.h:122
lldb_private::PathMappingList::GetModificationID
uint32_t GetModificationID() const
Definition: PathMappingList.h:109
lldb_private::PathMappingList::pair
std::pair< ConstString, ConstString > pair
Definition: PathMappingList.h:112
Status.h
lldb_private::PathMappingList::m_callback_baton
void * m_callback_baton
Definition: PathMappingList.h:123
lldb_private::PathMappingList::IsEmpty
bool IsEmpty() const
Definition: PathMappingList.h:45
lldb_private::PathMappingList::Dump
void Dump(Stream *s, int pair_index=-1)
Definition: PathMappingList.cpp:122
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:108
lldb_private::PathMappingList::Clear
void Clear(bool notify)
Definition: PathMappingList.cpp:138
lldb_private::PathMappingList::Insert
void Insert(ConstString path, ConstString replacement, uint32_t insert_idx, bool notify)
Definition: PathMappingList.cpp:81
lldb_private::PathMappingList::RemapPath
bool RemapPath(ConstString path, ConstString &new_path) const
Definition: PathMappingList.cpp:146
lldb_private::PathMappingList::ReverseRemapPath
bool ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const
Definition: PathMappingList.cpp:204