1 //===-- SBValue.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/SBValue.h" 10 #include "lldb/Utility/Instrumentation.h" 11 12 #include "lldb/API/SBDeclaration.h" 13 #include "lldb/API/SBStream.h" 14 #include "lldb/API/SBTypeFilter.h" 15 #include "lldb/API/SBTypeFormat.h" 16 #include "lldb/API/SBTypeSummary.h" 17 #include "lldb/API/SBTypeSynthetic.h" 18 19 #include "lldb/Breakpoint/Watchpoint.h" 20 #include "lldb/Core/Declaration.h" 21 #include "lldb/Core/Module.h" 22 #include "lldb/Core/Section.h" 23 #include "lldb/Core/StreamFile.h" 24 #include "lldb/Core/Value.h" 25 #include "lldb/Core/ValueObject.h" 26 #include "lldb/Core/ValueObjectConstResult.h" 27 #include "lldb/DataFormatters/DataVisualization.h" 28 #include "lldb/Symbol/Block.h" 29 #include "lldb/Symbol/ObjectFile.h" 30 #include "lldb/Symbol/Type.h" 31 #include "lldb/Symbol/Variable.h" 32 #include "lldb/Symbol/VariableList.h" 33 #include "lldb/Target/ExecutionContext.h" 34 #include "lldb/Target/Process.h" 35 #include "lldb/Target/StackFrame.h" 36 #include "lldb/Target/Target.h" 37 #include "lldb/Target/Thread.h" 38 #include "lldb/Utility/DataExtractor.h" 39 #include "lldb/Utility/Scalar.h" 40 #include "lldb/Utility/Stream.h" 41 42 #include "lldb/API/SBDebugger.h" 43 #include "lldb/API/SBExpressionOptions.h" 44 #include "lldb/API/SBFrame.h" 45 #include "lldb/API/SBProcess.h" 46 #include "lldb/API/SBTarget.h" 47 #include "lldb/API/SBThread.h" 48 49 #include <memory> 50 51 using namespace lldb; 52 using namespace lldb_private; 53 54 class ValueImpl { 55 public: 56 ValueImpl() = default; 57 58 ValueImpl(lldb::ValueObjectSP in_valobj_sp, 59 lldb::DynamicValueType use_dynamic, bool use_synthetic, 60 const char *name = nullptr) 61 : m_use_dynamic(use_dynamic), m_use_synthetic(use_synthetic), 62 m_name(name) { 63 if (in_valobj_sp) { 64 if ((m_valobj_sp = in_valobj_sp->GetQualifiedRepresentationIfAvailable( 65 lldb::eNoDynamicValues, false))) { 66 if (!m_name.IsEmpty()) 67 m_valobj_sp->SetName(m_name); 68 } 69 } 70 } 71 72 ValueImpl(const ValueImpl &rhs) 73 : m_valobj_sp(rhs.m_valobj_sp), m_use_dynamic(rhs.m_use_dynamic), 74 m_use_synthetic(rhs.m_use_synthetic), m_name(rhs.m_name) {} 75 76 ValueImpl &operator=(const ValueImpl &rhs) { 77 if (this != &rhs) { 78 m_valobj_sp = rhs.m_valobj_sp; 79 m_use_dynamic = rhs.m_use_dynamic; 80 m_use_synthetic = rhs.m_use_synthetic; 81 m_name = rhs.m_name; 82 } 83 return *this; 84 } 85 86 bool IsValid() { 87 if (m_valobj_sp.get() == nullptr) 88 return false; 89 else { 90 // FIXME: This check is necessary but not sufficient. We for sure don't 91 // want to touch SBValues whose owning 92 // targets have gone away. This check is a little weak in that it 93 // enforces that restriction when you call IsValid, but since IsValid 94 // doesn't lock the target, you have no guarantee that the SBValue won't 95 // go invalid after you call this... Also, an SBValue could depend on 96 // data from one of the modules in the target, and those could go away 97 // independently of the target, for instance if a module is unloaded. 98 // But right now, neither SBValues nor ValueObjects know which modules 99 // they depend on. So I have no good way to make that check without 100 // tracking that in all the ValueObject subclasses. 101 TargetSP target_sp = m_valobj_sp->GetTargetSP(); 102 return target_sp && target_sp->IsValid(); 103 } 104 } 105 106 lldb::ValueObjectSP GetRootSP() { return m_valobj_sp; } 107 108 lldb::ValueObjectSP GetSP(Process::StopLocker &stop_locker, 109 std::unique_lock<std::recursive_mutex> &lock, 110 Status &error) { 111 if (!m_valobj_sp) { 112 error.SetErrorString("invalid value object"); 113 return m_valobj_sp; 114 } 115 116 lldb::ValueObjectSP value_sp = m_valobj_sp; 117 118 Target *target = value_sp->GetTargetSP().get(); 119 if (!target) 120 return ValueObjectSP(); 121 122 lock = std::unique_lock<std::recursive_mutex>(target->GetAPIMutex()); 123 124 ProcessSP process_sp(value_sp->GetProcessSP()); 125 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock())) { 126 // We don't allow people to play around with ValueObject if the process 127 // is running. If you want to look at values, pause the process, then 128 // look. 129 error.SetErrorString("process must be stopped."); 130 return ValueObjectSP(); 131 } 132 133 if (m_use_dynamic != eNoDynamicValues) { 134 ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(m_use_dynamic); 135 if (dynamic_sp) 136 value_sp = dynamic_sp; 137 } 138 139 if (m_use_synthetic) { 140 ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue(); 141 if (synthetic_sp) 142 value_sp = synthetic_sp; 143 } 144 145 if (!value_sp) 146 error.SetErrorString("invalid value object"); 147 if (!m_name.IsEmpty()) 148 value_sp->SetName(m_name); 149 150 return value_sp; 151 } 152 153 void SetUseDynamic(lldb::DynamicValueType use_dynamic) { 154 m_use_dynamic = use_dynamic; 155 } 156 157 void SetUseSynthetic(bool use_synthetic) { m_use_synthetic = use_synthetic; } 158 159 lldb::DynamicValueType GetUseDynamic() { return m_use_dynamic; } 160 161 bool GetUseSynthetic() { return m_use_synthetic; } 162 163 // All the derived values that we would make from the m_valobj_sp will share 164 // the ExecutionContext with m_valobj_sp, so we don't need to do the 165 // calculations in GetSP to return the Target, Process, Thread or Frame. It 166 // is convenient to provide simple accessors for these, which I do here. 167 TargetSP GetTargetSP() { 168 if (m_valobj_sp) 169 return m_valobj_sp->GetTargetSP(); 170 else 171 return TargetSP(); 172 } 173 174 ProcessSP GetProcessSP() { 175 if (m_valobj_sp) 176 return m_valobj_sp->GetProcessSP(); 177 else 178 return ProcessSP(); 179 } 180 181 ThreadSP GetThreadSP() { 182 if (m_valobj_sp) 183 return m_valobj_sp->GetThreadSP(); 184 else 185 return ThreadSP(); 186 } 187 188 StackFrameSP GetFrameSP() { 189 if (m_valobj_sp) 190 return m_valobj_sp->GetFrameSP(); 191 else 192 return StackFrameSP(); 193 } 194 195 private: 196 lldb::ValueObjectSP m_valobj_sp; 197 lldb::DynamicValueType m_use_dynamic; 198 bool m_use_synthetic; 199 ConstString m_name; 200 }; 201 202 class ValueLocker { 203 public: 204 ValueLocker() = default; 205 206 ValueObjectSP GetLockedSP(ValueImpl &in_value) { 207 return in_value.GetSP(m_stop_locker, m_lock, m_lock_error); 208 } 209 210 Status &GetError() { return m_lock_error; } 211 212 private: 213 Process::StopLocker m_stop_locker; 214 std::unique_lock<std::recursive_mutex> m_lock; 215 Status m_lock_error; 216 }; 217 218 SBValue::SBValue() { LLDB_INSTRUMENT_VA(this); } 219 220 SBValue::SBValue(const lldb::ValueObjectSP &value_sp) { 221 LLDB_INSTRUMENT_VA(this, value_sp); 222 223 SetSP(value_sp); 224 } 225 226 SBValue::SBValue(const SBValue &rhs) { 227 LLDB_INSTRUMENT_VA(this, rhs); 228 229 SetSP(rhs.m_opaque_sp); 230 } 231 232 SBValue &SBValue::operator=(const SBValue &rhs) { 233 LLDB_INSTRUMENT_VA(this, rhs); 234 235 if (this != &rhs) { 236 SetSP(rhs.m_opaque_sp); 237 } 238 return *this; 239 } 240 241 SBValue::~SBValue() = default; 242 243 bool SBValue::IsValid() { 244 LLDB_INSTRUMENT_VA(this); 245 return this->operator bool(); 246 } 247 SBValue::operator bool() const { 248 LLDB_INSTRUMENT_VA(this); 249 250 // If this function ever changes to anything that does more than just check 251 // if the opaque shared pointer is non NULL, then we need to update all "if 252 // (m_opaque_sp)" code in this file. 253 return m_opaque_sp.get() != nullptr && m_opaque_sp->IsValid() && 254 m_opaque_sp->GetRootSP().get() != nullptr; 255 } 256 257 void SBValue::Clear() { 258 LLDB_INSTRUMENT_VA(this); 259 260 m_opaque_sp.reset(); 261 } 262 263 SBError SBValue::GetError() { 264 LLDB_INSTRUMENT_VA(this); 265 266 SBError sb_error; 267 268 ValueLocker locker; 269 lldb::ValueObjectSP value_sp(GetSP(locker)); 270 if (value_sp) 271 sb_error.SetError(value_sp->GetError()); 272 else 273 sb_error.SetErrorStringWithFormat("error: %s", 274 locker.GetError().AsCString()); 275 276 return sb_error; 277 } 278 279 user_id_t SBValue::GetID() { 280 LLDB_INSTRUMENT_VA(this); 281 282 ValueLocker locker; 283 lldb::ValueObjectSP value_sp(GetSP(locker)); 284 if (value_sp) 285 return value_sp->GetID(); 286 return LLDB_INVALID_UID; 287 } 288 289 const char *SBValue::GetName() { 290 LLDB_INSTRUMENT_VA(this); 291 292 const char *name = nullptr; 293 ValueLocker locker; 294 lldb::ValueObjectSP value_sp(GetSP(locker)); 295 if (value_sp) 296 name = value_sp->GetName().GetCString(); 297 298 return name; 299 } 300 301 const char *SBValue::GetTypeName() { 302 LLDB_INSTRUMENT_VA(this); 303 304 const char *name = nullptr; 305 ValueLocker locker; 306 lldb::ValueObjectSP value_sp(GetSP(locker)); 307 if (value_sp) { 308 name = value_sp->GetQualifiedTypeName().GetCString(); 309 } 310 311 return name; 312 } 313 314 const char *SBValue::GetDisplayTypeName() { 315 LLDB_INSTRUMENT_VA(this); 316 317 const char *name = nullptr; 318 ValueLocker locker; 319 lldb::ValueObjectSP value_sp(GetSP(locker)); 320 if (value_sp) { 321 name = value_sp->GetDisplayTypeName().GetCString(); 322 } 323 324 return name; 325 } 326 327 size_t SBValue::GetByteSize() { 328 LLDB_INSTRUMENT_VA(this); 329 330 size_t result = 0; 331 332 ValueLocker locker; 333 lldb::ValueObjectSP value_sp(GetSP(locker)); 334 if (value_sp) { 335 result = value_sp->GetByteSize().getValueOr(0); 336 } 337 338 return result; 339 } 340 341 bool SBValue::IsInScope() { 342 LLDB_INSTRUMENT_VA(this); 343 344 bool result = false; 345 346 ValueLocker locker; 347 lldb::ValueObjectSP value_sp(GetSP(locker)); 348 if (value_sp) { 349 result = value_sp->IsInScope(); 350 } 351 352 return result; 353 } 354 355 const char *SBValue::GetValue() { 356 LLDB_INSTRUMENT_VA(this); 357 358 const char *cstr = nullptr; 359 ValueLocker locker; 360 lldb::ValueObjectSP value_sp(GetSP(locker)); 361 if (value_sp) { 362 cstr = value_sp->GetValueAsCString(); 363 } 364 365 return cstr; 366 } 367 368 ValueType SBValue::GetValueType() { 369 LLDB_INSTRUMENT_VA(this); 370 371 ValueType result = eValueTypeInvalid; 372 ValueLocker locker; 373 lldb::ValueObjectSP value_sp(GetSP(locker)); 374 if (value_sp) 375 result = value_sp->GetValueType(); 376 377 return result; 378 } 379 380 const char *SBValue::GetObjectDescription() { 381 LLDB_INSTRUMENT_VA(this); 382 383 const char *cstr = nullptr; 384 ValueLocker locker; 385 lldb::ValueObjectSP value_sp(GetSP(locker)); 386 if (value_sp) { 387 cstr = value_sp->GetObjectDescription(); 388 } 389 390 return cstr; 391 } 392 393 SBType SBValue::GetType() { 394 LLDB_INSTRUMENT_VA(this); 395 396 SBType sb_type; 397 ValueLocker locker; 398 lldb::ValueObjectSP value_sp(GetSP(locker)); 399 TypeImplSP type_sp; 400 if (value_sp) { 401 type_sp = std::make_shared<TypeImpl>(value_sp->GetTypeImpl()); 402 sb_type.SetSP(type_sp); 403 } 404 405 return sb_type; 406 } 407 408 bool SBValue::GetValueDidChange() { 409 LLDB_INSTRUMENT_VA(this); 410 411 bool result = false; 412 ValueLocker locker; 413 lldb::ValueObjectSP value_sp(GetSP(locker)); 414 if (value_sp) { 415 if (value_sp->UpdateValueIfNeeded(false)) 416 result = value_sp->GetValueDidChange(); 417 } 418 419 return result; 420 } 421 422 const char *SBValue::GetSummary() { 423 LLDB_INSTRUMENT_VA(this); 424 425 const char *cstr = nullptr; 426 ValueLocker locker; 427 lldb::ValueObjectSP value_sp(GetSP(locker)); 428 if (value_sp) { 429 cstr = value_sp->GetSummaryAsCString(); 430 } 431 432 return cstr; 433 } 434 435 const char *SBValue::GetSummary(lldb::SBStream &stream, 436 lldb::SBTypeSummaryOptions &options) { 437 LLDB_INSTRUMENT_VA(this, stream, options); 438 439 ValueLocker locker; 440 lldb::ValueObjectSP value_sp(GetSP(locker)); 441 if (value_sp) { 442 std::string buffer; 443 if (value_sp->GetSummaryAsCString(buffer, options.ref()) && !buffer.empty()) 444 stream.Printf("%s", buffer.c_str()); 445 } 446 const char *cstr = stream.GetData(); 447 return cstr; 448 } 449 450 const char *SBValue::GetLocation() { 451 LLDB_INSTRUMENT_VA(this); 452 453 const char *cstr = nullptr; 454 ValueLocker locker; 455 lldb::ValueObjectSP value_sp(GetSP(locker)); 456 if (value_sp) { 457 cstr = value_sp->GetLocationAsCString(); 458 } 459 return cstr; 460 } 461 462 // Deprecated - use the one that takes an lldb::SBError 463 bool SBValue::SetValueFromCString(const char *value_str) { 464 LLDB_INSTRUMENT_VA(this, value_str); 465 466 lldb::SBError dummy; 467 return SetValueFromCString(value_str, dummy); 468 } 469 470 bool SBValue::SetValueFromCString(const char *value_str, lldb::SBError &error) { 471 LLDB_INSTRUMENT_VA(this, value_str, error); 472 473 bool success = false; 474 ValueLocker locker; 475 lldb::ValueObjectSP value_sp(GetSP(locker)); 476 if (value_sp) { 477 success = value_sp->SetValueFromCString(value_str, error.ref()); 478 } else 479 error.SetErrorStringWithFormat("Could not get value: %s", 480 locker.GetError().AsCString()); 481 482 return success; 483 } 484 485 lldb::SBTypeFormat SBValue::GetTypeFormat() { 486 LLDB_INSTRUMENT_VA(this); 487 488 lldb::SBTypeFormat format; 489 ValueLocker locker; 490 lldb::ValueObjectSP value_sp(GetSP(locker)); 491 if (value_sp) { 492 if (value_sp->UpdateValueIfNeeded(true)) { 493 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat(); 494 if (format_sp) 495 format.SetSP(format_sp); 496 } 497 } 498 return format; 499 } 500 501 lldb::SBTypeSummary SBValue::GetTypeSummary() { 502 LLDB_INSTRUMENT_VA(this); 503 504 lldb::SBTypeSummary summary; 505 ValueLocker locker; 506 lldb::ValueObjectSP value_sp(GetSP(locker)); 507 if (value_sp) { 508 if (value_sp->UpdateValueIfNeeded(true)) { 509 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat(); 510 if (summary_sp) 511 summary.SetSP(summary_sp); 512 } 513 } 514 return summary; 515 } 516 517 lldb::SBTypeFilter SBValue::GetTypeFilter() { 518 LLDB_INSTRUMENT_VA(this); 519 520 lldb::SBTypeFilter filter; 521 ValueLocker locker; 522 lldb::ValueObjectSP value_sp(GetSP(locker)); 523 if (value_sp) { 524 if (value_sp->UpdateValueIfNeeded(true)) { 525 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren(); 526 527 if (synthetic_sp && !synthetic_sp->IsScripted()) { 528 TypeFilterImplSP filter_sp = 529 std::static_pointer_cast<TypeFilterImpl>(synthetic_sp); 530 filter.SetSP(filter_sp); 531 } 532 } 533 } 534 return filter; 535 } 536 537 lldb::SBTypeSynthetic SBValue::GetTypeSynthetic() { 538 LLDB_INSTRUMENT_VA(this); 539 540 lldb::SBTypeSynthetic synthetic; 541 ValueLocker locker; 542 lldb::ValueObjectSP value_sp(GetSP(locker)); 543 if (value_sp) { 544 if (value_sp->UpdateValueIfNeeded(true)) { 545 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren(); 546 547 if (children_sp && children_sp->IsScripted()) { 548 ScriptedSyntheticChildrenSP synth_sp = 549 std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp); 550 synthetic.SetSP(synth_sp); 551 } 552 } 553 } 554 return synthetic; 555 } 556 557 lldb::SBValue SBValue::CreateChildAtOffset(const char *name, uint32_t offset, 558 SBType type) { 559 LLDB_INSTRUMENT_VA(this, name, offset, type); 560 561 lldb::SBValue sb_value; 562 ValueLocker locker; 563 lldb::ValueObjectSP value_sp(GetSP(locker)); 564 lldb::ValueObjectSP new_value_sp; 565 if (value_sp) { 566 TypeImplSP type_sp(type.GetSP()); 567 if (type.IsValid()) { 568 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset( 569 offset, type_sp->GetCompilerType(false), true), 570 GetPreferDynamicValue(), GetPreferSyntheticValue(), name); 571 } 572 } 573 return sb_value; 574 } 575 576 lldb::SBValue SBValue::Cast(SBType type) { 577 LLDB_INSTRUMENT_VA(this, type); 578 579 lldb::SBValue sb_value; 580 ValueLocker locker; 581 lldb::ValueObjectSP value_sp(GetSP(locker)); 582 TypeImplSP type_sp(type.GetSP()); 583 if (value_sp && type_sp) 584 sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType(false)), 585 GetPreferDynamicValue(), GetPreferSyntheticValue()); 586 return sb_value; 587 } 588 589 lldb::SBValue SBValue::CreateValueFromExpression(const char *name, 590 const char *expression) { 591 LLDB_INSTRUMENT_VA(this, name, expression); 592 593 SBExpressionOptions options; 594 options.ref().SetKeepInMemory(true); 595 return CreateValueFromExpression(name, expression, options); 596 } 597 598 lldb::SBValue SBValue::CreateValueFromExpression(const char *name, 599 const char *expression, 600 SBExpressionOptions &options) { 601 LLDB_INSTRUMENT_VA(this, name, expression, options); 602 603 lldb::SBValue sb_value; 604 ValueLocker locker; 605 lldb::ValueObjectSP value_sp(GetSP(locker)); 606 lldb::ValueObjectSP new_value_sp; 607 if (value_sp) { 608 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef()); 609 new_value_sp = ValueObject::CreateValueObjectFromExpression( 610 name, expression, exe_ctx, options.ref()); 611 if (new_value_sp) 612 new_value_sp->SetName(ConstString(name)); 613 } 614 sb_value.SetSP(new_value_sp); 615 return sb_value; 616 } 617 618 lldb::SBValue SBValue::CreateValueFromAddress(const char *name, 619 lldb::addr_t address, 620 SBType sb_type) { 621 LLDB_INSTRUMENT_VA(this, name, address, sb_type); 622 623 lldb::SBValue sb_value; 624 ValueLocker locker; 625 lldb::ValueObjectSP value_sp(GetSP(locker)); 626 lldb::ValueObjectSP new_value_sp; 627 lldb::TypeImplSP type_impl_sp(sb_type.GetSP()); 628 if (value_sp && type_impl_sp) { 629 CompilerType ast_type(type_impl_sp->GetCompilerType(true)); 630 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef()); 631 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, 632 exe_ctx, ast_type); 633 } 634 sb_value.SetSP(new_value_sp); 635 return sb_value; 636 } 637 638 lldb::SBValue SBValue::CreateValueFromData(const char *name, SBData data, 639 SBType sb_type) { 640 LLDB_INSTRUMENT_VA(this, name, data, sb_type); 641 642 lldb::SBValue sb_value; 643 lldb::ValueObjectSP new_value_sp; 644 ValueLocker locker; 645 lldb::ValueObjectSP value_sp(GetSP(locker)); 646 lldb::TypeImplSP type_impl_sp(sb_type.GetSP()); 647 if (value_sp && type_impl_sp) { 648 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef()); 649 new_value_sp = ValueObject::CreateValueObjectFromData( 650 name, **data, exe_ctx, type_impl_sp->GetCompilerType(true)); 651 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); 652 } 653 sb_value.SetSP(new_value_sp); 654 return sb_value; 655 } 656 657 SBValue SBValue::GetChildAtIndex(uint32_t idx) { 658 LLDB_INSTRUMENT_VA(this, idx); 659 660 const bool can_create_synthetic = false; 661 lldb::DynamicValueType use_dynamic = eNoDynamicValues; 662 TargetSP target_sp; 663 if (m_opaque_sp) 664 target_sp = m_opaque_sp->GetTargetSP(); 665 666 if (target_sp) 667 use_dynamic = target_sp->GetPreferDynamicValue(); 668 669 return GetChildAtIndex(idx, use_dynamic, can_create_synthetic); 670 } 671 672 SBValue SBValue::GetChildAtIndex(uint32_t idx, 673 lldb::DynamicValueType use_dynamic, 674 bool can_create_synthetic) { 675 LLDB_INSTRUMENT_VA(this, idx, use_dynamic, can_create_synthetic); 676 677 lldb::ValueObjectSP child_sp; 678 679 ValueLocker locker; 680 lldb::ValueObjectSP value_sp(GetSP(locker)); 681 if (value_sp) { 682 const bool can_create = true; 683 child_sp = value_sp->GetChildAtIndex(idx, can_create); 684 if (can_create_synthetic && !child_sp) { 685 child_sp = value_sp->GetSyntheticArrayMember(idx, can_create); 686 } 687 } 688 689 SBValue sb_value; 690 sb_value.SetSP(child_sp, use_dynamic, GetPreferSyntheticValue()); 691 692 return sb_value; 693 } 694 695 uint32_t SBValue::GetIndexOfChildWithName(const char *name) { 696 LLDB_INSTRUMENT_VA(this, name); 697 698 uint32_t idx = UINT32_MAX; 699 ValueLocker locker; 700 lldb::ValueObjectSP value_sp(GetSP(locker)); 701 if (value_sp) { 702 idx = value_sp->GetIndexOfChildWithName(ConstString(name)); 703 } 704 return idx; 705 } 706 707 SBValue SBValue::GetChildMemberWithName(const char *name) { 708 LLDB_INSTRUMENT_VA(this, name); 709 710 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues; 711 TargetSP target_sp; 712 if (m_opaque_sp) 713 target_sp = m_opaque_sp->GetTargetSP(); 714 715 if (target_sp) 716 use_dynamic_value = target_sp->GetPreferDynamicValue(); 717 return GetChildMemberWithName(name, use_dynamic_value); 718 } 719 720 SBValue 721 SBValue::GetChildMemberWithName(const char *name, 722 lldb::DynamicValueType use_dynamic_value) { 723 LLDB_INSTRUMENT_VA(this, name, use_dynamic_value); 724 725 lldb::ValueObjectSP child_sp; 726 const ConstString str_name(name); 727 728 ValueLocker locker; 729 lldb::ValueObjectSP value_sp(GetSP(locker)); 730 if (value_sp) { 731 child_sp = value_sp->GetChildMemberWithName(str_name, true); 732 } 733 734 SBValue sb_value; 735 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue()); 736 737 return sb_value; 738 } 739 740 lldb::SBValue SBValue::GetDynamicValue(lldb::DynamicValueType use_dynamic) { 741 LLDB_INSTRUMENT_VA(this, use_dynamic); 742 743 SBValue value_sb; 744 if (IsValid()) { 745 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), use_dynamic, 746 m_opaque_sp->GetUseSynthetic())); 747 value_sb.SetSP(proxy_sp); 748 } 749 return value_sb; 750 } 751 752 lldb::SBValue SBValue::GetStaticValue() { 753 LLDB_INSTRUMENT_VA(this); 754 755 SBValue value_sb; 756 if (IsValid()) { 757 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), 758 eNoDynamicValues, 759 m_opaque_sp->GetUseSynthetic())); 760 value_sb.SetSP(proxy_sp); 761 } 762 return value_sb; 763 } 764 765 lldb::SBValue SBValue::GetNonSyntheticValue() { 766 LLDB_INSTRUMENT_VA(this); 767 768 SBValue value_sb; 769 if (IsValid()) { 770 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), 771 m_opaque_sp->GetUseDynamic(), false)); 772 value_sb.SetSP(proxy_sp); 773 } 774 return value_sb; 775 } 776 777 lldb::DynamicValueType SBValue::GetPreferDynamicValue() { 778 LLDB_INSTRUMENT_VA(this); 779 780 if (!IsValid()) 781 return eNoDynamicValues; 782 return m_opaque_sp->GetUseDynamic(); 783 } 784 785 void SBValue::SetPreferDynamicValue(lldb::DynamicValueType use_dynamic) { 786 LLDB_INSTRUMENT_VA(this, use_dynamic); 787 788 if (IsValid()) 789 return m_opaque_sp->SetUseDynamic(use_dynamic); 790 } 791 792 bool SBValue::GetPreferSyntheticValue() { 793 LLDB_INSTRUMENT_VA(this); 794 795 if (!IsValid()) 796 return false; 797 return m_opaque_sp->GetUseSynthetic(); 798 } 799 800 void SBValue::SetPreferSyntheticValue(bool use_synthetic) { 801 LLDB_INSTRUMENT_VA(this, use_synthetic); 802 803 if (IsValid()) 804 return m_opaque_sp->SetUseSynthetic(use_synthetic); 805 } 806 807 bool SBValue::IsDynamic() { 808 LLDB_INSTRUMENT_VA(this); 809 810 ValueLocker locker; 811 lldb::ValueObjectSP value_sp(GetSP(locker)); 812 if (value_sp) 813 return value_sp->IsDynamic(); 814 return false; 815 } 816 817 bool SBValue::IsSynthetic() { 818 LLDB_INSTRUMENT_VA(this); 819 820 ValueLocker locker; 821 lldb::ValueObjectSP value_sp(GetSP(locker)); 822 if (value_sp) 823 return value_sp->IsSynthetic(); 824 return false; 825 } 826 827 bool SBValue::IsSyntheticChildrenGenerated() { 828 LLDB_INSTRUMENT_VA(this); 829 830 ValueLocker locker; 831 lldb::ValueObjectSP value_sp(GetSP(locker)); 832 if (value_sp) 833 return value_sp->IsSyntheticChildrenGenerated(); 834 return false; 835 } 836 837 void SBValue::SetSyntheticChildrenGenerated(bool is) { 838 LLDB_INSTRUMENT_VA(this, is); 839 840 ValueLocker locker; 841 lldb::ValueObjectSP value_sp(GetSP(locker)); 842 if (value_sp) 843 return value_sp->SetSyntheticChildrenGenerated(is); 844 } 845 846 lldb::SBValue SBValue::GetValueForExpressionPath(const char *expr_path) { 847 LLDB_INSTRUMENT_VA(this, expr_path); 848 849 lldb::ValueObjectSP child_sp; 850 ValueLocker locker; 851 lldb::ValueObjectSP value_sp(GetSP(locker)); 852 if (value_sp) { 853 // using default values for all the fancy options, just do it if you can 854 child_sp = value_sp->GetValueForExpressionPath(expr_path); 855 } 856 857 SBValue sb_value; 858 sb_value.SetSP(child_sp, GetPreferDynamicValue(), GetPreferSyntheticValue()); 859 860 return sb_value; 861 } 862 863 int64_t SBValue::GetValueAsSigned(SBError &error, int64_t fail_value) { 864 LLDB_INSTRUMENT_VA(this, error, fail_value); 865 866 error.Clear(); 867 ValueLocker locker; 868 lldb::ValueObjectSP value_sp(GetSP(locker)); 869 if (value_sp) { 870 bool success = true; 871 uint64_t ret_val = fail_value; 872 ret_val = value_sp->GetValueAsSigned(fail_value, &success); 873 if (!success) 874 error.SetErrorString("could not resolve value"); 875 return ret_val; 876 } else 877 error.SetErrorStringWithFormat("could not get SBValue: %s", 878 locker.GetError().AsCString()); 879 880 return fail_value; 881 } 882 883 uint64_t SBValue::GetValueAsUnsigned(SBError &error, uint64_t fail_value) { 884 LLDB_INSTRUMENT_VA(this, error, fail_value); 885 886 error.Clear(); 887 ValueLocker locker; 888 lldb::ValueObjectSP value_sp(GetSP(locker)); 889 if (value_sp) { 890 bool success = true; 891 uint64_t ret_val = fail_value; 892 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success); 893 if (!success) 894 error.SetErrorString("could not resolve value"); 895 return ret_val; 896 } else 897 error.SetErrorStringWithFormat("could not get SBValue: %s", 898 locker.GetError().AsCString()); 899 900 return fail_value; 901 } 902 903 int64_t SBValue::GetValueAsSigned(int64_t fail_value) { 904 LLDB_INSTRUMENT_VA(this, fail_value); 905 906 ValueLocker locker; 907 lldb::ValueObjectSP value_sp(GetSP(locker)); 908 if (value_sp) { 909 return value_sp->GetValueAsSigned(fail_value); 910 } 911 return fail_value; 912 } 913 914 uint64_t SBValue::GetValueAsUnsigned(uint64_t fail_value) { 915 LLDB_INSTRUMENT_VA(this, fail_value); 916 917 ValueLocker locker; 918 lldb::ValueObjectSP value_sp(GetSP(locker)); 919 if (value_sp) { 920 return value_sp->GetValueAsUnsigned(fail_value); 921 } 922 return fail_value; 923 } 924 925 bool SBValue::MightHaveChildren() { 926 LLDB_INSTRUMENT_VA(this); 927 928 bool has_children = false; 929 ValueLocker locker; 930 lldb::ValueObjectSP value_sp(GetSP(locker)); 931 if (value_sp) 932 has_children = value_sp->MightHaveChildren(); 933 934 return has_children; 935 } 936 937 bool SBValue::IsRuntimeSupportValue() { 938 LLDB_INSTRUMENT_VA(this); 939 940 bool is_support = false; 941 ValueLocker locker; 942 lldb::ValueObjectSP value_sp(GetSP(locker)); 943 if (value_sp) 944 is_support = value_sp->IsRuntimeSupportValue(); 945 946 return is_support; 947 } 948 949 uint32_t SBValue::GetNumChildren() { 950 LLDB_INSTRUMENT_VA(this); 951 952 return GetNumChildren(UINT32_MAX); 953 } 954 955 uint32_t SBValue::GetNumChildren(uint32_t max) { 956 LLDB_INSTRUMENT_VA(this, max); 957 958 uint32_t num_children = 0; 959 960 ValueLocker locker; 961 lldb::ValueObjectSP value_sp(GetSP(locker)); 962 if (value_sp) 963 num_children = value_sp->GetNumChildren(max); 964 965 return num_children; 966 } 967 968 SBValue SBValue::Dereference() { 969 LLDB_INSTRUMENT_VA(this); 970 971 SBValue sb_value; 972 ValueLocker locker; 973 lldb::ValueObjectSP value_sp(GetSP(locker)); 974 if (value_sp) { 975 Status error; 976 sb_value = value_sp->Dereference(error); 977 } 978 979 return sb_value; 980 } 981 982 // Deprecated - please use GetType().IsPointerType() instead. 983 bool SBValue::TypeIsPointerType() { 984 LLDB_INSTRUMENT_VA(this); 985 986 return GetType().IsPointerType(); 987 } 988 989 void *SBValue::GetOpaqueType() { 990 LLDB_INSTRUMENT_VA(this); 991 992 ValueLocker locker; 993 lldb::ValueObjectSP value_sp(GetSP(locker)); 994 if (value_sp) 995 return value_sp->GetCompilerType().GetOpaqueQualType(); 996 return nullptr; 997 } 998 999 lldb::SBTarget SBValue::GetTarget() { 1000 LLDB_INSTRUMENT_VA(this); 1001 1002 SBTarget sb_target; 1003 TargetSP target_sp; 1004 if (m_opaque_sp) { 1005 target_sp = m_opaque_sp->GetTargetSP(); 1006 sb_target.SetSP(target_sp); 1007 } 1008 1009 return sb_target; 1010 } 1011 1012 lldb::SBProcess SBValue::GetProcess() { 1013 LLDB_INSTRUMENT_VA(this); 1014 1015 SBProcess sb_process; 1016 ProcessSP process_sp; 1017 if (m_opaque_sp) { 1018 process_sp = m_opaque_sp->GetProcessSP(); 1019 sb_process.SetSP(process_sp); 1020 } 1021 1022 return sb_process; 1023 } 1024 1025 lldb::SBThread SBValue::GetThread() { 1026 LLDB_INSTRUMENT_VA(this); 1027 1028 SBThread sb_thread; 1029 ThreadSP thread_sp; 1030 if (m_opaque_sp) { 1031 thread_sp = m_opaque_sp->GetThreadSP(); 1032 sb_thread.SetThread(thread_sp); 1033 } 1034 1035 return sb_thread; 1036 } 1037 1038 lldb::SBFrame SBValue::GetFrame() { 1039 LLDB_INSTRUMENT_VA(this); 1040 1041 SBFrame sb_frame; 1042 StackFrameSP frame_sp; 1043 if (m_opaque_sp) { 1044 frame_sp = m_opaque_sp->GetFrameSP(); 1045 sb_frame.SetFrameSP(frame_sp); 1046 } 1047 1048 return sb_frame; 1049 } 1050 1051 lldb::ValueObjectSP SBValue::GetSP(ValueLocker &locker) const { 1052 if (!m_opaque_sp || !m_opaque_sp->IsValid()) { 1053 locker.GetError().SetErrorString("No value"); 1054 return ValueObjectSP(); 1055 } 1056 return locker.GetLockedSP(*m_opaque_sp.get()); 1057 } 1058 1059 lldb::ValueObjectSP SBValue::GetSP() const { 1060 LLDB_INSTRUMENT_VA(this); 1061 1062 ValueLocker locker; 1063 return GetSP(locker); 1064 } 1065 1066 void SBValue::SetSP(ValueImplSP impl_sp) { m_opaque_sp = impl_sp; } 1067 1068 void SBValue::SetSP(const lldb::ValueObjectSP &sp) { 1069 if (sp) { 1070 lldb::TargetSP target_sp(sp->GetTargetSP()); 1071 if (target_sp) { 1072 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue(); 1073 bool use_synthetic = 1074 target_sp->TargetProperties::GetEnableSyntheticValue(); 1075 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic)); 1076 } else 1077 m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, true)); 1078 } else 1079 m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, false)); 1080 } 1081 1082 void SBValue::SetSP(const lldb::ValueObjectSP &sp, 1083 lldb::DynamicValueType use_dynamic) { 1084 if (sp) { 1085 lldb::TargetSP target_sp(sp->GetTargetSP()); 1086 if (target_sp) { 1087 bool use_synthetic = 1088 target_sp->TargetProperties::GetEnableSyntheticValue(); 1089 SetSP(sp, use_dynamic, use_synthetic); 1090 } else 1091 SetSP(sp, use_dynamic, true); 1092 } else 1093 SetSP(sp, use_dynamic, false); 1094 } 1095 1096 void SBValue::SetSP(const lldb::ValueObjectSP &sp, bool use_synthetic) { 1097 if (sp) { 1098 lldb::TargetSP target_sp(sp->GetTargetSP()); 1099 if (target_sp) { 1100 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue(); 1101 SetSP(sp, use_dynamic, use_synthetic); 1102 } else 1103 SetSP(sp, eNoDynamicValues, use_synthetic); 1104 } else 1105 SetSP(sp, eNoDynamicValues, use_synthetic); 1106 } 1107 1108 void SBValue::SetSP(const lldb::ValueObjectSP &sp, 1109 lldb::DynamicValueType use_dynamic, bool use_synthetic) { 1110 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic)); 1111 } 1112 1113 void SBValue::SetSP(const lldb::ValueObjectSP &sp, 1114 lldb::DynamicValueType use_dynamic, bool use_synthetic, 1115 const char *name) { 1116 m_opaque_sp = 1117 ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic, name)); 1118 } 1119 1120 bool SBValue::GetExpressionPath(SBStream &description) { 1121 LLDB_INSTRUMENT_VA(this, description); 1122 1123 ValueLocker locker; 1124 lldb::ValueObjectSP value_sp(GetSP(locker)); 1125 if (value_sp) { 1126 value_sp->GetExpressionPath(description.ref()); 1127 return true; 1128 } 1129 return false; 1130 } 1131 1132 bool SBValue::GetExpressionPath(SBStream &description, 1133 bool qualify_cxx_base_classes) { 1134 LLDB_INSTRUMENT_VA(this, description, qualify_cxx_base_classes); 1135 1136 ValueLocker locker; 1137 lldb::ValueObjectSP value_sp(GetSP(locker)); 1138 if (value_sp) { 1139 value_sp->GetExpressionPath(description.ref()); 1140 return true; 1141 } 1142 return false; 1143 } 1144 1145 lldb::SBValue SBValue::EvaluateExpression(const char *expr) const { 1146 LLDB_INSTRUMENT_VA(this, expr); 1147 1148 ValueLocker locker; 1149 lldb::ValueObjectSP value_sp(GetSP(locker)); 1150 if (!value_sp) 1151 return SBValue(); 1152 1153 lldb::TargetSP target_sp = value_sp->GetTargetSP(); 1154 if (!target_sp) 1155 return SBValue(); 1156 1157 lldb::SBExpressionOptions options; 1158 options.SetFetchDynamicValue(target_sp->GetPreferDynamicValue()); 1159 options.SetUnwindOnError(true); 1160 options.SetIgnoreBreakpoints(true); 1161 1162 return EvaluateExpression(expr, options, nullptr); 1163 } 1164 1165 lldb::SBValue 1166 SBValue::EvaluateExpression(const char *expr, 1167 const SBExpressionOptions &options) const { 1168 LLDB_INSTRUMENT_VA(this, expr, options); 1169 1170 return EvaluateExpression(expr, options, nullptr); 1171 } 1172 1173 lldb::SBValue SBValue::EvaluateExpression(const char *expr, 1174 const SBExpressionOptions &options, 1175 const char *name) const { 1176 LLDB_INSTRUMENT_VA(this, expr, options, name); 1177 1178 if (!expr || expr[0] == '\0') { 1179 return SBValue(); 1180 } 1181 1182 1183 ValueLocker locker; 1184 lldb::ValueObjectSP value_sp(GetSP(locker)); 1185 if (!value_sp) { 1186 return SBValue(); 1187 } 1188 1189 lldb::TargetSP target_sp = value_sp->GetTargetSP(); 1190 if (!target_sp) { 1191 return SBValue(); 1192 } 1193 1194 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1195 ExecutionContext exe_ctx(target_sp.get()); 1196 1197 StackFrame *frame = exe_ctx.GetFramePtr(); 1198 if (!frame) { 1199 return SBValue(); 1200 } 1201 1202 ValueObjectSP res_val_sp; 1203 target_sp->EvaluateExpression(expr, frame, res_val_sp, options.ref(), nullptr, 1204 value_sp.get()); 1205 1206 if (name) 1207 res_val_sp->SetName(ConstString(name)); 1208 1209 SBValue result; 1210 result.SetSP(res_val_sp, options.GetFetchDynamicValue()); 1211 return result; 1212 } 1213 1214 bool SBValue::GetDescription(SBStream &description) { 1215 LLDB_INSTRUMENT_VA(this, description); 1216 1217 Stream &strm = description.ref(); 1218 1219 ValueLocker locker; 1220 lldb::ValueObjectSP value_sp(GetSP(locker)); 1221 if (value_sp) 1222 value_sp->Dump(strm); 1223 else 1224 strm.PutCString("No value"); 1225 1226 return true; 1227 } 1228 1229 lldb::Format SBValue::GetFormat() { 1230 LLDB_INSTRUMENT_VA(this); 1231 1232 ValueLocker locker; 1233 lldb::ValueObjectSP value_sp(GetSP(locker)); 1234 if (value_sp) 1235 return value_sp->GetFormat(); 1236 return eFormatDefault; 1237 } 1238 1239 void SBValue::SetFormat(lldb::Format format) { 1240 LLDB_INSTRUMENT_VA(this, format); 1241 1242 ValueLocker locker; 1243 lldb::ValueObjectSP value_sp(GetSP(locker)); 1244 if (value_sp) 1245 value_sp->SetFormat(format); 1246 } 1247 1248 lldb::SBValue SBValue::AddressOf() { 1249 LLDB_INSTRUMENT_VA(this); 1250 1251 SBValue sb_value; 1252 ValueLocker locker; 1253 lldb::ValueObjectSP value_sp(GetSP(locker)); 1254 if (value_sp) { 1255 Status error; 1256 sb_value.SetSP(value_sp->AddressOf(error), GetPreferDynamicValue(), 1257 GetPreferSyntheticValue()); 1258 } 1259 1260 return sb_value; 1261 } 1262 1263 lldb::addr_t SBValue::GetLoadAddress() { 1264 LLDB_INSTRUMENT_VA(this); 1265 1266 lldb::addr_t value = LLDB_INVALID_ADDRESS; 1267 ValueLocker locker; 1268 lldb::ValueObjectSP value_sp(GetSP(locker)); 1269 if (value_sp) { 1270 TargetSP target_sp(value_sp->GetTargetSP()); 1271 if (target_sp) { 1272 const bool scalar_is_load_address = true; 1273 AddressType addr_type; 1274 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); 1275 if (addr_type == eAddressTypeFile) { 1276 ModuleSP module_sp(value_sp->GetModule()); 1277 if (!module_sp) 1278 value = LLDB_INVALID_ADDRESS; 1279 else { 1280 Address addr; 1281 module_sp->ResolveFileAddress(value, addr); 1282 value = addr.GetLoadAddress(target_sp.get()); 1283 } 1284 } else if (addr_type == eAddressTypeHost || 1285 addr_type == eAddressTypeInvalid) 1286 value = LLDB_INVALID_ADDRESS; 1287 } 1288 } 1289 1290 return value; 1291 } 1292 1293 lldb::SBAddress SBValue::GetAddress() { 1294 LLDB_INSTRUMENT_VA(this); 1295 1296 Address addr; 1297 ValueLocker locker; 1298 lldb::ValueObjectSP value_sp(GetSP(locker)); 1299 if (value_sp) { 1300 TargetSP target_sp(value_sp->GetTargetSP()); 1301 if (target_sp) { 1302 lldb::addr_t value = LLDB_INVALID_ADDRESS; 1303 const bool scalar_is_load_address = true; 1304 AddressType addr_type; 1305 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); 1306 if (addr_type == eAddressTypeFile) { 1307 ModuleSP module_sp(value_sp->GetModule()); 1308 if (module_sp) 1309 module_sp->ResolveFileAddress(value, addr); 1310 } else if (addr_type == eAddressTypeLoad) { 1311 // no need to check the return value on this.. if it can actually do 1312 // the resolve addr will be in the form (section,offset), otherwise it 1313 // will simply be returned as (NULL, value) 1314 addr.SetLoadAddress(value, target_sp.get()); 1315 } 1316 } 1317 } 1318 1319 return SBAddress(addr); 1320 } 1321 1322 lldb::SBData SBValue::GetPointeeData(uint32_t item_idx, uint32_t item_count) { 1323 LLDB_INSTRUMENT_VA(this, item_idx, item_count); 1324 1325 lldb::SBData sb_data; 1326 ValueLocker locker; 1327 lldb::ValueObjectSP value_sp(GetSP(locker)); 1328 if (value_sp) { 1329 TargetSP target_sp(value_sp->GetTargetSP()); 1330 if (target_sp) { 1331 DataExtractorSP data_sp(new DataExtractor()); 1332 value_sp->GetPointeeData(*data_sp, item_idx, item_count); 1333 if (data_sp->GetByteSize() > 0) 1334 *sb_data = data_sp; 1335 } 1336 } 1337 1338 return sb_data; 1339 } 1340 1341 lldb::SBData SBValue::GetData() { 1342 LLDB_INSTRUMENT_VA(this); 1343 1344 lldb::SBData sb_data; 1345 ValueLocker locker; 1346 lldb::ValueObjectSP value_sp(GetSP(locker)); 1347 if (value_sp) { 1348 DataExtractorSP data_sp(new DataExtractor()); 1349 Status error; 1350 value_sp->GetData(*data_sp, error); 1351 if (error.Success()) 1352 *sb_data = data_sp; 1353 } 1354 1355 return sb_data; 1356 } 1357 1358 bool SBValue::SetData(lldb::SBData &data, SBError &error) { 1359 LLDB_INSTRUMENT_VA(this, data, error); 1360 1361 ValueLocker locker; 1362 lldb::ValueObjectSP value_sp(GetSP(locker)); 1363 bool ret = true; 1364 1365 if (value_sp) { 1366 DataExtractor *data_extractor = data.get(); 1367 1368 if (!data_extractor) { 1369 error.SetErrorString("No data to set"); 1370 ret = false; 1371 } else { 1372 Status set_error; 1373 1374 value_sp->SetData(*data_extractor, set_error); 1375 1376 if (!set_error.Success()) { 1377 error.SetErrorStringWithFormat("Couldn't set data: %s", 1378 set_error.AsCString()); 1379 ret = false; 1380 } 1381 } 1382 } else { 1383 error.SetErrorStringWithFormat( 1384 "Couldn't set data: could not get SBValue: %s", 1385 locker.GetError().AsCString()); 1386 ret = false; 1387 } 1388 1389 return ret; 1390 } 1391 1392 lldb::SBValue SBValue::Clone(const char *new_name) { 1393 LLDB_INSTRUMENT_VA(this, new_name); 1394 1395 ValueLocker locker; 1396 lldb::ValueObjectSP value_sp(GetSP(locker)); 1397 1398 if (value_sp) 1399 return lldb::SBValue(value_sp->Clone(ConstString(new_name))); 1400 else 1401 return lldb::SBValue(); 1402 } 1403 1404 lldb::SBDeclaration SBValue::GetDeclaration() { 1405 LLDB_INSTRUMENT_VA(this); 1406 1407 ValueLocker locker; 1408 lldb::ValueObjectSP value_sp(GetSP(locker)); 1409 SBDeclaration decl_sb; 1410 if (value_sp) { 1411 Declaration decl; 1412 if (value_sp->GetDeclaration(decl)) 1413 decl_sb.SetDeclaration(decl); 1414 } 1415 return decl_sb; 1416 } 1417 1418 lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read, bool write, 1419 SBError &error) { 1420 LLDB_INSTRUMENT_VA(this, resolve_location, read, write, error); 1421 1422 SBWatchpoint sb_watchpoint; 1423 1424 // If the SBValue is not valid, there's no point in even trying to watch it. 1425 ValueLocker locker; 1426 lldb::ValueObjectSP value_sp(GetSP(locker)); 1427 TargetSP target_sp(GetTarget().GetSP()); 1428 if (value_sp && target_sp) { 1429 // Read and Write cannot both be false. 1430 if (!read && !write) 1431 return sb_watchpoint; 1432 1433 // If the value is not in scope, don't try and watch and invalid value 1434 if (!IsInScope()) 1435 return sb_watchpoint; 1436 1437 addr_t addr = GetLoadAddress(); 1438 if (addr == LLDB_INVALID_ADDRESS) 1439 return sb_watchpoint; 1440 size_t byte_size = GetByteSize(); 1441 if (byte_size == 0) 1442 return sb_watchpoint; 1443 1444 uint32_t watch_type = 0; 1445 if (read) 1446 watch_type |= LLDB_WATCH_TYPE_READ; 1447 if (write) 1448 watch_type |= LLDB_WATCH_TYPE_WRITE; 1449 1450 Status rc; 1451 CompilerType type(value_sp->GetCompilerType()); 1452 WatchpointSP watchpoint_sp = 1453 target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc); 1454 error.SetError(rc); 1455 1456 if (watchpoint_sp) { 1457 sb_watchpoint.SetSP(watchpoint_sp); 1458 Declaration decl; 1459 if (value_sp->GetDeclaration(decl)) { 1460 if (decl.GetFile()) { 1461 StreamString ss; 1462 // True to show fullpath for declaration file. 1463 decl.DumpStopContext(&ss, true); 1464 watchpoint_sp->SetDeclInfo(std::string(ss.GetString())); 1465 } 1466 } 1467 } 1468 } else if (target_sp) { 1469 error.SetErrorStringWithFormat("could not get SBValue: %s", 1470 locker.GetError().AsCString()); 1471 } else { 1472 error.SetErrorString("could not set watchpoint, a target is required"); 1473 } 1474 1475 return sb_watchpoint; 1476 } 1477 1478 // FIXME: Remove this method impl (as well as the decl in .h) once it is no 1479 // longer needed. 1480 // Backward compatibility fix in the interim. 1481 lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read, 1482 bool write) { 1483 LLDB_INSTRUMENT_VA(this, resolve_location, read, write); 1484 1485 SBError error; 1486 return Watch(resolve_location, read, write, error); 1487 } 1488 1489 lldb::SBWatchpoint SBValue::WatchPointee(bool resolve_location, bool read, 1490 bool write, SBError &error) { 1491 LLDB_INSTRUMENT_VA(this, resolve_location, read, write, error); 1492 1493 SBWatchpoint sb_watchpoint; 1494 if (IsInScope() && GetType().IsPointerType()) 1495 sb_watchpoint = Dereference().Watch(resolve_location, read, write, error); 1496 return sb_watchpoint; 1497 } 1498 1499 lldb::SBValue SBValue::Persist() { 1500 LLDB_INSTRUMENT_VA(this); 1501 1502 ValueLocker locker; 1503 lldb::ValueObjectSP value_sp(GetSP(locker)); 1504 SBValue persisted_sb; 1505 if (value_sp) { 1506 persisted_sb.SetSP(value_sp->Persist()); 1507 } 1508 return persisted_sb; 1509 } 1510