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 if (value_sp->IsPointerType()) 973 { 974 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create); 975 } 976 else if (value_sp->IsArrayType()) 977 { 978 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create); 979 } 980 } 981 } 982 983 SBValue sb_value; 984 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue()); 985 if (log) 986 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", 987 static_cast<void*>(value_sp.get()), idx, 988 static_cast<void*>(value_sp.get())); 989 990 return sb_value; 991 } 992 993 uint32_t 994 SBValue::GetIndexOfChildWithName (const char *name) 995 { 996 uint32_t idx = UINT32_MAX; 997 ValueLocker locker; 998 lldb::ValueObjectSP value_sp(GetSP(locker)); 999 if (value_sp) 1000 { 1001 idx = value_sp->GetIndexOfChildWithName (ConstString(name)); 1002 } 1003 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1004 if (log) 1005 { 1006 if (idx == UINT32_MAX) 1007 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", 1008 static_cast<void*>(value_sp.get()), name); 1009 else 1010 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", 1011 static_cast<void*>(value_sp.get()), name, idx); 1012 } 1013 return idx; 1014 } 1015 1016 SBValue 1017 SBValue::GetChildMemberWithName (const char *name) 1018 { 1019 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues; 1020 TargetSP target_sp; 1021 if (m_opaque_sp) 1022 target_sp = m_opaque_sp->GetTargetSP(); 1023 1024 if (target_sp) 1025 use_dynamic_value = target_sp->GetPreferDynamicValue(); 1026 return GetChildMemberWithName (name, use_dynamic_value); 1027 } 1028 1029 SBValue 1030 SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value) 1031 { 1032 lldb::ValueObjectSP child_sp; 1033 const ConstString str_name (name); 1034 1035 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1036 1037 ValueLocker locker; 1038 lldb::ValueObjectSP value_sp(GetSP(locker)); 1039 if (value_sp) 1040 { 1041 child_sp = value_sp->GetChildMemberWithName (str_name, true); 1042 } 1043 1044 SBValue sb_value; 1045 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue()); 1046 1047 if (log) 1048 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", 1049 static_cast<void*>(value_sp.get()), name, 1050 static_cast<void*>(value_sp.get())); 1051 1052 return sb_value; 1053 } 1054 1055 lldb::SBValue 1056 SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic) 1057 { 1058 SBValue value_sb; 1059 if (IsValid()) 1060 { 1061 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic())); 1062 value_sb.SetSP(proxy_sp); 1063 } 1064 return value_sb; 1065 } 1066 1067 lldb::SBValue 1068 SBValue::GetStaticValue () 1069 { 1070 SBValue value_sb; 1071 if (IsValid()) 1072 { 1073 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic())); 1074 value_sb.SetSP(proxy_sp); 1075 } 1076 return value_sb; 1077 } 1078 1079 lldb::SBValue 1080 SBValue::GetNonSyntheticValue () 1081 { 1082 SBValue value_sb; 1083 if (IsValid()) 1084 { 1085 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false)); 1086 value_sb.SetSP(proxy_sp); 1087 } 1088 return value_sb; 1089 } 1090 1091 lldb::DynamicValueType 1092 SBValue::GetPreferDynamicValue () 1093 { 1094 if (!IsValid()) 1095 return eNoDynamicValues; 1096 return m_opaque_sp->GetUseDynamic(); 1097 } 1098 1099 void 1100 SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic) 1101 { 1102 if (IsValid()) 1103 return m_opaque_sp->SetUseDynamic (use_dynamic); 1104 } 1105 1106 bool 1107 SBValue::GetPreferSyntheticValue () 1108 { 1109 if (!IsValid()) 1110 return false; 1111 return m_opaque_sp->GetUseSynthetic(); 1112 } 1113 1114 void 1115 SBValue::SetPreferSyntheticValue (bool use_synthetic) 1116 { 1117 if (IsValid()) 1118 return m_opaque_sp->SetUseSynthetic (use_synthetic); 1119 } 1120 1121 bool 1122 SBValue::IsDynamic() 1123 { 1124 ValueLocker locker; 1125 lldb::ValueObjectSP value_sp(GetSP(locker)); 1126 if (value_sp) 1127 return value_sp->IsDynamic(); 1128 return false; 1129 } 1130 1131 bool 1132 SBValue::IsSynthetic () 1133 { 1134 ValueLocker locker; 1135 lldb::ValueObjectSP value_sp(GetSP(locker)); 1136 if (value_sp) 1137 return value_sp->IsSynthetic(); 1138 return false; 1139 } 1140 1141 lldb::SBValue 1142 SBValue::GetValueForExpressionPath(const char* expr_path) 1143 { 1144 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1145 lldb::ValueObjectSP child_sp; 1146 ValueLocker locker; 1147 lldb::ValueObjectSP value_sp(GetSP(locker)); 1148 if (value_sp) 1149 { 1150 // using default values for all the fancy options, just do it if you can 1151 child_sp = value_sp->GetValueForExpressionPath(expr_path); 1152 } 1153 1154 SBValue sb_value; 1155 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue()); 1156 1157 if (log) 1158 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", 1159 static_cast<void*>(value_sp.get()), expr_path, 1160 static_cast<void*>(value_sp.get())); 1161 1162 return sb_value; 1163 } 1164 1165 int64_t 1166 SBValue::GetValueAsSigned(SBError& error, int64_t fail_value) 1167 { 1168 error.Clear(); 1169 ValueLocker locker; 1170 lldb::ValueObjectSP value_sp(GetSP(locker)); 1171 if (value_sp) 1172 { 1173 bool success = true; 1174 uint64_t ret_val = fail_value; 1175 ret_val = value_sp->GetValueAsSigned(fail_value, &success); 1176 if (!success) 1177 error.SetErrorString("could not resolve value"); 1178 return ret_val; 1179 } 1180 else 1181 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString()); 1182 1183 return fail_value; 1184 } 1185 1186 uint64_t 1187 SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value) 1188 { 1189 error.Clear(); 1190 ValueLocker locker; 1191 lldb::ValueObjectSP value_sp(GetSP(locker)); 1192 if (value_sp) 1193 { 1194 bool success = true; 1195 uint64_t ret_val = fail_value; 1196 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success); 1197 if (!success) 1198 error.SetErrorString("could not resolve value"); 1199 return ret_val; 1200 } 1201 else 1202 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString()); 1203 1204 return fail_value; 1205 } 1206 1207 int64_t 1208 SBValue::GetValueAsSigned(int64_t fail_value) 1209 { 1210 ValueLocker locker; 1211 lldb::ValueObjectSP value_sp(GetSP(locker)); 1212 if (value_sp) 1213 { 1214 return value_sp->GetValueAsSigned(fail_value); 1215 } 1216 return fail_value; 1217 } 1218 1219 uint64_t 1220 SBValue::GetValueAsUnsigned(uint64_t fail_value) 1221 { 1222 ValueLocker locker; 1223 lldb::ValueObjectSP value_sp(GetSP(locker)); 1224 if (value_sp) 1225 { 1226 return value_sp->GetValueAsUnsigned(fail_value); 1227 } 1228 return fail_value; 1229 } 1230 1231 bool 1232 SBValue::MightHaveChildren () 1233 { 1234 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1235 bool has_children = false; 1236 ValueLocker locker; 1237 lldb::ValueObjectSP value_sp(GetSP(locker)); 1238 if (value_sp) 1239 has_children = value_sp->MightHaveChildren(); 1240 1241 if (log) 1242 log->Printf ("SBValue(%p)::MightHaveChildren() => %i", 1243 static_cast<void*>(value_sp.get()), has_children); 1244 return has_children; 1245 } 1246 1247 uint32_t 1248 SBValue::GetNumChildren () 1249 { 1250 uint32_t num_children = 0; 1251 1252 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1253 ValueLocker locker; 1254 lldb::ValueObjectSP value_sp(GetSP(locker)); 1255 if (value_sp) 1256 num_children = value_sp->GetNumChildren(); 1257 1258 if (log) 1259 log->Printf ("SBValue(%p)::GetNumChildren () => %u", 1260 static_cast<void*>(value_sp.get()), num_children); 1261 1262 return num_children; 1263 } 1264 1265 1266 SBValue 1267 SBValue::Dereference () 1268 { 1269 SBValue sb_value; 1270 ValueLocker locker; 1271 lldb::ValueObjectSP value_sp(GetSP(locker)); 1272 if (value_sp) 1273 { 1274 Error error; 1275 sb_value = value_sp->Dereference (error); 1276 } 1277 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1278 if (log) 1279 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", 1280 static_cast<void*>(value_sp.get()), 1281 static_cast<void*>(value_sp.get())); 1282 1283 return sb_value; 1284 } 1285 1286 bool 1287 SBValue::TypeIsPointerType () 1288 { 1289 bool is_ptr_type = false; 1290 1291 ValueLocker locker; 1292 lldb::ValueObjectSP value_sp(GetSP(locker)); 1293 if (value_sp) 1294 is_ptr_type = value_sp->IsPointerType(); 1295 1296 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1297 if (log) 1298 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", 1299 static_cast<void*>(value_sp.get()), is_ptr_type); 1300 1301 return is_ptr_type; 1302 } 1303 1304 void * 1305 SBValue::GetOpaqueType() 1306 { 1307 ValueLocker locker; 1308 lldb::ValueObjectSP value_sp(GetSP(locker)); 1309 if (value_sp) 1310 return value_sp->GetClangType().GetOpaqueQualType(); 1311 return NULL; 1312 } 1313 1314 lldb::SBTarget 1315 SBValue::GetTarget() 1316 { 1317 SBTarget sb_target; 1318 TargetSP target_sp; 1319 if (m_opaque_sp) 1320 { 1321 target_sp = m_opaque_sp->GetTargetSP(); 1322 sb_target.SetSP (target_sp); 1323 } 1324 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1325 if (log) 1326 { 1327 if (target_sp.get() == NULL) 1328 log->Printf ("SBValue(%p)::GetTarget () => NULL", 1329 static_cast<void*>(m_opaque_sp.get())); 1330 else 1331 log->Printf ("SBValue(%p)::GetTarget () => %p", 1332 static_cast<void*>(m_opaque_sp.get()), 1333 static_cast<void*>(target_sp.get())); 1334 } 1335 return sb_target; 1336 } 1337 1338 lldb::SBProcess 1339 SBValue::GetProcess() 1340 { 1341 SBProcess sb_process; 1342 ProcessSP process_sp; 1343 if (m_opaque_sp) 1344 { 1345 process_sp = m_opaque_sp->GetProcessSP(); 1346 sb_process.SetSP (process_sp); 1347 } 1348 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1349 if (log) 1350 { 1351 if (process_sp.get() == NULL) 1352 log->Printf ("SBValue(%p)::GetProcess () => NULL", 1353 static_cast<void*>(m_opaque_sp.get())); 1354 else 1355 log->Printf ("SBValue(%p)::GetProcess () => %p", 1356 static_cast<void*>(m_opaque_sp.get()), 1357 static_cast<void*>(process_sp.get())); 1358 } 1359 return sb_process; 1360 } 1361 1362 lldb::SBThread 1363 SBValue::GetThread() 1364 { 1365 SBThread sb_thread; 1366 ThreadSP thread_sp; 1367 if (m_opaque_sp) 1368 { 1369 thread_sp = m_opaque_sp->GetThreadSP(); 1370 sb_thread.SetThread(thread_sp); 1371 } 1372 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1373 if (log) 1374 { 1375 if (thread_sp.get() == NULL) 1376 log->Printf ("SBValue(%p)::GetThread () => NULL", 1377 static_cast<void*>(m_opaque_sp.get())); 1378 else 1379 log->Printf ("SBValue(%p)::GetThread () => %p", 1380 static_cast<void*>(m_opaque_sp.get()), 1381 static_cast<void*>(thread_sp.get())); 1382 } 1383 return sb_thread; 1384 } 1385 1386 lldb::SBFrame 1387 SBValue::GetFrame() 1388 { 1389 SBFrame sb_frame; 1390 StackFrameSP frame_sp; 1391 if (m_opaque_sp) 1392 { 1393 frame_sp = m_opaque_sp->GetFrameSP(); 1394 sb_frame.SetFrameSP (frame_sp); 1395 } 1396 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1397 if (log) 1398 { 1399 if (frame_sp.get() == NULL) 1400 log->Printf ("SBValue(%p)::GetFrame () => NULL", 1401 static_cast<void*>(m_opaque_sp.get())); 1402 else 1403 log->Printf ("SBValue(%p)::GetFrame () => %p", 1404 static_cast<void*>(m_opaque_sp.get()), 1405 static_cast<void*>(frame_sp.get())); 1406 } 1407 return sb_frame; 1408 } 1409 1410 1411 lldb::ValueObjectSP 1412 SBValue::GetSP (ValueLocker &locker) const 1413 { 1414 if (!m_opaque_sp || !m_opaque_sp->IsValid()) 1415 return ValueObjectSP(); 1416 return locker.GetLockedSP(*m_opaque_sp.get()); 1417 } 1418 1419 lldb::ValueObjectSP 1420 SBValue::GetSP () const 1421 { 1422 ValueLocker locker; 1423 return GetSP(locker); 1424 } 1425 1426 void 1427 SBValue::SetSP (ValueImplSP impl_sp) 1428 { 1429 m_opaque_sp = impl_sp; 1430 } 1431 1432 void 1433 SBValue::SetSP (const lldb::ValueObjectSP &sp) 1434 { 1435 if (sp) 1436 { 1437 lldb::TargetSP target_sp(sp->GetTargetSP()); 1438 if (target_sp) 1439 { 1440 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue(); 1441 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue(); 1442 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic)); 1443 } 1444 else 1445 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true)); 1446 } 1447 else 1448 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false)); 1449 } 1450 1451 void 1452 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic) 1453 { 1454 if (sp) 1455 { 1456 lldb::TargetSP target_sp(sp->GetTargetSP()); 1457 if (target_sp) 1458 { 1459 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue(); 1460 SetSP (sp, use_dynamic, use_synthetic); 1461 } 1462 else 1463 SetSP (sp, use_dynamic, true); 1464 } 1465 else 1466 SetSP (sp, use_dynamic, false); 1467 } 1468 1469 void 1470 SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic) 1471 { 1472 if (sp) 1473 { 1474 lldb::TargetSP target_sp(sp->GetTargetSP()); 1475 if (target_sp) 1476 { 1477 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue(); 1478 SetSP (sp, use_dynamic, use_synthetic); 1479 } 1480 else 1481 SetSP (sp, eNoDynamicValues, use_synthetic); 1482 } 1483 else 1484 SetSP (sp, eNoDynamicValues, use_synthetic); 1485 } 1486 1487 void 1488 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic) 1489 { 1490 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic)); 1491 } 1492 1493 void 1494 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name) 1495 { 1496 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name)); 1497 } 1498 1499 bool 1500 SBValue::GetExpressionPath (SBStream &description) 1501 { 1502 ValueLocker locker; 1503 lldb::ValueObjectSP value_sp(GetSP(locker)); 1504 if (value_sp) 1505 { 1506 value_sp->GetExpressionPath (description.ref(), false); 1507 return true; 1508 } 1509 return false; 1510 } 1511 1512 bool 1513 SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes) 1514 { 1515 ValueLocker locker; 1516 lldb::ValueObjectSP value_sp(GetSP(locker)); 1517 if (value_sp) 1518 { 1519 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes); 1520 return true; 1521 } 1522 return false; 1523 } 1524 1525 bool 1526 SBValue::GetDescription (SBStream &description) 1527 { 1528 Stream &strm = description.ref(); 1529 1530 ValueLocker locker; 1531 lldb::ValueObjectSP value_sp(GetSP(locker)); 1532 if (value_sp) 1533 value_sp->Dump(strm); 1534 else 1535 strm.PutCString ("No value"); 1536 1537 return true; 1538 } 1539 1540 lldb::Format 1541 SBValue::GetFormat () 1542 { 1543 ValueLocker locker; 1544 lldb::ValueObjectSP value_sp(GetSP(locker)); 1545 if (value_sp) 1546 return value_sp->GetFormat(); 1547 return eFormatDefault; 1548 } 1549 1550 void 1551 SBValue::SetFormat (lldb::Format format) 1552 { 1553 ValueLocker locker; 1554 lldb::ValueObjectSP value_sp(GetSP(locker)); 1555 if (value_sp) 1556 value_sp->SetFormat(format); 1557 } 1558 1559 lldb::SBValue 1560 SBValue::AddressOf() 1561 { 1562 SBValue sb_value; 1563 ValueLocker locker; 1564 lldb::ValueObjectSP value_sp(GetSP(locker)); 1565 if (value_sp) 1566 { 1567 Error error; 1568 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue()); 1569 } 1570 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1571 if (log) 1572 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", 1573 static_cast<void*>(value_sp.get()), 1574 static_cast<void*>(value_sp.get())); 1575 1576 return sb_value; 1577 } 1578 1579 lldb::addr_t 1580 SBValue::GetLoadAddress() 1581 { 1582 lldb::addr_t value = LLDB_INVALID_ADDRESS; 1583 ValueLocker locker; 1584 lldb::ValueObjectSP value_sp(GetSP(locker)); 1585 if (value_sp) 1586 { 1587 TargetSP target_sp (value_sp->GetTargetSP()); 1588 if (target_sp) 1589 { 1590 const bool scalar_is_load_address = true; 1591 AddressType addr_type; 1592 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); 1593 if (addr_type == eAddressTypeFile) 1594 { 1595 ModuleSP module_sp (value_sp->GetModule()); 1596 if (!module_sp) 1597 value = LLDB_INVALID_ADDRESS; 1598 else 1599 { 1600 Address addr; 1601 module_sp->ResolveFileAddress(value, addr); 1602 value = addr.GetLoadAddress(target_sp.get()); 1603 } 1604 } 1605 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid) 1606 value = LLDB_INVALID_ADDRESS; 1607 } 1608 } 1609 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1610 if (log) 1611 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")", 1612 static_cast<void*>(value_sp.get()), value); 1613 1614 return value; 1615 } 1616 1617 lldb::SBAddress 1618 SBValue::GetAddress() 1619 { 1620 Address addr; 1621 ValueLocker locker; 1622 lldb::ValueObjectSP value_sp(GetSP(locker)); 1623 if (value_sp) 1624 { 1625 TargetSP target_sp (value_sp->GetTargetSP()); 1626 if (target_sp) 1627 { 1628 lldb::addr_t value = LLDB_INVALID_ADDRESS; 1629 const bool scalar_is_load_address = true; 1630 AddressType addr_type; 1631 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); 1632 if (addr_type == eAddressTypeFile) 1633 { 1634 ModuleSP module_sp (value_sp->GetModule()); 1635 if (module_sp) 1636 module_sp->ResolveFileAddress(value, addr); 1637 } 1638 else if (addr_type == eAddressTypeLoad) 1639 { 1640 // no need to check the return value on this.. if it can actually do the resolve 1641 // addr will be in the form (section,offset), otherwise it will simply be returned 1642 // as (NULL, value) 1643 addr.SetLoadAddress(value, target_sp.get()); 1644 } 1645 } 1646 } 1647 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1648 if (log) 1649 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")", 1650 static_cast<void*>(value_sp.get()), 1651 (addr.GetSection() 1652 ? addr.GetSection()->GetName().GetCString() 1653 : "NULL"), 1654 addr.GetOffset()); 1655 return SBAddress(new Address(addr)); 1656 } 1657 1658 lldb::SBData 1659 SBValue::GetPointeeData (uint32_t item_idx, 1660 uint32_t item_count) 1661 { 1662 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1663 lldb::SBData sb_data; 1664 ValueLocker locker; 1665 lldb::ValueObjectSP value_sp(GetSP(locker)); 1666 if (value_sp) 1667 { 1668 TargetSP target_sp (value_sp->GetTargetSP()); 1669 if (target_sp) 1670 { 1671 DataExtractorSP data_sp(new DataExtractor()); 1672 value_sp->GetPointeeData(*data_sp, item_idx, item_count); 1673 if (data_sp->GetByteSize() > 0) 1674 *sb_data = data_sp; 1675 } 1676 } 1677 if (log) 1678 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)", 1679 static_cast<void*>(value_sp.get()), item_idx, item_count, 1680 static_cast<void*>(sb_data.get())); 1681 1682 return sb_data; 1683 } 1684 1685 lldb::SBData 1686 SBValue::GetData () 1687 { 1688 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1689 lldb::SBData sb_data; 1690 ValueLocker locker; 1691 lldb::ValueObjectSP value_sp(GetSP(locker)); 1692 if (value_sp) 1693 { 1694 DataExtractorSP data_sp(new DataExtractor()); 1695 Error error; 1696 value_sp->GetData(*data_sp, error); 1697 if (error.Success()) 1698 *sb_data = data_sp; 1699 } 1700 if (log) 1701 log->Printf ("SBValue(%p)::GetData () => SBData(%p)", 1702 static_cast<void*>(value_sp.get()), 1703 static_cast<void*>(sb_data.get())); 1704 1705 return sb_data; 1706 } 1707 1708 bool 1709 SBValue::SetData (lldb::SBData &data, SBError &error) 1710 { 1711 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1712 ValueLocker locker; 1713 lldb::ValueObjectSP value_sp(GetSP(locker)); 1714 bool ret = true; 1715 1716 if (value_sp) 1717 { 1718 DataExtractor *data_extractor = data.get(); 1719 1720 if (!data_extractor) 1721 { 1722 if (log) 1723 log->Printf ("SBValue(%p)::SetData() => error: no data to set", 1724 static_cast<void*>(value_sp.get())); 1725 1726 error.SetErrorString("No data to set"); 1727 ret = false; 1728 } 1729 else 1730 { 1731 Error set_error; 1732 1733 value_sp->SetData(*data_extractor, set_error); 1734 1735 if (!set_error.Success()) 1736 { 1737 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString()); 1738 ret = false; 1739 } 1740 } 1741 } 1742 else 1743 { 1744 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString()); 1745 ret = false; 1746 } 1747 1748 if (log) 1749 log->Printf ("SBValue(%p)::SetData (%p) => %s", 1750 static_cast<void*>(value_sp.get()), 1751 static_cast<void*>(data.get()), ret ? "true" : "false"); 1752 return ret; 1753 } 1754 1755 lldb::SBDeclaration 1756 SBValue::GetDeclaration () 1757 { 1758 ValueLocker locker; 1759 lldb::ValueObjectSP value_sp(GetSP(locker)); 1760 SBDeclaration decl_sb; 1761 if (value_sp) 1762 { 1763 Declaration decl; 1764 if (value_sp->GetDeclaration(decl)) 1765 decl_sb.SetDeclaration(decl); 1766 } 1767 return decl_sb; 1768 } 1769 1770 lldb::SBWatchpoint 1771 SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error) 1772 { 1773 SBWatchpoint sb_watchpoint; 1774 1775 // If the SBValue is not valid, there's no point in even trying to watch it. 1776 ValueLocker locker; 1777 lldb::ValueObjectSP value_sp(GetSP(locker)); 1778 TargetSP target_sp (GetTarget().GetSP()); 1779 if (value_sp && target_sp) 1780 { 1781 // Read and Write cannot both be false. 1782 if (!read && !write) 1783 return sb_watchpoint; 1784 1785 // If the value is not in scope, don't try and watch and invalid value 1786 if (!IsInScope()) 1787 return sb_watchpoint; 1788 1789 addr_t addr = GetLoadAddress(); 1790 if (addr == LLDB_INVALID_ADDRESS) 1791 return sb_watchpoint; 1792 size_t byte_size = GetByteSize(); 1793 if (byte_size == 0) 1794 return sb_watchpoint; 1795 1796 uint32_t watch_type = 0; 1797 if (read) 1798 watch_type |= LLDB_WATCH_TYPE_READ; 1799 if (write) 1800 watch_type |= LLDB_WATCH_TYPE_WRITE; 1801 1802 Error rc; 1803 ClangASTType type (value_sp->GetClangType()); 1804 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc); 1805 error.SetError(rc); 1806 1807 if (watchpoint_sp) 1808 { 1809 sb_watchpoint.SetSP (watchpoint_sp); 1810 Declaration decl; 1811 if (value_sp->GetDeclaration (decl)) 1812 { 1813 if (decl.GetFile()) 1814 { 1815 StreamString ss; 1816 // True to show fullpath for declaration file. 1817 decl.DumpStopContext(&ss, true); 1818 watchpoint_sp->SetDeclInfo(ss.GetString()); 1819 } 1820 } 1821 } 1822 } 1823 else if (target_sp) 1824 { 1825 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1826 if (log) 1827 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s", 1828 static_cast<void*>(value_sp.get()), 1829 locker.GetError().AsCString()); 1830 1831 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString()); 1832 } 1833 else 1834 { 1835 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1836 if (log) 1837 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target", 1838 static_cast<void*>(value_sp.get())); 1839 error.SetErrorString("could not set watchpoint, a target is required"); 1840 } 1841 1842 return sb_watchpoint; 1843 } 1844 1845 // FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed. 1846 // Backward compatibility fix in the interim. 1847 lldb::SBWatchpoint 1848 SBValue::Watch (bool resolve_location, bool read, bool write) 1849 { 1850 SBError error; 1851 return Watch(resolve_location, read, write, error); 1852 } 1853 1854 lldb::SBWatchpoint 1855 SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error) 1856 { 1857 SBWatchpoint sb_watchpoint; 1858 if (IsInScope() && GetType().IsPointerType()) 1859 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error); 1860 return sb_watchpoint; 1861 } 1862 1863 lldb::SBValue 1864 SBValue::Persist () 1865 { 1866 ValueLocker locker; 1867 lldb::ValueObjectSP value_sp(GetSP(locker)); 1868 SBValue persisted_sb; 1869 if (value_sp) 1870 { 1871 persisted_sb.SetSP(value_sp->Persist()); 1872 } 1873 return persisted_sb; 1874 } 1875