1ac7ddfbfSEd Maste //===-- SBData.cpp ----------------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10*b5893f02SDimitry Andric #include <inttypes.h>
110127ef0fSEd Maste 
12ac7ddfbfSEd Maste #include "lldb/API/SBData.h"
13ac7ddfbfSEd Maste #include "lldb/API/SBError.h"
14ac7ddfbfSEd Maste #include "lldb/API/SBStream.h"
15ac7ddfbfSEd Maste 
16f678e45dSDimitry Andric #include "lldb/Core/DumpDataExtractor.h"
17f678e45dSDimitry Andric #include "lldb/Utility/DataBufferHeap.h"
18f678e45dSDimitry Andric #include "lldb/Utility/DataExtractor.h"
19f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
20f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
21ac7ddfbfSEd Maste 
22ac7ddfbfSEd Maste using namespace lldb;
23ac7ddfbfSEd Maste using namespace lldb_private;
24ac7ddfbfSEd Maste 
SBData()25435933ddSDimitry Andric SBData::SBData() : m_opaque_sp(new DataExtractor()) {}
26ac7ddfbfSEd Maste 
SBData(const lldb::DataExtractorSP & data_sp)27435933ddSDimitry Andric SBData::SBData(const lldb::DataExtractorSP &data_sp) : m_opaque_sp(data_sp) {}
28ac7ddfbfSEd Maste 
SBData(const SBData & rhs)29435933ddSDimitry Andric SBData::SBData(const SBData &rhs) : m_opaque_sp(rhs.m_opaque_sp) {}
30ac7ddfbfSEd Maste 
operator =(const SBData & rhs)31435933ddSDimitry Andric const SBData &SBData::operator=(const SBData &rhs) {
32ac7ddfbfSEd Maste   if (this != &rhs)
33ac7ddfbfSEd Maste     m_opaque_sp = rhs.m_opaque_sp;
34ac7ddfbfSEd Maste   return *this;
35ac7ddfbfSEd Maste }
36ac7ddfbfSEd Maste 
~SBData()37435933ddSDimitry Andric SBData::~SBData() {}
38ac7ddfbfSEd Maste 
SetOpaque(const lldb::DataExtractorSP & data_sp)39435933ddSDimitry Andric void SBData::SetOpaque(const lldb::DataExtractorSP &data_sp) {
40ac7ddfbfSEd Maste   m_opaque_sp = data_sp;
41ac7ddfbfSEd Maste }
42ac7ddfbfSEd Maste 
get() const43435933ddSDimitry Andric lldb_private::DataExtractor *SBData::get() const { return m_opaque_sp.get(); }
44ac7ddfbfSEd Maste 
operator ->() const45435933ddSDimitry Andric lldb_private::DataExtractor *SBData::operator->() const {
46ac7ddfbfSEd Maste   return m_opaque_sp.operator->();
47ac7ddfbfSEd Maste }
48ac7ddfbfSEd Maste 
operator *()49435933ddSDimitry Andric lldb::DataExtractorSP &SBData::operator*() { return m_opaque_sp; }
50ac7ddfbfSEd Maste 
operator *() const51435933ddSDimitry Andric const lldb::DataExtractorSP &SBData::operator*() const { return m_opaque_sp; }
52ac7ddfbfSEd Maste 
IsValid()53435933ddSDimitry Andric bool SBData::IsValid() { return m_opaque_sp.get() != NULL; }
54ac7ddfbfSEd Maste 
GetAddressByteSize()55435933ddSDimitry Andric uint8_t SBData::GetAddressByteSize() {
56ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
57ac7ddfbfSEd Maste   uint8_t value = 0;
58ac7ddfbfSEd Maste   if (m_opaque_sp.get())
59ac7ddfbfSEd Maste     value = m_opaque_sp->GetAddressByteSize();
60ac7ddfbfSEd Maste   if (log)
61ac7ddfbfSEd Maste     log->Printf("SBData::GetAddressByteSize () => "
62435933ddSDimitry Andric                 "(%i)",
63435933ddSDimitry Andric                 value);
64ac7ddfbfSEd Maste   return value;
65ac7ddfbfSEd Maste }
66ac7ddfbfSEd Maste 
SetAddressByteSize(uint8_t addr_byte_size)67435933ddSDimitry Andric void SBData::SetAddressByteSize(uint8_t addr_byte_size) {
68ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
69ac7ddfbfSEd Maste   if (m_opaque_sp.get())
70ac7ddfbfSEd Maste     m_opaque_sp->SetAddressByteSize(addr_byte_size);
71ac7ddfbfSEd Maste   if (log)
72ac7ddfbfSEd Maste     log->Printf("SBData::SetAddressByteSize (%i)", addr_byte_size);
73ac7ddfbfSEd Maste }
74ac7ddfbfSEd Maste 
Clear()75435933ddSDimitry Andric void SBData::Clear() {
76ac7ddfbfSEd Maste   if (m_opaque_sp.get())
77ac7ddfbfSEd Maste     m_opaque_sp->Clear();
78ac7ddfbfSEd Maste }
79ac7ddfbfSEd Maste 
GetByteSize()80435933ddSDimitry Andric size_t SBData::GetByteSize() {
81ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
82ac7ddfbfSEd Maste   size_t value = 0;
83ac7ddfbfSEd Maste   if (m_opaque_sp.get())
84ac7ddfbfSEd Maste     value = m_opaque_sp->GetByteSize();
85ac7ddfbfSEd Maste   if (log)
86ac7ddfbfSEd Maste     log->Printf("SBData::GetByteSize () => "
87435933ddSDimitry Andric                 "( %" PRIu64 " )",
88435933ddSDimitry Andric                 (uint64_t)value);
89ac7ddfbfSEd Maste   return value;
90ac7ddfbfSEd Maste }
91ac7ddfbfSEd Maste 
GetByteOrder()92435933ddSDimitry Andric lldb::ByteOrder SBData::GetByteOrder() {
93ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
94ac7ddfbfSEd Maste   lldb::ByteOrder value = eByteOrderInvalid;
95ac7ddfbfSEd Maste   if (m_opaque_sp.get())
96ac7ddfbfSEd Maste     value = m_opaque_sp->GetByteOrder();
97ac7ddfbfSEd Maste   if (log)
98ac7ddfbfSEd Maste     log->Printf("SBData::GetByteOrder () => "
99435933ddSDimitry Andric                 "(%i)",
100435933ddSDimitry Andric                 value);
101ac7ddfbfSEd Maste   return value;
102ac7ddfbfSEd Maste }
103ac7ddfbfSEd Maste 
SetByteOrder(lldb::ByteOrder endian)104435933ddSDimitry Andric void SBData::SetByteOrder(lldb::ByteOrder endian) {
105ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
106ac7ddfbfSEd Maste   if (m_opaque_sp.get())
107ac7ddfbfSEd Maste     m_opaque_sp->SetByteOrder(endian);
108ac7ddfbfSEd Maste   if (log)
109ac7ddfbfSEd Maste     log->Printf("SBData::GetByteOrder (%i)", endian);
110ac7ddfbfSEd Maste }
111ac7ddfbfSEd Maste 
GetFloat(lldb::SBError & error,lldb::offset_t offset)112435933ddSDimitry Andric float SBData::GetFloat(lldb::SBError &error, lldb::offset_t offset) {
113ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
114ac7ddfbfSEd Maste   float value = 0;
115435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
116ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
117435933ddSDimitry Andric   } else {
118ac7ddfbfSEd Maste     uint32_t old_offset = offset;
119ac7ddfbfSEd Maste     value = m_opaque_sp->GetFloat(&offset);
120ac7ddfbfSEd Maste     if (offset == old_offset)
121ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
122ac7ddfbfSEd Maste   }
123ac7ddfbfSEd Maste   if (log)
1240127ef0fSEd Maste     log->Printf("SBData::GetFloat (error=%p,offset=%" PRIu64 ") => (%f)",
1250127ef0fSEd Maste                 static_cast<void *>(error.get()), offset, value);
126ac7ddfbfSEd Maste   return value;
127ac7ddfbfSEd Maste }
128ac7ddfbfSEd Maste 
GetDouble(lldb::SBError & error,lldb::offset_t offset)129435933ddSDimitry Andric double SBData::GetDouble(lldb::SBError &error, lldb::offset_t offset) {
130ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
131ac7ddfbfSEd Maste   double value = 0;
132435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
133ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
134435933ddSDimitry Andric   } else {
135ac7ddfbfSEd Maste     uint32_t old_offset = offset;
136ac7ddfbfSEd Maste     value = m_opaque_sp->GetDouble(&offset);
137ac7ddfbfSEd Maste     if (offset == old_offset)
138ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
139ac7ddfbfSEd Maste   }
140ac7ddfbfSEd Maste   if (log)
141ac7ddfbfSEd Maste     log->Printf("SBData::GetDouble (error=%p,offset=%" PRIu64 ") => "
142435933ddSDimitry Andric                 "(%f)",
143435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset, value);
144ac7ddfbfSEd Maste   return value;
145ac7ddfbfSEd Maste }
146ac7ddfbfSEd Maste 
GetLongDouble(lldb::SBError & error,lldb::offset_t offset)147435933ddSDimitry Andric long double SBData::GetLongDouble(lldb::SBError &error, lldb::offset_t offset) {
148ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
149ac7ddfbfSEd Maste   long double value = 0;
150435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
151ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
152435933ddSDimitry Andric   } else {
153ac7ddfbfSEd Maste     uint32_t old_offset = offset;
154ac7ddfbfSEd Maste     value = m_opaque_sp->GetLongDouble(&offset);
155ac7ddfbfSEd Maste     if (offset == old_offset)
156ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
157ac7ddfbfSEd Maste   }
158ac7ddfbfSEd Maste   if (log)
159ac7ddfbfSEd Maste     log->Printf("SBData::GetLongDouble (error=%p,offset=%" PRIu64 ") => "
160435933ddSDimitry Andric                 "(%Lf)",
161435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset, value);
162ac7ddfbfSEd Maste   return value;
163ac7ddfbfSEd Maste }
164ac7ddfbfSEd Maste 
GetAddress(lldb::SBError & error,lldb::offset_t offset)165435933ddSDimitry Andric lldb::addr_t SBData::GetAddress(lldb::SBError &error, lldb::offset_t offset) {
166ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
167ac7ddfbfSEd Maste   lldb::addr_t value = 0;
168435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
169ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
170435933ddSDimitry Andric   } else {
171ac7ddfbfSEd Maste     uint32_t old_offset = offset;
172ac7ddfbfSEd Maste     value = m_opaque_sp->GetAddress(&offset);
173ac7ddfbfSEd Maste     if (offset == old_offset)
174ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
175ac7ddfbfSEd Maste   }
176ac7ddfbfSEd Maste   if (log)
177ac7ddfbfSEd Maste     log->Printf("SBData::GetAddress (error=%p,offset=%" PRIu64 ") => "
178435933ddSDimitry Andric                 "(%p)",
179435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset,
1800127ef0fSEd Maste                 reinterpret_cast<void *>(value));
181ac7ddfbfSEd Maste   return value;
182ac7ddfbfSEd Maste }
183ac7ddfbfSEd Maste 
GetUnsignedInt8(lldb::SBError & error,lldb::offset_t offset)184435933ddSDimitry Andric uint8_t SBData::GetUnsignedInt8(lldb::SBError &error, lldb::offset_t offset) {
185ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
186ac7ddfbfSEd Maste   uint8_t value = 0;
187435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
188ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
189435933ddSDimitry Andric   } else {
190ac7ddfbfSEd Maste     uint32_t old_offset = offset;
191ac7ddfbfSEd Maste     value = m_opaque_sp->GetU8(&offset);
192ac7ddfbfSEd Maste     if (offset == old_offset)
193ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
194ac7ddfbfSEd Maste   }
195ac7ddfbfSEd Maste   if (log)
196ac7ddfbfSEd Maste     log->Printf("SBData::GetUnsignedInt8 (error=%p,offset=%" PRIu64 ") => "
197435933ddSDimitry Andric                 "(%c)",
198435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset, value);
199ac7ddfbfSEd Maste   return value;
200ac7ddfbfSEd Maste }
201ac7ddfbfSEd Maste 
GetUnsignedInt16(lldb::SBError & error,lldb::offset_t offset)202435933ddSDimitry Andric uint16_t SBData::GetUnsignedInt16(lldb::SBError &error, lldb::offset_t offset) {
203ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
204ac7ddfbfSEd Maste   uint16_t value = 0;
205435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
206ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
207435933ddSDimitry Andric   } else {
208ac7ddfbfSEd Maste     uint32_t old_offset = offset;
209ac7ddfbfSEd Maste     value = m_opaque_sp->GetU16(&offset);
210ac7ddfbfSEd Maste     if (offset == old_offset)
211ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
212ac7ddfbfSEd Maste   }
213ac7ddfbfSEd Maste   if (log)
214ac7ddfbfSEd Maste     log->Printf("SBData::GetUnsignedInt16 (error=%p,offset=%" PRIu64 ") => "
215435933ddSDimitry Andric                 "(%hd)",
216435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset, value);
217ac7ddfbfSEd Maste   return value;
218ac7ddfbfSEd Maste }
219ac7ddfbfSEd Maste 
GetUnsignedInt32(lldb::SBError & error,lldb::offset_t offset)220435933ddSDimitry Andric uint32_t SBData::GetUnsignedInt32(lldb::SBError &error, lldb::offset_t offset) {
221ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
222ac7ddfbfSEd Maste   uint32_t value = 0;
223435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
224ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
225435933ddSDimitry Andric   } else {
226ac7ddfbfSEd Maste     uint32_t old_offset = offset;
227ac7ddfbfSEd Maste     value = m_opaque_sp->GetU32(&offset);
228ac7ddfbfSEd Maste     if (offset == old_offset)
229ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
230ac7ddfbfSEd Maste   }
231ac7ddfbfSEd Maste   if (log)
232ac7ddfbfSEd Maste     log->Printf("SBData::GetUnsignedInt32 (error=%p,offset=%" PRIu64 ") => "
233435933ddSDimitry Andric                 "(%d)",
234435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset, value);
235ac7ddfbfSEd Maste   return value;
236ac7ddfbfSEd Maste }
237ac7ddfbfSEd Maste 
GetUnsignedInt64(lldb::SBError & error,lldb::offset_t offset)238435933ddSDimitry Andric uint64_t SBData::GetUnsignedInt64(lldb::SBError &error, lldb::offset_t offset) {
239ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
240ac7ddfbfSEd Maste   uint64_t value = 0;
241435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
242ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
243435933ddSDimitry Andric   } else {
244ac7ddfbfSEd Maste     uint32_t old_offset = offset;
245ac7ddfbfSEd Maste     value = m_opaque_sp->GetU64(&offset);
246ac7ddfbfSEd Maste     if (offset == old_offset)
247ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
248ac7ddfbfSEd Maste   }
249ac7ddfbfSEd Maste   if (log)
250ac7ddfbfSEd Maste     log->Printf("SBData::GetUnsignedInt64 (error=%p,offset=%" PRIu64 ") => "
251435933ddSDimitry Andric                 "(%" PRId64 ")",
252435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset, value);
253ac7ddfbfSEd Maste   return value;
254ac7ddfbfSEd Maste }
255ac7ddfbfSEd Maste 
GetSignedInt8(lldb::SBError & error,lldb::offset_t offset)256435933ddSDimitry Andric int8_t SBData::GetSignedInt8(lldb::SBError &error, lldb::offset_t offset) {
257ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
258ac7ddfbfSEd Maste   int8_t value = 0;
259435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
260ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
261435933ddSDimitry Andric   } else {
262ac7ddfbfSEd Maste     uint32_t old_offset = offset;
263ac7ddfbfSEd Maste     value = (int8_t)m_opaque_sp->GetMaxS64(&offset, 1);
264ac7ddfbfSEd Maste     if (offset == old_offset)
265ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
266ac7ddfbfSEd Maste   }
267ac7ddfbfSEd Maste   if (log)
268ac7ddfbfSEd Maste     log->Printf("SBData::GetSignedInt8 (error=%p,offset=%" PRIu64 ") => "
269435933ddSDimitry Andric                 "(%c)",
270435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset, value);
271ac7ddfbfSEd Maste   return value;
272ac7ddfbfSEd Maste }
273ac7ddfbfSEd Maste 
GetSignedInt16(lldb::SBError & error,lldb::offset_t offset)274435933ddSDimitry Andric int16_t SBData::GetSignedInt16(lldb::SBError &error, lldb::offset_t offset) {
275ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
276ac7ddfbfSEd Maste   int16_t value = 0;
277435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
278ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
279435933ddSDimitry Andric   } else {
280ac7ddfbfSEd Maste     uint32_t old_offset = offset;
281ac7ddfbfSEd Maste     value = (int16_t)m_opaque_sp->GetMaxS64(&offset, 2);
282ac7ddfbfSEd Maste     if (offset == old_offset)
283ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
284ac7ddfbfSEd Maste   }
285ac7ddfbfSEd Maste   if (log)
286ac7ddfbfSEd Maste     log->Printf("SBData::GetSignedInt16 (error=%p,offset=%" PRIu64 ") => "
287435933ddSDimitry Andric                 "(%hd)",
288435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset, value);
289ac7ddfbfSEd Maste   return value;
290ac7ddfbfSEd Maste }
291ac7ddfbfSEd Maste 
GetSignedInt32(lldb::SBError & error,lldb::offset_t offset)292435933ddSDimitry Andric int32_t SBData::GetSignedInt32(lldb::SBError &error, lldb::offset_t offset) {
293ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
294ac7ddfbfSEd Maste   int32_t value = 0;
295435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
296ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
297435933ddSDimitry Andric   } else {
298ac7ddfbfSEd Maste     uint32_t old_offset = offset;
299ac7ddfbfSEd Maste     value = (int32_t)m_opaque_sp->GetMaxS64(&offset, 4);
300ac7ddfbfSEd Maste     if (offset == old_offset)
301ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
302ac7ddfbfSEd Maste   }
303ac7ddfbfSEd Maste   if (log)
304ac7ddfbfSEd Maste     log->Printf("SBData::GetSignedInt32 (error=%p,offset=%" PRIu64 ") => "
305435933ddSDimitry Andric                 "(%d)",
306435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset, value);
307ac7ddfbfSEd Maste   return value;
308ac7ddfbfSEd Maste }
309ac7ddfbfSEd Maste 
GetSignedInt64(lldb::SBError & error,lldb::offset_t offset)310435933ddSDimitry Andric int64_t SBData::GetSignedInt64(lldb::SBError &error, lldb::offset_t offset) {
311ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
312ac7ddfbfSEd Maste   int64_t value = 0;
313435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
314ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
315435933ddSDimitry Andric   } else {
316ac7ddfbfSEd Maste     uint32_t old_offset = offset;
317ac7ddfbfSEd Maste     value = (int64_t)m_opaque_sp->GetMaxS64(&offset, 8);
318ac7ddfbfSEd Maste     if (offset == old_offset)
319ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
320ac7ddfbfSEd Maste   }
321ac7ddfbfSEd Maste   if (log)
322ac7ddfbfSEd Maste     log->Printf("SBData::GetSignedInt64 (error=%p,offset=%" PRIu64 ") => "
323435933ddSDimitry Andric                 "(%" PRId64 ")",
324435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset, value);
325ac7ddfbfSEd Maste   return value;
326ac7ddfbfSEd Maste }
327ac7ddfbfSEd Maste 
GetString(lldb::SBError & error,lldb::offset_t offset)328435933ddSDimitry Andric const char *SBData::GetString(lldb::SBError &error, lldb::offset_t offset) {
329ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
330ac7ddfbfSEd Maste   const char *value = 0;
331435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
332ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
333435933ddSDimitry Andric   } else {
334ac7ddfbfSEd Maste     uint32_t old_offset = offset;
335ac7ddfbfSEd Maste     value = m_opaque_sp->GetCStr(&offset);
336ac7ddfbfSEd Maste     if (offset == old_offset || (value == NULL))
337ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
338ac7ddfbfSEd Maste   }
339ac7ddfbfSEd Maste   if (log)
3400127ef0fSEd Maste     log->Printf("SBData::GetString (error=%p,offset=%" PRIu64 ") => (%p)",
3410127ef0fSEd Maste                 static_cast<void *>(error.get()), offset,
3420127ef0fSEd Maste                 static_cast<const void *>(value));
343ac7ddfbfSEd Maste   return value;
344ac7ddfbfSEd Maste }
345ac7ddfbfSEd Maste 
GetDescription(lldb::SBStream & description,lldb::addr_t base_addr)346435933ddSDimitry Andric bool SBData::GetDescription(lldb::SBStream &description,
347435933ddSDimitry Andric                             lldb::addr_t base_addr) {
348ac7ddfbfSEd Maste   Stream &strm = description.ref();
349ac7ddfbfSEd Maste 
350435933ddSDimitry Andric   if (m_opaque_sp) {
351f678e45dSDimitry Andric     DumpDataExtractor(*m_opaque_sp, &strm, 0, lldb::eFormatBytesWithASCII, 1,
352435933ddSDimitry Andric                       m_opaque_sp->GetByteSize(), 16, base_addr, 0, 0);
353435933ddSDimitry Andric   } else
354ac7ddfbfSEd Maste     strm.PutCString("No value");
355ac7ddfbfSEd Maste 
356ac7ddfbfSEd Maste   return true;
357ac7ddfbfSEd Maste }
358ac7ddfbfSEd Maste 
ReadRawData(lldb::SBError & error,lldb::offset_t offset,void * buf,size_t size)359435933ddSDimitry Andric size_t SBData::ReadRawData(lldb::SBError &error, lldb::offset_t offset,
360435933ddSDimitry Andric                            void *buf, size_t size) {
361ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
362ac7ddfbfSEd Maste   void *ok = NULL;
363435933ddSDimitry Andric   if (!m_opaque_sp.get()) {
364ac7ddfbfSEd Maste     error.SetErrorString("no value to read from");
365435933ddSDimitry Andric   } else {
366ac7ddfbfSEd Maste     uint32_t old_offset = offset;
367ac7ddfbfSEd Maste     ok = m_opaque_sp->GetU8(&offset, buf, size);
368ac7ddfbfSEd Maste     if ((offset == old_offset) || (ok == NULL))
369ac7ddfbfSEd Maste       error.SetErrorString("unable to read data");
370ac7ddfbfSEd Maste   }
371ac7ddfbfSEd Maste   if (log)
372435933ddSDimitry Andric     log->Printf("SBData::ReadRawData (error=%p,offset=%" PRIu64
373435933ddSDimitry Andric                 ",buf=%p,size=%" PRIu64 ") => "
374435933ddSDimitry Andric                 "(%p)",
375435933ddSDimitry Andric                 static_cast<void *>(error.get()), offset,
3760127ef0fSEd Maste                 static_cast<void *>(buf), static_cast<uint64_t>(size),
3770127ef0fSEd Maste                 static_cast<void *>(ok));
378ac7ddfbfSEd Maste   return ok ? size : 0;
379ac7ddfbfSEd Maste }
380ac7ddfbfSEd Maste 
SetData(lldb::SBError & error,const void * buf,size_t size,lldb::ByteOrder endian,uint8_t addr_size)381435933ddSDimitry Andric void SBData::SetData(lldb::SBError &error, const void *buf, size_t size,
382435933ddSDimitry Andric                      lldb::ByteOrder endian, uint8_t addr_size) {
383ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
384ac7ddfbfSEd Maste   if (!m_opaque_sp.get())
385ac7ddfbfSEd Maste     m_opaque_sp.reset(new DataExtractor(buf, size, endian, addr_size));
386ac7ddfbfSEd Maste   else
387f678e45dSDimitry Andric   {
388ac7ddfbfSEd Maste     m_opaque_sp->SetData(buf, size, endian);
389f678e45dSDimitry Andric     m_opaque_sp->SetAddressByteSize(addr_size);
390f678e45dSDimitry Andric   }
391f678e45dSDimitry Andric 
392ac7ddfbfSEd Maste   if (log)
393435933ddSDimitry Andric     log->Printf("SBData::SetData (error=%p,buf=%p,size=%" PRIu64
394435933ddSDimitry Andric                 ",endian=%d,addr_size=%c) => "
395435933ddSDimitry Andric                 "(%p)",
396435933ddSDimitry Andric                 static_cast<void *>(error.get()),
3970127ef0fSEd Maste                 static_cast<const void *>(buf), static_cast<uint64_t>(size),
3980127ef0fSEd Maste                 endian, addr_size, static_cast<void *>(m_opaque_sp.get()));
399ac7ddfbfSEd Maste }
400ac7ddfbfSEd Maste 
Append(const SBData & rhs)401435933ddSDimitry Andric bool SBData::Append(const SBData &rhs) {
402ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
403ac7ddfbfSEd Maste   bool value = false;
404ac7ddfbfSEd Maste   if (m_opaque_sp.get() && rhs.m_opaque_sp.get())
405ac7ddfbfSEd Maste     value = m_opaque_sp.get()->Append(*rhs.m_opaque_sp);
406ac7ddfbfSEd Maste   if (log)
4070127ef0fSEd Maste     log->Printf("SBData::Append (rhs=%p) => (%s)",
4080127ef0fSEd Maste                 static_cast<void *>(rhs.get()), value ? "true" : "false");
409ac7ddfbfSEd Maste   return value;
410ac7ddfbfSEd Maste }
411ac7ddfbfSEd Maste 
CreateDataFromCString(lldb::ByteOrder endian,uint32_t addr_byte_size,const char * data)412435933ddSDimitry Andric lldb::SBData SBData::CreateDataFromCString(lldb::ByteOrder endian,
413435933ddSDimitry Andric                                            uint32_t addr_byte_size,
414435933ddSDimitry Andric                                            const char *data) {
415ac7ddfbfSEd Maste   if (!data || !data[0])
416ac7ddfbfSEd Maste     return SBData();
417ac7ddfbfSEd Maste 
418ac7ddfbfSEd Maste   uint32_t data_len = strlen(data);
419ac7ddfbfSEd Maste 
420ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(data, data_len));
421435933ddSDimitry Andric   lldb::DataExtractorSP data_sp(
422435933ddSDimitry Andric       new DataExtractor(buffer_sp, endian, addr_byte_size));
423ac7ddfbfSEd Maste 
424ac7ddfbfSEd Maste   SBData ret(data_sp);
425ac7ddfbfSEd Maste 
426ac7ddfbfSEd Maste   return ret;
427ac7ddfbfSEd Maste }
428ac7ddfbfSEd Maste 
CreateDataFromUInt64Array(lldb::ByteOrder endian,uint32_t addr_byte_size,uint64_t * array,size_t array_len)429435933ddSDimitry Andric lldb::SBData SBData::CreateDataFromUInt64Array(lldb::ByteOrder endian,
430435933ddSDimitry Andric                                                uint32_t addr_byte_size,
431435933ddSDimitry Andric                                                uint64_t *array,
432435933ddSDimitry Andric                                                size_t array_len) {
433ac7ddfbfSEd Maste   if (!array || array_len == 0)
434ac7ddfbfSEd Maste     return SBData();
435ac7ddfbfSEd Maste 
436ac7ddfbfSEd Maste   size_t data_len = array_len * sizeof(uint64_t);
437ac7ddfbfSEd Maste 
438ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
439435933ddSDimitry Andric   lldb::DataExtractorSP data_sp(
440435933ddSDimitry Andric       new DataExtractor(buffer_sp, endian, addr_byte_size));
441ac7ddfbfSEd Maste 
442ac7ddfbfSEd Maste   SBData ret(data_sp);
443ac7ddfbfSEd Maste 
444ac7ddfbfSEd Maste   return ret;
445ac7ddfbfSEd Maste }
446ac7ddfbfSEd Maste 
CreateDataFromUInt32Array(lldb::ByteOrder endian,uint32_t addr_byte_size,uint32_t * array,size_t array_len)447435933ddSDimitry Andric lldb::SBData SBData::CreateDataFromUInt32Array(lldb::ByteOrder endian,
448435933ddSDimitry Andric                                                uint32_t addr_byte_size,
449435933ddSDimitry Andric                                                uint32_t *array,
450435933ddSDimitry Andric                                                size_t array_len) {
451ac7ddfbfSEd Maste   if (!array || array_len == 0)
452ac7ddfbfSEd Maste     return SBData();
453ac7ddfbfSEd Maste 
454ac7ddfbfSEd Maste   size_t data_len = array_len * sizeof(uint32_t);
455ac7ddfbfSEd Maste 
456ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
457435933ddSDimitry Andric   lldb::DataExtractorSP data_sp(
458435933ddSDimitry Andric       new DataExtractor(buffer_sp, endian, addr_byte_size));
459ac7ddfbfSEd Maste 
460ac7ddfbfSEd Maste   SBData ret(data_sp);
461ac7ddfbfSEd Maste 
462ac7ddfbfSEd Maste   return ret;
463ac7ddfbfSEd Maste }
464ac7ddfbfSEd Maste 
CreateDataFromSInt64Array(lldb::ByteOrder endian,uint32_t addr_byte_size,int64_t * array,size_t array_len)465435933ddSDimitry Andric lldb::SBData SBData::CreateDataFromSInt64Array(lldb::ByteOrder endian,
466435933ddSDimitry Andric                                                uint32_t addr_byte_size,
467435933ddSDimitry Andric                                                int64_t *array,
468435933ddSDimitry Andric                                                size_t array_len) {
469ac7ddfbfSEd Maste   if (!array || array_len == 0)
470ac7ddfbfSEd Maste     return SBData();
471ac7ddfbfSEd Maste 
472ac7ddfbfSEd Maste   size_t data_len = array_len * sizeof(int64_t);
473ac7ddfbfSEd Maste 
474ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
475435933ddSDimitry Andric   lldb::DataExtractorSP data_sp(
476435933ddSDimitry Andric       new DataExtractor(buffer_sp, endian, addr_byte_size));
477ac7ddfbfSEd Maste 
478ac7ddfbfSEd Maste   SBData ret(data_sp);
479ac7ddfbfSEd Maste 
480ac7ddfbfSEd Maste   return ret;
481ac7ddfbfSEd Maste }
482ac7ddfbfSEd Maste 
CreateDataFromSInt32Array(lldb::ByteOrder endian,uint32_t addr_byte_size,int32_t * array,size_t array_len)483435933ddSDimitry Andric lldb::SBData SBData::CreateDataFromSInt32Array(lldb::ByteOrder endian,
484435933ddSDimitry Andric                                                uint32_t addr_byte_size,
485435933ddSDimitry Andric                                                int32_t *array,
486435933ddSDimitry Andric                                                size_t array_len) {
487ac7ddfbfSEd Maste   if (!array || array_len == 0)
488ac7ddfbfSEd Maste     return SBData();
489ac7ddfbfSEd Maste 
490ac7ddfbfSEd Maste   size_t data_len = array_len * sizeof(int32_t);
491ac7ddfbfSEd Maste 
492ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
493435933ddSDimitry Andric   lldb::DataExtractorSP data_sp(
494435933ddSDimitry Andric       new DataExtractor(buffer_sp, endian, addr_byte_size));
495ac7ddfbfSEd Maste 
496ac7ddfbfSEd Maste   SBData ret(data_sp);
497ac7ddfbfSEd Maste 
498ac7ddfbfSEd Maste   return ret;
499ac7ddfbfSEd Maste }
500ac7ddfbfSEd Maste 
CreateDataFromDoubleArray(lldb::ByteOrder endian,uint32_t addr_byte_size,double * array,size_t array_len)501435933ddSDimitry Andric lldb::SBData SBData::CreateDataFromDoubleArray(lldb::ByteOrder endian,
502435933ddSDimitry Andric                                                uint32_t addr_byte_size,
503435933ddSDimitry Andric                                                double *array,
504435933ddSDimitry Andric                                                size_t array_len) {
505ac7ddfbfSEd Maste   if (!array || array_len == 0)
506ac7ddfbfSEd Maste     return SBData();
507ac7ddfbfSEd Maste 
508ac7ddfbfSEd Maste   size_t data_len = array_len * sizeof(double);
509ac7ddfbfSEd Maste 
510ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
511435933ddSDimitry Andric   lldb::DataExtractorSP data_sp(
512435933ddSDimitry Andric       new DataExtractor(buffer_sp, endian, addr_byte_size));
513ac7ddfbfSEd Maste 
514ac7ddfbfSEd Maste   SBData ret(data_sp);
515ac7ddfbfSEd Maste 
516ac7ddfbfSEd Maste   return ret;
517ac7ddfbfSEd Maste }
518ac7ddfbfSEd Maste 
SetDataFromCString(const char * data)519435933ddSDimitry Andric bool SBData::SetDataFromCString(const char *data) {
520ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
521ac7ddfbfSEd Maste 
522435933ddSDimitry Andric   if (!data) {
523ac7ddfbfSEd Maste     if (log)
5240127ef0fSEd Maste       log->Printf("SBData::SetDataFromCString (data=%p) => false",
5250127ef0fSEd Maste                   static_cast<const void *>(data));
526ac7ddfbfSEd Maste     return false;
527ac7ddfbfSEd Maste   }
528ac7ddfbfSEd Maste 
529ac7ddfbfSEd Maste   size_t data_len = strlen(data);
530ac7ddfbfSEd Maste 
531ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(data, data_len));
532ac7ddfbfSEd Maste 
533ac7ddfbfSEd Maste   if (!m_opaque_sp.get())
534435933ddSDimitry Andric     m_opaque_sp.reset(
535435933ddSDimitry Andric         new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
536ac7ddfbfSEd Maste   else
537ac7ddfbfSEd Maste     m_opaque_sp->SetData(buffer_sp);
538ac7ddfbfSEd Maste 
539ac7ddfbfSEd Maste   if (log)
5400127ef0fSEd Maste     log->Printf("SBData::SetDataFromCString (data=%p) => true",
5410127ef0fSEd Maste                 static_cast<const void *>(data));
542ac7ddfbfSEd Maste 
543ac7ddfbfSEd Maste   return true;
544ac7ddfbfSEd Maste }
545ac7ddfbfSEd Maste 
SetDataFromUInt64Array(uint64_t * array,size_t array_len)546435933ddSDimitry Andric bool SBData::SetDataFromUInt64Array(uint64_t *array, size_t array_len) {
547ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
548ac7ddfbfSEd Maste 
549435933ddSDimitry Andric   if (!array || array_len == 0) {
550ac7ddfbfSEd Maste     if (log)
551435933ddSDimitry Andric       log->Printf(
552435933ddSDimitry Andric           "SBData::SetDataFromUInt64Array (array=%p, array_len = %" PRIu64
553435933ddSDimitry Andric           ") => "
554435933ddSDimitry Andric           "false",
555435933ddSDimitry Andric           static_cast<void *>(array), static_cast<uint64_t>(array_len));
556ac7ddfbfSEd Maste     return false;
557ac7ddfbfSEd Maste   }
558ac7ddfbfSEd Maste 
559ac7ddfbfSEd Maste   size_t data_len = array_len * sizeof(uint64_t);
560ac7ddfbfSEd Maste 
561ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
562ac7ddfbfSEd Maste 
563ac7ddfbfSEd Maste   if (!m_opaque_sp.get())
564435933ddSDimitry Andric     m_opaque_sp.reset(
565435933ddSDimitry Andric         new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
566ac7ddfbfSEd Maste   else
567ac7ddfbfSEd Maste     m_opaque_sp->SetData(buffer_sp);
568ac7ddfbfSEd Maste 
569ac7ddfbfSEd Maste   if (log)
570435933ddSDimitry Andric     log->Printf("SBData::SetDataFromUInt64Array (array=%p, array_len = %" PRIu64
571435933ddSDimitry Andric                 ") => "
572435933ddSDimitry Andric                 "true",
573435933ddSDimitry Andric                 static_cast<void *>(array), static_cast<uint64_t>(array_len));
574ac7ddfbfSEd Maste 
575ac7ddfbfSEd Maste   return true;
576ac7ddfbfSEd Maste }
577ac7ddfbfSEd Maste 
SetDataFromUInt32Array(uint32_t * array,size_t array_len)578435933ddSDimitry Andric bool SBData::SetDataFromUInt32Array(uint32_t *array, size_t array_len) {
579ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
580ac7ddfbfSEd Maste 
581435933ddSDimitry Andric   if (!array || array_len == 0) {
582ac7ddfbfSEd Maste     if (log)
583435933ddSDimitry Andric       log->Printf(
584435933ddSDimitry Andric           "SBData::SetDataFromUInt32Array (array=%p, array_len = %" PRIu64
585435933ddSDimitry Andric           ") => "
586435933ddSDimitry Andric           "false",
587435933ddSDimitry Andric           static_cast<void *>(array), static_cast<uint64_t>(array_len));
588ac7ddfbfSEd Maste     return false;
589ac7ddfbfSEd Maste   }
590ac7ddfbfSEd Maste 
591ac7ddfbfSEd Maste   size_t data_len = array_len * sizeof(uint32_t);
592ac7ddfbfSEd Maste 
593ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
594ac7ddfbfSEd Maste 
595ac7ddfbfSEd Maste   if (!m_opaque_sp.get())
596435933ddSDimitry Andric     m_opaque_sp.reset(
597435933ddSDimitry Andric         new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
598ac7ddfbfSEd Maste   else
599ac7ddfbfSEd Maste     m_opaque_sp->SetData(buffer_sp);
600ac7ddfbfSEd Maste 
601ac7ddfbfSEd Maste   if (log)
602435933ddSDimitry Andric     log->Printf("SBData::SetDataFromUInt32Array (array=%p, array_len = %" PRIu64
603435933ddSDimitry Andric                 ") => "
604435933ddSDimitry Andric                 "true",
605435933ddSDimitry Andric                 static_cast<void *>(array), static_cast<uint64_t>(array_len));
606ac7ddfbfSEd Maste 
607ac7ddfbfSEd Maste   return true;
608ac7ddfbfSEd Maste }
609ac7ddfbfSEd Maste 
SetDataFromSInt64Array(int64_t * array,size_t array_len)610435933ddSDimitry Andric bool SBData::SetDataFromSInt64Array(int64_t *array, size_t array_len) {
611ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
612ac7ddfbfSEd Maste 
613435933ddSDimitry Andric   if (!array || array_len == 0) {
614ac7ddfbfSEd Maste     if (log)
615435933ddSDimitry Andric       log->Printf(
616435933ddSDimitry Andric           "SBData::SetDataFromSInt64Array (array=%p, array_len = %" PRIu64
617435933ddSDimitry Andric           ") => "
618435933ddSDimitry Andric           "false",
619435933ddSDimitry Andric           static_cast<void *>(array), static_cast<uint64_t>(array_len));
620ac7ddfbfSEd Maste     return false;
621ac7ddfbfSEd Maste   }
622ac7ddfbfSEd Maste 
623ac7ddfbfSEd Maste   size_t data_len = array_len * sizeof(int64_t);
624ac7ddfbfSEd Maste 
625ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
626ac7ddfbfSEd Maste 
627ac7ddfbfSEd Maste   if (!m_opaque_sp.get())
628435933ddSDimitry Andric     m_opaque_sp.reset(
629435933ddSDimitry Andric         new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
630ac7ddfbfSEd Maste   else
631ac7ddfbfSEd Maste     m_opaque_sp->SetData(buffer_sp);
632ac7ddfbfSEd Maste 
633ac7ddfbfSEd Maste   if (log)
634435933ddSDimitry Andric     log->Printf("SBData::SetDataFromSInt64Array (array=%p, array_len = %" PRIu64
635435933ddSDimitry Andric                 ") => "
636435933ddSDimitry Andric                 "true",
637435933ddSDimitry Andric                 static_cast<void *>(array), static_cast<uint64_t>(array_len));
638ac7ddfbfSEd Maste 
639ac7ddfbfSEd Maste   return true;
640ac7ddfbfSEd Maste }
641ac7ddfbfSEd Maste 
SetDataFromSInt32Array(int32_t * array,size_t array_len)642435933ddSDimitry Andric bool SBData::SetDataFromSInt32Array(int32_t *array, size_t array_len) {
643ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
644ac7ddfbfSEd Maste 
645435933ddSDimitry Andric   if (!array || array_len == 0) {
646ac7ddfbfSEd Maste     if (log)
647435933ddSDimitry Andric       log->Printf(
648435933ddSDimitry Andric           "SBData::SetDataFromSInt32Array (array=%p, array_len = %" PRIu64
649435933ddSDimitry Andric           ") => "
650435933ddSDimitry Andric           "false",
651435933ddSDimitry Andric           static_cast<void *>(array), static_cast<uint64_t>(array_len));
652ac7ddfbfSEd Maste     return false;
653ac7ddfbfSEd Maste   }
654ac7ddfbfSEd Maste 
655ac7ddfbfSEd Maste   size_t data_len = array_len * sizeof(int32_t);
656ac7ddfbfSEd Maste 
657ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
658ac7ddfbfSEd Maste 
659ac7ddfbfSEd Maste   if (!m_opaque_sp.get())
660435933ddSDimitry Andric     m_opaque_sp.reset(
661435933ddSDimitry Andric         new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
662ac7ddfbfSEd Maste   else
663ac7ddfbfSEd Maste     m_opaque_sp->SetData(buffer_sp);
664ac7ddfbfSEd Maste 
665ac7ddfbfSEd Maste   if (log)
666435933ddSDimitry Andric     log->Printf("SBData::SetDataFromSInt32Array (array=%p, array_len = %" PRIu64
667435933ddSDimitry Andric                 ") => "
668435933ddSDimitry Andric                 "true",
669435933ddSDimitry Andric                 static_cast<void *>(array), static_cast<uint64_t>(array_len));
670ac7ddfbfSEd Maste 
671ac7ddfbfSEd Maste   return true;
672ac7ddfbfSEd Maste }
673ac7ddfbfSEd Maste 
SetDataFromDoubleArray(double * array,size_t array_len)674435933ddSDimitry Andric bool SBData::SetDataFromDoubleArray(double *array, size_t array_len) {
675ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
676ac7ddfbfSEd Maste 
677435933ddSDimitry Andric   if (!array || array_len == 0) {
678ac7ddfbfSEd Maste     if (log)
679435933ddSDimitry Andric       log->Printf(
680435933ddSDimitry Andric           "SBData::SetDataFromDoubleArray (array=%p, array_len = %" PRIu64
681435933ddSDimitry Andric           ") => "
682435933ddSDimitry Andric           "false",
683435933ddSDimitry Andric           static_cast<void *>(array), static_cast<uint64_t>(array_len));
684ac7ddfbfSEd Maste     return false;
685ac7ddfbfSEd Maste   }
686ac7ddfbfSEd Maste 
687ac7ddfbfSEd Maste   size_t data_len = array_len * sizeof(double);
688ac7ddfbfSEd Maste 
689ac7ddfbfSEd Maste   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
690ac7ddfbfSEd Maste 
691ac7ddfbfSEd Maste   if (!m_opaque_sp.get())
692435933ddSDimitry Andric     m_opaque_sp.reset(
693435933ddSDimitry Andric         new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
694ac7ddfbfSEd Maste   else
695ac7ddfbfSEd Maste     m_opaque_sp->SetData(buffer_sp);
696ac7ddfbfSEd Maste 
697ac7ddfbfSEd Maste   if (log)
698435933ddSDimitry Andric     log->Printf("SBData::SetDataFromDoubleArray (array=%p, array_len = %" PRIu64
699435933ddSDimitry Andric                 ") => "
700435933ddSDimitry Andric                 "true",
701435933ddSDimitry Andric                 static_cast<void *>(array), static_cast<uint64_t>(array_len));
702ac7ddfbfSEd Maste 
703ac7ddfbfSEd Maste   return true;
704ac7ddfbfSEd Maste }
705