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_
19 // Other libraries and framework includes
21 #include "lldb/lldb-private.h"
22 #include "lldb/Host/FileSpec.h"
24 namespace lldb_private {
32 friend bool operator== (const SourceManager::File &lhs, const SourceManager::File &rhs);
35 File (const FileSpec &file_spec, Target *target);
42 DisplaySourceLines (uint32_t line,
43 uint32_t context_before,
44 uint32_t context_after,
47 FindLinesMatchingRegex (RegularExpression& regex,
50 std::vector<uint32_t> &match_lines);
53 GetLine (uint32_t line_no, std::string &buffer);
56 GetLineOffset (uint32_t line);
59 LineIsValid (uint32_t line);
62 FileSpecMatches (const FileSpec &file_spec);
71 GetSourceMapModificationID() const
73 return m_source_map_mod_id;
77 PeekLineData (uint32_t line);
80 GetLineLength (uint32_t line, bool include_newline_chars);
87 CalculateLineOffsets (uint32_t line = UINT32_MAX);
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;
99 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() = default;
108 ~SourceFileCache() = default;
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;
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);
132 return m_last_file_sp;
136 DisplaySourceLinesWithLineNumbers(const FileSpec &file,
138 uint32_t context_before,
139 uint32_t context_after,
140 const char* current_line_cstr,
142 const SymbolContextList *bp_locs = nullptr);
144 // This variant uses the last file we visited.
146 DisplaySourceLinesWithLineNumbersUsingLastFile(uint32_t start_line,
149 const char* current_line_cstr,
151 const SymbolContextList *bp_locs = nullptr);
154 DisplayMoreWithLineNumbers(Stream *s,
157 const SymbolContextList *bp_locs = nullptr);
160 SetDefaultFileAndLine (const FileSpec &file_spec, uint32_t line);
163 GetDefaultFileAndLine (FileSpec &file_spec, uint32_t &line);
166 DefaultFileAndLineSet ()
168 return (m_last_file_sp.get() != nullptr);
172 FindLinesMatchingRegex (FileSpec &file_spec,
173 RegularExpression& regex,
176 std::vector<uint32_t> &match_lines);
179 GetFile (const FileSpec &file_spec);
182 FileSP m_last_file_sp;
183 uint32_t m_last_line;
184 uint32_t m_last_count;
186 lldb::TargetWP m_target_wp;
187 lldb::DebuggerWP m_debugger_wp;
190 DISALLOW_COPY_AND_ASSIGN (SourceManager);
193 bool operator== (const SourceManager::File &lhs, const SourceManager::File &rhs);
195 } // namespace lldb_private
197 #endif // liblldb_SourceManager_h_