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