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 if (value_sp->UpdateValueIfNeeded(false)) 612 result = value_sp->GetValueDidChange (); 613 } 614 if (log) 615 log->Printf ("SBValue(%p)::GetValueDidChange() => %i", 616 static_cast<void*>(value_sp.get()), result); 617 618 return result; 619 } 620 621 #ifndef LLDB_DISABLE_PYTHON 622 const char * 623 SBValue::GetSummary () 624 { 625 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 626 const char *cstr = NULL; 627 ValueLocker locker; 628 lldb::ValueObjectSP value_sp(GetSP(locker)); 629 if (value_sp) 630 { 631 cstr = value_sp->GetSummaryAsCString(); 632 } 633 if (log) 634 { 635 if (cstr) 636 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", 637 static_cast<void*>(value_sp.get()), cstr); 638 else 639 log->Printf ("SBValue(%p)::GetSummary() => NULL", 640 static_cast<void*>(value_sp.get())); 641 } 642 return cstr; 643 } 644 645 const char * 646 SBValue::GetSummary (lldb::SBStream& stream, 647 lldb::SBTypeSummaryOptions& options) 648 { 649 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 650 ValueLocker locker; 651 lldb::ValueObjectSP value_sp(GetSP(locker)); 652 if (value_sp) 653 { 654 std::string buffer; 655 if (value_sp->GetSummaryAsCString(buffer,options.ref()) && !buffer.empty()) 656 stream.Printf("%s",buffer.c_str()); 657 } 658 const char* cstr = stream.GetData(); 659 if (log) 660 { 661 if (cstr) 662 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", 663 static_cast<void*>(value_sp.get()), cstr); 664 else 665 log->Printf ("SBValue(%p)::GetSummary() => NULL", 666 static_cast<void*>(value_sp.get())); 667 } 668 return cstr; 669 } 670 #endif // LLDB_DISABLE_PYTHON 671 672 const char * 673 SBValue::GetLocation () 674 { 675 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 676 const char *cstr = NULL; 677 ValueLocker locker; 678 lldb::ValueObjectSP value_sp(GetSP(locker)); 679 if (value_sp) 680 { 681 cstr = value_sp->GetLocationAsCString(); 682 } 683 if (log) 684 { 685 if (cstr) 686 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"", 687 static_cast<void*>(value_sp.get()), cstr); 688 else 689 log->Printf ("SBValue(%p)::GetLocation() => NULL", 690 static_cast<void*>(value_sp.get())); 691 } 692 return cstr; 693 } 694 695 // Deprecated - use the one that takes an lldb::SBError 696 bool 697 SBValue::SetValueFromCString (const char *value_str) 698 { 699 lldb::SBError dummy; 700 return SetValueFromCString(value_str,dummy); 701 } 702 703 bool 704 SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error) 705 { 706 bool success = false; 707 ValueLocker locker; 708 lldb::ValueObjectSP value_sp(GetSP(locker)); 709 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 710 if (value_sp) 711 { 712 success = value_sp->SetValueFromCString (value_str,error.ref()); 713 } 714 else 715 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString()); 716 717 if (log) 718 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", 719 static_cast<void*>(value_sp.get()), value_str, success); 720 721 return success; 722 } 723 724 lldb::SBTypeFormat 725 SBValue::GetTypeFormat () 726 { 727 lldb::SBTypeFormat format; 728 ValueLocker locker; 729 lldb::ValueObjectSP value_sp(GetSP(locker)); 730 if (value_sp) 731 { 732 if (value_sp->UpdateValueIfNeeded(true)) 733 { 734 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat(); 735 if (format_sp) 736 format.SetSP(format_sp); 737 } 738 } 739 return format; 740 } 741 742 #ifndef LLDB_DISABLE_PYTHON 743 lldb::SBTypeSummary 744 SBValue::GetTypeSummary () 745 { 746 lldb::SBTypeSummary summary; 747 ValueLocker locker; 748 lldb::ValueObjectSP value_sp(GetSP(locker)); 749 if (value_sp) 750 { 751 if (value_sp->UpdateValueIfNeeded(true)) 752 { 753 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat(); 754 if (summary_sp) 755 summary.SetSP(summary_sp); 756 } 757 } 758 return summary; 759 } 760 #endif // LLDB_DISABLE_PYTHON 761 762 lldb::SBTypeFilter 763 SBValue::GetTypeFilter () 764 { 765 lldb::SBTypeFilter filter; 766 ValueLocker locker; 767 lldb::ValueObjectSP value_sp(GetSP(locker)); 768 if (value_sp) 769 { 770 if (value_sp->UpdateValueIfNeeded(true)) 771 { 772 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren(); 773 774 if (synthetic_sp && !synthetic_sp->IsScripted()) 775 { 776 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp); 777 filter.SetSP(filter_sp); 778 } 779 } 780 } 781 return filter; 782 } 783 784 #ifndef LLDB_DISABLE_PYTHON 785 lldb::SBTypeSynthetic 786 SBValue::GetTypeSynthetic () 787 { 788 lldb::SBTypeSynthetic synthetic; 789 ValueLocker locker; 790 lldb::ValueObjectSP value_sp(GetSP(locker)); 791 if (value_sp) 792 { 793 if (value_sp->UpdateValueIfNeeded(true)) 794 { 795 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren(); 796 797 if (children_sp && children_sp->IsScripted()) 798 { 799 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp); 800 synthetic.SetSP(synth_sp); 801 } 802 } 803 } 804 return synthetic; 805 } 806 #endif 807 808 lldb::SBValue 809 SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type) 810 { 811 lldb::SBValue sb_value; 812 ValueLocker locker; 813 lldb::ValueObjectSP value_sp(GetSP(locker)); 814 lldb::ValueObjectSP new_value_sp; 815 if (value_sp) 816 { 817 TypeImplSP type_sp (type.GetSP()); 818 if (type.IsValid()) 819 { 820 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name); 821 } 822 } 823 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 824 if (log) 825 { 826 if (new_value_sp) 827 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"", 828 static_cast<void*>(value_sp.get()), 829 new_value_sp->GetName().AsCString()); 830 else 831 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL", 832 static_cast<void*>(value_sp.get())); 833 } 834 return sb_value; 835 } 836 837 lldb::SBValue 838 SBValue::Cast (SBType type) 839 { 840 lldb::SBValue sb_value; 841 ValueLocker locker; 842 lldb::ValueObjectSP value_sp(GetSP(locker)); 843 TypeImplSP type_sp (type.GetSP()); 844 if (value_sp && type_sp) 845 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue()); 846 return sb_value; 847 } 848 849 lldb::SBValue 850 SBValue::CreateValueFromExpression (const char *name, const char* expression) 851 { 852 SBExpressionOptions options; 853 options.ref().SetKeepInMemory(true); 854 return CreateValueFromExpression (name, expression, options); 855 } 856 857 lldb::SBValue 858 SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options) 859 { 860 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 861 lldb::SBValue sb_value; 862 ValueLocker locker; 863 lldb::ValueObjectSP value_sp(GetSP(locker)); 864 lldb::ValueObjectSP new_value_sp; 865 if (value_sp) 866 { 867 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); 868 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx, options.ref()); 869 if (new_value_sp) 870 new_value_sp->SetName(ConstString(name)); 871 } 872 sb_value.SetSP(new_value_sp); 873 if (log) 874 { 875 if (new_value_sp) 876 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)", 877 static_cast<void*>(value_sp.get()), name, expression, 878 static_cast<void*>(new_value_sp.get())); 879 else 880 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL", 881 static_cast<void*>(value_sp.get()), name, expression); 882 } 883 return sb_value; 884 } 885 886 lldb::SBValue 887 SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type) 888 { 889 lldb::SBValue sb_value; 890 ValueLocker locker; 891 lldb::ValueObjectSP value_sp(GetSP(locker)); 892 lldb::ValueObjectSP new_value_sp; 893 lldb::TypeImplSP type_impl_sp (sb_type.GetSP()); 894 if (value_sp && type_impl_sp) 895 { 896 ClangASTType ast_type(type_impl_sp->GetClangASTType(true)); 897 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); 898 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, ast_type); 899 } 900 sb_value.SetSP(new_value_sp); 901 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 902 if (log) 903 { 904 if (new_value_sp) 905 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", 906 static_cast<void*>(value_sp.get()), 907 new_value_sp->GetName().AsCString()); 908 else 909 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", 910 static_cast<void*>(value_sp.get())); 911 } 912 return sb_value; 913 } 914 915 lldb::SBValue 916 SBValue::CreateValueFromData (const char* name, SBData data, SBType type) 917 { 918 lldb::SBValue sb_value; 919 lldb::ValueObjectSP new_value_sp; 920 ValueLocker locker; 921 lldb::ValueObjectSP value_sp(GetSP(locker)); 922 if (value_sp) 923 { 924 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); 925 new_value_sp = ValueObject::CreateValueObjectFromData(name, **data, exe_ctx, type.GetSP()->GetClangASTType(true)); 926 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); 927 } 928 sb_value.SetSP(new_value_sp); 929 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 930 if (log) 931 { 932 if (new_value_sp) 933 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"", 934 static_cast<void*>(value_sp.get()), 935 new_value_sp->GetName().AsCString()); 936 else 937 log->Printf ("SBValue(%p)::CreateValueFromData => NULL", 938 static_cast<void*>(value_sp.get())); 939 } 940 return sb_value; 941 } 942 943 SBValue 944 SBValue::GetChildAtIndex (uint32_t idx) 945 { 946 const bool can_create_synthetic = false; 947 lldb::DynamicValueType use_dynamic = eNoDynamicValues; 948 TargetSP target_sp; 949 if (m_opaque_sp) 950 target_sp = m_opaque_sp->GetTargetSP(); 951 952 if (target_sp) 953 use_dynamic = target_sp->GetPreferDynamicValue(); 954 955 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic); 956 } 957 958 SBValue 959 SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic) 960 { 961 lldb::ValueObjectSP child_sp; 962 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 963 964 ValueLocker locker; 965 lldb::ValueObjectSP value_sp(GetSP(locker)); 966 if (value_sp) 967 { 968 const bool can_create = true; 969 child_sp = value_sp->GetChildAtIndex (idx, can_create); 970 if (can_create_synthetic && !child_sp) 971 { 972 child_sp = value_sp->GetSyntheticArrayMember(idx, can_create); 973 } 974 } 975 976 SBValue sb_value; 977 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue()); 978 if (log) 979 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", 980 static_cast<void*>(value_sp.get()), idx, 981 static_cast<void*>(value_sp.get())); 982 983 return sb_value; 984 } 985 986 uint32_t 987 SBValue::GetIndexOfChildWithName (const char *name) 988 { 989 uint32_t idx = UINT32_MAX; 990 ValueLocker locker; 991 lldb::ValueObjectSP value_sp(GetSP(locker)); 992 if (value_sp) 993 { 994 idx = value_sp->GetIndexOfChildWithName (ConstString(name)); 995 } 996 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 997 if (log) 998 { 999 if (idx == UINT32_MAX) 1000 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", 1001 static_cast<void*>(value_sp.get()), name); 1002 else 1003 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", 1004 static_cast<void*>(value_sp.get()), name, idx); 1005 } 1006 return idx; 1007 } 1008 1009 SBValue 1010 SBValue::GetChildMemberWithName (const char *name) 1011 { 1012 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues; 1013 TargetSP target_sp; 1014 if (m_opaque_sp) 1015 target_sp = m_opaque_sp->GetTargetSP(); 1016 1017 if (target_sp) 1018 use_dynamic_value = target_sp->GetPreferDynamicValue(); 1019 return GetChildMemberWithName (name, use_dynamic_value); 1020 } 1021 1022 SBValue 1023 SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value) 1024 { 1025 lldb::ValueObjectSP child_sp; 1026 const ConstString str_name (name); 1027 1028 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1029 1030 ValueLocker locker; 1031 lldb::ValueObjectSP value_sp(GetSP(locker)); 1032 if (value_sp) 1033 { 1034 child_sp = value_sp->GetChildMemberWithName (str_name, true); 1035 } 1036 1037 SBValue sb_value; 1038 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue()); 1039 1040 if (log) 1041 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", 1042 static_cast<void*>(value_sp.get()), name, 1043 static_cast<void*>(value_sp.get())); 1044 1045 return sb_value; 1046 } 1047 1048 lldb::SBValue 1049 SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic) 1050 { 1051 SBValue value_sb; 1052 if (IsValid()) 1053 { 1054 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic())); 1055 value_sb.SetSP(proxy_sp); 1056 } 1057 return value_sb; 1058 } 1059 1060 lldb::SBValue 1061 SBValue::GetStaticValue () 1062 { 1063 SBValue value_sb; 1064 if (IsValid()) 1065 { 1066 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic())); 1067 value_sb.SetSP(proxy_sp); 1068 } 1069 return value_sb; 1070 } 1071 1072 lldb::SBValue 1073 SBValue::GetNonSyntheticValue () 1074 { 1075 SBValue value_sb; 1076 if (IsValid()) 1077 { 1078 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false)); 1079 value_sb.SetSP(proxy_sp); 1080 } 1081 return value_sb; 1082 } 1083 1084 lldb::DynamicValueType 1085 SBValue::GetPreferDynamicValue () 1086 { 1087 if (!IsValid()) 1088 return eNoDynamicValues; 1089 return m_opaque_sp->GetUseDynamic(); 1090 } 1091 1092 void 1093 SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic) 1094 { 1095 if (IsValid()) 1096 return m_opaque_sp->SetUseDynamic (use_dynamic); 1097 } 1098 1099 bool 1100 SBValue::GetPreferSyntheticValue () 1101 { 1102 if (!IsValid()) 1103 return false; 1104 return m_opaque_sp->GetUseSynthetic(); 1105 } 1106 1107 void 1108 SBValue::SetPreferSyntheticValue (bool use_synthetic) 1109 { 1110 if (IsValid()) 1111 return m_opaque_sp->SetUseSynthetic (use_synthetic); 1112 } 1113 1114 bool 1115 SBValue::IsDynamic() 1116 { 1117 ValueLocker locker; 1118 lldb::ValueObjectSP value_sp(GetSP(locker)); 1119 if (value_sp) 1120 return value_sp->IsDynamic(); 1121 return false; 1122 } 1123 1124 bool 1125 SBValue::IsSynthetic () 1126 { 1127 ValueLocker locker; 1128 lldb::ValueObjectSP value_sp(GetSP(locker)); 1129 if (value_sp) 1130 return value_sp->IsSynthetic(); 1131 return false; 1132 } 1133 1134 lldb::SBValue 1135 SBValue::GetValueForExpressionPath(const char* expr_path) 1136 { 1137 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1138 lldb::ValueObjectSP child_sp; 1139 ValueLocker locker; 1140 lldb::ValueObjectSP value_sp(GetSP(locker)); 1141 if (value_sp) 1142 { 1143 // using default values for all the fancy options, just do it if you can 1144 child_sp = value_sp->GetValueForExpressionPath(expr_path); 1145 } 1146 1147 SBValue sb_value; 1148 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue()); 1149 1150 if (log) 1151 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", 1152 static_cast<void*>(value_sp.get()), expr_path, 1153 static_cast<void*>(value_sp.get())); 1154 1155 return sb_value; 1156 } 1157 1158 int64_t 1159 SBValue::GetValueAsSigned(SBError& error, int64_t fail_value) 1160 { 1161 error.Clear(); 1162 ValueLocker locker; 1163 lldb::ValueObjectSP value_sp(GetSP(locker)); 1164 if (value_sp) 1165 { 1166 bool success = true; 1167 uint64_t ret_val = fail_value; 1168 ret_val = value_sp->GetValueAsSigned(fail_value, &success); 1169 if (!success) 1170 error.SetErrorString("could not resolve value"); 1171 return ret_val; 1172 } 1173 else 1174 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString()); 1175 1176 return fail_value; 1177 } 1178 1179 uint64_t 1180 SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value) 1181 { 1182 error.Clear(); 1183 ValueLocker locker; 1184 lldb::ValueObjectSP value_sp(GetSP(locker)); 1185 if (value_sp) 1186 { 1187 bool success = true; 1188 uint64_t ret_val = fail_value; 1189 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success); 1190 if (!success) 1191 error.SetErrorString("could not resolve value"); 1192 return ret_val; 1193 } 1194 else 1195 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString()); 1196 1197 return fail_value; 1198 } 1199 1200 int64_t 1201 SBValue::GetValueAsSigned(int64_t fail_value) 1202 { 1203 ValueLocker locker; 1204 lldb::ValueObjectSP value_sp(GetSP(locker)); 1205 if (value_sp) 1206 { 1207 return value_sp->GetValueAsSigned(fail_value); 1208 } 1209 return fail_value; 1210 } 1211 1212 uint64_t 1213 SBValue::GetValueAsUnsigned(uint64_t fail_value) 1214 { 1215 ValueLocker locker; 1216 lldb::ValueObjectSP value_sp(GetSP(locker)); 1217 if (value_sp) 1218 { 1219 return value_sp->GetValueAsUnsigned(fail_value); 1220 } 1221 return fail_value; 1222 } 1223 1224 bool 1225 SBValue::MightHaveChildren () 1226 { 1227 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1228 bool has_children = false; 1229 ValueLocker locker; 1230 lldb::ValueObjectSP value_sp(GetSP(locker)); 1231 if (value_sp) 1232 has_children = value_sp->MightHaveChildren(); 1233 1234 if (log) 1235 log->Printf ("SBValue(%p)::MightHaveChildren() => %i", 1236 static_cast<void*>(value_sp.get()), has_children); 1237 return has_children; 1238 } 1239 1240 bool 1241 SBValue::IsRuntimeSupportValue () 1242 { 1243 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1244 bool is_support = false; 1245 ValueLocker locker; 1246 lldb::ValueObjectSP value_sp(GetSP(locker)); 1247 if (value_sp) 1248 is_support = value_sp->IsRuntimeSupportValue(); 1249 1250 if (log) 1251 log->Printf ("SBValue(%p)::IsRuntimeSupportValue() => %i", 1252 static_cast<void*>(value_sp.get()), is_support); 1253 return is_support; 1254 } 1255 1256 uint32_t 1257 SBValue::GetNumChildren () 1258 { 1259 uint32_t num_children = 0; 1260 1261 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1262 ValueLocker locker; 1263 lldb::ValueObjectSP value_sp(GetSP(locker)); 1264 if (value_sp) 1265 num_children = value_sp->GetNumChildren(); 1266 1267 if (log) 1268 log->Printf ("SBValue(%p)::GetNumChildren () => %u", 1269 static_cast<void*>(value_sp.get()), num_children); 1270 1271 return num_children; 1272 } 1273 1274 1275 SBValue 1276 SBValue::Dereference () 1277 { 1278 SBValue sb_value; 1279 ValueLocker locker; 1280 lldb::ValueObjectSP value_sp(GetSP(locker)); 1281 if (value_sp) 1282 { 1283 Error error; 1284 sb_value = value_sp->Dereference (error); 1285 } 1286 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1287 if (log) 1288 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", 1289 static_cast<void*>(value_sp.get()), 1290 static_cast<void*>(value_sp.get())); 1291 1292 return sb_value; 1293 } 1294 1295 bool 1296 SBValue::TypeIsPointerType () 1297 { 1298 bool is_ptr_type = false; 1299 1300 ValueLocker locker; 1301 lldb::ValueObjectSP value_sp(GetSP(locker)); 1302 if (value_sp) 1303 is_ptr_type = value_sp->IsPointerType(); 1304 1305 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1306 if (log) 1307 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", 1308 static_cast<void*>(value_sp.get()), is_ptr_type); 1309 1310 return is_ptr_type; 1311 } 1312 1313 void * 1314 SBValue::GetOpaqueType() 1315 { 1316 ValueLocker locker; 1317 lldb::ValueObjectSP value_sp(GetSP(locker)); 1318 if (value_sp) 1319 return value_sp->GetClangType().GetOpaqueQualType(); 1320 return NULL; 1321 } 1322 1323 lldb::SBTarget 1324 SBValue::GetTarget() 1325 { 1326 SBTarget sb_target; 1327 TargetSP target_sp; 1328 if (m_opaque_sp) 1329 { 1330 target_sp = m_opaque_sp->GetTargetSP(); 1331 sb_target.SetSP (target_sp); 1332 } 1333 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1334 if (log) 1335 { 1336 if (target_sp.get() == NULL) 1337 log->Printf ("SBValue(%p)::GetTarget () => NULL", 1338 static_cast<void*>(m_opaque_sp.get())); 1339 else 1340 log->Printf ("SBValue(%p)::GetTarget () => %p", 1341 static_cast<void*>(m_opaque_sp.get()), 1342 static_cast<void*>(target_sp.get())); 1343 } 1344 return sb_target; 1345 } 1346 1347 lldb::SBProcess 1348 SBValue::GetProcess() 1349 { 1350 SBProcess sb_process; 1351 ProcessSP process_sp; 1352 if (m_opaque_sp) 1353 { 1354 process_sp = m_opaque_sp->GetProcessSP(); 1355 sb_process.SetSP (process_sp); 1356 } 1357 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1358 if (log) 1359 { 1360 if (process_sp.get() == NULL) 1361 log->Printf ("SBValue(%p)::GetProcess () => NULL", 1362 static_cast<void*>(m_opaque_sp.get())); 1363 else 1364 log->Printf ("SBValue(%p)::GetProcess () => %p", 1365 static_cast<void*>(m_opaque_sp.get()), 1366 static_cast<void*>(process_sp.get())); 1367 } 1368 return sb_process; 1369 } 1370 1371 lldb::SBThread 1372 SBValue::GetThread() 1373 { 1374 SBThread sb_thread; 1375 ThreadSP thread_sp; 1376 if (m_opaque_sp) 1377 { 1378 thread_sp = m_opaque_sp->GetThreadSP(); 1379 sb_thread.SetThread(thread_sp); 1380 } 1381 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1382 if (log) 1383 { 1384 if (thread_sp.get() == NULL) 1385 log->Printf ("SBValue(%p)::GetThread () => NULL", 1386 static_cast<void*>(m_opaque_sp.get())); 1387 else 1388 log->Printf ("SBValue(%p)::GetThread () => %p", 1389 static_cast<void*>(m_opaque_sp.get()), 1390 static_cast<void*>(thread_sp.get())); 1391 } 1392 return sb_thread; 1393 } 1394 1395 lldb::SBFrame 1396 SBValue::GetFrame() 1397 { 1398 SBFrame sb_frame; 1399 StackFrameSP frame_sp; 1400 if (m_opaque_sp) 1401 { 1402 frame_sp = m_opaque_sp->GetFrameSP(); 1403 sb_frame.SetFrameSP (frame_sp); 1404 } 1405 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1406 if (log) 1407 { 1408 if (frame_sp.get() == NULL) 1409 log->Printf ("SBValue(%p)::GetFrame () => NULL", 1410 static_cast<void*>(m_opaque_sp.get())); 1411 else 1412 log->Printf ("SBValue(%p)::GetFrame () => %p", 1413 static_cast<void*>(m_opaque_sp.get()), 1414 static_cast<void*>(frame_sp.get())); 1415 } 1416 return sb_frame; 1417 } 1418 1419 1420 lldb::ValueObjectSP 1421 SBValue::GetSP (ValueLocker &locker) const 1422 { 1423 if (!m_opaque_sp || !m_opaque_sp->IsValid()) 1424 return ValueObjectSP(); 1425 return locker.GetLockedSP(*m_opaque_sp.get()); 1426 } 1427 1428 lldb::ValueObjectSP 1429 SBValue::GetSP () const 1430 { 1431 ValueLocker locker; 1432 return GetSP(locker); 1433 } 1434 1435 void 1436 SBValue::SetSP (ValueImplSP impl_sp) 1437 { 1438 m_opaque_sp = impl_sp; 1439 } 1440 1441 void 1442 SBValue::SetSP (const lldb::ValueObjectSP &sp) 1443 { 1444 if (sp) 1445 { 1446 lldb::TargetSP target_sp(sp->GetTargetSP()); 1447 if (target_sp) 1448 { 1449 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue(); 1450 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue(); 1451 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic)); 1452 } 1453 else 1454 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true)); 1455 } 1456 else 1457 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false)); 1458 } 1459 1460 void 1461 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic) 1462 { 1463 if (sp) 1464 { 1465 lldb::TargetSP target_sp(sp->GetTargetSP()); 1466 if (target_sp) 1467 { 1468 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue(); 1469 SetSP (sp, use_dynamic, use_synthetic); 1470 } 1471 else 1472 SetSP (sp, use_dynamic, true); 1473 } 1474 else 1475 SetSP (sp, use_dynamic, false); 1476 } 1477 1478 void 1479 SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic) 1480 { 1481 if (sp) 1482 { 1483 lldb::TargetSP target_sp(sp->GetTargetSP()); 1484 if (target_sp) 1485 { 1486 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue(); 1487 SetSP (sp, use_dynamic, use_synthetic); 1488 } 1489 else 1490 SetSP (sp, eNoDynamicValues, use_synthetic); 1491 } 1492 else 1493 SetSP (sp, eNoDynamicValues, use_synthetic); 1494 } 1495 1496 void 1497 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic) 1498 { 1499 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic)); 1500 } 1501 1502 void 1503 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name) 1504 { 1505 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name)); 1506 } 1507 1508 bool 1509 SBValue::GetExpressionPath (SBStream &description) 1510 { 1511 ValueLocker locker; 1512 lldb::ValueObjectSP value_sp(GetSP(locker)); 1513 if (value_sp) 1514 { 1515 value_sp->GetExpressionPath (description.ref(), false); 1516 return true; 1517 } 1518 return false; 1519 } 1520 1521 bool 1522 SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes) 1523 { 1524 ValueLocker locker; 1525 lldb::ValueObjectSP value_sp(GetSP(locker)); 1526 if (value_sp) 1527 { 1528 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes); 1529 return true; 1530 } 1531 return false; 1532 } 1533 1534 bool 1535 SBValue::GetDescription (SBStream &description) 1536 { 1537 Stream &strm = description.ref(); 1538 1539 ValueLocker locker; 1540 lldb::ValueObjectSP value_sp(GetSP(locker)); 1541 if (value_sp) 1542 value_sp->Dump(strm); 1543 else 1544 strm.PutCString ("No value"); 1545 1546 return true; 1547 } 1548 1549 lldb::Format 1550 SBValue::GetFormat () 1551 { 1552 ValueLocker locker; 1553 lldb::ValueObjectSP value_sp(GetSP(locker)); 1554 if (value_sp) 1555 return value_sp->GetFormat(); 1556 return eFormatDefault; 1557 } 1558 1559 void 1560 SBValue::SetFormat (lldb::Format format) 1561 { 1562 ValueLocker locker; 1563 lldb::ValueObjectSP value_sp(GetSP(locker)); 1564 if (value_sp) 1565 value_sp->SetFormat(format); 1566 } 1567 1568 lldb::SBValue 1569 SBValue::AddressOf() 1570 { 1571 SBValue sb_value; 1572 ValueLocker locker; 1573 lldb::ValueObjectSP value_sp(GetSP(locker)); 1574 if (value_sp) 1575 { 1576 Error error; 1577 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue()); 1578 } 1579 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1580 if (log) 1581 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", 1582 static_cast<void*>(value_sp.get()), 1583 static_cast<void*>(value_sp.get())); 1584 1585 return sb_value; 1586 } 1587 1588 lldb::addr_t 1589 SBValue::GetLoadAddress() 1590 { 1591 lldb::addr_t value = LLDB_INVALID_ADDRESS; 1592 ValueLocker locker; 1593 lldb::ValueObjectSP value_sp(GetSP(locker)); 1594 if (value_sp) 1595 { 1596 TargetSP target_sp (value_sp->GetTargetSP()); 1597 if (target_sp) 1598 { 1599 const bool scalar_is_load_address = true; 1600 AddressType addr_type; 1601 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); 1602 if (addr_type == eAddressTypeFile) 1603 { 1604 ModuleSP module_sp (value_sp->GetModule()); 1605 if (!module_sp) 1606 value = LLDB_INVALID_ADDRESS; 1607 else 1608 { 1609 Address addr; 1610 module_sp->ResolveFileAddress(value, addr); 1611 value = addr.GetLoadAddress(target_sp.get()); 1612 } 1613 } 1614 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid) 1615 value = LLDB_INVALID_ADDRESS; 1616 } 1617 } 1618 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1619 if (log) 1620 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")", 1621 static_cast<void*>(value_sp.get()), value); 1622 1623 return value; 1624 } 1625 1626 lldb::SBAddress 1627 SBValue::GetAddress() 1628 { 1629 Address addr; 1630 ValueLocker locker; 1631 lldb::ValueObjectSP value_sp(GetSP(locker)); 1632 if (value_sp) 1633 { 1634 TargetSP target_sp (value_sp->GetTargetSP()); 1635 if (target_sp) 1636 { 1637 lldb::addr_t value = LLDB_INVALID_ADDRESS; 1638 const bool scalar_is_load_address = true; 1639 AddressType addr_type; 1640 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); 1641 if (addr_type == eAddressTypeFile) 1642 { 1643 ModuleSP module_sp (value_sp->GetModule()); 1644 if (module_sp) 1645 module_sp->ResolveFileAddress(value, addr); 1646 } 1647 else if (addr_type == eAddressTypeLoad) 1648 { 1649 // no need to check the return value on this.. if it can actually do the resolve 1650 // addr will be in the form (section,offset), otherwise it will simply be returned 1651 // as (NULL, value) 1652 addr.SetLoadAddress(value, target_sp.get()); 1653 } 1654 } 1655 } 1656 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1657 if (log) 1658 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")", 1659 static_cast<void*>(value_sp.get()), 1660 (addr.GetSection() 1661 ? addr.GetSection()->GetName().GetCString() 1662 : "NULL"), 1663 addr.GetOffset()); 1664 return SBAddress(new Address(addr)); 1665 } 1666 1667 lldb::SBData 1668 SBValue::GetPointeeData (uint32_t item_idx, 1669 uint32_t item_count) 1670 { 1671 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1672 lldb::SBData sb_data; 1673 ValueLocker locker; 1674 lldb::ValueObjectSP value_sp(GetSP(locker)); 1675 if (value_sp) 1676 { 1677 TargetSP target_sp (value_sp->GetTargetSP()); 1678 if (target_sp) 1679 { 1680 DataExtractorSP data_sp(new DataExtractor()); 1681 value_sp->GetPointeeData(*data_sp, item_idx, item_count); 1682 if (data_sp->GetByteSize() > 0) 1683 *sb_data = data_sp; 1684 } 1685 } 1686 if (log) 1687 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)", 1688 static_cast<void*>(value_sp.get()), item_idx, item_count, 1689 static_cast<void*>(sb_data.get())); 1690 1691 return sb_data; 1692 } 1693 1694 lldb::SBData 1695 SBValue::GetData () 1696 { 1697 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1698 lldb::SBData sb_data; 1699 ValueLocker locker; 1700 lldb::ValueObjectSP value_sp(GetSP(locker)); 1701 if (value_sp) 1702 { 1703 DataExtractorSP data_sp(new DataExtractor()); 1704 Error error; 1705 value_sp->GetData(*data_sp, error); 1706 if (error.Success()) 1707 *sb_data = data_sp; 1708 } 1709 if (log) 1710 log->Printf ("SBValue(%p)::GetData () => SBData(%p)", 1711 static_cast<void*>(value_sp.get()), 1712 static_cast<void*>(sb_data.get())); 1713 1714 return sb_data; 1715 } 1716 1717 bool 1718 SBValue::SetData (lldb::SBData &data, SBError &error) 1719 { 1720 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1721 ValueLocker locker; 1722 lldb::ValueObjectSP value_sp(GetSP(locker)); 1723 bool ret = true; 1724 1725 if (value_sp) 1726 { 1727 DataExtractor *data_extractor = data.get(); 1728 1729 if (!data_extractor) 1730 { 1731 if (log) 1732 log->Printf ("SBValue(%p)::SetData() => error: no data to set", 1733 static_cast<void*>(value_sp.get())); 1734 1735 error.SetErrorString("No data to set"); 1736 ret = false; 1737 } 1738 else 1739 { 1740 Error set_error; 1741 1742 value_sp->SetData(*data_extractor, set_error); 1743 1744 if (!set_error.Success()) 1745 { 1746 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString()); 1747 ret = false; 1748 } 1749 } 1750 } 1751 else 1752 { 1753 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString()); 1754 ret = false; 1755 } 1756 1757 if (log) 1758 log->Printf ("SBValue(%p)::SetData (%p) => %s", 1759 static_cast<void*>(value_sp.get()), 1760 static_cast<void*>(data.get()), ret ? "true" : "false"); 1761 return ret; 1762 } 1763 1764 lldb::SBDeclaration 1765 SBValue::GetDeclaration () 1766 { 1767 ValueLocker locker; 1768 lldb::ValueObjectSP value_sp(GetSP(locker)); 1769 SBDeclaration decl_sb; 1770 if (value_sp) 1771 { 1772 Declaration decl; 1773 if (value_sp->GetDeclaration(decl)) 1774 decl_sb.SetDeclaration(decl); 1775 } 1776 return decl_sb; 1777 } 1778 1779 lldb::SBWatchpoint 1780 SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error) 1781 { 1782 SBWatchpoint sb_watchpoint; 1783 1784 // If the SBValue is not valid, there's no point in even trying to watch it. 1785 ValueLocker locker; 1786 lldb::ValueObjectSP value_sp(GetSP(locker)); 1787 TargetSP target_sp (GetTarget().GetSP()); 1788 if (value_sp && target_sp) 1789 { 1790 // Read and Write cannot both be false. 1791 if (!read && !write) 1792 return sb_watchpoint; 1793 1794 // If the value is not in scope, don't try and watch and invalid value 1795 if (!IsInScope()) 1796 return sb_watchpoint; 1797 1798 addr_t addr = GetLoadAddress(); 1799 if (addr == LLDB_INVALID_ADDRESS) 1800 return sb_watchpoint; 1801 size_t byte_size = GetByteSize(); 1802 if (byte_size == 0) 1803 return sb_watchpoint; 1804 1805 uint32_t watch_type = 0; 1806 if (read) 1807 watch_type |= LLDB_WATCH_TYPE_READ; 1808 if (write) 1809 watch_type |= LLDB_WATCH_TYPE_WRITE; 1810 1811 Error rc; 1812 ClangASTType type (value_sp->GetClangType()); 1813 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc); 1814 error.SetError(rc); 1815 1816 if (watchpoint_sp) 1817 { 1818 sb_watchpoint.SetSP (watchpoint_sp); 1819 Declaration decl; 1820 if (value_sp->GetDeclaration (decl)) 1821 { 1822 if (decl.GetFile()) 1823 { 1824 StreamString ss; 1825 // True to show fullpath for declaration file. 1826 decl.DumpStopContext(&ss, true); 1827 watchpoint_sp->SetDeclInfo(ss.GetString()); 1828 } 1829 } 1830 } 1831 } 1832 else if (target_sp) 1833 { 1834 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1835 if (log) 1836 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s", 1837 static_cast<void*>(value_sp.get()), 1838 locker.GetError().AsCString()); 1839 1840 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString()); 1841 } 1842 else 1843 { 1844 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1845 if (log) 1846 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target", 1847 static_cast<void*>(value_sp.get())); 1848 error.SetErrorString("could not set watchpoint, a target is required"); 1849 } 1850 1851 return sb_watchpoint; 1852 } 1853 1854 // FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed. 1855 // Backward compatibility fix in the interim. 1856 lldb::SBWatchpoint 1857 SBValue::Watch (bool resolve_location, bool read, bool write) 1858 { 1859 SBError error; 1860 return Watch(resolve_location, read, write, error); 1861 } 1862 1863 lldb::SBWatchpoint 1864 SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error) 1865 { 1866 SBWatchpoint sb_watchpoint; 1867 if (IsInScope() && GetType().IsPointerType()) 1868 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error); 1869 return sb_watchpoint; 1870 } 1871 1872 lldb::SBValue 1873 SBValue::Persist () 1874 { 1875 ValueLocker locker; 1876 lldb::ValueObjectSP value_sp(GetSP(locker)); 1877 SBValue persisted_sb; 1878 if (value_sp) 1879 { 1880 persisted_sb.SetSP(value_sp->Persist()); 1881 } 1882 return persisted_sb; 1883 } 1884