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