Symbol.h revision 3508c387c3f0c9ecc439d98048fd7694d41bab1b
1//===-- Symbol.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_Symbol_h_
11#define liblldb_Symbol_h_
12
13#include "lldb/lldb-private.h"
14#include "lldb/Core/AddressRange.h"
15#include "lldb/Core/Mangled.h"
16#include "lldb/Core/UserID.h"
17#include "lldb/Symbol/SymbolContextScope.h"
18
19namespace lldb_private {
20
21class Symbol :
22    public SymbolContextScope
23{
24public:
25    // ObjectFile readers can classify their symbol table entries and searches can be made
26    // on specific types where the symbol values will have drastically different meanings
27    // and sorting requirements.
28    Symbol();
29
30    Symbol (uint32_t symID,
31            const char *name,
32            bool name_is_mangled,
33            lldb::SymbolType type,
34            bool external,
35            bool is_debug,
36            bool is_trampoline,
37            bool is_artificial,
38            const lldb::SectionSP &section_sp,
39            lldb::addr_t value,
40            uint32_t size,
41            uint32_t flags);
42
43    Symbol (uint32_t symID,
44            const char *name,
45            bool name_is_mangled,
46            lldb::SymbolType type,
47            bool external,
48            bool is_debug,
49            bool is_trampoline,
50            bool is_artificial,
51            const AddressRange &range,
52            uint32_t flags);
53
54    Symbol (const Symbol& rhs);
55
56    const Symbol&
57    operator= (const Symbol& rhs);
58
59    void
60    Clear();
61
62    bool
63    Compare (const ConstString& name, lldb::SymbolType type) const;
64
65    void
66    Dump (Stream *s, Target *target, uint32_t index) const;
67
68    AddressRange *
69    GetAddressRangePtr ();
70
71    const AddressRange *
72    GetAddressRangePtr () const;
73
74    AddressRange &
75    GetAddressRangeRef() { return m_addr_range; }
76
77    const AddressRange &
78    GetAddressRangeRef() const { return m_addr_range; }
79
80    const ConstString &
81    GetName () { return m_mangled.GetName(); }
82
83    uint32_t
84    GetID() const
85    {
86        return m_uid;
87    }
88
89    void
90    SetID(uint32_t uid)
91    {
92        m_uid = uid;
93    }
94
95    Mangled&
96    GetMangled () { return m_mangled; }
97
98    const Mangled&
99    GetMangled () const { return m_mangled; }
100
101    bool
102    GetSizeIsSibling () const { return m_size_is_sibling; }
103
104    bool
105    GetSizeIsSynthesized() const { return m_size_is_synthesized; }
106
107    uint32_t
108    GetSiblingIndex () const;
109
110    lldb::addr_t
111    GetByteSize () const { return m_addr_range.GetByteSize(); }
112
113    lldb::SymbolType
114    GetType () const { return (lldb::SymbolType)m_type; }
115
116    void
117    SetType (lldb::SymbolType type) { m_type = (lldb::SymbolType)type; }
118
119    const char *
120    GetTypeAsString () const;
121
122    uint32_t
123    GetFlags () const { return m_flags; }
124
125    void
126    SetFlags (uint32_t flags) { m_flags = flags; }
127
128    void
129    GetDescription (Stream *s, lldb::DescriptionLevel level, Target *target) const;
130
131    Address &
132    GetValue () { return m_addr_range.GetBaseAddress(); }
133
134    const Address &
135    GetValue () const { return m_addr_range.GetBaseAddress(); }
136
137    bool
138    IsSynthetic () const { return m_is_synthetic; }
139
140    void
141    SetIsSynthetic (bool b) { m_is_synthetic = b; }
142
143    void
144    SetSizeIsSynthesized(bool b) { m_size_is_synthesized = b; }
145
146    bool
147    IsDebug () const { return m_is_debug; }
148
149    void
150    SetDebug (bool b) { m_is_debug = b; }
151
152    bool
153    IsExternal () const { return m_is_external; }
154
155    void
156    SetExternal (bool b) { m_is_external = b; }
157
158    bool
159    IsTrampoline () const;
160
161    void
162    SetByteSize (uint32_t size) { m_addr_range.SetByteSize(size); }
163
164    void
165    SetSizeIsSibling (bool b) { m_size_is_sibling = b; }
166
167    void
168    SetValue (Address &value) { m_addr_range.GetBaseAddress() = value; }
169
170    void
171    SetValue (const AddressRange &range) { m_addr_range = range; }
172
173    void
174    SetValue (lldb::addr_t value);
175
176    // If m_type is "Code" or "Function" then this will return the prologue size
177    // in bytes, else it will return zero.
178    uint32_t
179    GetPrologueByteSize ();
180
181    //------------------------------------------------------------------
182    /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)
183    ///
184    /// @see SymbolContextScope
185    //------------------------------------------------------------------
186    virtual void
187    CalculateSymbolContext (SymbolContext *sc);
188
189    virtual lldb::ModuleSP
190    CalculateSymbolContextModule ();
191
192    virtual Symbol *
193    CalculateSymbolContextSymbol ();
194
195    //------------------------------------------------------------------
196    /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*)
197    ///
198    /// @see SymbolContextScope
199    //------------------------------------------------------------------
200    virtual void
201    DumpSymbolContext (Stream *s);
202
203protected:
204
205    uint32_t        m_uid;                  // User ID (usually the original symbol table index)
206    Mangled         m_mangled;              // uniqued symbol name/mangled name pair
207    uint16_t        m_type_data;            // data specific to m_type
208    uint16_t        m_type_data_resolved:1, // True if the data in m_type_data has already been calculated
209                    m_is_synthetic:1,       // non-zero if this symbol is not actually in the symbol table, but synthesized from other info in the object file.
210                    m_is_debug:1,           // non-zero if this symbol is debug information in a symbol
211                    m_is_external:1,        // non-zero if this symbol is globally visible
212                    m_size_is_sibling:1,    // m_size contains the index of this symbol's sibling
213                    m_size_is_synthesized:1,// non-zero if this symbol's size was calculated using a delta between this symbol and the next
214                    m_type:8;
215    uint32_t        m_flags;                // A copy of the flags from the original symbol table, the ObjectFile plug-in can interpret these
216    AddressRange    m_addr_range;           // Contains the value, or the section offset address when the value is an address in a section, and the size (if any)
217};
218
219} // namespace lldb_private
220
221#endif  // liblldb_Symbol_h_
222