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