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