SBData.h revision a6b7e323caa2bbd1b2835dcce775340b27c13bf3
1//===-- SBData.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 LLDB_SBData_h_
11#define LLDB_SBData_h_
12
13#include "lldb/API/SBDefines.h"
14
15namespace lldb {
16
17class SBData
18{
19public:
20
21    SBData ();
22
23    SBData (const SBData &rhs);
24
25#ifndef SWIG
26    const SBData &
27    operator = (const SBData &rhs);
28#endif
29
30    ~SBData ();
31
32    uint8_t
33    GetAddressByteSize ();
34
35    void
36    SetAddressByteSize (uint8_t addr_byte_size);
37
38    void
39    Clear ();
40
41    bool
42    IsValid();
43
44    size_t
45    GetByteSize ();
46
47    lldb::ByteOrder
48    GetByteOrder();
49
50    void
51    SetByteOrder (lldb::ByteOrder endian);
52
53    float
54    GetFloat (lldb::SBError& error, uint32_t offset);
55
56    double
57    GetDouble (lldb::SBError& error, uint32_t offset);
58
59    long double
60    GetLongDouble (lldb::SBError& error, uint32_t offset);
61
62    lldb::addr_t
63    GetAddress (lldb::SBError& error, uint32_t offset);
64
65    uint8_t
66    GetUnsignedInt8 (lldb::SBError& error, uint32_t offset);
67
68    uint16_t
69    GetUnsignedInt16 (lldb::SBError& error, uint32_t offset);
70
71    uint32_t
72    GetUnsignedInt32 (lldb::SBError& error, uint32_t offset);
73
74    uint64_t
75    GetUnsignedInt64 (lldb::SBError& error, uint32_t offset);
76
77    int8_t
78    GetSignedInt8 (lldb::SBError& error, uint32_t offset);
79
80    int16_t
81    GetSignedInt16 (lldb::SBError& error, uint32_t offset);
82
83    int32_t
84    GetSignedInt32 (lldb::SBError& error, uint32_t offset);
85
86    int64_t
87    GetSignedInt64 (lldb::SBError& error, uint32_t offset);
88
89    const char*
90    GetString (lldb::SBError& error, uint32_t offset);
91
92    size_t
93    ReadRawData (lldb::SBError& error,
94                 uint32_t offset,
95                 void *buf,
96                 size_t size);
97
98    bool
99    GetDescription (lldb::SBStream &description, lldb::addr_t base_addr = LLDB_INVALID_ADDRESS);
100
101    // it would be nice to have SetData(SBError, const void*, size_t) when endianness and address size can be
102    // inferred from the existing DataExtractor, but having two SetData() signatures triggers a SWIG bug where
103    // the typemap isn't applied before resolving the overload, and thus the right function never gets called
104    void
105    SetData (lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size);
106
107    // see SetData() for why we don't have Append(const void* buf, size_t size)
108    bool
109    Append (const SBData& rhs);
110
111    static lldb::SBData
112    CreateDataFromCString (lldb::ByteOrder endian, uint32_t addr_byte_size, const char* data);
113
114    // in the following CreateData*() and SetData*() prototypes, the two parameters array and array_len
115    // should not be renamed or rearranged, because doing so will break the SWIG typemap
116    static lldb::SBData
117    CreateDataFromUInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint64_t* array, size_t array_len);
118
119    static lldb::SBData
120    CreateDataFromUInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint32_t* array, size_t array_len);
121
122    static lldb::SBData
123    CreateDataFromSInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int64_t* array, size_t array_len);
124
125    static lldb::SBData
126    CreateDataFromSInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int32_t* array, size_t array_len);
127
128    static lldb::SBData
129    CreateDataFromDoubleArray (lldb::ByteOrder endian, uint32_t addr_byte_size, double* array, size_t array_len);
130
131    bool
132    SetDataFromCString (const char* data);
133
134    bool
135    SetDataFromUInt64Array (uint64_t* array, size_t array_len);
136
137    bool
138    SetDataFromUInt32Array (uint32_t* array, size_t array_len);
139
140    bool
141    SetDataFromSInt64Array (int64_t* array, size_t array_len);
142
143    bool
144    SetDataFromSInt32Array (int32_t* array, size_t array_len);
145
146    bool
147    SetDataFromDoubleArray (double* array, size_t array_len);
148
149
150protected:
151
152#ifndef SWIG
153    // Mimic shared pointer...
154    lldb_private::DataExtractor *
155    get() const;
156
157    lldb_private::DataExtractor *
158    operator->() const;
159
160    lldb::DataExtractorSP &
161    operator*();
162
163    const lldb::DataExtractorSP &
164    operator*() const;
165#endif
166
167    SBData (const lldb::DataExtractorSP &data_sp);
168
169    void
170    SetOpaque (const lldb::DataExtractorSP &data_sp);
171
172private:
173    friend class SBInstruction;
174    friend class SBProcess;
175    friend class SBSection;
176    friend class SBValue;
177
178    lldb::DataExtractorSP  m_opaque_sp;
179};
180
181
182} // namespace lldb
183
184#endif // LLDB_SBData_h_
185