Symbol.h revision 4aa2edf602fa60693afa33d4fe0d1d459a488333
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    bool
69    ValueIsAddress() const;
70
71    //------------------------------------------------------------------
72    // Access the address value. Do NOT hand out the AddressRange as an
73    // object as the byte size of the address range may not be filled in
74    // and it should be accessed via GetByteSize().
75    //------------------------------------------------------------------
76    Address &
77    GetAddress()
78    {
79        return m_addr_range.GetBaseAddress();
80    }
81
82    //------------------------------------------------------------------
83    // Access the address value. Do NOT hand out the AddressRange as an
84    // object as the byte size of the address range may not be filled in
85    // and it should be accessed via GetByteSize().
86    //------------------------------------------------------------------
87    const Address &
88    GetAddress() const
89    {
90        return m_addr_range.GetBaseAddress();
91    }
92
93    const ConstString &
94    GetName ()
95    {
96        return m_mangled.GetName();
97    }
98
99    uint32_t
100    GetID() const
101    {
102        return m_uid;
103    }
104
105    void
106    SetID(uint32_t uid)
107    {
108        m_uid = uid;
109    }
110
111    Mangled&
112    GetMangled ()
113    {
114        return m_mangled;
115    }
116
117    const Mangled&
118    GetMangled () const
119    {
120        return m_mangled;
121    }
122
123    uint32_t
124    GetSiblingIndex () const;
125
126    lldb::SymbolType
127    GetType () const
128    {
129        return (lldb::SymbolType)m_type;
130    }
131
132    void
133    SetType (lldb::SymbolType type)
134    {
135        m_type = (lldb::SymbolType)type;
136    }
137
138    const char *
139    GetTypeAsString () const;
140
141    uint32_t
142    GetFlags () const
143    {
144        return m_flags;
145    }
146
147    void
148    SetFlags (uint32_t flags)
149    {
150        m_flags = flags;
151    }
152
153    void
154    GetDescription (Stream *s, lldb::DescriptionLevel level, Target *target) const;
155
156    bool
157    IsSynthetic () const
158    {
159        return m_is_synthetic;
160    }
161
162    void
163    SetIsSynthetic (bool b)
164    {
165        m_is_synthetic = b;
166    }
167
168
169    bool
170    GetSizeIsSynthesized() const
171    {
172        return m_size_is_synthesized;
173    }
174
175    void
176    SetSizeIsSynthesized(bool b)
177    {
178        m_size_is_synthesized = b;
179    }
180
181    bool
182    IsDebug () const
183    {
184        return m_is_debug;
185    }
186
187    void
188    SetDebug (bool b)
189    {
190        m_is_debug = b;
191    }
192
193    bool
194    IsExternal () const
195    {
196        return m_is_external;
197    }
198
199    void
200    SetExternal (bool b)
201    {
202        m_is_external = b;
203    }
204
205    bool
206    IsTrampoline () const;
207
208    lldb::addr_t
209    GetByteSize () const;
210
211    void
212    SetByteSize (uint32_t size)
213    {
214        m_calculated_size = size > 0;
215        m_addr_range.SetByteSize(size);
216    }
217
218    bool
219    GetSizeIsSibling () const
220    {
221        return m_size_is_sibling;
222    }
223
224    void
225    SetSizeIsSibling (bool b)
226    {
227        m_size_is_sibling = b;
228    }
229
230//    void
231//    SetValue (Address &value)
232//    {
233//        m_addr_range.GetBaseAddress() = value;
234//    }
235//
236//    void
237//    SetValue (const AddressRange &range)
238//    {
239//        m_addr_range = range;
240//    }
241//
242//    void
243//    SetValue (lldb::addr_t value);
244//    {
245//        m_addr_range.GetBaseAddress().SetRawAddress(value);
246//    }
247
248    // If m_type is "Code" or "Function" then this will return the prologue size
249    // in bytes, else it will return zero.
250    uint32_t
251    GetPrologueByteSize ();
252
253    //------------------------------------------------------------------
254    /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)
255    ///
256    /// @see SymbolContextScope
257    //------------------------------------------------------------------
258    virtual void
259    CalculateSymbolContext (SymbolContext *sc);
260
261    virtual lldb::ModuleSP
262    CalculateSymbolContextModule ();
263
264    virtual Symbol *
265    CalculateSymbolContextSymbol ();
266
267    //------------------------------------------------------------------
268    /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*)
269    ///
270    /// @see SymbolContextScope
271    //------------------------------------------------------------------
272    virtual void
273    DumpSymbolContext (Stream *s);
274
275protected:
276
277    uint32_t        m_uid;                  // User ID (usually the original symbol table index)
278    Mangled         m_mangled;              // uniqued symbol name/mangled name pair
279    uint16_t        m_type_data;            // data specific to m_type
280    uint16_t        m_type_data_resolved:1, // True if the data in m_type_data has already been calculated
281                    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.
282                    m_is_debug:1,           // non-zero if this symbol is debug information in a symbol
283                    m_is_external:1,        // non-zero if this symbol is globally visible
284                    m_size_is_sibling:1,    // m_size contains the index of this symbol's sibling
285                    m_size_is_synthesized:1,// non-zero if this symbol's size was calculated using a delta between this symbol and the next
286                    m_calculated_size:1,
287                    m_type:8;
288    uint32_t        m_flags;                // A copy of the flags from the original symbol table, the ObjectFile plug-in can interpret these
289    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)
290};
291
292} // namespace lldb_private
293
294#endif  // liblldb_Symbol_h_
295