1 //===-- SBData.cpp ----------------------------------------------*- 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 #include "lldb/API/SBData.h"
11 #include "lldb/API/SBError.h"
12 #include "lldb/API/SBStream.h"
13 
14 #include "lldb/Core/DataBufferHeap.h"
15 #include "lldb/Core/DataExtractor.h"
16 #include "lldb/Core/Log.h"
17 #include "lldb/Core/Stream.h"
18 
19 
20 using namespace lldb;
21 using namespace lldb_private;
22 
SBData()23 SBData::SBData () :
24     m_opaque_sp(new DataExtractor())
25 {
26 }
27 
SBData(const lldb::DataExtractorSP & data_sp)28 SBData::SBData (const lldb::DataExtractorSP& data_sp) :
29     m_opaque_sp (data_sp)
30 {
31 }
32 
SBData(const SBData & rhs)33 SBData::SBData(const SBData &rhs) :
34     m_opaque_sp (rhs.m_opaque_sp)
35 {
36 }
37 
38 const SBData &
operator =(const SBData & rhs)39 SBData::operator = (const SBData &rhs)
40 {
41     if (this != &rhs)
42         m_opaque_sp = rhs.m_opaque_sp;
43     return *this;
44 }
45 
~SBData()46 SBData::~SBData ()
47 {
48 }
49 
50 void
SetOpaque(const lldb::DataExtractorSP & data_sp)51 SBData::SetOpaque (const lldb::DataExtractorSP &data_sp)
52 {
53     m_opaque_sp = data_sp;
54 }
55 
56 lldb_private::DataExtractor *
get() const57 SBData::get() const
58 {
59     return m_opaque_sp.get();
60 }
61 
62 lldb_private::DataExtractor *
operator ->() const63 SBData::operator->() const
64 {
65     return m_opaque_sp.operator->();
66 }
67 
68 lldb::DataExtractorSP &
operator *()69 SBData::operator*()
70 {
71     return m_opaque_sp;
72 }
73 
74 const lldb::DataExtractorSP &
operator *() const75 SBData::operator*() const
76 {
77     return m_opaque_sp;
78 }
79 
80 bool
IsValid()81 SBData::IsValid()
82 {
83     return m_opaque_sp.get() != NULL;
84 }
85 
86 uint8_t
GetAddressByteSize()87 SBData::GetAddressByteSize ()
88 {
89     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
90     uint8_t value = 0;
91     if (m_opaque_sp.get())
92         value = m_opaque_sp->GetAddressByteSize();
93     if (log)
94         log->Printf ("SBData::GetAddressByteSize () => "
95                      "(%i)", value);
96     return value;
97 }
98 
99 void
SetAddressByteSize(uint8_t addr_byte_size)100 SBData::SetAddressByteSize (uint8_t addr_byte_size)
101 {
102     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
103     if (m_opaque_sp.get())
104         m_opaque_sp->SetAddressByteSize(addr_byte_size);
105     if (log)
106         log->Printf ("SBData::SetAddressByteSize (%i)", addr_byte_size);
107 }
108 
109 void
Clear()110 SBData::Clear ()
111 {
112     if (m_opaque_sp.get())
113         m_opaque_sp->Clear();
114 }
115 
116 size_t
GetByteSize()117 SBData::GetByteSize ()
118 {
119     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
120     size_t value = 0;
121     if (m_opaque_sp.get())
122         value = m_opaque_sp->GetByteSize();
123     if (log)
124         log->Printf ("SBData::GetByteSize () => "
125                      "(%lu)", value);
126     return value;
127 }
128 
129 lldb::ByteOrder
GetByteOrder()130 SBData::GetByteOrder ()
131 {
132     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
133     lldb::ByteOrder value = eByteOrderInvalid;
134     if (m_opaque_sp.get())
135         value = m_opaque_sp->GetByteOrder();
136     if (log)
137         log->Printf ("SBData::GetByteOrder () => "
138                      "(%i)", value);
139     return value;
140 }
141 
142 void
SetByteOrder(lldb::ByteOrder endian)143 SBData::SetByteOrder (lldb::ByteOrder endian)
144 {
145     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
146     if (m_opaque_sp.get())
147         m_opaque_sp->SetByteOrder(endian);
148     if (log)
149         log->Printf ("SBData::GetByteOrder (%i)", endian);
150 }
151 
152 
153 float
GetFloat(lldb::SBError & error,lldb::offset_t offset)154 SBData::GetFloat (lldb::SBError& error, lldb::offset_t offset)
155 {
156     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
157     float value = 0;
158     if (!m_opaque_sp.get())
159     {
160         error.SetErrorString("no value to read from");
161     }
162     else
163     {
164         uint32_t old_offset = offset;
165         value = m_opaque_sp->GetFloat(&offset);
166         if (offset == old_offset)
167             error.SetErrorString("unable to read data");
168     }
169     if (log)
170         log->Printf ("SBData::GetFloat (error=%p,offset=%" PRIu64 ") => "
171                      "(%f)", error.get(), offset, value);
172     return value;
173 }
174 
175 double
GetDouble(lldb::SBError & error,lldb::offset_t offset)176 SBData::GetDouble (lldb::SBError& error, lldb::offset_t offset)
177 {
178     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
179     double value = 0;
180     if (!m_opaque_sp.get())
181     {
182         error.SetErrorString("no value to read from");
183     }
184     else
185     {
186         uint32_t old_offset = offset;
187         value = m_opaque_sp->GetDouble(&offset);
188         if (offset == old_offset)
189             error.SetErrorString("unable to read data");
190     }
191     if (log)
192         log->Printf ("SBData::GetDouble (error=%p,offset=%" PRIu64 ") => "
193                      "(%f)", error.get(), offset, value);
194     return value;
195 }
196 
197 long double
GetLongDouble(lldb::SBError & error,lldb::offset_t offset)198 SBData::GetLongDouble (lldb::SBError& error, lldb::offset_t offset)
199 {
200     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
201     long double value = 0;
202     if (!m_opaque_sp.get())
203     {
204         error.SetErrorString("no value to read from");
205     }
206     else
207     {
208         uint32_t old_offset = offset;
209         value = m_opaque_sp->GetLongDouble(&offset);
210         if (offset == old_offset)
211             error.SetErrorString("unable to read data");
212     }
213     if (log)
214         log->Printf ("SBData::GetLongDouble (error=%p,offset=%" PRIu64 ") => "
215                      "(%Lf)", error.get(), offset, value);
216     return value;
217 }
218 
219 lldb::addr_t
GetAddress(lldb::SBError & error,lldb::offset_t offset)220 SBData::GetAddress (lldb::SBError& error, lldb::offset_t offset)
221 {
222     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
223     lldb::addr_t value = 0;
224     if (!m_opaque_sp.get())
225     {
226         error.SetErrorString("no value to read from");
227     }
228     else
229     {
230         uint32_t old_offset = offset;
231         value = m_opaque_sp->GetAddress(&offset);
232         if (offset == old_offset)
233             error.SetErrorString("unable to read data");
234     }
235     if (log)
236         log->Printf ("SBData::GetAddress (error=%p,offset=%" PRIu64 ") => "
237                      "(%p)", error.get(), offset, (void*)value);
238     return value;
239 }
240 
241 uint8_t
GetUnsignedInt8(lldb::SBError & error,lldb::offset_t offset)242 SBData::GetUnsignedInt8 (lldb::SBError& error, lldb::offset_t offset)
243 {
244     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
245     uint8_t value = 0;
246     if (!m_opaque_sp.get())
247     {
248         error.SetErrorString("no value to read from");
249     }
250     else
251     {
252         uint32_t old_offset = offset;
253         value = m_opaque_sp->GetU8(&offset);
254         if (offset == old_offset)
255             error.SetErrorString("unable to read data");
256     }
257     if (log)
258         log->Printf ("SBData::GetUnsignedInt8 (error=%p,offset=%" PRIu64 ") => "
259                      "(%c)", error.get(), offset, value);
260     return value;
261 }
262 
263 uint16_t
GetUnsignedInt16(lldb::SBError & error,lldb::offset_t offset)264 SBData::GetUnsignedInt16 (lldb::SBError& error, lldb::offset_t offset)
265 {
266     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
267     uint16_t value = 0;
268     if (!m_opaque_sp.get())
269     {
270         error.SetErrorString("no value to read from");
271     }
272     else
273     {
274         uint32_t old_offset = offset;
275         value = m_opaque_sp->GetU16(&offset);
276         if (offset == old_offset)
277             error.SetErrorString("unable to read data");
278     }
279     if (log)
280         log->Printf ("SBData::GetUnsignedInt16 (error=%p,offset=%" PRIu64 ") => "
281                      "(%hd)", error.get(), offset, value);
282     return value;
283 }
284 
285 uint32_t
GetUnsignedInt32(lldb::SBError & error,lldb::offset_t offset)286 SBData::GetUnsignedInt32 (lldb::SBError& error, lldb::offset_t offset)
287 {
288     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
289     uint32_t value = 0;
290     if (!m_opaque_sp.get())
291     {
292         error.SetErrorString("no value to read from");
293     }
294     else
295     {
296         uint32_t old_offset = offset;
297         value = m_opaque_sp->GetU32(&offset);
298         if (offset == old_offset)
299             error.SetErrorString("unable to read data");
300     }
301     if (log)
302         log->Printf ("SBData::GetUnsignedInt32 (error=%p,offset=%" PRIu64 ") => "
303                      "(%d)", error.get(), offset, value);
304     return value;
305 }
306 
307 uint64_t
GetUnsignedInt64(lldb::SBError & error,lldb::offset_t offset)308 SBData::GetUnsignedInt64 (lldb::SBError& error, lldb::offset_t offset)
309 {
310     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
311     uint64_t value = 0;
312     if (!m_opaque_sp.get())
313     {
314         error.SetErrorString("no value to read from");
315     }
316     else
317     {
318         uint32_t old_offset = offset;
319         value = m_opaque_sp->GetU64(&offset);
320         if (offset == old_offset)
321             error.SetErrorString("unable to read data");
322     }
323     if (log)
324         log->Printf ("SBData::GetUnsignedInt64 (error=%p,offset=%" PRIu64 ") => "
325                      "(%" PRId64 ")", error.get(), offset, value);
326     return value;
327 }
328 
329 int8_t
GetSignedInt8(lldb::SBError & error,lldb::offset_t offset)330 SBData::GetSignedInt8 (lldb::SBError& error, lldb::offset_t offset)
331 {
332     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
333     int8_t value = 0;
334     if (!m_opaque_sp.get())
335     {
336         error.SetErrorString("no value to read from");
337     }
338     else
339     {
340         uint32_t old_offset = offset;
341         value = (int8_t)m_opaque_sp->GetMaxS64(&offset, 1);
342         if (offset == old_offset)
343             error.SetErrorString("unable to read data");
344     }
345     if (log)
346         log->Printf ("SBData::GetSignedInt8 (error=%p,offset=%" PRIu64 ") => "
347                      "(%c)", error.get(), offset, value);
348     return value;
349 }
350 
351 int16_t
GetSignedInt16(lldb::SBError & error,lldb::offset_t offset)352 SBData::GetSignedInt16 (lldb::SBError& error, lldb::offset_t offset)
353 {
354     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
355     int16_t value = 0;
356     if (!m_opaque_sp.get())
357     {
358         error.SetErrorString("no value to read from");
359     }
360     else
361     {
362         uint32_t old_offset = offset;
363         value = (int16_t)m_opaque_sp->GetMaxS64(&offset, 2);
364         if (offset == old_offset)
365             error.SetErrorString("unable to read data");
366     }
367     if (log)
368         log->Printf ("SBData::GetSignedInt16 (error=%p,offset=%" PRIu64 ") => "
369                      "(%hd)", error.get(), offset, value);
370     return value;
371 }
372 
373 int32_t
GetSignedInt32(lldb::SBError & error,lldb::offset_t offset)374 SBData::GetSignedInt32 (lldb::SBError& error, lldb::offset_t offset)
375 {
376     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
377     int32_t value = 0;
378     if (!m_opaque_sp.get())
379     {
380         error.SetErrorString("no value to read from");
381     }
382     else
383     {
384         uint32_t old_offset = offset;
385         value = (int32_t)m_opaque_sp->GetMaxS64(&offset, 4);
386         if (offset == old_offset)
387             error.SetErrorString("unable to read data");
388     }
389     if (log)
390         log->Printf ("SBData::GetSignedInt32 (error=%p,offset=%" PRIu64 ") => "
391                      "(%d)", error.get(), offset, value);
392     return value;
393 }
394 
395 int64_t
GetSignedInt64(lldb::SBError & error,lldb::offset_t offset)396 SBData::GetSignedInt64 (lldb::SBError& error, lldb::offset_t offset)
397 {
398     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
399     int64_t value = 0;
400     if (!m_opaque_sp.get())
401     {
402         error.SetErrorString("no value to read from");
403     }
404     else
405     {
406         uint32_t old_offset = offset;
407         value = (int64_t)m_opaque_sp->GetMaxS64(&offset, 8);
408         if (offset == old_offset)
409             error.SetErrorString("unable to read data");
410     }
411     if (log)
412         log->Printf ("SBData::GetSignedInt64 (error=%p,offset=%" PRIu64 ") => "
413                      "(%" PRId64 ")", error.get(), offset, value);
414     return value;
415 }
416 
417 const char*
GetString(lldb::SBError & error,lldb::offset_t offset)418 SBData::GetString (lldb::SBError& error, lldb::offset_t offset)
419 {
420     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
421     const char* value = 0;
422     if (!m_opaque_sp.get())
423     {
424         error.SetErrorString("no value to read from");
425     }
426     else
427     {
428         uint32_t old_offset = offset;
429         value = m_opaque_sp->GetCStr(&offset);
430         if (offset == old_offset || (value == NULL))
431             error.SetErrorString("unable to read data");
432     }
433     if (log)
434         log->Printf ("SBData::GetString (error=%p,offset=%" PRIu64 ") => "
435                      "(%p)", error.get(), offset, value);
436     return value;
437 }
438 
439 bool
GetDescription(lldb::SBStream & description,lldb::addr_t base_addr)440 SBData::GetDescription (lldb::SBStream &description, lldb::addr_t base_addr)
441 {
442     Stream &strm = description.ref();
443 
444     if (m_opaque_sp)
445     {
446         m_opaque_sp->Dump (&strm,
447                            0,
448                            lldb::eFormatBytesWithASCII,
449                            1,
450                            m_opaque_sp->GetByteSize(),
451                            16,
452                            base_addr,
453                            0,
454                            0);
455     }
456     else
457         strm.PutCString ("No value");
458 
459     return true;
460 }
461 
462 size_t
ReadRawData(lldb::SBError & error,lldb::offset_t offset,void * buf,size_t size)463 SBData::ReadRawData (lldb::SBError& error,
464                      lldb::offset_t offset,
465                      void *buf,
466                      size_t size)
467 {
468     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
469     void* ok = NULL;
470     if (!m_opaque_sp.get())
471     {
472         error.SetErrorString("no value to read from");
473     }
474     else
475     {
476         uint32_t old_offset = offset;
477         ok = m_opaque_sp->GetU8(&offset, buf, size);
478         if ((offset == old_offset) || (ok == NULL))
479             error.SetErrorString("unable to read data");
480     }
481     if (log)
482         log->Printf ("SBData::ReadRawData (error=%p,offset=%" PRIu64 ",buf=%p,size=%lu) => "
483                      "(%p)", error.get(), offset, buf, size, ok);
484     return ok ? size : 0;
485 }
486 
487 void
SetData(lldb::SBError & error,const void * buf,size_t size,lldb::ByteOrder endian,uint8_t addr_size)488 SBData::SetData (lldb::SBError& error,
489                  const void *buf,
490                  size_t size,
491                  lldb::ByteOrder endian,
492                  uint8_t addr_size)
493 {
494     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
495     if (!m_opaque_sp.get())
496         m_opaque_sp.reset(new DataExtractor(buf, size, endian, addr_size));
497     else
498         m_opaque_sp->SetData(buf, size, endian);
499     if (log)
500         log->Printf ("SBData::SetData (error=%p,buf=%p,size=%lu,endian=%d,addr_size=%c) => "
501                      "(%p)", error.get(), buf, size, endian, addr_size, m_opaque_sp.get());
502 }
503 
504 bool
Append(const SBData & rhs)505 SBData::Append (const SBData& rhs)
506 {
507     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
508     bool value = false;
509     if (m_opaque_sp.get() && rhs.m_opaque_sp.get())
510         value = m_opaque_sp.get()->Append(*rhs.m_opaque_sp);
511     if (log)
512         log->Printf ("SBData::Append (rhs=%p) => "
513                      "(%s)", rhs.get(), value ? "true" : "false");
514     return value;
515 }
516 
517 lldb::SBData
CreateDataFromCString(lldb::ByteOrder endian,uint32_t addr_byte_size,const char * data)518 SBData::CreateDataFromCString (lldb::ByteOrder endian, uint32_t addr_byte_size, const char* data)
519 {
520     if (!data || !data[0])
521         return SBData();
522 
523     uint32_t data_len = strlen(data);
524 
525     lldb::DataBufferSP buffer_sp(new DataBufferHeap(data, data_len));
526     lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
527 
528     SBData ret(data_sp);
529 
530     return ret;
531 }
532 
533 lldb::SBData
CreateDataFromUInt64Array(lldb::ByteOrder endian,uint32_t addr_byte_size,uint64_t * array,size_t array_len)534 SBData::CreateDataFromUInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint64_t* array, size_t array_len)
535 {
536     if (!array || array_len == 0)
537         return SBData();
538 
539     size_t data_len = array_len * sizeof(uint64_t);
540 
541     lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
542     lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
543 
544     SBData ret(data_sp);
545 
546     return ret;
547 }
548 
549 lldb::SBData
CreateDataFromUInt32Array(lldb::ByteOrder endian,uint32_t addr_byte_size,uint32_t * array,size_t array_len)550 SBData::CreateDataFromUInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint32_t* array, size_t array_len)
551 {
552     if (!array || array_len == 0)
553         return SBData();
554 
555     size_t data_len = array_len * sizeof(uint32_t);
556 
557     lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
558     lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
559 
560     SBData ret(data_sp);
561 
562     return ret;
563 }
564 
565 lldb::SBData
CreateDataFromSInt64Array(lldb::ByteOrder endian,uint32_t addr_byte_size,int64_t * array,size_t array_len)566 SBData::CreateDataFromSInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int64_t* array, size_t array_len)
567 {
568     if (!array || array_len == 0)
569         return SBData();
570 
571     size_t data_len = array_len * sizeof(int64_t);
572 
573     lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
574     lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
575 
576     SBData ret(data_sp);
577 
578     return ret;
579 }
580 
581 lldb::SBData
CreateDataFromSInt32Array(lldb::ByteOrder endian,uint32_t addr_byte_size,int32_t * array,size_t array_len)582 SBData::CreateDataFromSInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int32_t* array, size_t array_len)
583 {
584     if (!array || array_len == 0)
585         return SBData();
586 
587     size_t data_len = array_len * sizeof(int32_t);
588 
589     lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
590     lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
591 
592     SBData ret(data_sp);
593 
594     return ret;
595 }
596 
597 lldb::SBData
CreateDataFromDoubleArray(lldb::ByteOrder endian,uint32_t addr_byte_size,double * array,size_t array_len)598 SBData::CreateDataFromDoubleArray (lldb::ByteOrder endian, uint32_t addr_byte_size, double* array, size_t array_len)
599 {
600     if (!array || array_len == 0)
601         return SBData();
602 
603     size_t data_len = array_len * sizeof(double);
604 
605     lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
606     lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
607 
608     SBData ret(data_sp);
609 
610     return ret;
611 }
612 
613 bool
SetDataFromCString(const char * data)614 SBData::SetDataFromCString (const char* data)
615 {
616     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
617 
618     if (!data)
619     {
620         if (log)
621             log->Printf ("SBData::SetDataFromCString (data=%p) => "
622                          "false", data);
623         return false;
624     }
625 
626     size_t data_len = strlen(data);
627 
628     lldb::DataBufferSP buffer_sp(new DataBufferHeap(data, data_len));
629 
630     if (!m_opaque_sp.get())
631         m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
632     else
633         m_opaque_sp->SetData(buffer_sp);
634 
635     if (log)
636         log->Printf ("SBData::SetDataFromCString (data=%p) => "
637                      "true", data);
638 
639     return true;
640 }
641 
642 bool
SetDataFromUInt64Array(uint64_t * array,size_t array_len)643 SBData::SetDataFromUInt64Array (uint64_t* array, size_t array_len)
644 {
645     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
646 
647     if (!array || array_len == 0)
648     {
649         if (log)
650             log->Printf ("SBData::SetDataFromUInt64Array (array=%p, array_len = %lu) => "
651                          "false", array, array_len);
652         return false;
653     }
654 
655     size_t data_len = array_len * sizeof(uint64_t);
656 
657     lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
658 
659     if (!m_opaque_sp.get())
660         m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
661     else
662         m_opaque_sp->SetData(buffer_sp);
663 
664     if (log)
665         log->Printf ("SBData::SetDataFromUInt64Array (array=%p, array_len = %lu) => "
666                      "true", array, array_len);
667 
668     return true;
669 }
670 
671 bool
SetDataFromUInt32Array(uint32_t * array,size_t array_len)672 SBData::SetDataFromUInt32Array (uint32_t* array, size_t array_len)
673 {
674     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
675 
676     if (!array || array_len == 0)
677     {
678         if (log)
679             log->Printf ("SBData::SetDataFromUInt32Array (array=%p, array_len = %lu) => "
680                          "false", array, array_len);
681         return false;
682     }
683 
684     size_t data_len = array_len * sizeof(uint32_t);
685 
686     lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
687 
688     if (!m_opaque_sp.get())
689         m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
690     else
691         m_opaque_sp->SetData(buffer_sp);
692 
693     if (log)
694         log->Printf ("SBData::SetDataFromUInt32Array (array=%p, array_len = %lu) => "
695                      "true", array, array_len);
696 
697     return true;
698 }
699 
700 bool
SetDataFromSInt64Array(int64_t * array,size_t array_len)701 SBData::SetDataFromSInt64Array (int64_t* array, size_t array_len)
702 {
703     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
704 
705     if (!array || array_len == 0)
706     {
707         if (log)
708             log->Printf ("SBData::SetDataFromSInt64Array (array=%p, array_len = %lu) => "
709                          "false", array, array_len);
710         return false;
711     }
712 
713     size_t data_len = array_len * sizeof(int64_t);
714 
715     lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
716 
717     if (!m_opaque_sp.get())
718         m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
719     else
720         m_opaque_sp->SetData(buffer_sp);
721 
722     if (log)
723         log->Printf ("SBData::SetDataFromSInt64Array (array=%p, array_len = %lu) => "
724                      "true", array, array_len);
725 
726     return true;
727 }
728 
729 bool
SetDataFromSInt32Array(int32_t * array,size_t array_len)730 SBData::SetDataFromSInt32Array (int32_t* array, size_t array_len)
731 {
732     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
733 
734     if (!array || array_len == 0)
735     {
736         if (log)
737             log->Printf ("SBData::SetDataFromSInt32Array (array=%p, array_len = %lu) => "
738                          "false", array, array_len);
739         return false;
740     }
741 
742     size_t data_len = array_len * sizeof(int32_t);
743 
744     lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
745 
746     if (!m_opaque_sp.get())
747         m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
748     else
749         m_opaque_sp->SetData(buffer_sp);
750 
751     if (log)
752         log->Printf ("SBData::SetDataFromSInt32Array (array=%p, array_len = %lu) => "
753                      "true", array, array_len);
754 
755     return true;
756 }
757 
758 bool
SetDataFromDoubleArray(double * array,size_t array_len)759 SBData::SetDataFromDoubleArray (double* array, size_t array_len)
760 {
761     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
762 
763     if (!array || array_len == 0)
764     {
765         if (log)
766             log->Printf ("SBData::SetDataFromDoubleArray (array=%p, array_len = %lu) => "
767                          "false", array, array_len);
768         return false;
769     }
770 
771     size_t data_len = array_len * sizeof(double);
772 
773     lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
774 
775     if (!m_opaque_sp.get())
776         m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
777     else
778         m_opaque_sp->SetData(buffer_sp);
779 
780     if (log)
781         log->Printf ("SBData::SetDataFromDoubleArray (array=%p, array_len = %lu) => "
782                      "true", array, array_len);
783 
784     return true;
785 }
786