1 //===-- SourceManager.h -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_SourceManager_h_
11 #define liblldb_SourceManager_h_
18 // Other libraries and framework includes
20 #include "lldb/lldb-private.h"
21 #include "lldb/Host/FileSpec.h"
23 namespace lldb_private {
32 friend bool operator== (const SourceManager::File &lhs, const SourceManager::File &rhs);
35 File (const FileSpec &file_spec, Target *target);
39 DisplaySourceLines (uint32_t line,
40 uint32_t context_before,
41 uint32_t context_after,
44 FindLinesMatchingRegex (RegularExpression& regex,
47 std::vector<uint32_t> &match_lines);
50 GetLine (uint32_t line_no, std::string &buffer);
53 GetLineOffset (uint32_t line);
56 LineIsValid (uint32_t line);
59 FileSpecMatches (const FileSpec &file_spec);
68 GetSourceMapModificationID() const
70 return m_source_map_mod_id;
74 PeekLineData (uint32_t line);
77 GetLineLength (uint32_t line, bool include_newline_chars);
85 CalculateLineOffsets (uint32_t line = UINT32_MAX);
87 FileSpec m_file_spec_orig; // The original file spec that was used (can be different from m_file_spec)
88 FileSpec m_file_spec; // The actualy file spec being used (if the target has source mappings, this might be different from m_file_spec_orig)
89 TimeValue m_mod_time; // Keep the modification time that this file data is valid for
90 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
91 lldb::DataBufferSP m_data_sp;
92 typedef std::vector<uint32_t> LineOffsets;
93 LineOffsets m_offsets;
98 typedef std::shared_ptr<File> FileSP;
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
107 SourceFileCache () {}
108 ~SourceFileCache() {}
110 void AddSourceFile (const FileSP &file_sp);
111 FileSP FindSourceFile (const FileSpec &file_spec) const;
114 typedef std::map <FileSpec, FileSP> FileCache;
115 FileCache m_file_cache;
120 //------------------------------------------------------------------
121 // Constructors and Destructors
122 //------------------------------------------------------------------
123 // A source manager can be made with a non-null target, in which case it can use the path remappings to find
124 // source files that are not in their build locations. With no target it won't be able to do this.
125 SourceManager (const lldb::DebuggerSP &debugger_sp);
126 SourceManager (const lldb::TargetSP &target_sp);
134 return m_last_file_sp;
138 DisplaySourceLinesWithLineNumbers (const FileSpec &file,
140 uint32_t context_before,
141 uint32_t context_after,
142 const char* current_line_cstr,
144 const SymbolContextList *bp_locs = NULL);
146 // This variant uses the last file we visited.
148 DisplaySourceLinesWithLineNumbersUsingLastFile (uint32_t start_line,
151 const char* current_line_cstr,
153 const SymbolContextList *bp_locs = NULL);
156 DisplayMoreWithLineNumbers (Stream *s,
159 const SymbolContextList *bp_locs = NULL);
162 SetDefaultFileAndLine (const FileSpec &file_spec, uint32_t line);
165 GetDefaultFileAndLine (FileSpec &file_spec, uint32_t &line);
168 DefaultFileAndLineSet ()
170 return (m_last_file_sp.get() != NULL);
174 FindLinesMatchingRegex (FileSpec &file_spec,
175 RegularExpression& regex,
178 std::vector<uint32_t> &match_lines);
181 GetFile (const FileSpec &file_spec);
185 //------------------------------------------------------------------
186 // Classes that inherit from SourceManager can see and modify these
187 //------------------------------------------------------------------
188 FileSP m_last_file_sp;
189 uint32_t m_last_line;
190 uint32_t m_last_count;
192 lldb::TargetWP m_target_wp;
193 lldb::DebuggerWP m_debugger_wp;
196 //------------------------------------------------------------------
197 // For SourceManager only
198 //------------------------------------------------------------------
199 DISALLOW_COPY_AND_ASSIGN (SourceManager);
202 bool operator== (const SourceManager::File &lhs, const SourceManager::File &rhs);
203 } // namespace lldb_private
205 #endif // liblldb_SourceManager_h_