SymbolFile.h revision 296417
1254721Semaste//===-- SymbolFile.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_SymbolFile_h_
11254721Semaste#define liblldb_SymbolFile_h_
12254721Semaste
13254721Semaste#include "lldb/lldb-private.h"
14254721Semaste#include "lldb/Core/PluginInterface.h"
15296417Sdim#include "lldb/Symbol/CompilerType.h"
16296417Sdim#include "lldb/Symbol/CompilerDecl.h"
17296417Sdim#include "lldb/Symbol/CompilerDeclContext.h"
18254721Semaste#include "lldb/Symbol/Type.h"
19254721Semaste
20254721Semastenamespace lldb_private {
21254721Semaste
22254721Semasteclass SymbolFile :
23254721Semaste    public PluginInterface
24254721Semaste{
25254721Semastepublic:
26254721Semaste    //------------------------------------------------------------------
27254721Semaste    // Symbol file ability bits.
28254721Semaste    //
29254721Semaste    // Each symbol file can claim to support one or more symbol file
30254721Semaste    // abilities. These get returned from SymbolFile::GetAbilities().
31254721Semaste    // These help us to determine which plug-in will be best to load
32254721Semaste    // the debug information found in files.
33254721Semaste    //------------------------------------------------------------------
34254721Semaste    enum Abilities
35254721Semaste    {
36254721Semaste        CompileUnits                        = (1u << 0),
37254721Semaste        LineTables                          = (1u << 1),
38254721Semaste        Functions                           = (1u << 2),
39254721Semaste        Blocks                              = (1u << 3),
40254721Semaste        GlobalVariables                     = (1u << 4),
41254721Semaste        LocalVariables                      = (1u << 5),
42254721Semaste        VariableTypes                       = (1u << 6),
43254721Semaste        kAllAbilities                       =((1u << 7) - 1u)
44254721Semaste    };
45254721Semaste
46254721Semaste    static SymbolFile *
47254721Semaste    FindPlugin (ObjectFile* obj_file);
48254721Semaste
49254721Semaste    //------------------------------------------------------------------
50254721Semaste    // Constructors and Destructors
51254721Semaste    //------------------------------------------------------------------
52254721Semaste    SymbolFile(ObjectFile* obj_file) :
53254721Semaste        m_obj_file(obj_file),
54254721Semaste        m_abilities(0),
55254721Semaste        m_calculated_abilities(false)
56254721Semaste    {
57254721Semaste    }
58254721Semaste
59296417Sdim    ~SymbolFile() override
60254721Semaste    {
61254721Semaste    }
62254721Semaste
63254721Semaste    //------------------------------------------------------------------
64254721Semaste    /// Get a mask of what this symbol file supports for the object file
65254721Semaste    /// that it was constructed with.
66254721Semaste    ///
67254721Semaste    /// Each symbol file gets to respond with a mask of abilities that
68254721Semaste    /// it supports for each object file. This happens when we are
69254721Semaste    /// trying to figure out which symbol file plug-in will get used
70276479Sdim    /// for a given object file. The plug-in that responds with the
71254721Semaste    /// best mix of "SymbolFile::Abilities" bits set, will get chosen to
72254721Semaste    /// be the symbol file parser. This allows each plug-in to check for
73254721Semaste    /// sections that contain data a symbol file plug-in would need. For
74254721Semaste    /// example the DWARF plug-in requires DWARF sections in a file that
75254721Semaste    /// contain debug information. If the DWARF plug-in doesn't find
76254721Semaste    /// these sections, it won't respond with many ability bits set, and
77254721Semaste    /// we will probably fall back to the symbol table SymbolFile plug-in
78254721Semaste    /// which uses any information in the symbol table. Also, plug-ins
79254721Semaste    /// might check for some specific symbols in a symbol table in the
80254721Semaste    /// case where the symbol table contains debug information (STABS
81254721Semaste    /// and COFF). Not a lot of work should happen in these functions
82254721Semaste    /// as the plug-in might not get selected due to another plug-in
83254721Semaste    /// having more abilities. Any initialization work should be saved
84254721Semaste    /// for "void SymbolFile::InitializeObject()" which will get called
85254721Semaste    /// on the SymbolFile object with the best set of abilities.
86254721Semaste    ///
87254721Semaste    /// @return
88254721Semaste    ///     A uint32_t mask containing bits from the SymbolFile::Abilities
89254721Semaste    ///     enumeration. Any bits that are set represent an ability that
90254721Semaste    ///     this symbol plug-in can parse from the object file.
91254721Semaste    ///------------------------------------------------------------------
92254721Semaste    uint32_t                GetAbilities ()
93254721Semaste    {
94254721Semaste        if (!m_calculated_abilities)
95254721Semaste        {
96254721Semaste            m_abilities = CalculateAbilities();
97254721Semaste            m_calculated_abilities = true;
98254721Semaste        }
99254721Semaste
100254721Semaste        return m_abilities;
101254721Semaste    }
102254721Semaste
103254721Semaste    virtual uint32_t        CalculateAbilities() = 0;
104254721Semaste
105254721Semaste    //------------------------------------------------------------------
106254721Semaste    /// Initialize the SymbolFile object.
107254721Semaste    ///
108254721Semaste    /// The SymbolFile object with the best set of abilities (detected
109254721Semaste    /// in "uint32_t SymbolFile::GetAbilities()) will have this function
110254721Semaste    /// called if it is chosen to parse an object file. More complete
111254721Semaste    /// initialization can happen in this function which will get called
112254721Semaste    /// prior to any other functions in the SymbolFile protocol.
113254721Semaste    //------------------------------------------------------------------
114254721Semaste    virtual void            InitializeObject() {}
115254721Semaste
116254721Semaste    //------------------------------------------------------------------
117254721Semaste    // Compile Unit function calls
118254721Semaste    //------------------------------------------------------------------
119254721Semaste    // Approach 1 - iterator
120254721Semaste    virtual uint32_t        GetNumCompileUnits() = 0;
121254721Semaste    virtual lldb::CompUnitSP  ParseCompileUnitAtIndex(uint32_t index) = 0;
122254721Semaste
123254721Semaste    virtual lldb::LanguageType ParseCompileUnitLanguage (const SymbolContext& sc) = 0;
124254721Semaste    virtual size_t          ParseCompileUnitFunctions (const SymbolContext& sc) = 0;
125254721Semaste    virtual bool            ParseCompileUnitLineTable (const SymbolContext& sc) = 0;
126296417Sdim    virtual bool            ParseCompileUnitDebugMacros (const SymbolContext& sc) = 0;
127254721Semaste    virtual bool            ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) = 0;
128288943Sdim    virtual bool            ParseImportedModules (const SymbolContext &sc, std::vector<ConstString> &imported_modules) = 0;
129254721Semaste    virtual size_t          ParseFunctionBlocks (const SymbolContext& sc) = 0;
130254721Semaste    virtual size_t          ParseTypes (const SymbolContext& sc) = 0;
131254721Semaste    virtual size_t          ParseVariablesForContext (const SymbolContext& sc) = 0;
132254721Semaste    virtual Type*           ResolveTypeUID (lldb::user_id_t type_uid) = 0;
133296417Sdim    virtual bool            CompleteType (CompilerType &compiler_type) = 0;
134296417Sdim    virtual void            ParseDeclsForContext (CompilerDeclContext decl_ctx) {}
135296417Sdim    virtual CompilerDecl    GetDeclForUID (lldb::user_id_t uid) { return CompilerDecl(); }
136296417Sdim    virtual CompilerDeclContext GetDeclContextForUID (lldb::user_id_t uid) { return CompilerDeclContext(); }
137296417Sdim    virtual CompilerDeclContext GetDeclContextContainingUID (lldb::user_id_t uid) { return CompilerDeclContext(); }
138254721Semaste    virtual uint32_t        ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) = 0;
139296417Sdim    virtual uint32_t        ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list);
140296417Sdim    virtual uint32_t        FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables);
141296417Sdim    virtual uint32_t        FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables);
142296417Sdim    virtual uint32_t        FindFunctions (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list);
143296417Sdim    virtual uint32_t        FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list);
144296417Sdim    virtual uint32_t        FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, TypeMap& types);
145296417Sdim    virtual size_t          FindTypes (const std::vector<CompilerContext> &context, bool append, TypeMap& types);
146296417Sdim
147296417Sdim    virtual void            GetMangledNamesForFunction(const std::string &scope_qualified_name, std::vector<ConstString> &mangled_names);
148254721Semaste//  virtual uint32_t        FindTypes (const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, TypeList& types) = 0;
149254721Semaste    virtual TypeList *      GetTypeList ();
150254721Semaste    virtual size_t          GetTypes (lldb_private::SymbolContextScope *sc_scope,
151254721Semaste                                      uint32_t type_mask,
152254721Semaste                                      lldb_private::TypeList &type_list) = 0;
153296417Sdim
154296417Sdim    virtual lldb_private::TypeSystem *
155296417Sdim                            GetTypeSystemForLanguage (lldb::LanguageType language);
156296417Sdim
157296417Sdim    virtual CompilerDeclContext
158254721Semaste                            FindNamespace (const SymbolContext& sc,
159254721Semaste                                           const ConstString &name,
160296417Sdim                                           const CompilerDeclContext *parent_decl_ctx)
161296417Sdim    {
162296417Sdim        return CompilerDeclContext();
163296417Sdim    }
164254721Semaste
165254721Semaste    ObjectFile*             GetObjectFile() { return m_obj_file; }
166254721Semaste    const ObjectFile*       GetObjectFile() const { return m_obj_file; }
167276479Sdim
168276479Sdim    //------------------------------------------------------------------
169276479Sdim    /// Notify the SymbolFile that the file addresses in the Sections
170276479Sdim    /// for this module have been changed.
171276479Sdim    //------------------------------------------------------------------
172276479Sdim    virtual void
173276479Sdim    SectionFileAddressesChanged ()
174276479Sdim    {
175276479Sdim    }
176276479Sdim
177254721Semasteprotected:
178254721Semaste    ObjectFile*             m_obj_file; // The object file that symbols can be extracted from.
179254721Semaste    uint32_t                m_abilities;
180254721Semaste    bool                    m_calculated_abilities;
181296417Sdim
182254721Semasteprivate:
183254721Semaste    DISALLOW_COPY_AND_ASSIGN (SymbolFile);
184254721Semaste};
185254721Semaste
186254721Semaste} // namespace lldb_private
187254721Semaste
188296417Sdim#endif // liblldb_SymbolFile_h_
189