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