]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Core/SourceManager.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / Core / SourceManager.h
1 //===-- SourceManager.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_SourceManager_h_
11 #define liblldb_SourceManager_h_
12
13 // Project includes
14 #include "lldb/Host/FileSpec.h"
15 #include "lldb/lldb-private.h"
16
17 // Other libraries and framework includes
18 #include "llvm/Support/Chrono.h"
19
20 // C Includes
21 // C++ Includes
22 #include <map>
23 #include <memory>
24 #include <vector>
25
26 namespace lldb_private {
27
28 class SourceManager {
29 public:
30 #ifndef SWIG
31   class File {
32     friend bool operator==(const SourceManager::File &lhs,
33                            const SourceManager::File &rhs);
34
35   public:
36     File(const FileSpec &file_spec, Target *target);
37     File(const FileSpec &file_spec, lldb::DebuggerSP debugger_sp);
38     ~File() = default;
39
40     void UpdateIfNeeded();
41
42     size_t DisplaySourceLines(uint32_t line, uint32_t column,
43                               uint32_t context_before, uint32_t context_after,
44                               Stream *s);
45     void FindLinesMatchingRegex(RegularExpression &regex, uint32_t start_line,
46                                 uint32_t end_line,
47                                 std::vector<uint32_t> &match_lines);
48
49     bool GetLine(uint32_t line_no, std::string &buffer);
50
51     uint32_t GetLineOffset(uint32_t line);
52
53     bool LineIsValid(uint32_t line);
54
55     bool FileSpecMatches(const FileSpec &file_spec);
56
57     const FileSpec &GetFileSpec() { return m_file_spec; }
58
59     uint32_t GetSourceMapModificationID() const { return m_source_map_mod_id; }
60
61     const char *PeekLineData(uint32_t line);
62
63     uint32_t GetLineLength(uint32_t line, bool include_newline_chars);
64
65     uint32_t GetNumLines();
66
67   protected:
68     bool CalculateLineOffsets(uint32_t line = UINT32_MAX);
69
70     FileSpec m_file_spec_orig; // The original file spec that was used (can be
71                                // different from m_file_spec)
72     FileSpec m_file_spec; // The actually file spec being used (if the target
73                           // has source mappings, this might be different from
74                           // m_file_spec_orig)
75
76     // Keep the modification time that this file data is valid for
77     llvm::sys::TimePoint<> m_mod_time;
78
79     // If the target uses path remappings, be sure to clear our notion of a
80     // source file if the path modification ID changes
81     uint32_t m_source_map_mod_id = 0;
82     lldb::DataBufferSP m_data_sp;
83     typedef std::vector<uint32_t> LineOffsets;
84     LineOffsets m_offsets;
85     lldb::DebuggerWP m_debugger_wp;
86
87   private:
88     void CommonInitializer(const FileSpec &file_spec, Target *target);
89   };
90 #endif // SWIG
91
92   typedef std::shared_ptr<File> FileSP;
93
94 #ifndef SWIG
95   // The SourceFileCache class separates the source manager from the cache of
96   // source files, so the
97   // cache can be stored in the Debugger, but the source managers can be per
98   // target.
99   class SourceFileCache {
100   public:
101     SourceFileCache() = default;
102     ~SourceFileCache() = default;
103
104     void AddSourceFile(const FileSP &file_sp);
105     FileSP FindSourceFile(const FileSpec &file_spec) const;
106
107   protected:
108     typedef std::map<FileSpec, FileSP> FileCache;
109     FileCache m_file_cache;
110   };
111 #endif // SWIG
112
113   //------------------------------------------------------------------
114   // Constructors and Destructors
115   //------------------------------------------------------------------
116   // A source manager can be made with a non-null target, in which case it can
117   // use the path remappings to find
118   // source files that are not in their build locations.  With no target it
119   // won't be able to do this.
120   SourceManager(const lldb::DebuggerSP &debugger_sp);
121   SourceManager(const lldb::TargetSP &target_sp);
122
123   ~SourceManager();
124
125   FileSP GetLastFile() { return m_last_file_sp; }
126
127   size_t
128   DisplaySourceLinesWithLineNumbers(const FileSpec &file, uint32_t line,
129                                     uint32_t column, uint32_t context_before,
130                                     uint32_t context_after,
131                                     const char *current_line_cstr, Stream *s,
132                                     const SymbolContextList *bp_locs = nullptr);
133
134   // This variant uses the last file we visited.
135   size_t DisplaySourceLinesWithLineNumbersUsingLastFile(
136       uint32_t start_line, uint32_t count, uint32_t curr_line, uint32_t column,
137       const char *current_line_cstr, Stream *s,
138       const SymbolContextList *bp_locs = nullptr);
139
140   size_t DisplayMoreWithLineNumbers(Stream *s, uint32_t count, bool reverse,
141                                     const SymbolContextList *bp_locs = nullptr);
142
143   bool SetDefaultFileAndLine(const FileSpec &file_spec, uint32_t line);
144
145   bool GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line);
146
147   bool DefaultFileAndLineSet() { return (m_last_file_sp.get() != nullptr); }
148
149   void FindLinesMatchingRegex(FileSpec &file_spec, RegularExpression &regex,
150                               uint32_t start_line, uint32_t end_line,
151                               std::vector<uint32_t> &match_lines);
152
153   FileSP GetFile(const FileSpec &file_spec);
154
155 protected:
156   FileSP m_last_file_sp;
157   uint32_t m_last_line;
158   uint32_t m_last_count;
159   bool m_default_set;
160   lldb::TargetWP m_target_wp;
161   lldb::DebuggerWP m_debugger_wp;
162
163 private:
164   DISALLOW_COPY_AND_ASSIGN(SourceManager);
165 };
166
167 bool operator==(const SourceManager::File &lhs, const SourceManager::File &rhs);
168
169 } // namespace lldb_private
170
171 #endif // liblldb_SourceManager_h_