DWARFFormValue.h revision 309124
1//===-- DWARFFormValue.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 SymbolFileDWARF_DWARFFormValue_h_
11#define SymbolFileDWARF_DWARFFormValue_h_
12
13#include <stddef.h> // for NULL
14#include "DWARFDataExtractor.h"
15
16class DWARFCompileUnit;
17
18class DWARFFormValue
19{
20public:
21    typedef struct ValueTypeTag
22    {
23        ValueTypeTag() :
24            value(),
25            data(NULL)
26        {
27            value.uval = 0;
28        }
29
30        union
31        {
32            uint64_t uval;
33            int64_t sval;
34            const char* cstr;
35        } value;
36        const uint8_t* data;
37    } ValueType;
38
39    class FixedFormSizes
40    {
41    public:
42        FixedFormSizes() :
43            m_fix_sizes(nullptr), m_size(0)
44        {}
45
46        FixedFormSizes(const uint8_t* fix_sizes, size_t size) :
47            m_fix_sizes(fix_sizes), m_size(size)
48        {}
49
50        uint8_t
51        GetSize(uint32_t index) const
52        {
53            return index < m_size ? m_fix_sizes[index] : 0;
54        }
55
56        bool
57        Empty() const
58        {
59            return m_size == 0;
60        }
61
62    private:
63        const uint8_t* m_fix_sizes;
64        size_t         m_size;
65    };
66
67    enum
68    {
69        eValueTypeInvalid = 0,
70        eValueTypeUnsigned,
71        eValueTypeSigned,
72        eValueTypeCStr,
73        eValueTypeBlock
74    };
75
76    DWARFFormValue();
77    DWARFFormValue(const DWARFCompileUnit* cu, dw_form_t form);
78    const DWARFCompileUnit* GetCompileUnit () const { return m_cu; }
79    void                SetCompileUnit (const DWARFCompileUnit* cu) { m_cu = cu; }
80    dw_form_t           Form()  const { return m_form; }
81    void                SetForm(dw_form_t form) { m_form = form; }
82    const ValueType&    Value() const { return m_value; }
83    void                Dump(lldb_private::Stream &s) const;
84    bool                ExtractValue(const lldb_private::DWARFDataExtractor& data,
85                                     lldb::offset_t* offset_ptr);
86    const uint8_t*      BlockData() const;
87    uint64_t            Reference() const;
88    uint64_t            Reference (dw_offset_t offset) const;
89    bool                Boolean() const { return m_value.value.uval != 0; }
90    uint64_t            Unsigned() const { return m_value.value.uval; }
91    void                SetUnsigned(uint64_t uval) { m_value.value.uval = uval; }
92    int64_t             Signed() const { return m_value.value.sval; }
93    void                SetSigned(int64_t sval) { m_value.value.sval = sval; }
94    const char*         AsCString() const;
95    dw_addr_t           Address() const;
96    bool                IsValid() const { return m_form != 0; }
97    bool                SkipValue(const lldb_private::DWARFDataExtractor& debug_info_data, lldb::offset_t *offset_ptr) const;
98    static bool         SkipValue(const dw_form_t form, const lldb_private::DWARFDataExtractor& debug_info_data, lldb::offset_t *offset_ptr, const DWARFCompileUnit* cu);
99    static bool         IsBlockForm(const dw_form_t form);
100    static bool         IsDataForm(const dw_form_t form);
101    static FixedFormSizes GetFixedFormSizesForAddressSize (uint8_t addr_size, bool is_dwarf64);
102    static int          Compare (const DWARFFormValue& a,
103                                 const DWARFFormValue& b);
104    void                Clear();
105protected:
106    const DWARFCompileUnit* m_cu; // Compile unit for this form
107    dw_form_t   m_form;     // Form for this value
108    ValueType   m_value;    // Contains all data for the form
109};
110
111
112#endif  // SymbolFileDWARF_DWARFFormValue_h_
113