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