1254721Semaste//===-- CompileUnit.h -------------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#ifndef liblldb_CompUnit_h_ 11254721Semaste#define liblldb_CompUnit_h_ 12254721Semaste 13254721Semaste#include "lldb/lldb-enumerations.h" 14254721Semaste#include "lldb/Symbol/Function.h" 15254721Semaste#include "lldb/Core/FileSpecList.h" 16254721Semaste#include "lldb/Core/ModuleChild.h" 17254721Semaste#include "lldb/Core/Stream.h" 18254721Semaste#include "lldb/Core/UserID.h" 19254721Semaste 20254721Semastenamespace lldb_private { 21254721Semaste//---------------------------------------------------------------------- 22254721Semaste/// @class CompileUnit CompileUnit.h "lldb/Symbol/CompileUnit.h" 23254721Semaste/// @brief A class that describes a compilation unit. 24254721Semaste/// 25254721Semaste/// A representation of a compilation unit, or compiled source file. 26254721Semaste/// The UserID of the compile unit is specified by the SymbolFile 27254721Semaste/// plug-in and can have any value as long as the value is unique 28254721Semaste/// within the Module that owns this compile units. 29254721Semaste/// 30254721Semaste/// Each compile unit has a list of functions, global and static 31254721Semaste/// variables, support file list (include files and inlined source 32254721Semaste/// files), and a line table. 33254721Semaste//---------------------------------------------------------------------- 34254721Semasteclass CompileUnit : 35254721Semaste public std::enable_shared_from_this<CompileUnit>, 36254721Semaste public ModuleChild, 37254721Semaste public FileSpec, 38254721Semaste public UserID, 39254721Semaste public SymbolContextScope 40254721Semaste{ 41254721Semastepublic: 42254721Semaste //------------------------------------------------------------------ 43254721Semaste /// Construct with a module, path, UID and language. 44254721Semaste /// 45254721Semaste /// Initialize the compile unit given the owning \a module, a path 46254721Semaste /// to convert into a FileSpec, the SymbolFile plug-in supplied 47254721Semaste /// \a uid, and the source language type. 48254721Semaste /// 49254721Semaste /// @param[in] module 50254721Semaste /// The parent module that owns this compile unit. This value 51254721Semaste /// must be a valid pointer value. 52254721Semaste /// 53254721Semaste /// @param[in] user_data 54254721Semaste /// User data where the SymbolFile parser can store data. 55254721Semaste /// 56254721Semaste /// @param[in] pathname 57254721Semaste /// The path to the source file for this compile unit. 58254721Semaste /// 59254721Semaste /// @param[in] uid 60254721Semaste /// The user ID of the compile unit. This value is supplied by 61254721Semaste /// the SymbolFile plug-in and should be a value that allows 62254721Semaste /// the SymbolFile plug-in to easily locate and parse additional 63254721Semaste /// information for the compile unit. 64254721Semaste /// 65254721Semaste /// @param[in] language 66254721Semaste /// A language enumeration type that describes the main language 67254721Semaste /// of this compile unit. 68254721Semaste /// 69254721Semaste /// @see lldb::LanguageType 70254721Semaste //------------------------------------------------------------------ 71254721Semaste CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, const char *pathname, lldb::user_id_t uid, lldb::LanguageType language); 72254721Semaste 73254721Semaste //------------------------------------------------------------------ 74254721Semaste /// Construct with a module, file spec, UID and language. 75254721Semaste /// 76254721Semaste /// Initialize the compile unit given the owning \a module, a path 77254721Semaste /// to convert into a FileSpec, the SymbolFile plug-in supplied 78254721Semaste /// \a uid, and the source language type. 79254721Semaste /// 80254721Semaste /// @param[in] module 81254721Semaste /// The parent module that owns this compile unit. This value 82254721Semaste /// must be a valid pointer value. 83254721Semaste /// 84254721Semaste /// @param[in] user_data 85254721Semaste /// User data where the SymbolFile parser can store data. 86254721Semaste /// 87254721Semaste /// @param[in] file_spec 88254721Semaste /// The file specification for the source file of this compile 89254721Semaste /// unit. 90254721Semaste /// 91254721Semaste /// @param[in] uid 92254721Semaste /// The user ID of the compile unit. This value is supplied by 93254721Semaste /// the SymbolFile plug-in and should be a value that allows 94254721Semaste /// the plug-in to easily locate and parse 95254721Semaste /// additional information for the compile unit. 96254721Semaste /// 97254721Semaste /// @param[in] language 98254721Semaste /// A language enumeration type that describes the main language 99254721Semaste /// of this compile unit. 100254721Semaste /// 101254721Semaste /// @see lldb::LanguageType 102254721Semaste //------------------------------------------------------------------ 103254721Semaste CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, const FileSpec &file_spec, lldb::user_id_t uid, lldb::LanguageType language); 104254721Semaste 105254721Semaste //------------------------------------------------------------------ 106254721Semaste /// Destructor 107254721Semaste //------------------------------------------------------------------ 108254721Semaste virtual 109254721Semaste ~CompileUnit(); 110254721Semaste 111254721Semaste //------------------------------------------------------------------ 112254721Semaste /// Add a function to this compile unit. 113254721Semaste /// 114254721Semaste /// Typically called by the SymbolFile plug-ins as they partially 115254721Semaste /// parse the debug information. 116254721Semaste /// 117254721Semaste /// @param[in] function_sp 118254721Semaste /// A shared pointer to the a Function object. 119254721Semaste //------------------------------------------------------------------ 120254721Semaste void 121254721Semaste AddFunction(lldb::FunctionSP& function_sp); 122254721Semaste 123254721Semaste //------------------------------------------------------------------ 124254721Semaste /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*) 125254721Semaste /// 126254721Semaste /// @see SymbolContextScope 127254721Semaste //------------------------------------------------------------------ 128254721Semaste virtual void 129254721Semaste CalculateSymbolContext(SymbolContext* sc); 130254721Semaste 131254721Semaste virtual lldb::ModuleSP 132254721Semaste CalculateSymbolContextModule (); 133254721Semaste 134254721Semaste virtual CompileUnit * 135254721Semaste CalculateSymbolContextCompileUnit (); 136254721Semaste 137254721Semaste //------------------------------------------------------------------ 138254721Semaste /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*) 139254721Semaste /// 140254721Semaste /// @see SymbolContextScope 141254721Semaste //------------------------------------------------------------------ 142254721Semaste virtual void 143254721Semaste DumpSymbolContext(Stream *s); 144254721Semaste 145254721Semaste lldb::LanguageType 146254721Semaste GetLanguage(); 147254721Semaste 148254721Semaste void 149254721Semaste SetLanguage(lldb::LanguageType language) 150254721Semaste { 151254721Semaste m_flags.Set(flagsParsedLanguage); 152254721Semaste m_language = language; 153254721Semaste } 154254721Semaste 155254721Semaste void 156254721Semaste GetDescription(Stream *s, lldb::DescriptionLevel level) const; 157254721Semaste 158254721Semaste //------------------------------------------------------------------ 159254721Semaste /// Get a shared pointer to a function in this compile unit by 160254721Semaste /// index. 161254721Semaste /// 162254721Semaste /// Typically called when iterating though all functions in a 163254721Semaste /// compile unit after all functions have been parsed. This provides 164254721Semaste /// raw access to the function shared pointer list and will not 165254721Semaste /// cause the SymbolFile plug-in to parse any unparsed functions. 166254721Semaste /// 167254721Semaste /// @param[in] idx 168254721Semaste /// An index into the function list. 169254721Semaste /// 170254721Semaste /// @return 171254721Semaste /// A shared pointer to a function that might contain a NULL 172254721Semaste /// Function class pointer. 173254721Semaste //------------------------------------------------------------------ 174254721Semaste lldb::FunctionSP 175254721Semaste GetFunctionAtIndex (size_t idx); 176254721Semaste 177254721Semaste //------------------------------------------------------------------ 178254721Semaste /// Dump the compile unit contents to the stream \a s. 179254721Semaste /// 180254721Semaste /// @param[in] s 181254721Semaste /// The stream to which to dump the object descripton. 182254721Semaste /// 183254721Semaste /// @param[in] show_context 184254721Semaste /// If \b true, variables will dump their symbol context 185254721Semaste /// information. 186254721Semaste //------------------------------------------------------------------ 187254721Semaste void 188254721Semaste Dump (Stream *s, bool show_context) const; 189254721Semaste 190254721Semaste //------------------------------------------------------------------ 191254721Semaste /// Find the line entry by line and optional inlined file spec. 192254721Semaste /// 193254721Semaste /// Finds the first line entry that has an index greater than 194254721Semaste /// \a start_idx that matches \a line. If \a file_spec_ptr 195254721Semaste /// is NULL, then the search matches line entries whose file matches 196254721Semaste /// the file for the compile unit. If \a file_spec_ptr is 197254721Semaste /// not NULL, line entries must match the specified file spec (for 198254721Semaste /// inlined line table entries). 199254721Semaste /// 200254721Semaste /// Multiple calls to this function can find all entries that match 201254721Semaste /// a given file and line by starting with \a start_idx equal to zero, 202254721Semaste /// and calling this function back with the return valeu + 1. 203254721Semaste /// 204254721Semaste /// @param[in] start_idx 205254721Semaste /// The zero based index at which to start looking for matches. 206254721Semaste /// 207254721Semaste /// @param[in] line 208254721Semaste /// The line number to search for. 209254721Semaste /// 210254721Semaste /// @param[in] file_spec_ptr 211254721Semaste /// If non-NULL search for entries that match this file spec, 212254721Semaste /// else if NULL, search for line entries that match the compile 213254721Semaste /// unit file. 214254721Semaste /// 215254721Semaste /// @param[in] exact 216254721Semaste /// If \btrue match only if there is a line table entry for this line number. 217254721Semaste /// If \bfalse, find the line table entry equal to or after this line number. 218254721Semaste /// 219254721Semaste /// @param[out] line_entry 220254721Semaste /// If non-NULL, a copy of the line entry that was found. 221254721Semaste /// 222254721Semaste /// @return 223254721Semaste /// The zero based index of a matching line entry, or UINT32_MAX 224254721Semaste /// if no matching line entry is found. 225254721Semaste //------------------------------------------------------------------ 226254721Semaste uint32_t 227254721Semaste FindLineEntry (uint32_t start_idx, 228254721Semaste uint32_t line, 229254721Semaste const FileSpec* file_spec_ptr, 230254721Semaste bool exact, 231254721Semaste LineEntry *line_entry); 232254721Semaste 233254721Semaste //------------------------------------------------------------------ 234254721Semaste /// Get the line table for the compile unit. 235254721Semaste /// 236254721Semaste /// Called by clients and the SymbolFile plug-in. The SymbolFile 237254721Semaste /// plug-ins use this function to determine if the line table has 238254721Semaste /// be parsed yet. Clients use this function to get the line table 239254721Semaste /// from a compile unit. 240254721Semaste /// 241254721Semaste /// @return 242254721Semaste /// The line table object pointer, or NULL if this line table 243254721Semaste /// hasn't been parsed yet. 244254721Semaste //------------------------------------------------------------------ 245254721Semaste LineTable* 246254721Semaste GetLineTable (); 247254721Semaste 248254721Semaste //------------------------------------------------------------------ 249254721Semaste /// Get the compile unit's support file list. 250254721Semaste /// 251254721Semaste /// The support file list is used by the line table, and any objects 252254721Semaste /// that have valid Declaration objects. 253254721Semaste /// 254254721Semaste /// @return 255254721Semaste /// A support file list object. 256254721Semaste //------------------------------------------------------------------ 257254721Semaste FileSpecList& 258254721Semaste GetSupportFiles (); 259254721Semaste 260254721Semaste //------------------------------------------------------------------ 261254721Semaste /// Get the SymbolFile plug-in user data. 262254721Semaste /// 263254721Semaste /// SymbolFile plug-ins can store user data to internal state or 264254721Semaste /// objects to quickly allow them to parse more information for a 265254721Semaste /// given object. 266254721Semaste /// 267254721Semaste /// @return 268254721Semaste /// The user data stored with the CompileUnit when it was 269254721Semaste /// constructed. 270254721Semaste //------------------------------------------------------------------ 271254721Semaste void * 272254721Semaste GetUserData () const; 273254721Semaste 274254721Semaste //------------------------------------------------------------------ 275254721Semaste /// Get the variable list for a compile unit. 276254721Semaste /// 277254721Semaste /// Called by clients to get the variable list for a compile unit. 278254721Semaste /// The variable list will contain all global and static variables 279254721Semaste /// that were defined at the compile unit level. 280254721Semaste /// 281254721Semaste /// @param[in] can_create 282254721Semaste /// If \b true, the variable list will be parsed on demand. If 283254721Semaste /// \b false, the current variable list will be returned even 284254721Semaste /// if it contains a NULL VariableList object (typically 285254721Semaste /// called by dumping routines that want to display only what 286254721Semaste /// has currently been parsed). 287254721Semaste /// 288254721Semaste /// @return 289254721Semaste /// A shared pointer to a variable list, that can contain NULL 290254721Semaste /// VariableList pointer if there are no global or static 291254721Semaste /// variables. 292254721Semaste //------------------------------------------------------------------ 293254721Semaste lldb::VariableListSP 294254721Semaste GetVariableList (bool can_create); 295254721Semaste 296254721Semaste //------------------------------------------------------------------ 297254721Semaste /// Finds a function by user ID. 298254721Semaste /// 299254721Semaste /// Typically used by SymbolFile plug-ins when partially parsing 300254721Semaste /// the debug information to see if the function has been parsed 301254721Semaste /// yet. 302254721Semaste /// 303254721Semaste /// @param[in] uid 304254721Semaste /// The user ID of the function to find. This value is supplied 305254721Semaste /// by the SymbolFile plug-in and should be a value that 306254721Semaste /// allows the plug-in to easily locate and parse additional 307254721Semaste /// information in the function. 308254721Semaste /// 309254721Semaste /// @return 310254721Semaste /// A shared pointer to the function object that might contain 311254721Semaste /// a NULL Function pointer. 312254721Semaste //------------------------------------------------------------------ 313254721Semaste lldb::FunctionSP 314254721Semaste FindFunctionByUID (lldb::user_id_t uid); 315254721Semaste 316254721Semaste //------------------------------------------------------------------ 317254721Semaste /// Set the line table for the compile unit. 318254721Semaste /// 319254721Semaste /// Called by the SymbolFile plug-in when if first parses the line 320254721Semaste /// table and hands ownership of the line table to this object. The 321254721Semaste /// compile unit owns the line table object and will delete the 322254721Semaste /// object when it is deleted. 323254721Semaste /// 324254721Semaste /// @param[in] line_table 325254721Semaste /// A line table object pointer that this object now owns. 326254721Semaste //------------------------------------------------------------------ 327254721Semaste void 328254721Semaste SetLineTable(LineTable* line_table); 329254721Semaste 330254721Semaste //------------------------------------------------------------------ 331254721Semaste /// Set accessor for the variable list. 332254721Semaste /// 333254721Semaste /// Called by the SymbolFile plug-ins after they have parsed the 334254721Semaste /// variable lists and are ready to hand ownership of the list over 335254721Semaste /// to this object. 336254721Semaste /// 337254721Semaste /// @param[in] variable_list_sp 338254721Semaste /// A shared pointer to a VariableList. 339254721Semaste //------------------------------------------------------------------ 340254721Semaste void 341254721Semaste SetVariableList (lldb::VariableListSP& variable_list_sp); 342254721Semaste 343254721Semaste //------------------------------------------------------------------ 344254721Semaste /// Resolve symbol contexts by file and line. 345254721Semaste /// 346254721Semaste /// Given a file in \a file_spec, and a line number, find all 347254721Semaste /// instances and append them to the supplied symbol context list 348254721Semaste /// \a sc_list. 349254721Semaste /// 350254721Semaste /// @param[in] file_spec 351254721Semaste /// A file specification. If \a file_spec contains no directory 352254721Semaste /// information, only the basename will be used when matching 353254721Semaste /// contexts. If the directory in \a file_spec is valid, a 354254721Semaste /// complete file specification match will be performed. 355254721Semaste /// 356254721Semaste /// @param[in] line 357254721Semaste /// The line number to match against the compile unit's line 358254721Semaste /// tables. 359254721Semaste /// 360254721Semaste /// @param[in] check_inlines 361254721Semaste /// If \b true this function will also match any inline 362254721Semaste /// file and line matches. If \b false, the compile unit's 363254721Semaste /// file specification must match \a file_spec for any matches 364254721Semaste /// to be returned. 365254721Semaste /// 366254721Semaste /// @param[in] exact 367254721Semaste /// If true, only resolve the context if \a line exists in the line table. 368254721Semaste /// If false, resolve the context to the closest line greater than \a line 369254721Semaste /// in the line table. 370254721Semaste /// 371254721Semaste /// @param[in] resolve_scope 372254721Semaste /// For each matching line entry, this bitfield indicates what 373254721Semaste /// values within each SymbolContext that gets added to \a 374254721Semaste /// sc_list will be resolved. See the SymbolContext::Scope 375254721Semaste /// enumeration for a list of all available bits that can be 376254721Semaste /// resolved. Only SymbolContext entries that can be resolved 377254721Semaste /// using a LineEntry base address will be able to be resolved. 378254721Semaste /// 379254721Semaste /// @param[out] sc_list 380254721Semaste /// A SymbolContext list class that willl get any matching 381254721Semaste /// entries appended to. 382254721Semaste /// 383254721Semaste /// @return 384254721Semaste /// The number of new matches that were added to \a sc_list. 385254721Semaste /// 386254721Semaste /// @see enum SymbolContext::Scope 387254721Semaste //------------------------------------------------------------------ 388254721Semaste uint32_t 389254721Semaste ResolveSymbolContext (const FileSpec& file_spec, 390254721Semaste uint32_t line, 391254721Semaste bool check_inlines, 392254721Semaste bool exact, 393254721Semaste uint32_t resolve_scope, 394254721Semaste SymbolContextList &sc_list); 395254721Semaste 396254721Semaste 397254721Semasteprotected: 398254721Semaste void *m_user_data; ///< User data for the SymbolFile parser to store information into. 399254721Semaste lldb::LanguageType m_language; ///< The programming language enumeration value. 400254721Semaste Flags m_flags; ///< Compile unit flags that help with partial parsing. 401254721Semaste std::vector<lldb::FunctionSP> m_functions; ///< The sparsely populated list of shared pointers to functions 402254721Semaste ///< that gets populated as functions get partially parsed. 403254721Semaste FileSpecList m_support_files; ///< Files associated with this compile unit's line table and declarations. 404254721Semaste std::unique_ptr<LineTable> m_line_table_ap; ///< Line table that will get parsed on demand. 405254721Semaste lldb::VariableListSP m_variables; ///< Global and static variable list that will get parsed on demand. 406254721Semaste 407254721Semasteprivate: 408254721Semaste enum 409254721Semaste { 410254721Semaste flagsParsedAllFunctions = (1u << 0), ///< Have we already parsed all our functions 411254721Semaste flagsParsedVariables = (1u << 1), ///< Have we already parsed globals and statics? 412254721Semaste flagsParsedSupportFiles = (1u << 2), ///< Have we already parsed the support files for this compile unit? 413254721Semaste flagsParsedLineTable = (1u << 3), ///< Have we parsed the line table already? 414254721Semaste flagsParsedLanguage = (1u << 4) ///< Have we parsed the line table already? 415254721Semaste }; 416254721Semaste 417254721Semaste DISALLOW_COPY_AND_ASSIGN (CompileUnit); 418254721Semaste}; 419254721Semaste 420254721Semaste} // namespace lldb_private 421254721Semaste 422254721Semaste#endif // liblldb_CompUnit_h_ 423