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