Symbol.h revision 269024
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    ConstString
126    GetReExportedSymbolName() const;
127
128    FileSpec
129    GetReExportedSymbolSharedLibrary () const;
130
131    bool
132    SetReExportedSymbolName(const ConstString &name);
133
134    bool
135    SetReExportedSymbolSharedLibrary (const FileSpec &fspec);
136
137    Symbol *
138    ResolveReExportedSymbol (Target &target);
139
140    uint32_t
141    GetSiblingIndex () const;
142
143    lldb::SymbolType
144    GetType () const
145    {
146        return (lldb::SymbolType)m_type;
147    }
148
149    void
150    SetType (lldb::SymbolType type)
151    {
152        m_type = (lldb::SymbolType)type;
153    }
154
155    const char *
156    GetTypeAsString () const;
157
158    uint32_t
159    GetFlags () const
160    {
161        return m_flags;
162    }
163
164    void
165    SetFlags (uint32_t flags)
166    {
167        m_flags = flags;
168    }
169
170    void
171    GetDescription (Stream *s, lldb::DescriptionLevel level, Target *target) const;
172
173    bool
174    IsSynthetic () const
175    {
176        return m_is_synthetic;
177    }
178
179    void
180    SetIsSynthetic (bool b)
181    {
182        m_is_synthetic = b;
183    }
184
185
186    bool
187    GetSizeIsSynthesized() const
188    {
189        return m_size_is_synthesized;
190    }
191
192    void
193    SetSizeIsSynthesized(bool b)
194    {
195        m_size_is_synthesized = b;
196    }
197
198    bool
199    IsDebug () const
200    {
201        return m_is_debug;
202    }
203
204    void
205    SetDebug (bool b)
206    {
207        m_is_debug = b;
208    }
209
210    bool
211    IsExternal () const
212    {
213        return m_is_external;
214    }
215
216    void
217    SetExternal (bool b)
218    {
219        m_is_external = b;
220    }
221
222    bool
223    IsTrampoline () const;
224
225    bool
226    IsIndirect () const;
227
228    bool
229    GetByteSizeIsValid () const
230    {
231        return m_size_is_valid;
232    }
233
234    lldb::addr_t
235    GetByteSize () const;
236
237    void
238    SetByteSize (lldb::addr_t size)
239    {
240        m_size_is_valid = size > 0;
241        m_addr_range.SetByteSize(size);
242    }
243
244    bool
245    GetSizeIsSibling () const
246    {
247        return m_size_is_sibling;
248    }
249
250    void
251    SetSizeIsSibling (bool b)
252    {
253        m_size_is_sibling = b;
254    }
255
256    // If m_type is "Code" or "Function" then this will return the prologue size
257    // in bytes, else it will return zero.
258    uint32_t
259    GetPrologueByteSize ();
260
261    bool
262    GetDemangledNameIsSynthesized() const
263    {
264        return m_demangled_is_synthesized;
265    }
266    void
267    SetDemangledNameIsSynthesized(bool b)
268    {
269        m_demangled_is_synthesized = b;
270    }
271
272    //------------------------------------------------------------------
273    /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)
274    ///
275    /// @see SymbolContextScope
276    //------------------------------------------------------------------
277    virtual void
278    CalculateSymbolContext (SymbolContext *sc);
279
280    virtual lldb::ModuleSP
281    CalculateSymbolContextModule ();
282
283    virtual Symbol *
284    CalculateSymbolContextSymbol ();
285
286    //------------------------------------------------------------------
287    /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*)
288    ///
289    /// @see SymbolContextScope
290    //------------------------------------------------------------------
291    virtual void
292    DumpSymbolContext (Stream *s);
293
294    lldb::DisassemblerSP
295    GetInstructions (const ExecutionContext &exe_ctx,
296                     const char *flavor,
297                     bool prefer_file_cache);
298
299    bool
300    GetDisassembly (const ExecutionContext &exe_ctx,
301                    const char *flavor,
302                    bool prefer_file_cache,
303                    Stream &strm);
304
305protected:
306
307    uint32_t        m_uid;                  // User ID (usually the original symbol table index)
308    uint16_t        m_type_data;            // data specific to m_type
309    uint16_t        m_type_data_resolved:1, // True if the data in m_type_data has already been calculated
310                    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.
311                    m_is_debug:1,           // non-zero if this symbol is debug information in a symbol
312                    m_is_external:1,        // non-zero if this symbol is globally visible
313                    m_size_is_sibling:1,    // m_size contains the index of this symbol's sibling
314                    m_size_is_synthesized:1,// non-zero if this symbol's size was calculated using a delta between this symbol and the next
315                    m_size_is_valid:1,
316                    m_demangled_is_synthesized:1, // The demangled name was created should not be used for expressions or other lookups
317                    m_type:8;
318    Mangled         m_mangled;              // uniqued symbol name/mangled name pair
319    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)
320    uint32_t        m_flags;                // A copy of the flags from the original symbol table, the ObjectFile plug-in can interpret these
321};
322
323} // namespace lldb_private
324
325#endif  // liblldb_Symbol_h_
326