Symbol.h revision 4fb08150367853dae24bb92904356788e919a72f
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 UserID,   // Used to uniquely identify this symbol in its symbol table
23    public SymbolContextScope
24{
25public:
26    // ObjectFile readers can classify their symbol table entries and searches can be made
27    // on specific types where the symbol values will have drastically different meanings
28    // and sorting requirements.
29    Symbol();
30
31    Symbol (lldb::user_id_t symID,
32            const char *name,
33            bool name_is_mangled,
34            lldb::SymbolType type,
35            bool external,
36            bool is_debug,
37            bool is_trampoline,
38            bool is_artificial,
39            const Section* section,
40            lldb::addr_t value,
41            uint32_t size,
42            uint32_t flags);
43
44    Symbol (lldb::user_id_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            uint32_t flags);
54
55    Symbol (const Symbol& rhs);
56
57    const Symbol&
58    operator= (const Symbol& rhs);
59
60    bool
61    Compare (const ConstString& name, lldb::SymbolType type) const;
62
63    void
64    Dump (Stream *s, Process *process, uint32_t index) const;
65
66    AddressRange *
67    GetAddressRangePtr ();
68
69    const AddressRange *
70    GetAddressRangePtr () const;
71
72    AddressRange &
73    GetAddressRangeRef() { return m_addr_range; }
74
75    const AddressRange &
76    GetAddressRangeRef() const { return m_addr_range; }
77
78    Mangled&
79    GetMangled () { return m_mangled; }
80
81    const Mangled&
82    GetMangled () const { return m_mangled; }
83
84    bool
85    GetSizeIsSibling () const { return m_size_is_sibling; }
86
87    bool
88    GetSizeIsSynthesized() const { return m_size_is_synthesized; }
89
90    uint32_t
91    GetSiblingIndex () const;
92
93    uint32_t
94    GetByteSize () const { return m_addr_range.GetByteSize(); }
95
96    lldb::SymbolType
97    GetType () const { return m_type; }
98
99    void
100    SetType (lldb::SymbolType type) { m_type = type; }
101
102    const char *
103    GetTypeAsString () const;
104
105    uint32_t
106    GetFlags () const { return m_flags; }
107
108    void
109    SetFlags (uint32_t flags) { m_flags = flags; }
110
111    void
112    GetDescription (Stream *s, lldb::DescriptionLevel level, Process *process) const;
113
114    Function *
115    GetFunction ();
116
117    Address &
118    GetValue () { return m_addr_range.GetBaseAddress(); }
119
120    const Address &
121    GetValue () const { return m_addr_range.GetBaseAddress(); }
122
123    bool
124    IsSynthetic () const { return m_is_synthetic; }
125
126    void
127    SetIsSynthetic (bool b) { m_is_synthetic = b; }
128
129    void
130    SetSizeIsSynthesized(bool b) { m_size_is_synthesized = b; }
131
132    bool
133    IsDebug () const { return m_is_debug; }
134
135    void
136    SetDebug (bool b) { m_is_debug = b; }
137
138    bool
139    IsExternal () const { return m_is_external; }
140
141    void
142    SetExternal (bool b) { m_is_external = b; }
143
144    bool
145    IsTrampoline () const;
146
147    void
148    SetByteSize (uint32_t size) { m_addr_range.SetByteSize(size); }
149
150    void
151    SetSizeIsSibling (bool b) { m_size_is_sibling = b; }
152
153    void
154    SetValue (Address &value) { m_addr_range.GetBaseAddress() = value; }
155
156    void
157    SetValue (const AddressRange &range) { m_addr_range = range; }
158
159    void
160    SetValue (lldb::addr_t value);
161
162    // If m_type is "Code" or "Function" then this will return the prologue size
163    // in bytes, else it will return zero.
164    uint32_t
165    GetPrologueByteSize ();
166
167    //------------------------------------------------------------------
168    /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)
169    ///
170    /// @see SymbolContextScope
171    //------------------------------------------------------------------
172    virtual void
173    CalculateSymbolContext (SymbolContext *sc);
174
175    //------------------------------------------------------------------
176    /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*)
177    ///
178    /// @see SymbolContextScope
179    //------------------------------------------------------------------
180    virtual void
181    DumpSymbolContext (Stream *s);
182
183protected:
184
185    Mangled         m_mangled;              // uniqued symbol name/mangled name pair
186    lldb::SymbolType m_type;                 // symbol type
187    uint16_t        m_type_data;            // data specific to m_type
188    uint16_t        m_type_data_resolved:1, // True if the data in m_type_data has already been calculated
189                    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.
190                    m_is_debug:1,           // non-zero if this symbol is debug information in a symbol
191                    m_is_external:1,        // non-zero if this symbol is globally visible
192                    m_size_is_sibling:1,    // m_size contains the index of this symbol's sibling
193                    m_size_is_synthesized:1,// non-zero if this symbol's size was calculated using a delta between this symbol and the next
194                    m_searched_for_function:1;// non-zero if we have looked for the function associated with this symbol already.
195    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)
196    uint32_t        m_flags;                // A copy of the flags from the original symbol table, the ObjectFile plug-in can interpret these
197    Function *      m_function;
198};
199
200} // namespace lldb_private
201
202#endif  // liblldb_Symbol_h_
203