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;
76 CalculateLineOffsets (uint32_t line = UINT32_MAX);
78 FileSpec m_file_spec_orig; // The original file spec that was used (can be different from m_file_spec)
79 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)
80 TimeValue m_mod_time; // Keep the modification time that this file data is valid for
81 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
82 lldb::DataBufferSP m_data_sp;
83 typedef std::vector<uint32_t> LineOffsets;
84 LineOffsets m_offsets;
89 typedef std::shared_ptr<File> FileSP;
93 // The SourceFileCache class separates the source manager from the cache of source files, so the
94 // cache can be stored in the Debugger, but the source managers can be per target.
101 void AddSourceFile (const FileSP &file_sp);
102 FileSP FindSourceFile (const FileSpec &file_spec) const;
105 typedef std::map <FileSpec, FileSP> FileCache;
106 FileCache m_file_cache;
111 //------------------------------------------------------------------
112 // Constructors and Destructors
113 //------------------------------------------------------------------
114 // A source manager can be made with a non-null target, in which case it can use the path remappings to find
115 // source files that are not in their build locations. With no target it won't be able to do this.
116 SourceManager (const lldb::DebuggerSP &debugger_sp);
117 SourceManager (const lldb::TargetSP &target_sp);
125 return m_last_file_sp;
129 DisplaySourceLinesWithLineNumbers (const FileSpec &file,
131 uint32_t context_before,
132 uint32_t context_after,
133 const char* current_line_cstr,
135 const SymbolContextList *bp_locs = NULL);
137 // This variant uses the last file we visited.
139 DisplaySourceLinesWithLineNumbersUsingLastFile (uint32_t start_line,
142 const char* current_line_cstr,
144 const SymbolContextList *bp_locs = NULL);
147 DisplayMoreWithLineNumbers (Stream *s,
150 const SymbolContextList *bp_locs = NULL);
153 SetDefaultFileAndLine (const FileSpec &file_spec, uint32_t line);
156 GetDefaultFileAndLine (FileSpec &file_spec, uint32_t &line);
159 DefaultFileAndLineSet ()
161 return (m_last_file_sp.get() != NULL);
165 FindLinesMatchingRegex (FileSpec &file_spec,
166 RegularExpression& regex,
169 std::vector<uint32_t> &match_lines);
174 GetFile (const FileSpec &file_spec);
176 //------------------------------------------------------------------
177 // Classes that inherit from SourceManager can see and modify these
178 //------------------------------------------------------------------
179 FileSP m_last_file_sp;
180 uint32_t m_last_line;
181 uint32_t m_last_count;
183 lldb::TargetWP m_target_wp;
184 lldb::DebuggerWP m_debugger_wp;
187 //------------------------------------------------------------------
188 // For SourceManager only
189 //------------------------------------------------------------------
190 DISALLOW_COPY_AND_ASSIGN (SourceManager);
193 bool operator== (const SourceManager::File &lhs, const SourceManager::File &rhs);
194 } // namespace lldb_private
196 #endif // liblldb_SourceManager_h_