CompileUnit.h revision 9488b7423b556c7c777b721d2094fd5ec4a47578
1//===-- CompileUnit.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_CompUnit_h_ 11#define liblldb_CompUnit_h_ 12 13#include "lldb/Symbol/Function.h" 14#include "lldb/Core/FileSpecList.h" 15#include "lldb/Core/Language.h" 16#include "lldb/Core/ModuleChild.h" 17#include "lldb/Core/Stream.h" 18#include "lldb/Core/UserID.h" 19 20namespace lldb_private { 21//---------------------------------------------------------------------- 22/// @class CompileUnit CompileUnit.h "lldb/Symbol/CompileUnit.h" 23/// @brief A class that describes a compilation unit. 24/// 25/// A representation of a compilation unit, or compiled source file. 26/// The UserID of the compile unit is specified by the SymbolFile 27/// plug-in and can have any value as long as the value is unique 28/// within the Module that owns this compile units. 29/// 30/// Each compile unit has a list of functions, global and static 31/// variables, support file list (include files and inlined source 32/// files), and a line table. 33//---------------------------------------------------------------------- 34class CompileUnit : 35 public ModuleChild, 36 public FileSpec, 37 public UserID, 38 public Language, 39 public SymbolContextScope 40{ 41public: 42 //------------------------------------------------------------------ 43 /// Construct with a module, path, UID and language. 44 /// 45 /// Initialize the compile unit given the owning \a module, a path 46 /// to convert into a FileSpec, the SymbolFile plug-in supplied 47 /// \a uid, and the source language type. 48 /// 49 /// @param[in] module 50 /// The parent module that owns this compile unit. This value 51 /// must be a valid pointer value. 52 /// 53 /// @param[in] user_data 54 /// User data where the SymbolFile parser can store data. 55 /// 56 /// @param[in] pathname 57 /// The path to the source file for this compile unit. 58 /// 59 /// @param[in] uid 60 /// The user ID of the compile unit. This value is supplied by 61 /// the SymbolFile plug-in and should be a value that allows 62 /// the SymbolFile plug-in to easily locate and parse additional 63 /// information for the compile unit. 64 /// 65 /// @param[in] language 66 /// A language enumeration type that describes the main language 67 /// of this compile unit. 68 /// 69 /// @see lldb::LanguageType 70 //------------------------------------------------------------------ 71 CompileUnit(Module *module, void *user_data, const char *pathname, lldb::user_id_t uid, lldb::LanguageType language); 72 73 //------------------------------------------------------------------ 74 /// Construct with a module, file spec, UID and language. 75 /// 76 /// Initialize the compile unit given the owning \a module, a path 77 /// to convert into a FileSpec, the SymbolFile plug-in supplied 78 /// \a uid, and the source language type. 79 /// 80 /// @param[in] module 81 /// The parent module that owns this compile unit. This value 82 /// must be a valid pointer value. 83 /// 84 /// @param[in] user_data 85 /// User data where the SymbolFile parser can store data. 86 /// 87 /// @param[in] file_spec 88 /// The file specification for the source file of this compile 89 /// unit. 90 /// 91 /// @param[in] uid 92 /// The user ID of the compile unit. This value is supplied by 93 /// the SymbolFile plug-in and should be a value that allows 94 /// the plug-in to easily locate and parse 95 /// additional information for the compile unit. 96 /// 97 /// @param[in] language 98 /// A language enumeration type that describes the main language 99 /// of this compile unit. 100 /// 101 /// @see lldb::LanguageType 102 //------------------------------------------------------------------ 103 CompileUnit(Module *module, void *user_data, const FileSpec &file_spec, lldb::user_id_t uid, lldb::LanguageType language); 104 105 //------------------------------------------------------------------ 106 /// Destructor 107 //------------------------------------------------------------------ 108 ~CompileUnit(); 109 110 //------------------------------------------------------------------ 111 /// Add a function to this compile unit. 112 /// 113 /// Typically called by the SymbolFile plug-ins as they partially 114 /// parse the debug information. 115 /// 116 /// @param[in] function_sp 117 /// A shared pointer to the a Function object. 118 //------------------------------------------------------------------ 119 void 120 AddFunction(lldb::FunctionSP& function_sp); 121 122 //------------------------------------------------------------------ 123 /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*) 124 /// 125 /// @see SymbolContextScope 126 //------------------------------------------------------------------ 127 virtual void 128 CalculateSymbolContext(SymbolContext* sc); 129 130 //------------------------------------------------------------------ 131 /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*) 132 /// 133 /// @see SymbolContextScope 134 //------------------------------------------------------------------ 135 virtual void 136 DumpSymbolContext(Stream *s); 137 138 139 void 140 GetDescription(Stream *s, lldb::DescriptionLevel level) const; 141 142 //------------------------------------------------------------------ 143 /// Get a shared pointer to a function in this compile unit by 144 /// index. 145 /// 146 /// Typically called when iterating though all functions in a 147 /// compile unit after all functions have been parsed. This provides 148 /// raw access to the function shared pointer list and will not 149 /// cause the SymbolFile plug-in to parse any unparsed functions. 150 /// 151 /// @param[in] idx 152 /// An index into the function list. 153 /// 154 /// @return 155 /// A shared pointer to a function that might contain a NULL 156 /// Function class pointer. 157 //------------------------------------------------------------------ 158 lldb::FunctionSP 159 GetFunctionAtIndex (size_t idx); 160 161 //------------------------------------------------------------------ 162 /// Dump the compile unit contents to the stream \a s. 163 /// 164 /// @param[in] s 165 /// The stream to which to dump the object descripton. 166 /// 167 /// @param[in] show_context 168 /// If \b true, variables will dump their symbol context 169 /// information. 170 //------------------------------------------------------------------ 171 void 172 Dump (Stream *s, bool show_context) const; 173 174 //------------------------------------------------------------------ 175 /// Find the line entry by line and optional inlined file spec. 176 /// 177 /// Finds the first line entry that has an index greater than 178 /// \a start_idx that matches \a line. If \a file_spec_ptr 179 /// is NULL, then the search matches line entries whose file matches 180 /// the file for the compile unit. If \a file_spec_ptr is 181 /// not NULL, line entries must match the specified file spec (for 182 /// inlined line table entries). 183 /// 184 /// Multiple calls to this function can find all entries that match 185 /// a given file and line by starting with \a start_idx equal to zero, 186 /// and calling this function back with the return valeu + 1. 187 /// 188 /// @param[in] start_idx 189 /// The zero based index at which to start looking for matches. 190 /// 191 /// @param[in] line 192 /// The line number to search for. 193 /// 194 /// @param[in] file_spec_ptr 195 /// If non-NULL search for entries that match this file spec, 196 /// else if NULL, search for line entries that match the compile 197 /// unit file. 198 /// 199 /// @param[out] line_entry 200 /// If non-NULL, a copy of the line entry that was found. 201 /// 202 /// @return 203 /// The zero based index of a matching line entry, or UINT32_MAX 204 /// if no matching line entry is found. 205 //------------------------------------------------------------------ 206 uint32_t 207 FindLineEntry (uint32_t start_idx, 208 uint32_t line, 209 const FileSpec* file_spec_ptr, 210 LineEntry *line_entry); 211 212 //------------------------------------------------------------------ 213 /// Get the line table for the compile unit. 214 /// 215 /// Called by clients and the SymbolFile plug-in. The SymbolFile 216 /// plug-ins use this function to determine if the line table has 217 /// be parsed yet. Clients use this function to get the line table 218 /// from a compile unit. 219 /// 220 /// @return 221 /// The line table object pointer, or NULL if this line table 222 /// hasn't been parsed yet. 223 //------------------------------------------------------------------ 224 LineTable* 225 GetLineTable (); 226 227 //------------------------------------------------------------------ 228 /// Get the compile unit's support file list. 229 /// 230 /// The support file list is used by the line table, and any objects 231 /// that have valid Declaration objects. 232 /// 233 /// @return 234 /// A support file list object. 235 //------------------------------------------------------------------ 236 FileSpecList& 237 GetSupportFiles (); 238 239 //------------------------------------------------------------------ 240 /// Get the SymbolFile plug-in user data. 241 /// 242 /// SymbolFile plug-ins can store user data to internal state or 243 /// objects to quickly allow them to parse more information for a 244 /// given object. 245 /// 246 /// @return 247 /// The user data stored with the CompileUnit when it was 248 /// constructed. 249 //------------------------------------------------------------------ 250 void * 251 GetUserData () const; 252 253 //------------------------------------------------------------------ 254 /// Get the variable list for a compile unit. 255 /// 256 /// Called by clients to get the variable list for a compile unit. 257 /// The variable list will contain all global and static variables 258 /// that were defined at the compile unit level. 259 /// 260 /// @param[in] can_create 261 /// If \b true, the variable list will be parsed on demand. If 262 /// \b false, the current variable list will be returned even 263 /// if it contains a NULL VariableList object (typically 264 /// called by dumping routines that want to display only what 265 /// has currently been parsed). 266 /// 267 /// @return 268 /// A shared pointer to a variable list, that can contain NULL 269 /// VariableList pointer if there are no global or static 270 /// variables. 271 //------------------------------------------------------------------ 272 lldb::VariableListSP 273 GetVariableList (bool can_create); 274 275 //------------------------------------------------------------------ 276 /// Finds a function by user ID. 277 /// 278 /// Typically used by SymbolFile plug-ins when partially parsing 279 /// the debug information to see if the function has been parsed 280 /// yet. 281 /// 282 /// @param[in] uid 283 /// The user ID of the function to find. This value is supplied 284 /// by the SymbolFile plug-in and should be a value that 285 /// allows the plug-in to easily locate and parse additional 286 /// information in the function. 287 /// 288 /// @return 289 /// A shared pointer to the function object that might contain 290 /// a NULL Function pointer. 291 //------------------------------------------------------------------ 292 lldb::FunctionSP 293 FindFunctionByUID (lldb::user_id_t uid); 294 295 //------------------------------------------------------------------ 296 /// Set the line table for the compile unit. 297 /// 298 /// Called by the SymbolFile plug-in when if first parses the line 299 /// table and hands ownership of the line table to this object. The 300 /// compile unit owns the line table object and will delete the 301 /// object when it is deleted. 302 /// 303 /// @param[in] line_table 304 /// A line table object pointer that this object now owns. 305 //------------------------------------------------------------------ 306 void 307 SetLineTable(LineTable* line_table); 308 309 //------------------------------------------------------------------ 310 /// Set accessor for the variable list. 311 /// 312 /// Called by the SymbolFile plug-ins after they have parsed the 313 /// variable lists and are ready to hand ownership of the list over 314 /// to this object. 315 /// 316 /// @param[in] variable_list_sp 317 /// A shared pointer to a VariableList. 318 //------------------------------------------------------------------ 319 void 320 SetVariableList (lldb::VariableListSP& variable_list_sp); 321 322 //------------------------------------------------------------------ 323 /// Resolve symbol contexts by file and line. 324 /// 325 /// Given a file in \a file_spec, and a line number, find all 326 /// instances and append them to the supplied symbol context list 327 /// \a sc_list. 328 /// 329 /// @param[in] file_spec 330 /// A file specification. If \a file_spec contains no directory 331 /// information, only the basename will be used when matching 332 /// contexts. If the directory in \a file_spec is valid, a 333 /// complete file specification match will be performed. 334 /// 335 /// @param[in] line 336 /// The line number to match against the compile unit's line 337 /// tables. 338 /// 339 /// @param[in] check_inlines 340 /// If \b true this function will also match any inline 341 /// file and line matches. If \b false, the compile unit's 342 /// file specification must match \a file_spec for any matches 343 /// to be returned. 344 /// 345 /// @param[in] exact 346 /// If true, only resolve the context if \a line exists in the line table. 347 /// If false, resolve the context to the closest line greater than \a line 348 /// in the line table. 349 /// 350 /// @param[in] resolve_scope 351 /// For each matching line entry, this bitfield indicates what 352 /// values within each SymbolContext that gets added to \a 353 /// sc_list will be resolved. See the SymbolContext::Scope 354 /// enumeration for a list of all available bits that can be 355 /// resolved. Only SymbolContext entries that can be resolved 356 /// using a LineEntry base address will be able to be resolved. 357 /// 358 /// @param[out] sc_list 359 /// A SymbolContext list class that willl get any matching 360 /// entries appended to. 361 /// 362 /// @return 363 /// The number of new matches that were added to \a sc_list. 364 /// 365 /// @see enum SymbolContext::Scope 366 //------------------------------------------------------------------ 367 uint32_t 368 ResolveSymbolContext (const FileSpec& file_spec, 369 uint32_t line, 370 bool check_inlines, 371 bool exact, 372 uint32_t resolve_scope, 373 SymbolContextList &sc_list); 374 375 376protected: 377 void *m_user_data; ///< User data for the SymbolFile parser to store information into. 378 Flags m_flags; ///< Compile unit flags that help with partial parsing. 379 std::vector<lldb::FunctionSP> m_functions; ///< The sparsely populated list of shared pointers to functions 380 ///< that gets populated as functions get partially parsed. 381 FileSpecList m_support_files; ///< Files associated with this compile unit's line table and declarations. 382 std::auto_ptr<LineTable> m_line_table_ap; ///< Line table that will get parsed on demand. 383 lldb::VariableListSP m_variables; ///< Global and static variable list that will get parsed on demand. 384 385private: 386 enum 387 { 388 flagsParsedAllFunctions = (1 << 0), ///< Have we already parsed all our functions 389 flagsParsedVariables = (1 << 1), ///< Have we already parsed globals and statics? 390 flagsParsedSupportFiles = (1 << 2), ///< Have we already parsed the support files for this compile unit? 391 flagsParsedLineTable = (1 << 3) ///< Have we parsed the line table already? 392 }; 393 394 DISALLOW_COPY_AND_ASSIGN (CompileUnit); 395}; 396 397} // namespace lldb_private 398 399#endif // liblldb_CompUnit_h_ 400