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