SymbolFile.h revision 673f3dbea64b116166dfa668006cdc84224a27c0
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
19namespace lldb_private {
20
21class SymbolFile :
22    public PluginInterface
23{
24public:
25    enum Abilities
26    {
27        Labels                              = (1 << 0),
28        AddressAcceleratorTable             = (1 << 1),
29        FunctionAcceleratorTable            = (1 << 2),
30        TypeAcceleratorTable                = (1 << 3),
31        MacroInformation                    = (1 << 4),
32        CallFrameInformation                = (1 << 5),
33        RuntimeTypes                        = (1 << 6),
34        CompileUnits                        = (1 << 7),
35        LineTables                          = (1 << 8),
36        LineColumns                         = (1 << 9),
37        Functions                           = (1 << 10),
38        Blocks                              = (1 << 11),
39        GlobalVariables                     = (1 << 12),
40        LocalVariables                      = (1 << 13),
41        VariableTypes                       = (1 << 14),
42    };
43
44    static SymbolFile *
45    FindPlugin (ObjectFile* obj_file);
46
47    //------------------------------------------------------------------
48    // Constructors and Destructors
49    //------------------------------------------------------------------
50    SymbolFile(ObjectFile* obj_file) :
51        m_obj_file(obj_file)
52    {
53    }
54
55    virtual
56    ~SymbolFile()
57    {
58    }
59
60    //------------------------------------------------------------------
61    /// Get a mask of what this symbol file supports for the object file
62    /// that it was constructed with.
63    ///
64    /// Each symbol file gets to respond with a mask of abilities that
65    /// it supports for each object file. This happens when we are
66    /// trying to figure out which symbol file plug-in will get used
67    /// for a given object file. The plug-in that resoonds with the
68    /// best mix of "SymbolFile::Abilities" bits set, will get chosen to
69    /// be the symbol file parser. This allows each plug-in to check for
70    /// sections that contain data a symbol file plug-in would need. For
71    /// example the DWARF plug-in requires DWARF sections in a file that
72    /// contain debug information. If the DWARF plug-in doesn't find
73    /// these sections, it won't respond with many ability bits set, and
74    /// we will probably fall back to the symbol table SymbolFile plug-in
75    /// which uses any information in the symbol table. Also, plug-ins
76    /// might check for some specific symbols in a symbol table in the
77    /// case where the symbol table contains debug information (STABS
78    /// and COFF). Not a lot of work should happen in these functions
79    /// as the plug-in might not get selected due to another plug-in
80    /// having more abilities. Any initialization work should be saved
81    /// for "void SymbolFile::InitializeObject()" which will get called
82    /// on the SymbolFile object with the best set of abilities.
83    ///
84    /// @return
85    ///     A uint32_t mask containing bits from the SymbolFile::Abilities
86    ///     enumeration. Any bits that are set represent an ability that
87    ///     this symbol plug-in can parse from the object file.
88    ///------------------------------------------------------------------
89    virtual uint32_t        GetAbilities () = 0;
90
91    //------------------------------------------------------------------
92    /// Initialize the SymbolFile object.
93    ///
94    /// The SymbolFile object with the best set of abilities (detected
95    /// in "uint32_t SymbolFile::GetAbilities()) will have this function
96    /// called if it is chosen to parse an object file. More complete
97    /// initialization can happen in this function which will get called
98    /// prior to any other functions in the SymbolFile protocol.
99    //------------------------------------------------------------------
100    virtual void            InitializeObject() {}
101
102    //------------------------------------------------------------------
103    // Compile Unit function calls
104    //------------------------------------------------------------------
105    // Approach 1 - iterator
106    virtual uint32_t        GetNumCompileUnits() = 0;
107    virtual lldb::CompUnitSP  ParseCompileUnitAtIndex(uint32_t index) = 0;
108
109    virtual size_t          ParseCompileUnitFunctions (const SymbolContext& sc) = 0;
110    virtual bool            ParseCompileUnitLineTable (const SymbolContext& sc) = 0;
111    virtual bool            ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) = 0;
112    virtual size_t          ParseFunctionBlocks (const SymbolContext& sc) = 0;
113    virtual size_t          ParseTypes (const SymbolContext& sc) = 0;
114    virtual size_t          ParseVariablesForContext (const SymbolContext& sc) = 0;
115    virtual Type*           ResolveTypeUID (lldb::user_id_t type_uid) = 0;
116    virtual lldb::clang_type_t ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) = 0;
117    virtual clang::DeclContext* GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) { return NULL; }
118    virtual clang::DeclContext* GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) { return NULL; }
119    virtual uint32_t        ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) = 0;
120    virtual uint32_t        ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) = 0;
121    virtual uint32_t        FindGlobalVariables (const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) = 0;
122    virtual uint32_t        FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) = 0;
123    virtual uint32_t        FindFunctions (const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool append, SymbolContextList& sc_list) = 0;
124    virtual uint32_t        FindFunctions (const RegularExpression& regex, bool append, SymbolContextList& sc_list) = 0;
125    virtual uint32_t        FindTypes (const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, TypeList& types) = 0;
126//  virtual uint32_t        FindTypes (const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, TypeList& types) = 0;
127    virtual TypeList *      GetTypeList ();
128    virtual ClangASTContext &
129                            GetClangASTContext ();
130    virtual ClangNamespaceDecl
131                            FindNamespace (const SymbolContext& sc,
132                                           const ConstString &name,
133                                           const ClangNamespaceDecl *parent_namespace_decl) = 0;
134
135    ObjectFile*             GetObjectFile() { return m_obj_file; }
136    const ObjectFile*       GetObjectFile() const { return m_obj_file; }
137
138    // Special error functions that can do printf style formatting that will prepend the message with
139    // something appropriate for this symbol file (like the architecture, path and object name). This
140    // centralizes code so that everyone doesn't need to format their error and log messages on their
141    // own and keeps the output a bit more consistent.
142    void                    LogMessage (Log *log, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
143    void                    ReportWarning (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
144    void                    ReportError (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
145protected:
146    ObjectFile*             m_obj_file; // The object file that symbols can be extracted from.
147
148private:
149    DISALLOW_COPY_AND_ASSIGN (SymbolFile);
150};
151
152
153} // namespace lldb_private
154
155#endif  // liblldb_SymbolFile_h_
156