SymbolFile.h revision 309124
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
20309124Sdim#include "llvm/ADT/DenseSet.h"
21309124Sdim
22254721Semastenamespace lldb_private {
23254721Semaste
24254721Semasteclass SymbolFile :
25254721Semaste    public PluginInterface
26254721Semaste{
27254721Semastepublic:
28254721Semaste    //------------------------------------------------------------------
29254721Semaste    // Symbol file ability bits.
30254721Semaste    //
31254721Semaste    // Each symbol file can claim to support one or more symbol file
32254721Semaste    // abilities. These get returned from SymbolFile::GetAbilities().
33254721Semaste    // These help us to determine which plug-in will be best to load
34254721Semaste    // the debug information found in files.
35254721Semaste    //------------------------------------------------------------------
36254721Semaste    enum Abilities
37254721Semaste    {
38254721Semaste        CompileUnits                        = (1u << 0),
39254721Semaste        LineTables                          = (1u << 1),
40254721Semaste        Functions                           = (1u << 2),
41254721Semaste        Blocks                              = (1u << 3),
42254721Semaste        GlobalVariables                     = (1u << 4),
43254721Semaste        LocalVariables                      = (1u << 5),
44254721Semaste        VariableTypes                       = (1u << 6),
45254721Semaste        kAllAbilities                       =((1u << 7) - 1u)
46254721Semaste    };
47254721Semaste
48254721Semaste    static SymbolFile *
49254721Semaste    FindPlugin (ObjectFile* obj_file);
50254721Semaste
51254721Semaste    //------------------------------------------------------------------
52254721Semaste    // Constructors and Destructors
53254721Semaste    //------------------------------------------------------------------
54254721Semaste    SymbolFile(ObjectFile* obj_file) :
55254721Semaste        m_obj_file(obj_file),
56254721Semaste        m_abilities(0),
57254721Semaste        m_calculated_abilities(false)
58254721Semaste    {
59254721Semaste    }
60254721Semaste
61296417Sdim    ~SymbolFile() override
62254721Semaste    {
63254721Semaste    }
64254721Semaste
65254721Semaste    //------------------------------------------------------------------
66254721Semaste    /// Get a mask of what this symbol file supports for the object file
67254721Semaste    /// that it was constructed with.
68254721Semaste    ///
69254721Semaste    /// Each symbol file gets to respond with a mask of abilities that
70254721Semaste    /// it supports for each object file. This happens when we are
71254721Semaste    /// trying to figure out which symbol file plug-in will get used
72276479Sdim    /// for a given object file. The plug-in that responds with the
73254721Semaste    /// best mix of "SymbolFile::Abilities" bits set, will get chosen to
74254721Semaste    /// be the symbol file parser. This allows each plug-in to check for
75254721Semaste    /// sections that contain data a symbol file plug-in would need. For
76254721Semaste    /// example the DWARF plug-in requires DWARF sections in a file that
77254721Semaste    /// contain debug information. If the DWARF plug-in doesn't find
78254721Semaste    /// these sections, it won't respond with many ability bits set, and
79254721Semaste    /// we will probably fall back to the symbol table SymbolFile plug-in
80254721Semaste    /// which uses any information in the symbol table. Also, plug-ins
81254721Semaste    /// might check for some specific symbols in a symbol table in the
82254721Semaste    /// case where the symbol table contains debug information (STABS
83254721Semaste    /// and COFF). Not a lot of work should happen in these functions
84254721Semaste    /// as the plug-in might not get selected due to another plug-in
85254721Semaste    /// having more abilities. Any initialization work should be saved
86254721Semaste    /// for "void SymbolFile::InitializeObject()" which will get called
87254721Semaste    /// on the SymbolFile object with the best set of abilities.
88254721Semaste    ///
89254721Semaste    /// @return
90254721Semaste    ///     A uint32_t mask containing bits from the SymbolFile::Abilities
91254721Semaste    ///     enumeration. Any bits that are set represent an ability that
92254721Semaste    ///     this symbol plug-in can parse from the object file.
93254721Semaste    ///------------------------------------------------------------------
94254721Semaste    uint32_t                GetAbilities ()
95254721Semaste    {
96254721Semaste        if (!m_calculated_abilities)
97254721Semaste        {
98254721Semaste            m_abilities = CalculateAbilities();
99254721Semaste            m_calculated_abilities = true;
100254721Semaste        }
101254721Semaste
102254721Semaste        return m_abilities;
103254721Semaste    }
104254721Semaste
105254721Semaste    virtual uint32_t        CalculateAbilities() = 0;
106254721Semaste
107254721Semaste    //------------------------------------------------------------------
108254721Semaste    /// Initialize the SymbolFile object.
109254721Semaste    ///
110254721Semaste    /// The SymbolFile object with the best set of abilities (detected
111254721Semaste    /// in "uint32_t SymbolFile::GetAbilities()) will have this function
112254721Semaste    /// called if it is chosen to parse an object file. More complete
113254721Semaste    /// initialization can happen in this function which will get called
114254721Semaste    /// prior to any other functions in the SymbolFile protocol.
115254721Semaste    //------------------------------------------------------------------
116254721Semaste    virtual void            InitializeObject() {}
117254721Semaste
118254721Semaste    //------------------------------------------------------------------
119254721Semaste    // Compile Unit function calls
120254721Semaste    //------------------------------------------------------------------
121254721Semaste    // Approach 1 - iterator
122254721Semaste    virtual uint32_t        GetNumCompileUnits() = 0;
123254721Semaste    virtual lldb::CompUnitSP  ParseCompileUnitAtIndex(uint32_t index) = 0;
124254721Semaste
125254721Semaste    virtual lldb::LanguageType ParseCompileUnitLanguage (const SymbolContext& sc) = 0;
126254721Semaste    virtual size_t          ParseCompileUnitFunctions (const SymbolContext& sc) = 0;
127254721Semaste    virtual bool            ParseCompileUnitLineTable (const SymbolContext& sc) = 0;
128296417Sdim    virtual bool            ParseCompileUnitDebugMacros (const SymbolContext& sc) = 0;
129254721Semaste    virtual bool            ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) = 0;
130309124Sdim    virtual bool
131309124Sdim    ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc)
132309124Sdim    {
133309124Sdim        return false;
134309124Sdim    }
135288943Sdim    virtual bool            ParseImportedModules (const SymbolContext &sc, std::vector<ConstString> &imported_modules) = 0;
136254721Semaste    virtual size_t          ParseFunctionBlocks (const SymbolContext& sc) = 0;
137254721Semaste    virtual size_t          ParseTypes (const SymbolContext& sc) = 0;
138254721Semaste    virtual size_t          ParseVariablesForContext (const SymbolContext& sc) = 0;
139254721Semaste    virtual Type*           ResolveTypeUID (lldb::user_id_t type_uid) = 0;
140296417Sdim    virtual bool            CompleteType (CompilerType &compiler_type) = 0;
141296417Sdim    virtual void            ParseDeclsForContext (CompilerDeclContext decl_ctx) {}
142296417Sdim    virtual CompilerDecl    GetDeclForUID (lldb::user_id_t uid) { return CompilerDecl(); }
143296417Sdim    virtual CompilerDeclContext GetDeclContextForUID (lldb::user_id_t uid) { return CompilerDeclContext(); }
144296417Sdim    virtual CompilerDeclContext GetDeclContextContainingUID (lldb::user_id_t uid) { return CompilerDeclContext(); }
145254721Semaste    virtual uint32_t        ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) = 0;
146296417Sdim    virtual uint32_t        ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list);
147296417Sdim    virtual uint32_t        FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables);
148296417Sdim    virtual uint32_t        FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables);
149296417Sdim    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);
150296417Sdim    virtual uint32_t        FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list);
151309124Sdim    virtual uint32_t        FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, TypeMap& types);
152296417Sdim    virtual size_t          FindTypes (const std::vector<CompilerContext> &context, bool append, TypeMap& types);
153296417Sdim
154296417Sdim    virtual void            GetMangledNamesForFunction(const std::string &scope_qualified_name, std::vector<ConstString> &mangled_names);
155254721Semaste//  virtual uint32_t        FindTypes (const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, TypeList& types) = 0;
156254721Semaste    virtual TypeList *      GetTypeList ();
157254721Semaste    virtual size_t          GetTypes (lldb_private::SymbolContextScope *sc_scope,
158254721Semaste                                      uint32_t type_mask,
159254721Semaste                                      lldb_private::TypeList &type_list) = 0;
160296417Sdim
161296417Sdim    virtual lldb_private::TypeSystem *
162296417Sdim                            GetTypeSystemForLanguage (lldb::LanguageType language);
163296417Sdim
164296417Sdim    virtual CompilerDeclContext
165254721Semaste                            FindNamespace (const SymbolContext& sc,
166254721Semaste                                           const ConstString &name,
167296417Sdim                                           const CompilerDeclContext *parent_decl_ctx)
168296417Sdim    {
169296417Sdim        return CompilerDeclContext();
170296417Sdim    }
171254721Semaste
172254721Semaste    ObjectFile*             GetObjectFile() { return m_obj_file; }
173254721Semaste    const ObjectFile*       GetObjectFile() const { return m_obj_file; }
174276479Sdim
175276479Sdim    //------------------------------------------------------------------
176276479Sdim    /// Notify the SymbolFile that the file addresses in the Sections
177276479Sdim    /// for this module have been changed.
178276479Sdim    //------------------------------------------------------------------
179276479Sdim    virtual void
180276479Sdim    SectionFileAddressesChanged ()
181276479Sdim    {
182276479Sdim    }
183276479Sdim
184254721Semasteprotected:
185254721Semaste    ObjectFile*             m_obj_file; // The object file that symbols can be extracted from.
186254721Semaste    uint32_t                m_abilities;
187254721Semaste    bool                    m_calculated_abilities;
188296417Sdim
189254721Semasteprivate:
190254721Semaste    DISALLOW_COPY_AND_ASSIGN (SymbolFile);
191254721Semaste};
192254721Semaste
193254721Semaste} // namespace lldb_private
194254721Semaste
195296417Sdim#endif // liblldb_SymbolFile_h_
196