Home | History | Annotate | Download | only in Symbol
      1 //===-- SymbolFile.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_SymbolFile_h_
     11 #define liblldb_SymbolFile_h_
     12 
     13 #include "lldb/lldb-private.h"
     14 #include "lldb/Core/PluginInterface.h"
     15 #include "lldb/Symbol/ClangASTType.h"
     16 #include "lldb/Symbol/ClangNamespaceDecl.h"
     17 #include "lldb/Symbol/Type.h"
     18 
     19 namespace lldb_private {
     20 
     21 class SymbolFile :
     22     public PluginInterface
     23 {
     24 public:
     25     //------------------------------------------------------------------
     26     // Symbol file ability bits.
     27     //
     28     // Each symbol file can claim to support one or more symbol file
     29     // abilities. These get returned from SymbolFile::GetAbilities().
     30     // These help us to determine which plug-in will be best to load
     31     // the debug information found in files.
     32     //------------------------------------------------------------------
     33     enum Abilities
     34     {
     35         CompileUnits                        = (1u << 0),
     36         LineTables                          = (1u << 1),
     37         Functions                           = (1u << 2),
     38         Blocks                              = (1u << 3),
     39         GlobalVariables                     = (1u << 4),
     40         LocalVariables                      = (1u << 5),
     41         VariableTypes                       = (1u << 6),
     42         kAllAbilities                       =((1u << 7) - 1u)
     43     };
     44 
     45     static SymbolFile *
     46     FindPlugin (ObjectFile* obj_file);
     47 
     48     //------------------------------------------------------------------
     49     // Constructors and Destructors
     50     //------------------------------------------------------------------
     51     SymbolFile(ObjectFile* obj_file) :
     52         m_obj_file(obj_file),
     53         m_abilities(0),
     54         m_calculated_abilities(false)
     55     {
     56     }
     57 
     58     virtual
     59     ~SymbolFile()
     60     {
     61     }
     62 
     63     //------------------------------------------------------------------
     64     /// Get a mask of what this symbol file supports for the object file
     65     /// that it was constructed with.
     66     ///
     67     /// Each symbol file gets to respond with a mask of abilities that
     68     /// it supports for each object file. This happens when we are
     69     /// trying to figure out which symbol file plug-in will get used
     70     /// for a given object file. The plug-in that resoonds with the
     71     /// best mix of "SymbolFile::Abilities" bits set, will get chosen to
     72     /// be the symbol file parser. This allows each plug-in to check for
     73     /// sections that contain data a symbol file plug-in would need. For
     74     /// example the DWARF plug-in requires DWARF sections in a file that
     75     /// contain debug information. If the DWARF plug-in doesn't find
     76     /// these sections, it won't respond with many ability bits set, and
     77     /// we will probably fall back to the symbol table SymbolFile plug-in
     78     /// which uses any information in the symbol table. Also, plug-ins
     79     /// might check for some specific symbols in a symbol table in the
     80     /// case where the symbol table contains debug information (STABS
     81     /// and COFF). Not a lot of work should happen in these functions
     82     /// as the plug-in might not get selected due to another plug-in
     83     /// having more abilities. Any initialization work should be saved
     84     /// for "void SymbolFile::InitializeObject()" which will get called
     85     /// on the SymbolFile object with the best set of abilities.
     86     ///
     87     /// @return
     88     ///     A uint32_t mask containing bits from the SymbolFile::Abilities
     89     ///     enumeration. Any bits that are set represent an ability that
     90     ///     this symbol plug-in can parse from the object file.
     91     ///------------------------------------------------------------------
     92     uint32_t                GetAbilities ()
     93     {
     94         if (!m_calculated_abilities)
     95         {
     96             m_abilities = CalculateAbilities();
     97             m_calculated_abilities = true;
     98         }
     99 
    100         return m_abilities;
    101     }
    102 
    103     virtual uint32_t        CalculateAbilities() = 0;
    104 
    105     //------------------------------------------------------------------
    106     /// Initialize the SymbolFile object.
    107     ///
    108     /// The SymbolFile object with the best set of abilities (detected
    109     /// in "uint32_t SymbolFile::GetAbilities()) will have this function
    110     /// called if it is chosen to parse an object file. More complete
    111     /// initialization can happen in this function which will get called
    112     /// prior to any other functions in the SymbolFile protocol.
    113     //------------------------------------------------------------------
    114     virtual void            InitializeObject() {}
    115 
    116     //------------------------------------------------------------------
    117     // Compile Unit function calls
    118     //------------------------------------------------------------------
    119     // Approach 1 - iterator
    120     virtual uint32_t        GetNumCompileUnits() = 0;
    121     virtual lldb::CompUnitSP  ParseCompileUnitAtIndex(uint32_t index) = 0;
    122 
    123     virtual lldb::LanguageType ParseCompileUnitLanguage (const SymbolContext& sc) = 0;
    124     virtual size_t          ParseCompileUnitFunctions (const SymbolContext& sc) = 0;
    125     virtual bool            ParseCompileUnitLineTable (const SymbolContext& sc) = 0;
    126     virtual bool            ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) = 0;
    127     virtual size_t          ParseFunctionBlocks (const SymbolContext& sc) = 0;
    128     virtual size_t          ParseTypes (const SymbolContext& sc) = 0;
    129     virtual size_t          ParseVariablesForContext (const SymbolContext& sc) = 0;
    130     virtual Type*           ResolveTypeUID (lldb::user_id_t type_uid) = 0;
    131     virtual bool            ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type) = 0;
    132     virtual clang::DeclContext* GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) { return NULL; }
    133     virtual clang::DeclContext* GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) { return NULL; }
    134     virtual uint32_t        ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) = 0;
    135     virtual uint32_t        ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) = 0;
    136     virtual uint32_t        FindGlobalVariables (const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) = 0;
    137     virtual uint32_t        FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) = 0;
    138     virtual uint32_t        FindFunctions (const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list) = 0;
    139     virtual uint32_t        FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list) = 0;
    140     virtual uint32_t        FindTypes (const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, TypeList& types) = 0;
    141 //  virtual uint32_t        FindTypes (const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, TypeList& types) = 0;
    142     virtual TypeList *      GetTypeList ();
    143     virtual size_t          GetTypes (lldb_private::SymbolContextScope *sc_scope,
    144                                       uint32_t type_mask,
    145                                       lldb_private::TypeList &type_list) = 0;
    146     virtual ClangASTContext &
    147                             GetClangASTContext ();
    148     virtual ClangNamespaceDecl
    149                             FindNamespace (const SymbolContext& sc,
    150                                            const ConstString &name,
    151                                            const ClangNamespaceDecl *parent_namespace_decl) = 0;
    152 
    153     ObjectFile*             GetObjectFile() { return m_obj_file; }
    154     const ObjectFile*       GetObjectFile() const { return m_obj_file; }
    155 
    156 protected:
    157     ObjectFile*             m_obj_file; // The object file that symbols can be extracted from.
    158     uint32_t                m_abilities;
    159     bool                    m_calculated_abilities;
    160 private:
    161     DISALLOW_COPY_AND_ASSIGN (SymbolFile);
    162 };
    163 
    164 
    165 } // namespace lldb_private
    166 
    167 #endif  // liblldb_SymbolFile_h_
    168