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