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