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/Utility/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 { 387 m_opaque_sp->SetData(buf, size, endian); 388 m_opaque_sp->SetAddressByteSize(addr_size); 389 } 390 391 if (log) 392 log->Printf("SBData::SetData (error=%p,buf=%p,size=%" PRIu64 393 ",endian=%d,addr_size=%c) => " 394 "(%p)", 395 static_cast<void *>(error.get()), 396 static_cast<const void *>(buf), static_cast<uint64_t>(size), 397 endian, addr_size, static_cast<void *>(m_opaque_sp.get())); 398 } 399 400 bool SBData::Append(const SBData &rhs) { 401 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 402 bool value = false; 403 if (m_opaque_sp.get() && rhs.m_opaque_sp.get()) 404 value = m_opaque_sp.get()->Append(*rhs.m_opaque_sp); 405 if (log) 406 log->Printf("SBData::Append (rhs=%p) => (%s)", 407 static_cast<void *>(rhs.get()), value ? "true" : "false"); 408 return value; 409 } 410 411 lldb::SBData SBData::CreateDataFromCString(lldb::ByteOrder endian, 412 uint32_t addr_byte_size, 413 const char *data) { 414 if (!data || !data[0]) 415 return SBData(); 416 417 uint32_t data_len = strlen(data); 418 419 lldb::DataBufferSP buffer_sp(new DataBufferHeap(data, data_len)); 420 lldb::DataExtractorSP data_sp( 421 new DataExtractor(buffer_sp, endian, addr_byte_size)); 422 423 SBData ret(data_sp); 424 425 return ret; 426 } 427 428 lldb::SBData SBData::CreateDataFromUInt64Array(lldb::ByteOrder endian, 429 uint32_t addr_byte_size, 430 uint64_t *array, 431 size_t array_len) { 432 if (!array || array_len == 0) 433 return SBData(); 434 435 size_t data_len = array_len * sizeof(uint64_t); 436 437 lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); 438 lldb::DataExtractorSP data_sp( 439 new DataExtractor(buffer_sp, endian, addr_byte_size)); 440 441 SBData ret(data_sp); 442 443 return ret; 444 } 445 446 lldb::SBData SBData::CreateDataFromUInt32Array(lldb::ByteOrder endian, 447 uint32_t addr_byte_size, 448 uint32_t *array, 449 size_t array_len) { 450 if (!array || array_len == 0) 451 return SBData(); 452 453 size_t data_len = array_len * sizeof(uint32_t); 454 455 lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); 456 lldb::DataExtractorSP data_sp( 457 new DataExtractor(buffer_sp, endian, addr_byte_size)); 458 459 SBData ret(data_sp); 460 461 return ret; 462 } 463 464 lldb::SBData SBData::CreateDataFromSInt64Array(lldb::ByteOrder endian, 465 uint32_t addr_byte_size, 466 int64_t *array, 467 size_t array_len) { 468 if (!array || array_len == 0) 469 return SBData(); 470 471 size_t data_len = array_len * sizeof(int64_t); 472 473 lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); 474 lldb::DataExtractorSP data_sp( 475 new DataExtractor(buffer_sp, endian, addr_byte_size)); 476 477 SBData ret(data_sp); 478 479 return ret; 480 } 481 482 lldb::SBData SBData::CreateDataFromSInt32Array(lldb::ByteOrder endian, 483 uint32_t addr_byte_size, 484 int32_t *array, 485 size_t array_len) { 486 if (!array || array_len == 0) 487 return SBData(); 488 489 size_t data_len = array_len * sizeof(int32_t); 490 491 lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); 492 lldb::DataExtractorSP data_sp( 493 new DataExtractor(buffer_sp, endian, addr_byte_size)); 494 495 SBData ret(data_sp); 496 497 return ret; 498 } 499 500 lldb::SBData SBData::CreateDataFromDoubleArray(lldb::ByteOrder endian, 501 uint32_t addr_byte_size, 502 double *array, 503 size_t array_len) { 504 if (!array || array_len == 0) 505 return SBData(); 506 507 size_t data_len = array_len * sizeof(double); 508 509 lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); 510 lldb::DataExtractorSP data_sp( 511 new DataExtractor(buffer_sp, endian, addr_byte_size)); 512 513 SBData ret(data_sp); 514 515 return ret; 516 } 517 518 bool SBData::SetDataFromCString(const char *data) { 519 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 520 521 if (!data) { 522 if (log) 523 log->Printf("SBData::SetDataFromCString (data=%p) => false", 524 static_cast<const void *>(data)); 525 return false; 526 } 527 528 size_t data_len = strlen(data); 529 530 lldb::DataBufferSP buffer_sp(new DataBufferHeap(data, data_len)); 531 532 if (!m_opaque_sp.get()) 533 m_opaque_sp.reset( 534 new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize())); 535 else 536 m_opaque_sp->SetData(buffer_sp); 537 538 if (log) 539 log->Printf("SBData::SetDataFromCString (data=%p) => true", 540 static_cast<const void *>(data)); 541 542 return true; 543 } 544 545 bool SBData::SetDataFromUInt64Array(uint64_t *array, size_t array_len) { 546 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 547 548 if (!array || array_len == 0) { 549 if (log) 550 log->Printf( 551 "SBData::SetDataFromUInt64Array (array=%p, array_len = %" PRIu64 552 ") => " 553 "false", 554 static_cast<void *>(array), static_cast<uint64_t>(array_len)); 555 return false; 556 } 557 558 size_t data_len = array_len * sizeof(uint64_t); 559 560 lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); 561 562 if (!m_opaque_sp.get()) 563 m_opaque_sp.reset( 564 new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize())); 565 else 566 m_opaque_sp->SetData(buffer_sp); 567 568 if (log) 569 log->Printf("SBData::SetDataFromUInt64Array (array=%p, array_len = %" PRIu64 570 ") => " 571 "true", 572 static_cast<void *>(array), static_cast<uint64_t>(array_len)); 573 574 return true; 575 } 576 577 bool SBData::SetDataFromUInt32Array(uint32_t *array, size_t array_len) { 578 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 579 580 if (!array || array_len == 0) { 581 if (log) 582 log->Printf( 583 "SBData::SetDataFromUInt32Array (array=%p, array_len = %" PRIu64 584 ") => " 585 "false", 586 static_cast<void *>(array), static_cast<uint64_t>(array_len)); 587 return false; 588 } 589 590 size_t data_len = array_len * sizeof(uint32_t); 591 592 lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); 593 594 if (!m_opaque_sp.get()) 595 m_opaque_sp.reset( 596 new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize())); 597 else 598 m_opaque_sp->SetData(buffer_sp); 599 600 if (log) 601 log->Printf("SBData::SetDataFromUInt32Array (array=%p, array_len = %" PRIu64 602 ") => " 603 "true", 604 static_cast<void *>(array), static_cast<uint64_t>(array_len)); 605 606 return true; 607 } 608 609 bool SBData::SetDataFromSInt64Array(int64_t *array, size_t array_len) { 610 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 611 612 if (!array || array_len == 0) { 613 if (log) 614 log->Printf( 615 "SBData::SetDataFromSInt64Array (array=%p, array_len = %" PRIu64 616 ") => " 617 "false", 618 static_cast<void *>(array), static_cast<uint64_t>(array_len)); 619 return false; 620 } 621 622 size_t data_len = array_len * sizeof(int64_t); 623 624 lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); 625 626 if (!m_opaque_sp.get()) 627 m_opaque_sp.reset( 628 new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize())); 629 else 630 m_opaque_sp->SetData(buffer_sp); 631 632 if (log) 633 log->Printf("SBData::SetDataFromSInt64Array (array=%p, array_len = %" PRIu64 634 ") => " 635 "true", 636 static_cast<void *>(array), static_cast<uint64_t>(array_len)); 637 638 return true; 639 } 640 641 bool SBData::SetDataFromSInt32Array(int32_t *array, size_t array_len) { 642 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 643 644 if (!array || array_len == 0) { 645 if (log) 646 log->Printf( 647 "SBData::SetDataFromSInt32Array (array=%p, array_len = %" PRIu64 648 ") => " 649 "false", 650 static_cast<void *>(array), static_cast<uint64_t>(array_len)); 651 return false; 652 } 653 654 size_t data_len = array_len * sizeof(int32_t); 655 656 lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); 657 658 if (!m_opaque_sp.get()) 659 m_opaque_sp.reset( 660 new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize())); 661 else 662 m_opaque_sp->SetData(buffer_sp); 663 664 if (log) 665 log->Printf("SBData::SetDataFromSInt32Array (array=%p, array_len = %" PRIu64 666 ") => " 667 "true", 668 static_cast<void *>(array), static_cast<uint64_t>(array_len)); 669 670 return true; 671 } 672 673 bool SBData::SetDataFromDoubleArray(double *array, size_t array_len) { 674 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 675 676 if (!array || array_len == 0) { 677 if (log) 678 log->Printf( 679 "SBData::SetDataFromDoubleArray (array=%p, array_len = %" PRIu64 680 ") => " 681 "false", 682 static_cast<void *>(array), static_cast<uint64_t>(array_len)); 683 return false; 684 } 685 686 size_t data_len = array_len * sizeof(double); 687 688 lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); 689 690 if (!m_opaque_sp.get()) 691 m_opaque_sp.reset( 692 new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize())); 693 else 694 m_opaque_sp->SetData(buffer_sp); 695 696 if (log) 697 log->Printf("SBData::SetDataFromDoubleArray (array=%p, array_len = %" PRIu64 698 ") => " 699 "true", 700 static_cast<void *>(array), static_cast<uint64_t>(array_len)); 701 702 return true; 703 } 704